Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielVictorF committed Nov 18, 2019
1 parent 88d8e42 commit 50497b5
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 125 deletions.
140 changes: 36 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component } from '@angular/core';
import { Platform, LoadingController, AlertController } from 'ionic-angular';

import { TabsPage } from '../pages/tabs/tabs';
import { LoginPage } from '../pages/login/login';

Expand All @@ -16,7 +15,7 @@ export class MyApp {
constructor(platform: Platform, public api: ApiProvider, public functions: FunctionsProvider,
public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
platform.ready().then(() => {
if (localStorage.userToken) {
if (localStorage.getItem('userToken')) {
this.api.validaToken().subscribe(res => {
if (res) {
this.rootPage = TabsPage;
Expand All @@ -43,8 +42,8 @@ export class MyApp {
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.clear();
this.rootPage = LoginPage;
localStorage.removeItem("userToken");
});
}
}]
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ion-menu [content]="menu">
<ion-menu [content]="menu" type="reveal">
<ion-header>
<ion-toolbar>
<ion-title>
Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler, Navbar } from 'ionic-angular';

import { MyApp } from './app.component';
import { HttpClientModule } from '@angular/common/http';

Expand All @@ -22,6 +23,7 @@ import { AlimentosPage } from '../pages/alimentos/alimentos';
import { CadastrarPage } from '../pages/cadastrar/cadastrar';
import { PerfilPage } from '../pages/perfil/perfil';
import { ModalRelatorioPage } from '../pages/relatorio-resultado/modal-relatorio/modal-relatorio';
import { ModalEditarPerfilPage } from '../pages/perfil/modal-editar-perfil/modal-editar-perfil';
import { FeedbackPage } from '../pages/feedback/feedback';
import { HelpPage } from '../pages/help/help';
import { DicasPage } from '../pages/dicas/dicas';
Expand Down Expand Up @@ -83,6 +85,7 @@ export class SentryIonicErrorHandler extends IonicErrorHandler {
CadastrarPage,
PerfilPage,
ModalRelatorioPage,
ModalEditarPerfilPage,
FeedbackPage,
HelpPage,
DicasPage,
Expand Down Expand Up @@ -121,6 +124,7 @@ export class SentryIonicErrorHandler extends IonicErrorHandler {
CadastrarPage,
PerfilPage,
ModalRelatorioPage,
ModalEditarPerfilPage,
FeedbackPage,
HelpPage,
DicasPage
Expand Down
10 changes: 5 additions & 5 deletions src/components/menu/menu.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<button ion-item icon-end (click)="pagePerfil()">
<button ion-item icon-end (click)="pagePerfil()" menuClose>
Meu Perfil
<ion-icon name="contact" ></ion-icon>
</button>
<button ion-item icon-end (click)="feedback()">
<button ion-item icon-end (click)="feedback()" menuClose>
Feedback
<ion-icon name="megaphone" ></ion-icon>
</button>
<button ion-item icon-end (click)="ajuda()">
<button ion-item icon-end (click)="ajuda()" menuClose>
Sobre o app
<ion-icon name="help-circle" ></ion-icon>
</button>
<button ion-item icon-end (click)="dicas()">
<button ion-item icon-end (click)="dicas()" menuClose>
Dicas e dúvidas
<ion-icon name="md-bulb"></ion-icon>
</button>
<button ion-item icon-end (click)="logout()">
<button ion-item icon-end (click)="logout()" menuClose>
Sair
<ion-icon name="exit" ></ion-icon>
</button>
4 changes: 3 additions & 1 deletion src/components/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ logout() {
this.api.logout().subscribe(res => {
load.dismiss();
this.menuCtrl.close();
localStorage.removeItem("userToken");
//console.log("TOKEN ANTES DE LOGAR:" + localStorage.getItem("userToken"));
//localStorage.removeItem("userToken");
localStorage.clear();
this.app.getRootNavs()[0].setRoot(LoginPage); //Erro de tabs solved
},
Error => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/login/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export class LoginPage {
}); load.present();
this.api.login(this.user.email, this.user.password).subscribe(res => {
load.dismiss();
localStorage.setItem("userToken", res["user-token"]); //Token para reqs posteriores
localStorage.setItem("userId", res.objectId); // Id do usuário atual logado
localStorage.setItem('userToken', res["user-token"]); //Token para reqs posteriores
localStorage.setItem('userId', res.objectId); // Id do usuário atual logado
console.log("TOKEN DEPOIS DE LOGAR:" + localStorage.getItem("userToken"));
this.navCtrl.setRoot(TabsPage);
},
Error => { //Login
Expand Down
17 changes: 13 additions & 4 deletions src/pages/medicoes/medicoes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class MedicoesPage {
total: 0,
semana: 0
}
private error = 0;

constructor(public navCtrl: NavController, public navParams: NavParams, private api: ApiProvider,
public functions: FunctionsProvider, public loadingCtrl: LoadingController, public alertCtrl: AlertController) {
Expand Down Expand Up @@ -58,13 +59,21 @@ export class MedicoesPage {
let hoje = this.functions.toEpoch();
let intervalo = this.functions.calculaEssaSemana();
console.log(hoje)
this.api.getQuantidadeObjDia(hoje).subscribe(res => this.qtdObj.hoje = res);
this.api.getQuantidadeObjSemana(intervalo.i1, intervalo.i2).subscribe(res => this.qtdObj.semana = res);
this.api.getQuantidadeObjDia(hoje).subscribe(
res => this.qtdObj.hoje = res,
Error => console.log("ERRRRRRRRRRRRRRO")
);
this.api.getQuantidadeObjSemana(intervalo.i1, intervalo.i2).subscribe(
res => this.qtdObj.semana = res,
Error => this.error++
);
this.api.getQuantidadeObj().subscribe(res => {
this.qtdObj.total = res;
console.log(res);
}, Error => {
this.functions.showAlert("Ops!", this.functions.filtraErro(Error.error.code));
Error => this.error++;
});

if (this.error > 0)
this.functions.showAlert("Ops", "foram encontrados erro ao exibir esta página");
}
}
31 changes: 31 additions & 0 deletions src/pages/perfil/modal-editar-perfil/modal-editar-perfil.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<ion-header>
<ion-navbar color="navBarColor">
<ion-buttons right>
<button ion-button (click)="dismiss()">
<span ion-text color="primary" showWhen="ios">Cancel</span>
<ion-icon name="md-close" showWhen="android, windows"></ion-icon>
</button>
</ion-buttons>
<ion-title text-center><span class="titulo">Alterar Perfil</span></ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-item>
<ion-label stacked>
<ion-icon name="body" item-start></ion-icon><b>Nome</b>
</ion-label>
<ion-input type="text" name="" placeholder="Insira seu nome..." [(ngModel)]="user.name"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>
<ion-icon name="calendar" item-start></ion-icon> <b>Data de nascimento</b>
</ion-label>
<ion-datetime displayFormat="DD-MM-YYYY" pickerFormat="DD MMMM YYYY" [(ngModel)]="user.nascimento"
monthNames="{{functions.monthNames}}" cancelText="Cancelar" doneText="Feito"
placeholder="Digite sua data de nascimento">
</ion-datetime>
</ion-item>
<ion-item>
<button ion-button full color="primary" (click)="cadastrar()">Cadastrar</button>
</ion-item>
</ion-content>
26 changes: 26 additions & 0 deletions src/pages/perfil/modal-editar-perfil/modal-editar-perfil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Component } from '@angular/core';
import { NavParams, ViewController } from 'ionic-angular';

import { FunctionsProvider } from '../../../providers/functions/functions';
import { ApiProvider } from '../../../providers/api/api';

@Component({
selector: 'modal-editar-perfil',
templateUrl: 'modal-editar-perfil.html',
})

export class ModalEditarPerfilPage {
public user = this.navParams.get('data');
private password = {
password: '',
password2: ''
};

constructor(public navParams: NavParams, public viewCtrl: ViewController,
public functions: FunctionsProvider, public api: ApiProvider) {
}

public dismiss() {
this.viewCtrl.dismiss();
}
}
15 changes: 13 additions & 2 deletions src/pages/perfil/perfil.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<input type="file" ion-input>
</ion-item> -->
<ion-item>
<strong>Ùltimo login: </strong>{{ dadosUser?.lastLogin | data}}
<strong>Último login: </strong>{{ dadosUser?.lastLogin | data}}
</ion-item>
<ion-item>
<strong>Status da conta: </strong>{{ dadosUser?.userStatus }}
Expand All @@ -33,6 +33,17 @@
<strong>Nome do usuário: </strong>{{ dadosUser?.name }}
</ion-item>
<ion-item>
<strong>Ùltima modificação: </strong>{{ dadosUser?.updated | data}}
<strong>Última modificação: </strong>{{ dadosUser?.updated | data}}
</ion-item>
<ion-item>
<button ion-button full rounded (click)="alterarSenha()">
Quero alterar minha senha
</button>
</ion-item>
<ion-item>
<button ion-button full rounded (click)="alterarPerfil()" icon-end>
Quero alterar meu perfil
<ion-icon name="send"></ion-icon>
</button>
</ion-item>
</ion-content>
19 changes: 17 additions & 2 deletions src/pages/perfil/perfil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { IonicPage, NavController, NavParams, ModalController } from 'ionic-angular';

import { ApiProvider } from '../../providers/api/api';
import { FunctionsProvider } from '../../providers/functions/functions';

import { ModalEditarPerfilPage } from './modal-editar-perfil/modal-editar-perfil';

/**
* Generated class for the PerfilPage page.
Expand All @@ -19,7 +22,7 @@ export class PerfilPage {
private dadosUser;

constructor(public navCtrl: NavController, public navParams: NavParams,
public api: ApiProvider) {
public api: ApiProvider, public modalCtrl: ModalController, public functions: FunctionsProvider) {
this.getInfoUserLogado()
}

Expand All @@ -32,4 +35,16 @@ export class PerfilPage {
this.dadosUser = res;
});
}

public alterarPerfil() {
let modal = this.modalCtrl.create(ModalEditarPerfilPage, { "data": this.dadosUser });
modal.present();
}

public alterarSenha() {
console.log("Ok")
this.api.getAlterPassword().subscribe(() =>
this.functions.showAlert("Sucesso", "Um link de alteração da sua senha foi enviado ao seu e-mail!")
);
}
}
7 changes: 6 additions & 1 deletion src/providers/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ApiProvider {

public logout() {
const url = `${this.REST_API}/users/logout`;
return this.http.get(url, this.httpOptionsNoToken);
return this.http.get(url, this.httpOptions);
}

public getQuantidadeObj() { //Retorna a quantidade de objetos na tabela medicoes
Expand Down Expand Up @@ -190,4 +190,9 @@ export class ApiProvider {
};
return this.http.post(url, body, this.httpOptions);
}

public getAlterPassword() {
const url = `${this.REST_API}/users/restorepassword/${localStorage.getItem("userId")}`;
return this.http.get(url, this.httpOptionsNoToken);
}
}

0 comments on commit 50497b5

Please sign in to comment.