diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 8947bc9b1..b8f7fd590 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -4,7 +4,7 @@ import { EventsService } from '../services/events.service'; import { Event } from '../models/event.model'; import { ProcessesService } from '../services/processes.service'; import { NotificationsService } from '../services/notifications.service'; -import { ModalController, AlertController, AnimationController } from '@ionic/angular'; +import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular'; //import { AlertController } from 'ionic-angular'; /* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core'; */ import { Router } from '@angular/router'; @@ -61,7 +61,8 @@ export class HomePage implements OnInit { public modalCtrl: AlertController, private fcm: FCM, private animationController: AnimationController, - private notificatinsservice: NotificationsService,) { + private notificatinsservice: NotificationsService, + private platform: Platform) { router.events.subscribe((val) => { document.querySelectorAll('ion-modal').forEach((e) => e.remove()) @@ -105,40 +106,47 @@ export class HomePage implements OnInit { } pushCordova() { - this.fcm.onNotification().subscribe(data => { - this.viewEventDetail(data.IdObject) - if (data.wasTapped) { - console.log("Received in background: ", data); + if(this.platform.is('desktop')) { + console.log('Notifications not supported') + } else { - if (data.Service === "agenda") { - //this.router.navigate(['/home/', service, IdObject, 'home']); - this.viewEventDetail(data.IdObject) - } - else if (data.Service === "gabinete-digital" && data.Object === "expediente") { - console.log('expediante 1') - this.viewExpedientDetail(data.IdObject) - } - else if (data.Service === "gabinete-digital" && data.Object === "event-list") { - // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', IdObject])}) - this.openApproveModal(data.IdObject); - } - else if (data.Service === "accoes" && data.Object === "accao") { - this.viewPublications(data.IdObject) - alert(data.IdObject) - } - else if (data.Service === "accoes" && data.Object === "publicacao") { - this.viewPublicationDetail(data.IdObject) - } + this.fcm.onNotification().subscribe(data => { + this.viewEventDetail(data.IdObject) + if (data.wasTapped === true) { + console.log("Received in background: ", data); + + if (data.Service === "agenda") { + //this.router.navigate(['/home/', service, IdObject, 'home']); + this.viewEventDetail(data.IdObject) + } + else if (data.Service === "gabinete-digital" && data.Object === "expediente") { + console.log('expediante 1') + this.viewExpedientDetail(data.IdObject) + } + else if (data.Service === "gabinete-digital" && data.Object === "event-list") { + // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', IdObject])}) + this.openApproveModal(data.IdObject); + } + else if (data.Service === "accoes" && data.Object === "accao") { + this.viewPublications(data.IdObject) + alert(data.IdObject) + } + else if (data.Service === "accoes" && data.Object === "publicacao") { + this.viewPublicationDetail(data.IdObject) + } + + } else { + console.log("Received in foreground: ", data); + + console.log(data.Service) + console.log(data.Object) + console.log(data.IdObject) + + }; + }); + } - } else { - console.log("Received in foreground: ", data); - - console.log(data.Service) - console.log(data.Object) - console.log(data.IdObject) - - }; - }); + } diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index 6c9b6cdc7..a569b9b56 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -10,7 +10,7 @@ import { ExpedientePage } from '../pages/gabinete-digital/expediente/expediente. import { EventListPage } from '../pages/gabinete-digital/event-list/event-list.page'; import { PublicationsPage } from '../pages/publications/publications.page' import { ViewPublicationsPage } from '../pages/publications/view-publications/view-publications.page' */ -import { ModalController, AlertController, AnimationController } from '@ionic/angular'; +import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular'; import { ViewEventPage } from '../pages/agenda/view-event/view-event.page'; import { ExpedienteDetailPage } from '../pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page'; import { PublicationDetailPage } from '../pages/publications/publication-detail/publication-detail.page'; @@ -26,12 +26,13 @@ export class NotificationsService { folderId: string; constructor( - private http: HttpClient, - private fcm: FCM, + private http: HttpClient, + private fcm: FCM, private storageService: StorageService, - private modalController: ModalController, + private modalController: ModalController, public modalCtrl: AlertController, - private animationController: AnimationController,/* , + private animationController: AnimationController, + private platform: Platform/* , public agenda: AgendaPage, public expediante: ExpedientePage, public eventList: EventListPage, @@ -45,7 +46,11 @@ export class NotificationsService { } getAndpostToken(username) { - const geturl = environment.apiURL + 'notifications/token'; + if(this.platform.is('desktop')) { + console.log('Notifications not supported') + } else { + + const geturl = environment.apiURL + 'notifications/token'; return this.fcm.getToken().then(token => { console.log('token: ', token) @@ -69,10 +74,12 @@ export class NotificationsService { }); }); + } + } - async onReceviNotification(viewEventDetail,viewExpedientDetail,openApproveModal,viewPublications,viewPublicationDetail) { - this.fcm.onNotification().subscribe(data => { + async onReceviNotification(viewEventDetail, viewExpedientDetail, openApproveModal, viewPublications, viewPublicationDetail) { + this.fcm.onNotification().subscribe(data => { if (data.click_action) { console.log("Received in background: ", data); @@ -105,6 +112,13 @@ export class NotificationsService { }); } + platformVerify() { + + if (this.platform.is('cordova')) { + } else { + } + } + async viewEventDetail(eventId: any) { const modal = await this.modalController.create({ @@ -124,17 +138,17 @@ export class NotificationsService { }); } - async openApproveModal(eventSerialNumber){ + async openApproveModal(eventSerialNumber) { let classs; - if( window.innerWidth <= 1024){ + if (window.innerWidth <= 1024) { classs = 'cal-modal modal modal-desktop' - } else { + } else { classs = 'gabinete-digital-mobile-modal-to-Desktop' } const modal = await this.modalController.create({ component: ApproveEventModalPage, - componentProps:{ + componentProps: { serialNumber: eventSerialNumber, }, cssClass: 'event-list', @@ -153,7 +167,7 @@ export class NotificationsService { } else { classs = 'modal modal-desktop showAsideOptions' } - console.log(serialNumber); + console.log(serialNumber); console.log('expediante 2') const modal = await this.modalController.create({ component: ExpedienteDetailPage, @@ -183,7 +197,7 @@ export class NotificationsService { }); await modal.present(); modal.onDidDismiss().then(() => { - + }); } @@ -225,5 +239,5 @@ export class NotificationsService { }); await modal.present(); modal.onDidDismiss(); - } + } }