mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
merge
This commit is contained in:
@@ -6,7 +6,10 @@ import { Router, NavigationEnd } from '@angular/router'
|
||||
export class NavigationService {
|
||||
private history: string[] = []
|
||||
|
||||
constructor(private router: Router, private location: Location) {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private location: Location
|
||||
) {
|
||||
this.router.events.subscribe((event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
this.history.push(event.urlAfterRedirects)
|
||||
|
||||
@@ -80,92 +80,92 @@ export class NotificationsService {
|
||||
}
|
||||
|
||||
getTokenByUserIdAndId(user, userID) {
|
||||
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
// const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
|
||||
return this.http.get<Tokenn[]>(`${geturl}`);
|
||||
// return this.http.get<Tokenn[]>(`${geturl}`);
|
||||
}
|
||||
|
||||
requestPermissions() {
|
||||
PushNotifications.requestPermissions().then(result => {
|
||||
if (result.receive === 'granted') {
|
||||
// Register with Apple / Google to receive push via APNS/FCM
|
||||
PushNotifications.register();
|
||||
} else {
|
||||
// Show some error
|
||||
}
|
||||
});
|
||||
// PushNotifications.requestPermissions().then(result => {
|
||||
// if (result.receive === 'granted') {
|
||||
// // Register with Apple / Google to receive push via APNS/FCM
|
||||
// PushNotifications.register();
|
||||
// } else {
|
||||
// // Show some error
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
getAndpostToken(username) {
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
console.log('Notifications not supported')
|
||||
} else {
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
PushNotifications.addListener('registration',
|
||||
(token: Token) => {
|
||||
console.log('token: ', token.value)
|
||||
this.storageService.store(username, token.value);
|
||||
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.value,
|
||||
Status: 1,
|
||||
Service: 1
|
||||
};
|
||||
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
// console.log('Notifications not supported')
|
||||
// } else {
|
||||
// const geturl = environment.apiURL + 'notifications/token';
|
||||
// PushNotifications.addListener('registration',
|
||||
// (token: Token) => {
|
||||
// console.log('token: ', token.value)
|
||||
// this.storageService.store(username, token.value);
|
||||
// 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.value,
|
||||
// Status: 1,
|
||||
// Service: 1
|
||||
// };
|
||||
|
||||
this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
}, (error) => {
|
||||
console.log('Post token to backend', error)
|
||||
})
|
||||
});
|
||||
// this.http.post<Tokenn>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||
// console.log('TOKEN USER MIDLE', data);
|
||||
// }, (error) => {
|
||||
// console.log('Post token to backend', error)
|
||||
// })
|
||||
// });
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
registrationError() {
|
||||
PushNotifications.addListener('registrationError',
|
||||
(error: any) => {
|
||||
console.log('Error on registration: ' + JSON.stringify(error));
|
||||
}
|
||||
);
|
||||
// PushNotifications.addListener('registrationError',
|
||||
// (error: any) => {
|
||||
// console.log('Error on registration: ' + JSON.stringify(error));
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
onReciveForeground() {
|
||||
PushNotifications.addListener('pushNotificationReceived',
|
||||
(notification: PushNotificationSchema) => {
|
||||
console.log('Push received: ' + JSON.stringify(notification));
|
||||
this.DataArray.push(notification)
|
||||
console.log("On ReceiveNotification", this.DataArray)
|
||||
this.storageService.store("Notifications", this.DataArray)
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
}
|
||||
);
|
||||
// PushNotifications.addListener('pushNotificationReceived',
|
||||
// (notification: PushNotificationSchema) => {
|
||||
// console.log('Push received: ' + JSON.stringify(notification));
|
||||
// this.DataArray.push(notification)
|
||||
// console.log("On ReceiveNotification", this.DataArray)
|
||||
// this.storageService.store("Notifications", this.DataArray)
|
||||
// this.eventtrigger.publishSomeData({
|
||||
// notification: "recive"
|
||||
// })
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
onReciveBackground() {
|
||||
PushNotifications.addListener('pushNotificationActionPerformed',
|
||||
(notification: ActionPerformed) => {
|
||||
console.log('Push action performed: ' + JSON.stringify(notification));
|
||||
/* this.DataArray.push(notification.notification)
|
||||
console.log("On ReceiveNotification", this.DataArray)
|
||||
this.storageService.store("Notifications", this.DataArray)
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
}) */
|
||||
this.notificatinsRoutes(notification)
|
||||
}
|
||||
);
|
||||
// PushNotifications.addListener('pushNotificationActionPerformed',
|
||||
// (notification: ActionPerformed) => {
|
||||
// console.log('Push action performed: ' + JSON.stringify(notification));
|
||||
// /* this.DataArray.push(notification.notification)
|
||||
// console.log("On ReceiveNotification", this.DataArray)
|
||||
// this.storageService.store("Notifications", this.DataArray)
|
||||
// this.eventtrigger.publishSomeData({
|
||||
// notification: "recive"
|
||||
// }) */
|
||||
// this.notificatinsRoutes(notification)
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
tempClearArray() {
|
||||
@@ -175,51 +175,51 @@ export class NotificationsService {
|
||||
|
||||
notificatinsRoutes = (notification) => {
|
||||
|
||||
console.log('Push action performed 2222: ' + JSON.stringify(notification.data));
|
||||
// console.log('Push action performed 2222: ' + JSON.stringify(notification.data));
|
||||
|
||||
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
|
||||
console.log("Id Lenght", notification.notification.data.IdObject.length)
|
||||
this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expediente") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
|
||||
//this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
|
||||
this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
|
||||
// if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
|
||||
// console.log("Id Lenght", notification.notification.data.IdObject.length)
|
||||
// this.zone.run(() => this.router.navigate(['/home/agenda', notification.notification.data.IdObject, 'agenda']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expediente") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expediente', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "agenda" && notification.notification.data.Object === "event-list") {
|
||||
// //this.zone.run(() => this.router.navigate(['/home/gabinete-digital/event-list/approve-event',IdObject, 'agenda']));
|
||||
// this.zone.run(() => this.router.navigate(['/home/agenda/event-list/approve-event', notification.notification.data.IdObject, 'agenda']));
|
||||
|
||||
} else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
|
||||
// } else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos', notification.notification.data.IdObject, 'gabinete-digital'], { replaceUrl: true }));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "parecer") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "deferimento") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/pedidos', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "despachos-pr") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
|
||||
this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
|
||||
}
|
||||
else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
|
||||
this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/despachos-pr', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "accao") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/publications', notification.notification.data.IdObject]));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "accoes" && notification.notification.data.Object === "publicacao") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/publications/view-publications', notification.notification.data.FolderId, notification.data.IdObject]));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "diplomas-assinar") {
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
}
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/diplomas-assinar', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
// else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
|
||||
// this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RouteService } from './route.service';
|
||||
|
||||
describe('RouteService', () => {
|
||||
let service: RouteService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RouteService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NavigationEnd, Router, NavigationStart } from '@angular/router';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RouteService {
|
||||
|
||||
history: any = [];
|
||||
isGoBack = false;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
) {
|
||||
this.router.events.forEach((event) => {
|
||||
if (event instanceof NavigationEnd) {
|
||||
|
||||
const lastRoute = this.history.slice(-1)
|
||||
|
||||
if(event.url != lastRoute) {
|
||||
this.history.push(event.url)
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
window['RouteService'] = this
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url [string] incase no history to go back
|
||||
* @param option [Object] some options to the url
|
||||
*/
|
||||
goBack(url = null, option: object = {}) {
|
||||
if(this.history.length >= 2) {
|
||||
this.history.pop();
|
||||
const goTo = this.history.pop();
|
||||
this.isGoBack = true;
|
||||
this.router.navigate([goTo]);
|
||||
} else if(url) {
|
||||
this.goTo({url})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
goTo({url}) {
|
||||
this.router.navigate([url]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user