mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
Some changes
This commit is contained in:
@@ -9,7 +9,7 @@ import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { Token } from '../models/token.model';
|
||||
import { ModalController, AlertController, AnimationController, Platform } from '@ionic/angular';
|
||||
import { NavigationExtras,Router } from '@angular/router';
|
||||
import { NavigationExtras, Router } from '@angular/router';
|
||||
import { ToastService } from '../services/toast.service';
|
||||
import { JsonStore } from './jsonStore.service';
|
||||
import { BackgroundService } from './background.service';
|
||||
@@ -18,6 +18,7 @@ import { EventTrigger } from '../services/eventTrigger.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
|
||||
import { FCM } from '@ionic-native/fcm/ngx';
|
||||
//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -41,38 +42,38 @@ export class NotificationsService {
|
||||
public modalCtrl: AlertController,
|
||||
private animationController: AnimationController,
|
||||
private platform: Platform,
|
||||
private router: Router,
|
||||
private router: Router,
|
||||
private toastService: ToastService,
|
||||
private zone: NgZone,
|
||||
private activeroute: ActivatedRoute,
|
||||
private jsonstore: JsonStore,
|
||||
private eventtrigger: EventTrigger,
|
||||
private backgroundservice: BackgroundService,
|
||||
private fcm: FCM) {
|
||||
private fcm: FCM) {
|
||||
|
||||
this.storageService.get("Notifications").then((value) => {
|
||||
|
||||
}).catch(()=>{
|
||||
this.storageService.get("Notifications").then((value) => {
|
||||
|
||||
this.storageService.store("Notifications",[])
|
||||
})
|
||||
}).catch(() => {
|
||||
|
||||
}
|
||||
this.storageService.store("Notifications", [])
|
||||
})
|
||||
|
||||
registerCallback(type: string, funx: Function, object: any = {} ) {
|
||||
}
|
||||
|
||||
registerCallback(type: string, funx: Function, object: any = {}) {
|
||||
|
||||
const id = uuidv4()
|
||||
this.callbacks.push({type, funx, id})
|
||||
if(!object.hasOwnProperty('desktop') && object['desktop'] != false) {
|
||||
this.backgroundservice.registerBackService('Notification',funx, type)
|
||||
this.callbacks.push({ type, funx, id })
|
||||
if (!object.hasOwnProperty('desktop') && object['desktop'] != false) {
|
||||
this.backgroundservice.registerBackService('Notification', funx, type)
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
deleteCallback(id) {
|
||||
this.callbacks.forEach((e, index)=>{
|
||||
if(e.id == id) {
|
||||
this.callbacks.forEach((e, index) => {
|
||||
if (e.id == id) {
|
||||
if (index > -1) {
|
||||
this.callbacks.splice(index, 1);
|
||||
}
|
||||
@@ -88,36 +89,36 @@ export class NotificationsService {
|
||||
}
|
||||
|
||||
getAndpostToken(username) {
|
||||
if(this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
console.log('Notifications not supported')
|
||||
} else {
|
||||
|
||||
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
|
||||
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': SessionStore.user.BasicAuthKey };
|
||||
const body = {
|
||||
UserId: res.UserId,
|
||||
TokenId: token,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
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': SessionStore.user.BasicAuthKey };
|
||||
const body = {
|
||||
UserId: res.UserId,
|
||||
TokenId: token,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
|
||||
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
})
|
||||
});
|
||||
|
||||
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
async onReceviNotification() {
|
||||
@@ -127,15 +128,19 @@ export class NotificationsService {
|
||||
|
||||
this.notificatinsRoutes(data)
|
||||
|
||||
} /* else {
|
||||
} else {
|
||||
console.log("Received in foreground: ", data);
|
||||
|
||||
console.log(data.Service)
|
||||
console.log(data.Object)
|
||||
console.log(data.IdObject)
|
||||
this.openApproveModal(data.IdObject);
|
||||
|
||||
}; */
|
||||
|
||||
/* this.DataArray.push(data)
|
||||
console.log("On ReceiveNotification", this.DataArray)
|
||||
this.storageService.store("Notifications", this.DataArray) */
|
||||
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,56 +153,122 @@ export class NotificationsService {
|
||||
return this.http.get<Token[]>(`${geturl}`);
|
||||
}
|
||||
*/
|
||||
/* getAndpostToken(username) {
|
||||
/* getAndpostToken(username) {
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
//console.log('Notifications not supported')
|
||||
} else {
|
||||
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
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, async (successResponse) => {
|
||||
console.log("Successfully registered: " + JSON.stringify(successResponse));
|
||||
console.log('token: ', successResponse.deviceId)
|
||||
await this.storageService.store(username, successResponse.deviceId).then((tokennoti) => {
|
||||
console.log('token store',tokennoti)
|
||||
});
|
||||
await 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': SessionStore.user.BasicAuthKey };
|
||||
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));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} */
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
//console.log('Notifications not supported')
|
||||
} else {
|
||||
tempClearArray() {
|
||||
this.DataArray = [];
|
||||
}
|
||||
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
/* async onReceviNotification() {
|
||||
|
||||
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);
|
||||
console.log("Push notification Successfully intialized: " + successResponse);
|
||||
window['MFPPush'].registerNotificationsCallback(notificationReceived);
|
||||
},
|
||||
function (failureResponse) {
|
||||
console.log("Push notification failure Service intialized: " + failureResponse);
|
||||
console.log("Push notification failure intialized: " + failureResponse);
|
||||
}
|
||||
);
|
||||
|
||||
window['MFPPush'].registerDevice(null, async (successResponse) => {
|
||||
console.log("Successfully registered: " + JSON.stringify(successResponse));
|
||||
console.log('token: ', successResponse.deviceId)
|
||||
await this.storageService.store(username, successResponse.deviceId).then((tokennoti) => {
|
||||
console.log('token store',tokennoti)
|
||||
});
|
||||
await 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': SessionStore.user.BasicAuthKey };
|
||||
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));
|
||||
var notificationReceived = (message) => {
|
||||
//this.jsonstore.createCollection('Notifications',message);
|
||||
this.DataArray.push(message)
|
||||
console.log("On ReceiveNotification", this.DataArray)
|
||||
this.storageService.store("Notifications",this.DataArray)
|
||||
|
||||
console.log(message);
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
var data = JSON.parse(message.payload);
|
||||
|
||||
//synchro.$send(data)
|
||||
|
||||
console.log('data.Service', data.Service); // module
|
||||
console.log('data.IdObject', data.IdObject); // Object id
|
||||
console.log('data.Object', data.Object); // details
|
||||
|
||||
if(message.actionName){
|
||||
this.notificatinsRoutes(data);
|
||||
} else {
|
||||
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
|
||||
//this.notificatinsRoutes(data);
|
||||
console.log(data)
|
||||
}
|
||||
);
|
||||
|
||||
this.callbacks.forEach( e=> {
|
||||
if(e.type == data.Object || e.type == "any") {
|
||||
e.funx()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}, (error) => {
|
||||
console.log('Push notification recived: failure ' + error.responseText);
|
||||
console.log(JSON.stringify(error));
|
||||
@@ -205,120 +276,54 @@ export class NotificationsService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} */
|
||||
|
||||
tempClearArray(){
|
||||
this.DataArray = [];
|
||||
}
|
||||
|
||||
/* async onReceviNotification() {
|
||||
|
||||
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 intialized: " + successResponse);
|
||||
window['MFPPush'].registerNotificationsCallback(notificationReceived);
|
||||
},
|
||||
function (failureResponse) {
|
||||
console.log("Push notification failure intialized: " + failureResponse);
|
||||
}
|
||||
);
|
||||
var notificationReceived = (message) => {
|
||||
//this.jsonstore.createCollection('Notifications',message);
|
||||
this.DataArray.push(message)
|
||||
console.log("On ReceiveNotification", this.DataArray)
|
||||
this.storageService.store("Notifications",this.DataArray)
|
||||
|
||||
console.log(message);
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
var data = JSON.parse(message.payload);
|
||||
|
||||
//synchro.$send(data)
|
||||
|
||||
console.log('data.Service', data.Service); // module
|
||||
console.log('data.IdObject', data.IdObject); // Object id
|
||||
console.log('data.Object', data.Object); // details
|
||||
|
||||
if(message.actionName){
|
||||
this.notificatinsRoutes(data);
|
||||
} else {
|
||||
/* this.toastService.notificationMessage(message.alert,this.notificatinsRoutes, data);
|
||||
//this.notificatinsRoutes(data);
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
this.callbacks.forEach( e=> {
|
||||
if(e.type == data.Object || e.type == "any") {
|
||||
e.funx()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}, (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']));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (data.Service === "agenda" && data.Object === "event-list") {
|
||||
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event',data.IdObject, 'agenda']));
|
||||
}else if (data.Service === "gabinete-digital" && data.Object === "despachos") {
|
||||
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', data.IdObject, 'agenda']));
|
||||
} else if (data.Service === "gabinete-digital" && data.Object === "despachos") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos',data.IdObject,'gabinete-digital'],{replaceUrl: true}));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "parecer") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "deferimento") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos',data.IdObject,'gabinete-digital']));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "despachos-pr") {
|
||||
|
||||
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/despachos-pr',data.IdObject,'gabinete-digital']));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (data.Service === "accoes" && data.Object === "accao") {
|
||||
this.zone.run(() => this.router.navigate(['/home/publications',data.IdObject]));
|
||||
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]));
|
||||
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', data.FolderId, data.IdObject]));
|
||||
}
|
||||
else if (data.Service === "gabinete-digital" && data.Object === "diplomas") {
|
||||
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas', data.IdObject, 'gabinete-digital']));
|
||||
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,
|
||||
"serialNumber": data.IdObject,
|
||||
}
|
||||
};
|
||||
this.zone.run(() =>this.router.navigate(['/home/gabinete-digital/diplomas-assinar/diploma-assinar'], navigationExtras));
|
||||
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']));
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user