diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts
index ea986db4e..2aaa7e562 100644
--- a/src/app/home/home.page.ts
+++ b/src/app/home/home.page.ts
@@ -6,21 +6,8 @@ import { Event } from '../models/event.model';
import { ProcessesService } from '../services/processes.service';
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 { NavigationExtras,Router } from '@angular/router';
-
-// import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
-import { ViewEventPage } from '../pages/agenda/view-event/view-event.page';
-import { ExpedienteDetailPage } from '../pages/gabinete-digital/expediente/expediente-detail/expediente-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';
-import { PublicationDetailPage } from '../pages/publications/view-publications/publication-detail/publication-detail.page';
import { ToastService } from '../services/toast.service';
-import { SuccessMessagePage } from '../shared/popover/success-message/success-message.page';
-//import MFPPush from 'ibm-mfp-web-push';
-
-/* const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins; */
@Component({
selector: 'app-home',
@@ -80,7 +67,7 @@ export class HomePage implements OnInit {
ngOnInit() {
if(!this.platform.is('desktop')) {
- this.wlCommonInit();
+ this.notificatinsservice.onReceviNotification();
}
this.count();
@@ -112,140 +99,4 @@ export class HomePage implements OnInit {
}
- wlCommonInit() {
-
- this.mobileFirstTest();
- this.mobileFirstPush();
- }
-
- mobileFirstTest() {
-
- }
-
- mobileFirstPush() {
- WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
- (token) => {
- console.log('Push Notification: Success ' + token);
-
- MFPPush.initialize(
- function (successResponse) {
- console.log("Push notification Successfully intialized: " + successResponse);
- MFPPush.registerNotificationsCallback(notificationReceived);
- },
- function (failureResponse) {
- console.log("Push notification failure intialized: " + failureResponse);
- }
- );
-
- MFPPush.registerDevice(null, function (successResponse) {
- console.log("Successfully registered: " + JSON.stringify(successResponse) );
- },
- function (failureResponse) {
- console.log("Successfully failue: " + failureResponse);
- }
- );
- var notificationReceived = (message) => {
- console.log(message);
- var data = JSON.parse(message.payload);
- console.log(data.Service);
- console.log(data.IdObject);
- console.log(data.Object);
-
- if(message.actionName){
- this.notificatinsRoutes(data);
- } else {
- this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
- }
-
- }
- }, (error) => {
- console.log('Push notification recived: failure ' + error.responseText);
- console.log(JSON.stringify(error));
- }
- );
-
- }
-
- notificatinsRoutes = (data) => {
- if (data.Service === "agenda") {
- //this.router.navigate(['/home/', service, IdObject, 'home']);
- //this.router.navigate(['/home/agenda', data.IdObject, 'agenda']);
- this.zone.run(() => 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.zone.run(() =>this.openApproveModal(data.IdObject));
- }
- else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
- // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', IdObject])})
- this.zone.run(() =>this.viewPedidoParecerDetail(data.IdObject));
- }
- else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
- // this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', IdObject])})
- this.zone.run(() =>this.viewPedidoDefereimentoDetail(data.IdObject));
- }
- else if (data.Service === "accoes" && data.Object === "accao") {
- this.zone.run(() => this.viewPublications(data.IdObject));
- }
- else if (data.Service === "accoes" && data.Object === "publicacao") {
- this.zone.run(() => this.viewPublicationDetail(data.FolderId,data.IdObject));
- }
- }
-
- async viewEventDetail(eventId: any) {
- console.log('home noti '+ eventId);
- this.router.navigate(['/home/agenda', eventId, 'agenda']);
- }
-
- async openApproveModal(serialNumber) {
- this.router.navigate(['/home/gabinete-digital/event-list/approve-event',serialNumber, 'gabinete-digital'])
- }
-
- async viewExpedientDetail(serialNumber:any) {
- this.router.navigate(['/home/gabinete-digital/expediente',serialNumber,'gabinete-digital']);
- }
-
- async viewPublicationDetail(FolderId: string, publicationId: string ) {
- this.router.navigate(['/home/publications/view-publications', FolderId, publicationId]);
- }
-
-
- async viewPublications(folderId) {
-
- this.router.navigate(['/home/publications',folderId]);
- }
-
- async viewPedidoParecerDetail(serialNumber:any) {
-
- let navigationExtras: NavigationExtras = {
- queryParams: {
- enterAnimation: "",
- serialNumber: serialNumber,
- }
- };
- this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras);
-
- }
-
- async viewPedidoDefereimentoDetail(serialNumber:any) {
-
- let navigationExtras: NavigationExtras = {
- queryParams: {
- enterAnimation: "",
- serialNumber: serialNumber,
- }
- };
- this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras);
-
- }
-
-
-
-
-
-
}
diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts
index e6d604414..50b902e5c 100644
--- a/src/app/pages/login/login.page.ts
+++ b/src/app/pages/login/login.page.ts
@@ -114,7 +114,7 @@ export class LoginPage implements OnInit {
} */
getToken() {
- // this.notificatinsservice.getAndpostToken(this.username);
+ this.notificatinsservice.getAndpostToken(this.username);
}
async Login() {
@@ -133,7 +133,7 @@ export class LoginPage implements OnInit {
if (attempt) {
//this.loginRocketChat();
this.authService.loginChat(this.userattempt);
- //this.getToken();
+ this.getToken();
if(!this.pin) {
this.setPint = true
diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts
index 77f21570e..0846829e1 100644
--- a/src/app/services/notifications.service.ts
+++ b/src/app/services/notifications.service.ts
@@ -1,21 +1,13 @@
-import { Injectable } from '@angular/core';
+///
+import { Injectable, NgZone } 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';
+import { NavigationExtras,Router } from '@angular/router';
+import { ToastService } from '../services/toast.service';
@Injectable({
providedIn: 'root'
@@ -27,17 +19,14 @@ export class NotificationsService {
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 */) { }
+ private platform: Platform,
+ private router: Router,
+ private toastService: ToastService,
+ private zone: NgZone) { }
getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
@@ -45,199 +34,137 @@ export class NotificationsService {
return this.http.get(`${geturl}`);
}
- // getAndpostToken(username) {
- // if(this.platform.is('desktop')) {
- // console.log('Notifications not supported')
- // } else {
-
- // const geturl = environment.apiURL + 'notifications/token';
+ getAndpostToken(username) {
+ if (this.platform.is('desktop')) {
+ console.log('Notifications not supported')
+ } else {
- // 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
- // };
+ const geturl = environment.apiURL + 'notifications/token';
- // this.http.post(`${geturl}`, body, { headers }).subscribe(data => {
- // console.log('TOKEN USER MIDLE', data);
- // })
- // });
+ WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
+ (token) => {
+ console.log('Push Notification: Success ' + token);
- // });
- // });
- // }
-
- // }
+ MFPPush.initialize(
+ function (successResponse) {
+ console.log("Push notification Successfully Service intialized: " + successResponse);
+ },
+ function (failureResponse) {
+ console.log("Push notification failure Service intialized: " + failureResponse);
+ }
+ );
- async onReceviNotification(viewEventDetail, viewExpedientDetail, openApproveModal, viewPublications, viewPublicationDetail) {
- // this.fcm.onNotification().subscribe(data => {
- // if (data.click_action) {
- // console.log("Received in background: ", data);
+ MFPPush.registerDevice(null, (successResponse) => {
+ console.log("Successfully registered: " + JSON.stringify(successResponse));
+ console.log('token: ', successResponse.deviceId)
+ this.storageService.store(username, successResponse.deviceId);
+ 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: successResponse.deviceId,
+ Status: 1,
+ Service: 1
+ };
+ this.http.post(`${geturl}`, body, { headers }).subscribe(data => {
+ console.log('TOKEN USER MIDLE', 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)
- // }
+ });
+ },
+ function (failureResponse) {
+ console.log("Successfully failue: " + JSON.stringify(failureResponse));
+ }
+ );
+ }, (error) => {
+ console.log('Push notification recived: failure ' + error.responseText);
+ console.log(JSON.stringify(error));
+ }
+ );
+ }
- // } /* else {
- // console.log("Received in foreground: ", data);
+ }
- // console.log(data.Service)
- // console.log(data.Object)
- // console.log(data.IdObject)
- // this.openApproveModal(data.IdObject);
-
- // }; */
- // });
+ async onReceviNotification() {
+ WLAuthorizationManager.obtainAccessToken("push.mobileclient").then(
+ (token) => {
+ console.log('Push Notification: Success ' + token);
+
+ MFPPush.initialize(
+ function (successResponse) {
+ console.log("Push notification Successfully intialized: " + successResponse);
+ MFPPush.registerNotificationsCallback(notificationReceived);
+ },
+ function (failureResponse) {
+ console.log("Push notification failure intialized: " + failureResponse);
+ }
+ );
+ var notificationReceived = (message) => {
+ console.log(message);
+ var data = JSON.parse(message.payload);
+ console.log(data.Service);
+ console.log(data.IdObject);
+ console.log(data.Object);
+
+ if(message.actionName){
+ this.notificatinsRoutes(data);
+ } else {
+ this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
+ }
+
+ }
+ }, (error) => {
+ console.log('Push notification recived: failure ' + error.responseText);
+ console.log(JSON.stringify(error));
+ }
+ );
+ }
+
+ notificatinsRoutes = (data) => {
+ if (data.Service === "agenda") {
+ this.zone.run(() => this.router.navigate(['/home/agenda', data.IdObject, 'agenda']));
+ }
+ else if (data.Service === "gabinete-digital" && data.Object === "expediente") {
+ this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente',data.IdObject,'gabinete-digital']));
+ }
+ else if (data.Service === "gabinete-digital" && data.Object === "event-list") {
+ this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',data.IdObject, 'gabinete-digital']));
+ }
+ else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
+ let navigationExtras: NavigationExtras = {
+ queryParams: {
+ enterAnimation: "",
+ serialNumber: data.IdObject,
+ }
+ };
+ this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras));
+ }
+ else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
+ let navigationExtras: NavigationExtras = {
+ queryParams: {
+ enterAnimation: "",
+ serialNumber: data.IdObject,
+ }
+ };
+ this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos/pedido'], navigationExtras));
+ }
+ else if (data.Service === "accoes" && data.Object === "accao") {
+ this.zone.run(() => this.router.navigate(['/home/publications',data.IdObject]));
+ }
+ else if (data.Service === "accoes" && data.Object === "publicacao") {
+ this.zone.run(() => this.router.navigate(['/home/publications/view-publications',data.FolderId,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 modal-desktop'
- } 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();
- }
}