Files
doneit-web/src/app/services/webnotifications.service.ts
T

214 lines
6.4 KiB
TypeScript
Raw Normal View History

2021-06-28 13:36:08 +01:00
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 { Tokenn } from '../models/token.model';
2021-06-28 13:36:08 +01:00
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
import { NavigationExtras, Router } from '@angular/router';
2021-06-28 13:36:08 +01:00
import { ToastService } from './toast.service';
@Injectable({
providedIn: 'root'
})
export class WebNotificationsService {
adding: "intervenient" | "CC" = "intervenient";
folderId: string;
constructor(
private http: HttpClient,
private storageService: StorageService,
private modalController: ModalController,
public modalCtrl: AlertController,
private animationController: AnimationController,
private platform: Platform,
private router: Router,
2021-11-23 17:11:23 +01:00
private toastService: ToastService) { }
2021-06-28 13:36:08 +01:00
webconnection() {
var inicializeObj = {
appId: "com.gpr.gabinetedigital",
mfpContextRoot: "/mfp",
/* serverUrl: "http://gpr-dev-10.gabinetedigital.local:9080",
safariWebsitePushId: "http://gpr-dev-10.gabinetedigital.local:9080", */
}
2021-08-25 16:29:15 +01:00
/* MFPPush.initialize({
2021-06-28 13:36:08 +01:00
appId: "com.gpr.gabinetedigital",
2021-06-30 15:33:12 +01:00
mfpContextRoot: "/mfp",
2021-08-25 16:29:15 +01:00
}); */
2021-09-07 12:18:12 +01:00
/* MFPPush.registerDevice()
2021-06-30 15:33:12 +01:00
.then((res) => {
2022-04-28 09:32:27 +01:00
2021-08-31 13:46:39 +01:00
setTimeout(()=>{
MFPPush.registerDevice()
.then((res) => {
2022-04-28 09:32:27 +01:00
2021-08-31 13:46:39 +01:00
})
.catch((err) => {
2022-04-28 09:32:27 +01:00
2021-08-31 13:46:39 +01:00
});
}, 1000)
2021-06-30 15:33:12 +01:00
})
.catch((err) => {
2022-04-28 09:32:27 +01:00
2021-09-07 12:18:12 +01:00
}); */
2021-06-28 13:36:08 +01:00
}
/* getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
return this.http.get<Token[]>(`${geturl}`);
} */
/* getAndpostToken(username) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-04-28 09:32:27 +01:00
2021-06-28 13:36:08 +01:00
} else {
const geturl = environment.apiURL + 'notifications/token'; */
/*
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
(token) => {
2022-04-28 09:32:27 +01:00
MFPPush.initialize(
function (successResponse) {
2022-04-28 09:32:27 +01:00
},
function (failureResponse) {
2022-04-28 09:32:27 +01:00
}
);
MFPPush.registerDevice(null, (successResponse) => {
2022-04-28 09:32:27 +01:00
this.storageService.store(username, successResponse.deviceId);
this.storageService.get(username).then(value => {
2022-04-28 09:32:27 +01:00
this.storageService.get(AuthConnstants.USER).then(res => {
2022-04-28 09:32:27 +01:00
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 => {
2022-04-28 09:32:27 +01:00
})
});
});
},
function (failureResponse) {
2022-04-28 09:32:27 +01:00
}
);
}, (error) => {
2022-04-28 09:32:27 +01:00
}
);
}
} */
/*
async onReceviNotification() {
2021-07-08 10:48:26 +01:00
window['WLAuthorizationManager'].obtainAccessToken("push.mobileclient").then(
2021-06-28 13:36:08 +01:00
(token) => {
2022-04-28 09:32:27 +01:00
2021-06-28 13:36:08 +01:00
MFPPush.initialize(
function (successResponse) {
2022-04-28 09:32:27 +01:00
MFPPush.registerNotificationsCallback(notificationReceived);
2021-06-28 13:36:08 +01:00
},
function (failureResponse) {
2022-04-28 09:32:27 +01:00
2021-06-28 13:36:08 +01:00
}
);
var notificationReceived = (message) => {
2022-04-28 09:32:27 +01:00
var data = JSON.parse(message.payload);
2022-04-28 09:32:27 +01:00
if(message.actionName){
this.notificatinsRoutes(data);
} else {
this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
2021-06-28 13:36:08 +01:00
}
}
2021-06-28 13:36:08 +01:00
}, (error) => {
2022-04-28 09:32:27 +01:00
2021-06-28 13:36:08 +01:00
}
);
} */
2021-06-28 13:36:08 +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']));
}
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 === "despachos") {
let navigationExtras: NavigationExtras = {
queryParams: {
"serialNumber": data.IdObject,
}
};
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos/despacho'], navigationExtras));
}
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 {
}
} */
}