2021-07-08 14:07:33 +01:00
|
|
|
/* eslint-disable */
|
2021-07-08 14:45:38 +01:00
|
|
|
/* tslint:disable */
|
2021-06-25 09:35:50 +01:00
|
|
|
///<reference path="../../../plugins/cordova-plugin-mfp-push/typings/mfppush.d.ts" />
|
|
|
|
|
import { Injectable, NgZone } from '@angular/core';
|
2021-07-07 15:28:29 +01:00
|
|
|
import { ActivatedRoute } from '@angular/router'
|
2021-02-01 13:31:33 +01:00
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
2021-04-12 08:34:17 +01:00
|
|
|
import { StorageService } from 'src/app/services/storage.service';
|
|
|
|
|
import { AuthConnstants } from 'src/app/config/auth-constants';
|
2021-02-01 13:31:33 +01:00
|
|
|
import { Token } from '../models/token.model';
|
2021-04-12 15:39:44 +01:00
|
|
|
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
|
2021-06-25 09:35:50 +01:00
|
|
|
import { NavigationExtras,Router } from '@angular/router';
|
|
|
|
|
import { ToastService } from '../services/toast.service';
|
2021-07-08 10:43:40 +01:00
|
|
|
import { Optional } from '@angular/core';
|
2021-07-29 16:02:39 +01:00
|
|
|
import { JsonStore } from './jsonStore.service';
|
2021-02-01 13:31:33 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class NotificationsService {
|
|
|
|
|
|
2021-04-12 08:34:17 +01:00
|
|
|
adding: "intervenient" | "CC" = "intervenient";
|
|
|
|
|
folderId: string;
|
2021-07-31 22:04:09 +01:00
|
|
|
DataArray: Array<String> = [];
|
2021-04-12 08:34:17 +01:00
|
|
|
|
|
|
|
|
constructor(
|
2021-07-08 10:43:40 +01:00
|
|
|
private http: HttpClient,
|
2021-04-12 08:34:17 +01:00
|
|
|
private storageService: StorageService,
|
2021-04-12 15:39:44 +01:00
|
|
|
private modalController: ModalController,
|
2021-04-12 08:34:17 +01:00
|
|
|
public modalCtrl: AlertController,
|
2021-04-12 15:39:44 +01:00
|
|
|
private animationController: AnimationController,
|
2021-06-25 09:35:50 +01:00
|
|
|
private platform: Platform,
|
2021-07-08 10:43:40 +01:00
|
|
|
private router: Router,
|
2021-06-25 09:35:50 +01:00
|
|
|
private toastService: ToastService,
|
2021-07-07 15:28:29 +01:00
|
|
|
private zone: NgZone,
|
2021-07-29 16:02:39 +01:00
|
|
|
private activeroute: ActivatedRoute,
|
|
|
|
|
private jsonstore: JsonStore) { }
|
2021-02-01 13:31:33 +01:00
|
|
|
|
|
|
|
|
getTokenByUserIdAndId(user, userID) {
|
|
|
|
|
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
|
|
|
|
|
|
|
|
|
return this.http.get<Token[]>(`${geturl}`);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 09:35:50 +01:00
|
|
|
getAndpostToken(username) {
|
2021-07-29 16:02:39 +01:00
|
|
|
|
2021-06-25 14:37:52 +01:00
|
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
2021-06-25 09:35:50 +01:00
|
|
|
console.log('Notifications not supported')
|
2021-04-12 15:39:44 +01:00
|
|
|
} else {
|
2021-04-12 08:34:17 +01:00
|
|
|
|
2021-06-25 09:35:50 +01:00
|
|
|
const geturl = environment.apiURL + 'notifications/token';
|
2021-08-13 17:31:01 +01:00
|
|
|
if(window['WLAuthorizationManager']) {
|
|
|
|
|
if(window['WLAuthorizationManager'].obtainAccessToken) {
|
|
|
|
|
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
|
|
|
|
|
(token) => {
|
|
|
|
|
console.log('Push Notification: Success ' + token);
|
|
|
|
|
|
|
|
|
|
window['MFPPush'].initialize(
|
|
|
|
|
function (successResponse) {
|
|
|
|
|
console.log("Push notification Successfully Service intialized: " + successResponse);
|
|
|
|
|
},
|
|
|
|
|
function (failureResponse) {
|
|
|
|
|
console.log("Push notification failure Service intialized: " + failureResponse);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
window['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<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
|
|
|
|
console.log('TOKEN USER MIDLE', data);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-13 16:39:28 +01:00
|
|
|
});
|
2021-08-13 17:31:01 +01:00
|
|
|
},
|
|
|
|
|
function (failureResponse) {
|
|
|
|
|
console.log("Successfully failue: " + JSON.stringify(failureResponse));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log('Push notification recived: failure ' + error.responseText);
|
|
|
|
|
console.log(JSON.stringify(error));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-08-13 16:39:28 +01:00
|
|
|
}
|
2021-06-25 09:35:50 +01:00
|
|
|
|
|
|
|
|
|
2021-08-13 17:31:01 +01:00
|
|
|
|
2021-04-12 08:34:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 22:04:09 +01:00
|
|
|
getAndpostToken2() {
|
|
|
|
|
|
|
|
|
|
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
|
|
|
|
console.log('Notifications not supported')
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
const geturl = environment.apiURL + 'notifications/token';
|
2021-08-13 17:31:01 +01:00
|
|
|
if(window['WLAuthorizationManager']) {
|
|
|
|
|
if(window['WLAuthorizationManager'].obtainAccessToken) {
|
|
|
|
|
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
|
|
|
|
|
(token) => {
|
|
|
|
|
console.log('Push Notification: Success ' + token);
|
|
|
|
|
|
|
|
|
|
window['MFPPush'].initialize(
|
|
|
|
|
function (successResponse) {
|
|
|
|
|
console.log("Push notification Successfully Service intialized: " + successResponse);
|
|
|
|
|
},
|
|
|
|
|
function (failureResponse) {
|
|
|
|
|
console.log("Push notification failure Service intialized: " + failureResponse);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
window['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<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
|
|
|
|
console.log('TOKEN USER MIDLE', data);
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}); */
|
|
|
|
|
},
|
|
|
|
|
function (failureResponse) {
|
|
|
|
|
console.log("Successfully failue: " + JSON.stringify(failureResponse));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}, (error) => {
|
|
|
|
|
console.log('Push notification recived: failure ' + error.responseText);
|
|
|
|
|
console.log(JSON.stringify(error));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 17:36:40 +01:00
|
|
|
removeDepartment(index): void {
|
|
|
|
|
/* this.DataArray[this.DataArray.findIndex(item => item.index == index)];
|
|
|
|
|
this.DataArray.splice( this.DataArray.findIndex(item => item.indexOf(index.to) === 'William'),1); */
|
|
|
|
|
const indexx = this.DataArray.indexOf(index, 0);
|
|
|
|
|
if (indexx > -1) {
|
|
|
|
|
this.DataArray.splice(index, 1);
|
|
|
|
|
console.log('This notificatio', this.DataArray);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 16:59:44 +01:00
|
|
|
tempClearArray(){
|
|
|
|
|
this.DataArray = [];
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 17:31:01 +01:00
|
|
|
async onReceviNotification() {
|
|
|
|
|
|
|
|
|
|
if(window['WLAuthorizationManager']) {
|
2021-08-13 16:39:28 +01:00
|
|
|
if(window['WLAuthorizationManager'].obtainAccessToken) {
|
|
|
|
|
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
|
|
|
|
|
(token) => {
|
|
|
|
|
console.log('Push Notification: Success ' + token);
|
2021-08-13 17:31:01 +01:00
|
|
|
|
2021-08-13 16:39:28 +01:00
|
|
|
window['MFPPush'].initialize(
|
|
|
|
|
function (successResponse) {
|
2021-08-13 17:31:01 +01:00
|
|
|
console.log("Push notification Successfully intialized: " + successResponse);
|
|
|
|
|
window['MFPPush'].registerNotificationsCallback(notificationReceived);
|
2021-08-13 16:39:28 +01:00
|
|
|
},
|
|
|
|
|
function (failureResponse) {
|
2021-08-13 17:31:01 +01:00
|
|
|
console.log("Push notification failure intialized: " + failureResponse);
|
2021-08-13 16:39:28 +01:00
|
|
|
}
|
|
|
|
|
);
|
2021-08-13 17:31:01 +01:00
|
|
|
var notificationReceived = (message) => {
|
|
|
|
|
//this.jsonstore.createCollection('Notifications',message);
|
|
|
|
|
this.DataArray.push(message)
|
2021-08-19 13:58:43 +01:00
|
|
|
console.log("On ReceiveNotification", this.DataArray)
|
2021-08-13 17:31:01 +01:00
|
|
|
this.storageService.store("Notifications",JSON.stringify(this.DataArray))
|
|
|
|
|
|
|
|
|
|
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 {
|
2021-08-18 17:36:40 +01:00
|
|
|
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data); */
|
|
|
|
|
//this.notificatinsRoutes(data);
|
|
|
|
|
console.log(data)
|
2021-08-13 16:39:28 +01:00
|
|
|
}
|
2021-08-13 17:31:01 +01:00
|
|
|
|
|
|
|
|
}
|
2021-08-13 16:39:28 +01:00
|
|
|
}, (error) => {
|
|
|
|
|
console.log('Push notification recived: failure ' + error.responseText);
|
|
|
|
|
console.log(JSON.stringify(error));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 22:04:09 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-25 09:35:50 +01:00
|
|
|
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']));
|
|
|
|
|
}
|
2021-08-20 16:43:17 +01:00
|
|
|
else if (data.Service === "agenda" && data.Object === "event-list") {
|
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event',data.IdObject, 'agenda']));
|
2021-06-25 14:37:52 +01:00
|
|
|
}else if (data.Service === "gabinete-digital" && data.Object === "despachos") {
|
2021-07-30 16:06:58 +01:00
|
|
|
|
2021-07-07 15:28:29 +01:00
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos',data.IdObject,'gabinete-digital'],{replaceUrl: true}));
|
2021-06-25 09:35:50 +01:00
|
|
|
}
|
|
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
|
2021-07-07 15:28:29 +01:00
|
|
|
|
|
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
|
2021-06-25 09:35:50 +01:00
|
|
|
}
|
|
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
|
2021-07-30 16:06:58 +01:00
|
|
|
|
2021-07-07 15:28:29 +01:00
|
|
|
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
|
2021-06-25 09:35:50 +01:00
|
|
|
}
|
2021-07-06 09:02:24 +01:00
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "despachos-pr") {
|
2021-07-30 16:06:58 +01:00
|
|
|
|
2021-08-18 18:28:21 +01:00
|
|
|
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/despachos-pr',data.IdObject,'gabinete-digital']));
|
2021-06-25 09:35:50 +01:00
|
|
|
}
|
|
|
|
|
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]));
|
|
|
|
|
}
|
2021-07-06 16:17:03 +01:00
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "diplomas") {
|
|
|
|
|
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas', data.IdObject, 'gabinete-digital']));
|
|
|
|
|
}
|
|
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "diplomas-assinar") {
|
|
|
|
|
let navigationExtras: NavigationExtras = {
|
|
|
|
|
queryParams: {
|
|
|
|
|
"serialNumber": data.IdObject,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas-assinar/diploma-assinar'], navigationExtras));
|
|
|
|
|
}
|
|
|
|
|
else if (data.Service === "gabinete-digital" && data.Object === "expedientes-pr") {
|
|
|
|
|
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/expedientes-pr',data.IdObject,'gabinete-digital']));
|
|
|
|
|
}
|
2021-04-12 08:34:17 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-25 09:35:50 +01:00
|
|
|
platformVerify() {
|
2021-04-12 08:34:17 +01:00
|
|
|
|
2021-06-25 09:35:50 +01:00
|
|
|
if (this.platform.is('cordova')) {
|
|
|
|
|
} else {
|
2021-04-12 08:34:17 +01:00
|
|
|
}
|
2021-04-12 15:39:44 +01:00
|
|
|
}
|
2021-06-25 09:35:50 +01:00
|
|
|
|
2021-02-01 13:31:33 +01:00
|
|
|
}
|