Skip to content

Commit

Permalink
Component de menu para logout e perfil add
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielVictorF committed Apr 21, 2019
1 parent 6d8dda2 commit c208bbf
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 204 deletions.
3 changes: 1 addition & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ export class MyApp {
public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
platform.ready().then(() => {
if (localStorage.userToken) {
console.log("Tem token!");
this.api.validaToken().subscribe(res => {
if (res) {
this.rootPage = TabsPage;
} else {
this.logout();
}
});
}, Error => this.rootPage = LoginPage);
} else {
this.rootPage = LoginPage;
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/menu/menu.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<ion-item>Meu Perfil</ion-item>
<ion-item (click)="logout()">Sair</ion-item>
<button ion-item icon-end>
Meu Perfil
<ion-icon name="contact"></ion-icon>
</button>
<button ion-item icon-end (click)="logout()">
Sair
<ion-icon name="exit"></ion-icon>
</button>
9 changes: 6 additions & 3 deletions src/pages/alimentos/alimentos.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
Ionic pages and navigation.
-->
<ion-header>

<ion-navbar>
<ion-title>alimentos</ion-title>
<ion-title>Alimentos</ion-title>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
</ion-navbar>

</ion-header>


Expand Down
5 changes: 5 additions & 0 deletions src/pages/cadastrar/cadastrar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<ion-title>
Cadastro de usuário
</ion-title>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
</ion-navbar>
</ion-header>

Expand Down
6 changes: 3 additions & 3 deletions src/pages/detalhe/detalhe.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-header>
<ion-navbar>
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title>Detalhe do item</ion-title>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/detalhe/detalhe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,6 @@ export class DetalhePage {
this.state[1] = "arrow-round-up";
}

logout() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}

actionSheet() {
const action = this.actionSheetCtrl.create({
title: "Selecione a operação",
Expand Down
6 changes: 3 additions & 3 deletions src/pages/edita/edita.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-header>
<ion-navbar>
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/edita/edita.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,4 @@ export class EditaPage {
console.log(Error);
});
}

logout() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}
}
5 changes: 1 addition & 4 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component } from '@angular/core';
import { NavController, LoadingController, AlertController } from 'ionic-angular';
import { App } from 'ionic-angular';

import { MedicoesPage } from '../medicoes/medicoes';
import { LoginPage } from '../login/login';
Expand All @@ -18,7 +17,7 @@ export class HomePage {
protected turno: string;
constructor(public navCtrl: NavController, public api: ApiProvider,
public functions: FunctionsProvider, public loadingCtrl: LoadingController,
public alertCtrl: AlertController, public app: App) {
public alertCtrl: AlertController) {
var turnoAgora = new Date().getHours();
if (turnoAgora <= 5)
this.turno = "Boa madrugada";
Expand All @@ -32,8 +31,6 @@ export class HomePage {
this.navCtrl.push(MedicoesPage);
}



relatorios() {
this.navCtrl.push(RelatoriosPage);
}
Expand Down
12 changes: 3 additions & 9 deletions src/pages/medicoes/medicoes.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
<!--
Generated template for the MedicoesPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar color="light">
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title><span class="titulo">Medições</span></ion-title>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/medicoes/medicoes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,4 @@ export class MedicoesPage {
console.log(res);
});
}

logout() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}
}
6 changes: 3 additions & 3 deletions src/pages/relatorio-resultado/relatorio-resultado.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-header>
<ion-navbar color="light">
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title text-center><span class="titulo">Relatórios</span></ion-title>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/relatorio-resultado/relatorio-resultado.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,6 @@ export class RelatorioResultadoPage {
});
}

logout() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}

filtraFuncao() {
switch(this.funcao) {
case 1: //Relatorio do mes
Expand Down
6 changes: 3 additions & 3 deletions src/pages/relatorios/relatorios.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-header>
<ion-navbar color="light">
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title text-center><span class="titulo">Relatórios</span></ion-title>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/relatorios/relatorios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,4 @@ export class RelatoriosPage {
relatorioSemana() {
this.navCtrl.push(RelatorioResultadoPage, {"funcao": 3});
}

logout() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}
}
6 changes: 3 additions & 3 deletions src/pages/resultado/resultado.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<ion-header>
<ion-navbar color="light">
<ion-buttons start>
<button ion-button icon-only (click)="logout()">
<ion-icon name="exit"></ion-icon>
<ion-buttons right>
<button ion-button icon-only menuToggle>
<ion-icon name='menu'></ion-icon>
</button>
</ion-buttons>
<ion-title text-center><span class="titulo">Resultado</span></ion-title>
Expand Down
30 changes: 1 addition & 29 deletions src/pages/resultado/resultado.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ResultadoPage {
}, Error => {
let erro = this.functions.filtraErro(Error.error.code);
this.functions.showAlert("Ops!", erro);
this.loading.dismiss().then(this.logout());
this.loading.dismiss();
});
break;
case 2: //Desativado
Expand Down Expand Up @@ -230,32 +230,4 @@ export class ResultadoPage {
this.medias.pos = soma.pos / length;
this.medias.injetado = soma.injetado / length;
}

logoutInterface() {
const confirm = this.alertCtrl.create({
title: 'Um momento',
message: 'Tem certeza que deseja sair?',
buttons: [{
text: 'Sim',
handler: () => {
const load = this.loadingCtrl.create({
content: 'Saindo...'
});
load.present();
this.api.logout().subscribe(res => {
load.dismiss();
localStorage.removeItem("userToken");
this.navCtrl.setRoot(LoginPage);
},
Error => {
console.log(Error);
});
}
},
{
text: 'Não'
}]
});
confirm.present();
}
}

0 comments on commit c208bbf

Please sign in to comment.