mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Notification code Refactory
This commit is contained in:
+15
-23
@@ -3,6 +3,7 @@ import { Component, OnInit, NgZone } from '@angular/core';
|
|||||||
import { EventsService } from '../services/events.service';
|
import { EventsService } from '../services/events.service';
|
||||||
import { Event } from '../models/event.model';
|
import { Event } from '../models/event.model';
|
||||||
import { ProcessesService } from '../services/processes.service';
|
import { ProcessesService } from '../services/processes.service';
|
||||||
|
import { NotificationsService } from '../services/notifications.service';
|
||||||
import { ModalController, AlertController, AnimationController } from '@ionic/angular';
|
import { ModalController, AlertController, AnimationController } from '@ionic/angular';
|
||||||
//import { AlertController } from 'ionic-angular';
|
//import { AlertController } from 'ionic-angular';
|
||||||
/* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core'; */
|
/* import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core'; */
|
||||||
@@ -52,7 +53,15 @@ export class HomePage implements OnInit {
|
|||||||
postEvent: any;
|
postEvent: any;
|
||||||
folderId: string;
|
folderId: string;
|
||||||
|
|
||||||
constructor(private zone: NgZone, private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController, public modalCtrl: AlertController, private fcm: FCM, private animationController: AnimationController,) {
|
constructor(private zone: NgZone,
|
||||||
|
private eventService: EventsService,
|
||||||
|
private processesbackend: ProcessesService,
|
||||||
|
private router: Router,
|
||||||
|
private modalController: ModalController,
|
||||||
|
public modalCtrl: AlertController,
|
||||||
|
private fcm: FCM,
|
||||||
|
private animationController: AnimationController,
|
||||||
|
private notificatinsservice: NotificationsService,) {
|
||||||
|
|
||||||
router.events.subscribe((val) => {
|
router.events.subscribe((val) => {
|
||||||
document.querySelectorAll('ion-modal').forEach((e) => e.remove())
|
document.querySelectorAll('ion-modal').forEach((e) => e.remove())
|
||||||
@@ -66,7 +75,7 @@ export class HomePage implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
this.pushCordova()
|
this.pushCordova();
|
||||||
/* //Initialize profile as mdgpr
|
/* //Initialize profile as mdgpr
|
||||||
|
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
@@ -94,7 +103,6 @@ export class HomePage implements OnInit {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
pushCordova() {
|
pushCordova() {
|
||||||
|
|
||||||
this.fcm.onNotification().subscribe(data => {
|
this.fcm.onNotification().subscribe(data => {
|
||||||
@@ -128,29 +136,13 @@ export class HomePage implements OnInit {
|
|||||||
console.log(data.Service)
|
console.log(data.Service)
|
||||||
console.log(data.Object)
|
console.log(data.Object)
|
||||||
console.log(data.IdObject)
|
console.log(data.IdObject)
|
||||||
this.openApproveModal(data.IdObject);
|
//this.openApproveModal(data.IdObject);
|
||||||
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.fcm.onTokenRefresh().subscribe(token => {
|
|
||||||
// Register your new token in your back-end if you want
|
|
||||||
// backend.registerToken(token);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ubscribeToTopic() {
|
|
||||||
this.fcm.subscribeToTopic('enappd');
|
|
||||||
}
|
|
||||||
getToken() {
|
|
||||||
this.fcm.getToken().then(token => {
|
|
||||||
console.log('token: ', token)
|
|
||||||
// Register your new token in your back-end if you want
|
|
||||||
// backend.registerToken(token);
|
|
||||||
});
|
|
||||||
} */
|
|
||||||
|
|
||||||
async viewEventDetail(eventId: any) {
|
async viewEventDetail(eventId: any) {
|
||||||
console.log(this.profile);
|
console.log(this.profile);
|
||||||
|
|
||||||
@@ -200,8 +192,8 @@ export class HomePage implements OnInit {
|
|||||||
} else {
|
} else {
|
||||||
classs = 'modal modal-desktop showAsideOptions'
|
classs = 'modal modal-desktop showAsideOptions'
|
||||||
}
|
}
|
||||||
/* console.log(this.profile);
|
console.log(this.profile);
|
||||||
console.log(serialNumber); */
|
console.log(serialNumber);
|
||||||
console.log('expediante 2')
|
console.log('expediante 2')
|
||||||
const modal = await this.modalController.create({
|
const modal = await this.modalController.create({
|
||||||
component: ExpedienteDetailPage,
|
component: ExpedienteDetailPage,
|
||||||
@@ -231,7 +223,7 @@ export class HomePage implements OnInit {
|
|||||||
});
|
});
|
||||||
await modal.present();
|
await modal.present();
|
||||||
modal.onDidDismiss().then(() => {
|
modal.onDidDismiss().then(() => {
|
||||||
//this.getPublications();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,28 +81,7 @@ export class LoginPage implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getToken() {
|
getToken() {
|
||||||
this.fcm.getToken().then(token => {
|
this.notificatinsservice.getAndpostToken(this.username)
|
||||||
console.log('token: ', token)
|
|
||||||
this.storageService.store(this.username, token);
|
|
||||||
this.storageService.get(this.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
|
|
||||||
};
|
|
||||||
|
|
||||||
this.http.post<Token>('https://equilibrium.dyndns.info/GabineteDigital.Services/V4/api/notifications/token', body, { headers }).subscribe(data => {
|
|
||||||
console.log('TOKEN USER MIDLE', data);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,42 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
import { environment } from 'src/environments/environment';
|
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 { 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 } 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';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class NotificationsService {
|
export class NotificationsService {
|
||||||
|
|
||||||
constructor(private http: HttpClient,) { }
|
adding: "intervenient" | "CC" = "intervenient";
|
||||||
|
folderId: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: HttpClient,
|
||||||
|
private fcm: FCM,
|
||||||
|
private storageService: StorageService,
|
||||||
|
private modalController: ModalController,
|
||||||
|
public modalCtrl: AlertController,
|
||||||
|
private animationController: AnimationController,/* ,
|
||||||
|
public agenda: AgendaPage,
|
||||||
|
public expediante: ExpedientePage,
|
||||||
|
public eventList: EventListPage,
|
||||||
|
public publication: PublicationsPage,
|
||||||
|
public viewPublication: ViewPublicationsPage */) { }
|
||||||
|
|
||||||
getTokenByUserIdAndId(user, userID) {
|
getTokenByUserIdAndId(user, userID) {
|
||||||
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||||
@@ -16,15 +44,186 @@ export class NotificationsService {
|
|||||||
return this.http.get<Token[]>(`${geturl}`);
|
return this.http.get<Token[]>(`${geturl}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
postToken(userId, token) {
|
getAndpostToken(username) {
|
||||||
const geturl = environment.apiURL + 'notifications/token';
|
const geturl = environment.apiURL + 'notifications/token';
|
||||||
|
|
||||||
let data = {
|
return this.fcm.getToken().then(token => {
|
||||||
UserId: userId,
|
console.log('token: ', token)
|
||||||
TokenId: token,
|
this.storageService.store(username, token);
|
||||||
Status: 1,
|
this.storageService.get(username).then(value => {
|
||||||
Service: 2
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
this.http.post<Token>(`${geturl}`, body, { headers }).subscribe(data => {
|
||||||
|
console.log('TOKEN USER MIDLE', data);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async onReceviNotification(viewEventDetail,viewExpedientDetail,openApproveModal,viewPublications,viewPublicationDetail) {
|
||||||
|
this.fcm.onNotification().subscribe(data => {
|
||||||
|
if (data.click_action) {
|
||||||
|
console.log("Received in background: ", 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* else {
|
||||||
|
console.log("Received in foreground: ", data);
|
||||||
|
|
||||||
|
console.log(data.Service)
|
||||||
|
console.log(data.Object)
|
||||||
|
console.log(data.IdObject)
|
||||||
|
this.openApproveModal(data.IdObject);
|
||||||
|
|
||||||
|
}; */
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
}
|
}
|
||||||
return this.http.post<Token[]>(`${geturl}`,data);
|
|
||||||
|
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'
|
||||||
|
} 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user