Instantly share code, notes, and snippets.
Last active
March 21, 2018 17:14
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save btinelli/1f13dd4870bbcca62ad6d7d17c9fc7ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StorageServiceProvider } from './../../providers/storage/storage-service'; | |
import { NotificacoesServiceProvider } from './../../providers/notificacoes/notificacoes-service'; | |
import { Component } from '@angular/core'; | |
import { App, Platform, IonicPage, NavController, NavParams, AlertController, LoadingController, ModalController, Events } from 'ionic-angular'; | |
import { LoginServiceProvider } from "../../providers/login/login-service"; | |
import { MenuServiceProvider } from "../../providers/menu/menu-service"; | |
import { LogAcessoServiceProvider } from '../../providers/log-acesso/log-acesso-service'; | |
import { ScreenOrientation } from '@ionic-native/screen-orientation'; | |
import { Push, PushObject, PushOptions } from '@ionic-native/push'; | |
import { ModalPage } from '../modal/modal'; | |
import { ConfigCliente } from '../../conf/config-cliente'; | |
import { Util } from '../../helpers/util'; | |
import { BasePage } from '../base-page/base-page'; | |
import { ToastProvider } from '../../providers/toast/toast'; | |
import { AuthServiceProvider } from '../../providers/auth/auth-service'; | |
declare var PushNotification; | |
declare var WindowsAzure: any; | |
@IonicPage() | |
@Component({ | |
selector: 'page-menu-principal', | |
templateUrl: 'menu-principal.html', | |
}) | |
export class MenuPrincipalPage extends BasePage { | |
n:number = 0; | |
userInitials: string; | |
userName: string; | |
firstAndLastUserName: string; | |
listaItemMenuPrincipal: object[]; | |
cardPrincipalClass: string = "padd-overflow"; | |
notificationHubPath: string = ConfigCliente.notificationHubPathDev; | |
connectionString: string = ConfigCliente.connectionStringDev; | |
tags:any; | |
push; // = PushNotification; | |
constructor(protected navCtrl: NavController, | |
protected navParams: NavParams, | |
protected platform: Platform, | |
protected appCtrl: App, | |
protected loginService: LoginServiceProvider, | |
protected logAcessoService: LogAcessoServiceProvider, | |
private screenOrientation: ScreenOrientation, | |
protected notificacaoService: NotificacoesServiceProvider, | |
protected loadingCtrl: LoadingController, | |
protected toastCtrl: ToastProvider, | |
protected modalCtrl: ModalController, | |
protected authService: AuthServiceProvider, | |
protected menuService: MenuServiceProvider, | |
public events: Events, | |
public alertCtrl: AlertController) { | |
super(navCtrl, navParams, loadingCtrl, toastCtrl, modalCtrl, authService, menuService, platform, appCtrl); | |
console.log("Menu Principal"); | |
this.notificacaoService.salvaNotificacaoCliente(Util.getCarteiraByCpf(this.usuario.nr_cpf),this.usuario.nr_cpf); | |
this.events.subscribe('cart:updated', (count) => { | |
this.n = this.notificacaoService.getQtdNotificacaoes(); | |
}); | |
this.userInitials = this.loginService.getUserInitials(); | |
this.firstAndLastUserName = this.loginService.getFirstAndLastUserName(); | |
this.userName = this.loginService.getUserName(); | |
this.listaItemMenuPrincipal = this.menuService.getMenuPrincipalData(); | |
this.tags = NotificacoesServiceProvider.getTagsPushNotification(); | |
this.screenOrientation.onChange().subscribe( | |
() => { | |
if(new String(this.screenOrientation.type).startsWith('portrait')) { | |
this.cardPrincipalClass = "padd-overflow"; | |
} else { | |
this.cardPrincipalClass = "padd"; | |
} | |
console.log("Orientation Changed"); | |
} | |
); | |
this.platform.ready().then((readySource) => { | |
if(this.platform.is('android') || this.platform.is('ios') ) | |
{ | |
this.push = PushNotification; | |
this.pushNotifications(); | |
} | |
}); | |
} | |
tratarBackButton() | |
{ | |
if(this.navCtrl.canGoBack()) | |
{ | |
this.navCtrl.pop(); | |
} | |
} | |
ionViewDidLoad() | |
{ | |
this.loginService.login(); | |
this.hideCustomOverlay(); | |
/* | |
this.platform.registerBackButtonAction(() => | |
{ | |
this.tratarBackButton(); | |
}); | |
*/ | |
} | |
/* | |
ionViewCanLeave(): boolean | |
{ | |
this.platform.registerBackButtonAction(() => | |
{ | |
this.tratarBackButton(); | |
}, 1000); | |
return true; | |
} | |
*/ | |
ionViewWillEnter(){ | |
this.n = this.notificacaoService.getQtdNotificacaoes(); | |
} | |
actionClick(pActionCode, descricaoMenu) | |
{ | |
this.logAcessoService.inserirLogAcesso(pActionCode, this.loginService.getUserLogin(), this.loginService.getNumCarteiraPrincipal(), this.loginService.getUserName()); | |
StorageServiceProvider.setModuloSelecionado(descricaoMenu); | |
this.navCtrl.push(pActionCode); | |
} | |
notificacoes(){ | |
this.navCtrl.push('NotificacoesPage'); | |
} | |
logout() { | |
if(this.platform.is('android') || this.platform.is('ios')) { | |
this.push.unregister(() => { | |
console.log('success'); | |
}, () => { | |
console.log('error'); | |
}); | |
} | |
this.loginService.logout(); | |
setTimeout(()=> this.navCtrl.setRoot('HomePage'), 500); | |
} | |
pushNotifications() { | |
PushNotification.hasPermission((data) => { | |
if (data.isEnabled) { | |
this.push = PushNotification.init({ | |
notificationHubPath:this.notificationHubPath, | |
connectionString:this.connectionString, | |
android: { | |
senderID: '', | |
alert: true, | |
sound: true, | |
icon: 'icon', | |
topics: [this.tags], | |
vibrate: true, | |
forceShow:true, | |
}, | |
ios: { | |
alert: "true", | |
badge: true, | |
sound: 'false' | |
} | |
}); | |
this.push.on('registration', (data) => { | |
let client = new WindowsAzure.MobileServiceClient('https://.azurewebsites.net'); | |
let handle = data.registrationId; | |
// alert("Tags:" + this.tags.toString()); | |
//alert("ID:" + handle); | |
if (this.platform.is('android')) { | |
this.notificacaoService.registrarTags(handle,this.tags,4) | |
.subscribe( | |
data => { | |
console.log(JSON.stringify(data)); | |
}, | |
err => { | |
console.log(JSON.stringify(err)); | |
} | |
); | |
client.push.register('gcm', handle, { | |
}).then(function(data){ | |
},function(error){ | |
console.log(error); | |
}); | |
} else if (this.platform.is('ios')) { | |
this.notificacaoService.registrarTags(handle,this.tags,2) | |
.subscribe( | |
data => { | |
console.log(JSON.stringify(data)); | |
}, | |
err => { | |
console.log(JSON.stringify(err)); | |
} | |
); | |
client.push.register('apns', handle, { | |
}).then(function(data){ | |
console.log("success"); | |
},function(error){ | |
console.log(error); | |
}); | |
} | |
}); | |
this.push.on('error', (e) => { | |
console.log("error: "+e); | |
}); | |
this.push.on('notification', (data) => { | |
this.notificacaoService.insereConfirmacaoNotificacaoCliente(data.additionalData.cd_notificacao_mensagem, Util.getCarteiraByCpf(this.usuario.nr_cpf)); | |
console.log(data); | |
let route = data.additionalData.rota; | |
if (route) { | |
switch(route){ | |
case 'InfoPrestador': | |
this.navCtrl.push('ListaPrestadoresPage', { | |
prestador: data.additionalData.prestador, | |
isPush:true | |
}); | |
break; | |
case 'Notificacoes': | |
this.navCtrl.push('NotificacoesPage'); | |
break; | |
case 'ResultadoDeExames': | |
this.navCtrl.push('ResultadoDeExamesPage',{ | |
exame: data.additionalData.exame, | |
carteiraSelecionada:data.additionalData.carteira, | |
isPush:true | |
}); | |
break; | |
case 'BoletosPage': | |
this.navCtrl.push("BoletosPage",{ | |
carteiraSelecionada:data.additionalData.carteira, | |
tipoBoleto: data.additionalData.tipoBoleto, | |
isPush:true | |
}); | |
break; | |
case 'UtilizacaoDeServicos': | |
this.navCtrl.push('UtilizacaoDeServicosPage',{ | |
carteiraSelecionada:data.additionalData.carteira, | |
tipServico: data.additionalData.tipServico, | |
anoGuia: data.additionalData.anoGuia, | |
numGuia:data.additionalData.numGuia, | |
isPush:true | |
}); | |
break; | |
case 'AgendamentoDeExames': | |
this.navCtrl.push('AgendamentoDeExamesPage',{ | |
carteiraSelecionada:data.additionalData.carteira, | |
tipServico: data.additionalData.tipServico, | |
isPush:true | |
}); | |
break; | |
} | |
} | |
}); | |
} | |
}); | |
} | |
carregaNotificacaoCliente() { | |
this.loading = this.getLoading(); | |
this.loading.present().then(() => | |
{ | |
this.notificacaoService.carregaNotificacaoCliente(Util.getCarteiraByCpf(this.usuario.nr_cpf),this.usuario.nr_cpf) | |
.subscribe( | |
(responseData) => | |
{ | |
NotificacoesServiceProvider.setNotifications(responseData); | |
this.loading.dismiss(); | |
}, | |
err => | |
{ | |
console.log(err); | |
this.loading.dismiss(); | |
this.showToastError(err); | |
} | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment