Files
doneit-web/src/app/home/home.page.ts
T

281 lines
8.9 KiB
TypeScript
Raw Normal View History

2021-02-10 11:46:43 +01:00
import { Component, OnInit, NgZone } from '@angular/core';
2020-09-08 11:17:07 +01:00
import { EventsService } from '../services/events.service';
import { formatDate } from '@angular/common';
import { Event } from '../models/event.model';
2020-09-08 11:25:00 +01:00
import { ProcessesService } from '../services/processes.service';
2021-01-26 17:00:41 +01:00
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';
2021-02-01 16:29:11 +01:00
import { ExpedienteDetailPage } from '../../app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page'
2021-02-10 11:46:43 +01:00
import { ViewEventPage } from '../../app/pages/agenda/view-event/view-event.page'
import { ApproveEventModalPage } from '../../app/pages/gabinete-digital/event-list/approve-event-modal/approve-event-modal.page';
2020-08-05 15:39:16 +01:00
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core';
2021-01-26 17:00:41 +01:00
import { Router } from '@angular/router';
import { MethodCall } from '@angular/compiler';
2021-01-20 17:00:56 +01:00
2021-02-03 15:13:23 +01:00
const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugins;
2021-01-20 17:00:56 +01:00
2020-08-05 15:39:16 +01:00
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
2020-09-08 11:17:07 +01:00
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
2021-01-26 17:00:41 +01:00
totalEvent = 0;
totalExpediente = 0;
profile: string;
2020-08-05 15:39:16 +01:00
2021-02-10 11:46:43 +01:00
constructor(private ngZone: NgZone,private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController,) { }
2020-08-05 15:39:16 +01:00
ngOnInit() {
//Initialize profile as mdgpr
2021-02-10 13:51:39 +01:00
let date = new Date();
date.setMonth(date.getMonth() + 1);
let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds();
let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59";
2020-11-26 09:04:22 +01:00
this.profile = "mdgpr";
2021-01-26 17:00:41 +01:00
if (this.profile == "mdgpr") {
2021-02-10 13:51:39 +01:00
this.eventService.getAllMdEvents(start, end).subscribe(res => {
this.eventsList = res;
this.totalEvent = this.eventsList.length;
2021-01-26 17:00:41 +01:00
});
}
2021-01-26 17:00:41 +01:00
else {
2021-02-10 13:51:39 +01:00
this.eventService.getAllPrEvents(start, end).subscribe(res => {
2020-11-24 15:01:16 +01:00
this.eventsList = res;
this.totalEvent = this.eventsList.length;
2021-01-26 17:00:41 +01:00
});
}
2021-01-26 17:00:41 +01:00
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
this.totalExpediente = result;
});
2021-01-26 17:00:41 +01:00
/*
(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)) */
2020-08-05 15:39:16 +01:00
2021-02-10 11:46:43 +01:00
PushNotifications.addListener('registrationError', (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
2021-01-26 17:00:41 +01:00
2021-02-10 11:46:43 +01:00
PushNotifications.addListener('pushNotificationReceived', notification => {
2021-02-08 11:22:36 +01:00
//const isPushNotification = !!notification.title || !!notification.body;
// if this is a push notification received when the app is in the foreground on Android
//if (isAndroid && isPushNotification) {
// We schedule a LocalNotification 1 second later since Capacitor for Android doesn't show anything in this case
2021-02-10 11:46:43 +01:00
console.log('Recived: ', notification)
2021-02-08 11:22:36 +01:00
//}
2021-02-10 11:46:43 +01:00
});
2021-02-08 11:22:36 +01:00
2021-01-26 17:00:41 +01:00
2021-02-10 11:46:43 +01:00
PushNotifications.addListener(
2021-01-20 17:00:56 +01:00
'pushNotificationActionPerformed',
(notification: PushNotificationActionPerformed) => {
2021-02-10 11:46:43 +01:00
let service = notification.notification.data.Service;
let object = notification.notification.data.Object;
let idObject = notification.notification.data.IdObject;
console.log('Complete Object: ', notification.notification )
2021-01-26 17:00:41 +01:00
2021-02-04 09:01:58 +01:00
console.log('Service: ', service);
console.log('Object: ', object);
console.log('idObject: ', idObject);
/* 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]);
// }
2021-01-26 17:00:41 +01:00
2021-02-03 15:13:23 +01:00
//if (service != null) {
2021-01-26 17:00:41 +01:00
2021-02-08 11:22:36 +01:00
/*const routeValue = {
"agenda": this.router.navigate(['/home/', service, idObject, 'home']),
"gabinete-digital": this.router.navigate(['/home/', service]),
"accoes": this.viewExpedientDetail(idObject),
}
const route = routeValue[service] && object ;
service = "agenda" ? this.router.navigate(['/home/', service, idObject, 'home']) : */
2021-02-10 11:46:43 +01:00
if (service === "agenda") {
//this.router.navigate(['/home/', service, idObject, 'home']);
this.viewEventDetail(idObject)
2021-02-10 18:02:37 +01:00
}
else if (service === "gabinete-digital" && object === "expediente") {
2021-02-01 16:29:11 +01:00
this.viewExpedientDetail(idObject)
2021-02-10 18:02:37 +01:00
}
else if (service === "gabinete-digital" && object === "event-list") {
2021-02-10 11:46:43 +01:00
/* this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])}) */
this.openApproveModal(idObject);
2021-02-10 18:02:37 +01:00
}
else if (service === "accoes" && object === "accao") {
2021-02-03 15:13:23 +01:00
this.viewPublications(idObject)
2021-02-10 18:02:37 +01:00
}
else if (service === "accoes" && object === "publicacao") {
2021-02-03 15:13:23 +01:00
this.viewPublicationDetail(idObject)
}
2021-02-10 11:46:43 +01:00
2021-01-26 17:00:41 +01:00
/*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/']);
}*/
2021-02-10 11:46:43 +01:00
},
);
2021-01-26 17:00:41 +01:00
}
2021-02-10 11:46:43 +01:00
async localNotificationPresent(notification) {
2021-02-03 15:13:23 +01:00
LocalNotificationAction.
LocalNotifications.schedule({
notifications: [
{
title: notification.title,
body: notification.body,
id: 1,
schedule: { at: new Date(Date.now() + 1000) },
sound: null,
attachments: null,
actionTypeId: "",
2021-02-03 15:13:23 +01:00
extra: null,
foreground: true,
}
]
});
2021-02-10 11:46:43 +01:00
}
async openApproveModal(eventSerialNumber){
const modal = await this.modalController.create({
component: ApproveEventModalPage,
componentProps:{
serialNumber: eventSerialNumber,
},
cssClass: 'cal-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async viewEventDetail(eventId:any) {
console.log(this.profile);
const modal = await this.modalController.create({
component: ViewEventPage,
componentProps:{
eventId: eventId,
},
cssClass: 'modal',
backdropDismiss: false
});
await modal.present();
2021-02-10 13:51:39 +01:00
modal.onDidDismiss();
2021-02-10 11:46:43 +01:00
}
2021-02-10 11:46:43 +01:00
async viewExpedientDetail(serialNumber:any) {
2021-02-01 16:29:11 +01:00
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();
2021-02-10 13:51:39 +01:00
modal.onDidDismiss();
2021-02-01 16:29:11 +01:00
}
2021-02-03 15:13:23 +01:00
async viewPublicationDetail(folderId) {
2021-01-26 17:00:41 +01:00
const modal = await this.modalController.create({
component: PublicationDetailPage,
componentProps: {
2021-02-03 15:13:23 +01:00
folderId: folderId,
2021-01-26 17:00:41 +01:00
},
cssClass: 'publication-detail',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
2021-02-03 15:13:23 +01:00
async viewPublications(folderId) {
2021-01-26 17:00:41 +01:00
const modal = await this.modalController.create({
component: ViewPublicationsPage,
/* enterAnimation,
leaveAnimation, */
2021-02-10 11:46:43 +01:00
componentProps: {
item: folderId,
2021-01-26 17:00:41 +01:00
},
cssClass: 'new-action',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
2021-02-10 11:46:43 +01:00
}
}