mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
224 lines
7.0 KiB
TypeScript
224 lines
7.0 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { EventsService } from '../services/events.service';
|
|
import { formatDate } from '@angular/common';
|
|
import { Event } from '../models/event.model';
|
|
import { ProcessesService } from '../services/processes.service';
|
|
import { StorageService } from 'src/app/services/storage.service';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { PublicationDetailPage } from '../../app/pages/publications/view-publications/publication-detail/publication-detail.page';
|
|
import { ViewPublicationsPage } from '../../app/pages/publications/view-publications/view-publications.page';
|
|
import { ExpedienteDetailPage } from '../../app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page'
|
|
|
|
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core';
|
|
import { Router } from '@angular/router';
|
|
import { MethodCall } from '@angular/compiler';
|
|
|
|
const { PushNotifications, LocalNotifications } = Plugins;
|
|
|
|
@Component({
|
|
selector: 'app-home',
|
|
templateUrl: './home.page.html',
|
|
styleUrls: ['./home.page.scss'],
|
|
})
|
|
export class HomePage implements OnInit {
|
|
eventsList: Event[];
|
|
prEventList: Event[];
|
|
mdEventList: Event[];
|
|
|
|
totalEvent = 0;
|
|
totalExpediente = 0;
|
|
profile: string;
|
|
|
|
constructor(private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController,) { }
|
|
|
|
ngOnInit() {
|
|
//Initialize profile as mdgpr
|
|
this.profile = "mdgpr";
|
|
if (this.profile == "mdgpr") {
|
|
this.eventService.getAllMdEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
|
|
this.eventsList = res;
|
|
this.totalEvent = this.eventsList.length;
|
|
});
|
|
}
|
|
else {
|
|
this.eventService.getAllPrEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
|
|
this.eventsList = res;
|
|
this.totalEvent = this.eventsList.length;
|
|
});
|
|
|
|
}
|
|
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
|
|
this.totalExpediente = result;
|
|
});
|
|
/*
|
|
(PushNotifications as any).requestPermission().then(result => {
|
|
PushNotifications.register();
|
|
});
|
|
|
|
PushNotifications.addListener(
|
|
'registration',
|
|
(token: PushNotificationToken) => {
|
|
alert('Push registration success, token: ' + token.value);
|
|
console.log('FIREBASE: ', token.value)
|
|
this.storageService.store(this.username,token.value);
|
|
},
|
|
);
|
|
|
|
console.log(this.storageService.get(this.username)) */
|
|
|
|
PushNotifications.addListener('registrationError', (error: any) => {
|
|
alert('Error on registration: ' + JSON.stringify(error));
|
|
});
|
|
|
|
PushNotifications.addListener(
|
|
'pushNotificationReceived',
|
|
(notification: PushNotification) => {
|
|
//alert('Push received: ' + JSON.stringify(notification));
|
|
//this.localNotificationPresent(notification);
|
|
|
|
},
|
|
);
|
|
|
|
PushNotifications.addListener(
|
|
'pushNotificationActionPerformed',
|
|
(notification: PushNotificationActionPerformed) => {
|
|
let service = notification.notification.data.service;
|
|
|
|
let object = notification.notification.data.object;
|
|
let idObject = notification.notification.data.idObject;
|
|
let folder = notification.notification.data.folder;
|
|
let publicationId = notification.notification.data.publicationId;
|
|
let processId = notification.notification.data.processId;
|
|
|
|
console.log('FOLDER PROCESS', folder.ProcessId)
|
|
|
|
if (service != null) {
|
|
|
|
if (service === "events") {
|
|
this.router.navigate(['/home/', service, idObject, 'home']);
|
|
} else if (service === "agenda") {
|
|
this.router.navigate(['/home/', service, idObject, 'home']);
|
|
} else if (service === "gabinete-digital" && object != "expediente") {
|
|
this.router.navigate(['/home/', service]);
|
|
} else if (service === "gabinete-digital" && object === "expediente") {
|
|
this.viewExpedientDetail(idObject)
|
|
}
|
|
} else {
|
|
|
|
if (processId || publicationId != null) {
|
|
this.viewPublicationDetail(processId, publicationId)
|
|
}
|
|
|
|
if (notification.notification.data.folder.ProcessId != null) {
|
|
this.viewPublications(folder)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*switch (service) {
|
|
case "events":
|
|
this.router.navigate(['/home/', service, idObject, 'home']);
|
|
break;
|
|
case "agenda":
|
|
this.router.navigate(['/home/', service, idObject, 'home']);
|
|
break;
|
|
case "gabinete-digital":
|
|
this.router.navigate(['/home/', service]);
|
|
break;
|
|
case "gabinete-digital-expediente":
|
|
this.router.navigate(['/home/gabinete-digital/', object, idObject, 'home']);
|
|
break;
|
|
case "": {
|
|
|
|
if(publicationId && processId != null) {
|
|
this.viewPublicationDetail(publicationId,processId)
|
|
}
|
|
if (folder.ProcessId != null) {
|
|
this.viewPublications(folder)
|
|
}
|
|
}
|
|
|
|
default:
|
|
this.router.navigate(['/home/']);
|
|
}*/
|
|
|
|
|
|
|
|
},
|
|
);
|
|
}
|
|
|
|
async localNotificationPresent(notification) {
|
|
|
|
LocalNotifications.schedule({
|
|
notifications: [
|
|
{
|
|
title: notification.title,
|
|
body: notification.body,
|
|
id: 1,
|
|
schedule: { at: new Date(Date.now() + 1000) },
|
|
sound: null,
|
|
attachments: null,
|
|
actionTypeId: "",
|
|
extra: null
|
|
}
|
|
]
|
|
});
|
|
}
|
|
|
|
async viewExpedientDetail(serialNumber:any) {
|
|
console.log(this.profile);
|
|
|
|
const modal = await this.modalController.create({
|
|
component: ExpedienteDetailPage,
|
|
componentProps:{
|
|
serialNumber: serialNumber,
|
|
profile: this.profile,
|
|
},
|
|
cssClass: 'modal',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss().then((res)=>{
|
|
if(res){
|
|
console.log(res);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
async viewPublicationDetail(processId: string, publicationId: string) {
|
|
const modal = await this.modalController.create({
|
|
component: PublicationDetailPage,
|
|
componentProps: {
|
|
publicationId: publicationId,
|
|
folderId: processId,
|
|
},
|
|
cssClass: 'publication-detail',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
async viewPublications(folder) {
|
|
|
|
const modal = await this.modalController.create({
|
|
component: ViewPublicationsPage,
|
|
/* enterAnimation,
|
|
leaveAnimation, */
|
|
componentProps: {
|
|
item: folder,
|
|
},
|
|
cssClass: 'new-action',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
modal.onDidDismiss();
|
|
}
|
|
|
|
}
|