diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index f21ca4760..d6a45060a 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -65,9 +65,8 @@ export class HomePage implements OnInit { } ngOnInit() { - //this.securityCheck() - this.mobileFirstTest() - //this.pushCordova() + + this.pushCordova() /* //Initialize profile as mdgpr let date = new Date(); @@ -96,83 +95,192 @@ export class HomePage implements OnInit { */ } - mobileFirstTest() { - this.zone.run(() => { - console.log("Hello MobileFirst"); - console.log("Connecting to Server..."); - }); - WLAuthorizationManager.obtainAccessToken("").then( - (token) => { - console.log('--> pingMFP(): Success ', token); - this.zone.run(() => { - console.log("Yay!"); - console.log("Connected to MobileFirst Server"); - }); - var resourceRequest = new WLResourceRequest("/adapters/javaAdapter/resource/greet/", - WLResourceRequest.GET - ); + pushCordova() { - resourceRequest.setQueryParameter("name", "world"); - resourceRequest.send().then( - (response) => { - // Will display "Hello world" in an alert dialog. - console.log("Success: " + response.responseText); + this.fcm.onNotification().subscribe(data => { + this.viewEventDetail(data.idObject) + if (data.click_action) { + console.log("Received in background: ", data); - //this.MFPushNotification() - }, - (error) => { - console.log("Failure: " + JSON.stringify(error)); - } - ); - }, (error) => { - console.log(JSON.stringify(error)) - this.zone.run(() => { - console.log("Bummer..."); - console.log("Failed to connect to MobileFirst Server"); - }); - } - ); - } - - MFPushNotification() { - - /* var pushNotificationReceived = function (message) { - console.log(JSON.stringify(message)); - } - - MFPPush.initialize ( - function(successResponse) { - //alert("Successfully intialized"); - MFPPush.registerNotificationsCallback(notificationReceived); - }, - function(failureResponse) { - console.log("Failed to initialize"); + if (data.service === "agenda") { + //this.router.navigate(['/home/', service, idObject, 'home']); + this.viewEventDetail(data.idObject) } - ); - MFPPush.isPushSupported ( - function(successResponse) { - //alert("Push Supported: " + successResponse); - }, - function(failureResponse) { - console.log("Failed to get push support status"); - } - ); - MFPPush.registerDevice( - null,function(successResponse) { - console.log("Successfully registered: "+ successResponse); - }, - function(failureResponse) { - console.log("Successfully registered: "+ failureResponse); - } - ); - function notificationReceived(message) { - alert(message) - console.log(JSON.stringify(message.alert)); - } */ + 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) + } + + } 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.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); + + 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) { + const modal = await this.modalController.create({ + component: ApproveEventModalPage, + componentProps: { + serialNumber: eventSerialNumber, + }, + cssClass: 'cal-modal', + 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(this.profile); + console.log(serialNumber); */ + + const modal = await this.modalController.create({ + component: ExpedienteDetailPage, + componentProps: { + serialNumber: serialNumber, + profile: this.profile, + }, + 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(() => { + //this.getPublications(); + }); + } + + + 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(); + } + +