From 81b374f8f684da19a38470003d600c4ed287f5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 26 Jan 2021 17:00:41 +0100 Subject: [PATCH] Especific route for notifications on click --- src/app/home/home.page.ts | 154 +++++++++++++++++++++++++++++++------- 1 file changed, 128 insertions(+), 26 deletions(-) diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 1b21e96f5..256b3a4b2 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -3,8 +3,14 @@ import { EventsService } from '../services/events.service'; import { formatDate } from '@angular/common'; import { Event } from '../models/event.model'; import { ProcessesService } from '../services/processes.service'; +import { StorageService } from 'src/app/services/storage.service'; +import { ModalController } from '@ionic/angular'; +import { PublicationDetailPage } from '../../app/pages/publications/view-publications/publication-detail/publication-detail.page'; +import { ViewPublicationsPage } from '../../app/pages/publications/view-publications/view-publications.page'; -import { Plugins, PushNotification,PushNotificationToken,PushNotificationActionPerformed} from '@capacitor/core'; +import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core'; +import { Router } from '@angular/router'; +import { MethodCall } from '@angular/compiler'; const { PushNotifications } = Plugins; @@ -18,61 +24,157 @@ export class HomePage implements OnInit { prEventList: Event[]; mdEventList: Event[]; - totalEvent=0; - totalExpediente=0; - profile:string; + totalEvent = 0; + totalExpediente = 0; + profile: string; - constructor(private eventService: EventsService, private processesbackend:ProcessesService) { } + constructor(private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController,) { } ngOnInit() { //Initialize profile as mdgpr this.profile = "mdgpr"; - if(this.profile == "mdgpr"){ + if (this.profile == "mdgpr") { this.eventService.getAllMdEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => { this.eventsList = res; this.totalEvent = this.eventsList.length; - }); + }); } - else{ + else { this.eventService.getAllPrEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => { this.eventsList = res; this.totalEvent = this.eventsList.length; - }); + }); } - this.processesbackend.GetTasksList("Expediente", true).subscribe(result =>{ + this.processesbackend.GetTasksList("Expediente", true).subscribe(result => { this.totalExpediente = result; }); + /* + (PushNotifications as any).requestPermission().then(result => { + PushNotifications.register(); + }); + + PushNotifications.addListener( + 'registration', + (token: PushNotificationToken) => { + alert('Push registration success, token: ' + token.value); + console.log('FIREBASE: ', token.value) + this.storageService.store(this.username,token.value); + }, + ); + + console.log(this.storageService.get(this.username)) */ - (PushNotifications as any).requestPermission().then(result => { - PushNotifications.register(); - }); - - PushNotifications.addListener( - 'registration', - (token: PushNotificationToken) => { - alert('Push registration success, token: ' + token.value); - console.log('FIREBASE: ', token.value) - }, - ); - PushNotifications.addListener('registrationError', (error: any) => { alert('Error on registration: ' + JSON.stringify(error)); }); - + PushNotifications.addListener( 'pushNotificationReceived', (notification: PushNotification) => { alert('Push received: ' + JSON.stringify(notification)); }, ); - + PushNotifications.addListener( 'pushNotificationActionPerformed', (notification: PushNotificationActionPerformed) => { - alert('Push action performed: ' + JSON.stringify(notification)); + let service = notification.notification.data.service; + + let object = notification.notification.data.object; + let idObject = notification.notification.data.idObject; + let folder = notification.notification.data.folder; + let publicationId = notification.notification.data.publicationId; + let processId = notification.notification.data.processId; + + console.log('FOLDER PROCESS',folder.ProcessId) + + if (service != null) { + + if (service === "events") { + this.router.navigate(['/home/', service, idObject, 'home']); + } else if (service === "agenda") { + this.router.navigate(['/home/', service, idObject, 'home']); + } else if (service === "gabinete-digital") { + this.router.navigate(['/home/', service]); + } else if (service === "gabinete-digital-expediente") { + this.router.navigate(['/home/gabinete-digital/', object,idObject]); + } + } else { + + if ( processId || publicationId != null) { + this.viewPublicationDetail(processId,publicationId) + } + + if (notification.notification.data.folder.ProcessId != null) { + this.viewPublications(folder) + } + + } + + + + /*switch (service) { + case "events": + this.router.navigate(['/home/', service, idObject, 'home']); + break; + case "agenda": + this.router.navigate(['/home/', service, idObject, 'home']); + break; + case "gabinete-digital": + this.router.navigate(['/home/', service]); + break; + case "gabinete-digital-expediente": + this.router.navigate(['/home/gabinete-digital/', object, idObject, 'home']); + break; + case "": { + + if(publicationId && processId != null) { + this.viewPublicationDetail(publicationId,processId) + } + if (folder.ProcessId != null) { + this.viewPublications(folder) + } + } + + default: + this.router.navigate(['/home/']); + }*/ + + + }, ); - } + } + + async viewPublicationDetail(processId: string, publicationId: string) { + const modal = await this.modalController.create({ + component: PublicationDetailPage, + componentProps: { + publicationId: publicationId, + folderId: processId, + }, + cssClass: 'publication-detail', + backdropDismiss: false + }); + await modal.present(); + modal.onDidDismiss(); + } + + async viewPublications(folder) { + + const modal = await this.modalController.create({ + component: ViewPublicationsPage, + /* enterAnimation, + leaveAnimation, */ + componentProps: { + item: folder, + }, + cssClass: 'new-action', + backdropDismiss: false + }); + await modal.present(); + modal.onDidDismiss(); + } }