diff --git a/package.json b/package.json index cbe0e9b78..e58adc7f1 100644 --- a/package.json +++ b/package.json @@ -120,14 +120,7 @@ "cordova-plugin-mfp": {}, "cordova-plugin-androidx": {}, "cordova-plugin-androidx-adapter": {}, - "cordova-plugin-fcm-with-dependecy-updated": { - "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher", - "ANDROID_FCM_VERSION": "21.0.0", - "ANDROID_FIREBASE_BOM_VERSION": "26.0.0", - "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4", - "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0", - "IOS_FIREBASE_MESSAGING_VERSION": "~> 7.4.0" - } + "cordova-plugin-fcm-with-dependecy-updated": {} }, "platforms": [ "browser", diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 67e5fd7ab..0b71daa26 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -3,17 +3,18 @@ import { Component, OnInit, NgZone } from '@angular/core'; import { EventsService } from '../services/events.service'; import { Event } from '../models/event.model'; import { ProcessesService } from '../services/processes.service'; -import { ModalController, AlertController, AnimationController } from '@ionic/angular'; +import { NotificationsService } from '../services/notifications.service'; +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'; -//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; +import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; import { ViewEventPage } from '../pages/agenda/view-event/view-event.page'; -import { ApproveEventModalPage } from '../pages/agenda/approve-event-modal/approve-event-modal.page'; import { ExpedienteDetailPage } from '../pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page'; import { PublicationDetailPage } from '../pages/publications/publication-detail/publication-detail.page'; import { ViewPublicationsPage } from '../pages/publications/view-publications/view-publications.page'; +import { ApproveEventModalPage } from '../pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page'; /* const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins; */ @@ -58,8 +59,10 @@ export class HomePage implements OnInit { private router: Router, private modalController: ModalController, public modalCtrl: AlertController, - //private fcm: FCM, - private animationController: AnimationController,) { + private fcm: FCM, + private animationController: AnimationController, + private notificatinsservice: NotificationsService, + private platform: Platform) { router.events.subscribe((val) => { document.querySelectorAll('ion-modal').forEach((e) => e.remove()) @@ -73,11 +76,10 @@ export class HomePage implements OnInit { ngOnInit() { - //Add a test - //this.pushCordova(); - //Initialize profile as mdgpr + this.pushCordova(); + //Initialize profile as mdgpr - let date = new Date(); + /* let date = new Date(); date.setMonth(date.getMonth() + 1); let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds(); let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59"; @@ -97,81 +99,56 @@ export class HomePage implements OnInit { } this.processesbackend.GetTasksList("Expediente", true).subscribe(result => { - this.totalExpediente = result; - }); + this.totalExpediente = result; + });*/ - } - pushCordova() { -/* - this.fcm.onNotification().subscribe(data => { - this.viewEventDetail(data.idObject) - if (data.click_action) { - 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") { - 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) - } + if(this.platform.is('desktop')) { + console.log('Notifications not supported') + } else { - } else { - console.log("Received in foreground: ", 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") { - 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) - } - 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) + + }; + }); + } - this.fcm.onTokenRefresh().subscribe(token => { - // Register your new token in your back-end if you want - // backend.registerToken(token); - }); - - this.ubscribeToTopic() - this.getToken() */ + } - /* ubscribeToTopic() { - this.fcm.subscribeToTopic('enappd'); - } - getToken() { - this.fcm.getToken().then(token => { - console.log('token: ', token) - // Register your new token in your back-end if you want - // backend.registerToken(token); - }); - } */ - async viewEventDetail(eventId: any) { console.log(this.profile); @@ -192,17 +169,25 @@ export class HomePage implements OnInit { }); } - async openApproveModal(eventSerialNumber) { + async openApproveModal(eventSerialNumber){ + let classs; + if( window.innerWidth <= 1024){ + classs = 'cal-modal modal modal-desktop' + } else { + classs = 'gabinete-digital-mobile-modal-to-Desktop' + } + const modal = await this.modalController.create({ component: ApproveEventModalPage, - componentProps: { + componentProps:{ serialNumber: eventSerialNumber, }, - cssClass: 'cal-modal', + cssClass: 'event-list', backdropDismiss: false }); await modal.present(); + modal.onDidDismiss(); } @@ -213,14 +198,14 @@ export class HomePage implements OnInit { } else { classs = 'modal modal-desktop showAsideOptions' } - /* console.log(this.profile); - console.log(serialNumber); */ - + console.log(this.profile); + console.log(serialNumber); + console.log('expediante 2') const modal = await this.modalController.create({ component: ExpedienteDetailPage, componentProps: { serialNumber: serialNumber, - profile: this.profile, + profile: "MDGPR", }, cssClass: classs, }); @@ -244,7 +229,7 @@ export class HomePage implements OnInit { }); await modal.present(); modal.onDidDismiss().then(() => { - //this.getPublications(); + }); } diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 697c9f9e7..3e288ecf2 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -11,6 +11,7 @@ import { PhotoService } from 'src/app/services/photo.service'; import { NotificationsService } from 'src/app/services/notifications.service'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Token } from '../../models/token.model'; +import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; /* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core'; @@ -38,7 +39,8 @@ export class LoginPage implements OnInit { private storageService: StorageService, private toastService: ToastService, private photoService: PhotoService, - public alertController: AlertController) { } + public alertController: AlertController, + private fcm: FCM) { } ngOnInit() { @@ -78,40 +80,9 @@ export class LoginPage implements OnInit { }); } - /* storeUserIdANdToken() { - - (PushNotifications as any).requestPermission().then(result => { - PushNotifications.register(); - }); - - PushNotifications.addListener( - 'registration', - (token: PushNotificationToken) => { - console.log('FIREBASE TOKEN', token.value) - this.storageService.store(this.username, token.value); - this.storageService.get(this.username).then(value => { - console.log('STORAGE TOKEN', value) - this.storageService.get(AuthConnstants.USER).then(res => { - console.log('USERID', res); - const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; - const body = { - UserId: res, - TokenId: token.value, - Status: 1, - Service: 1 - }; - - this.http.post('https://equilibrium.dyndns.info/GabineteDigital.Services/V4/api/notifications/token', body, { headers }).subscribe(data => { - console.log('TOKEN USER MIDLE', data); - }) - }); - - }); - - }, - ); - - }; */ + getToken() { + this.notificatinsservice.getAndpostToken(this.username); + } async Login() { @@ -127,7 +98,7 @@ export class LoginPage implements OnInit { } if (await this.authService.login(this.userattempt)) { this.loginRocketChat(); - //this.storeUserIdANdToken(); + this.getToken(); this.router.navigate(['/home/events']); } diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts index c4374bea8..a569b9b56 100644 --- a/src/app/services/notifications.service.ts +++ b/src/app/services/notifications.service.ts @@ -1,14 +1,43 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { environment } from 'src/environments/environment'; +import { StorageService } from 'src/app/services/storage.service'; +import { AuthConnstants } from 'src/app/config/auth-constants'; import { Token } from '../models/token.model'; +import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx'; +/* import { AgendaPage } from '../pages/agenda/agenda.page' +import { ExpedientePage } from '../pages/gabinete-digital/expediente/expediente.page' +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, 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'; +import { ViewPublicationsPage } from '../pages/publications/view-publications/view-publications.page'; +import { ApproveEventModalPage } from '../pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page'; @Injectable({ providedIn: 'root' }) export class NotificationsService { - constructor(private http: HttpClient,) { } + adding: "intervenient" | "CC" = "intervenient"; + folderId: string; + + constructor( + private http: HttpClient, + private fcm: FCM, + private storageService: StorageService, + private modalController: ModalController, + public modalCtrl: AlertController, + private animationController: AnimationController, + private platform: Platform/* , + public agenda: AgendaPage, + public expediante: ExpedientePage, + public eventList: EventListPage, + public publication: PublicationsPage, + public viewPublication: ViewPublicationsPage */) { } getTokenByUserIdAndId(user, userID) { const geturl = environment.apiURL + 'notifications/user/' + userID; @@ -16,15 +45,199 @@ export class NotificationsService { return this.http.get(`${geturl}`); } - postToken(userId, token) { - const geturl = environment.apiURL + 'notifications/token'; + getAndpostToken(username) { + if(this.platform.is('desktop')) { + console.log('Notifications not supported') + } else { + + const geturl = environment.apiURL + 'notifications/token'; - let data = { - UserId: userId, - TokenId: token, - Status: 1, - Service: 2 + return this.fcm.getToken().then(token => { + console.log('token: ', token) + this.storageService.store(username, token); + this.storageService.get(username).then(value => { + console.log('STORAGE TOKEN', value) + this.storageService.get(AuthConnstants.USER).then(res => { + console.log('USERID', res); + const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' }; + const body = { + UserId: res.UserId, + TokenId: token, + Status: 1, + Service: 1 + }; + + this.http.post(`${geturl}`, body, { headers }).subscribe(data => { + console.log('TOKEN USER MIDLE', data); + }) + }); + + }); + }); } - return this.http.post(`${geturl}`,data); + + } + + async onReceviNotification(viewEventDetail, viewExpedientDetail, openApproveModal, viewPublications, viewPublicationDetail) { + this.fcm.onNotification().subscribe(data => { + if (data.click_action) { + console.log("Received in background: ", data); + + if (data.Service === "agenda") { + viewEventDetail(data.IdObject) + } + else if (data.Service === "gabinete-digital" && data.Object === "expediente") { + console.log('expediante 1') + viewExpedientDetail(data.IdObject) + } + else if (data.Service === "gabinete-digital" && data.Object === "event-list") { + openApproveModal(data.IdObject); + } + else if (data.Service === "accoes" && data.Object === "accao") { + viewPublications(data.IdObject) + } + else if (data.Service === "accoes" && data.Object === "publicacao") { + viewPublicationDetail(data.IdObject) + } + + } /* else { + console.log("Received in foreground: ", data); + + console.log(data.Service) + console.log(data.Object) + console.log(data.IdObject) + this.openApproveModal(data.IdObject); + + }; */ + }); + } + + platformVerify() { + + if (this.platform.is('cordova')) { + } else { + } + } + + async viewEventDetail(eventId: any) { + + const modal = await this.modalController.create({ + component: ViewEventPage, + componentProps: { + eventId: eventId, + adding: this.adding + }, + cssClass: 'modal modal-desktop', + backdropDismiss: false + }); + await modal.present(); + modal.onDidDismiss().then((res) => { + if (res) { + //this.viewEventDetailDismiss(res); + } + }); + } + + async openApproveModal(eventSerialNumber) { + let classs; + if (window.innerWidth <= 1024) { + classs = 'cal-modal modal modal-desktop' + } else { + classs = 'gabinete-digital-mobile-modal-to-Desktop' + } + + const modal = await this.modalController.create({ + component: ApproveEventModalPage, + componentProps: { + serialNumber: eventSerialNumber, + }, + cssClass: 'event-list', + backdropDismiss: false + }); + + await modal.present(); + + modal.onDidDismiss(); + } + + async viewExpedientDetail(serialNumber: any) { + let classs; + if (window.innerWidth <= 800) { + classs = 'modal' + } else { + classs = 'modal modal-desktop showAsideOptions' + } + console.log(serialNumber); + console.log('expediante 2') + const modal = await this.modalController.create({ + component: ExpedienteDetailPage, + componentProps: { + serialNumber: serialNumber, + profile: "MDGPR", + }, + cssClass: classs, + }); + await modal.present(); + modal.onDidDismiss().then((res) => { + if (res) { + console.log(res); + } + }); + } + + async viewPublicationDetail(publicationId: string) { + const modal = await this.modalController.create({ + component: PublicationDetailPage, + componentProps: { + publicationId: publicationId, + folderId: this.folderId, + }, + cssClass: 'publication-detail', + backdropDismiss: false + }); + await modal.present(); + modal.onDidDismiss().then(() => { + + }); + } + + + async viewPublications(folderId) { + + const enterAnimation = (baseEl: any) => { + const backdropAnimation = this.animationController.create() + .addElement(baseEl.querySelector('ion-backdrop')!) + .fromTo('opacity', '0.01', 'var(--backdrop-opacity)'); + + const wrapperAnimation = this.animationController.create() + .addElement(baseEl.querySelector('.modal-wrapper')!) + .keyframes([ + { offset: 0, opacity: '0', transform: 'scale(0)' }, + { offset: 1, opacity: '0.99', transform: 'scale(1)' } + ]); + + return this.animationController.create() + .addElement(baseEl) + .easing('ease-out') + .duration(500) + .addAnimation([backdropAnimation, wrapperAnimation]); + } + + const leaveAnimation = (baseEl: any) => { + return enterAnimation(baseEl).direction('reverse'); + } + + const modal = await this.modalController.create({ + component: ViewPublicationsPage, + enterAnimation, + leaveAnimation, + componentProps: { + folderId: folderId, + }, + cssClass: 'new-action', + backdropDismiss: false + }); + await modal.present(); + modal.onDidDismiss(); } }