update home ts

This commit is contained in:
tiago.kayaya
2021-02-10 11:46:43 +01:00
parent 9396e01464
commit e15506c8b4
+73 -46
View File
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, NgZone } from '@angular/core';
import { EventsService } from '../services/events.service';
import { formatDate } from '@angular/common';
import { Event } from '../models/event.model';
@@ -8,6 +8,8 @@ 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 { 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';
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core';
import { Router } from '@angular/router';
@@ -21,9 +23,6 @@ const { PushNotifications, LocalNotifications, LocalNotificationAction } = Plugi
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
today = new Date();
todayEnd = new Date();
eventsList: Event[];
prEventList: Event[];
mdEventList: Event[];
@@ -32,19 +31,19 @@ export class HomePage implements OnInit {
totalExpediente = 0;
profile: string;
constructor(private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController,) { }
constructor(private ngZone: NgZone,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(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
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(this.today.toLocaleString(), this.todayEnd.toLocaleString()).subscribe(res => {
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;
});
@@ -53,10 +52,6 @@ export class HomePage implements OnInit {
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
this.totalExpediente = result;
});
}
}
/*
(PushNotifications as any).requestPermission().then(result => {
PushNotifications.register();
@@ -73,11 +68,11 @@ export class HomePage implements OnInit {
console.log(this.storageService.get(this.username)) */
/* PushNotifications.addListener('registrationError', (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
}); */
PushNotifications.addListener('registrationError', (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
/* PushNotifications.addListener('pushNotificationReceived', notification => {
PushNotifications.addListener('pushNotificationReceived', notification => {
//const isPushNotification = !!notification.title || !!notification.body;
@@ -85,28 +80,19 @@ export class HomePage implements OnInit {
//if (isAndroid && isPushNotification) {
// We schedule a LocalNotification 1 second later since Capacitor for Android doesn't show anything in this case
LocalNotifications.schedule({
notifications: [{
title: notification.title,
body: notification.body,
id: new Date().getUTCMilliseconds(),
schedule: {
at: new Date(Date.now() + 1000)
},
extra: notification.data,
channelId: 'pop-notifications'
}]
});
console.log('Recived: ', notification)
//}
}); */
});
/* PushNotifications.addListener(
PushNotifications.addListener(
'pushNotificationActionPerformed',
(notification: PushNotificationActionPerformed) => {
let service = notification.notification.data.service;
let object = notification.notification.data.object;
let idObject = notification.notification.data.idObject;
let service = notification.notification.data.Service;
let object = notification.notification.data.Object;
let idObject = notification.notification.data.IdObject;
console.log('Complete Object: ', notification.notification )
console.log('Service: ', service);
console.log('Object: ', object);
@@ -133,18 +119,22 @@ export class HomePage implements OnInit {
service = "agenda" ? this.router.navigate(['/home/', service, idObject, 'home']) : */
/* if (service === "agenda") {
this.router.navigate(['/home/', service, idObject, 'home']);
} else if (service === "gabinete-digital" && object != "expediente") {
this.router.navigate(['/home/', service]);
if (service === "agenda") {
//this.router.navigate(['/home/', service, idObject, 'home']);
this.viewEventDetail(idObject)
} else if (service === "gabinete-digital" && object != "expediente" || object != "event-list") {
this.router.navigate(['/home/gabinete-digital']);
} else if (service === "gabinete-digital" && object === "expediente") {
this.viewExpedientDetail(idObject)
} else if (service === "gabinete-digital" && object === "event-list") {
/* this.ngZone.run(() => {this.router.navigate(['/home/gabinete-digital/event-list', idObject])}) */
this.openApproveModal(idObject);
} else if (service === "accoes" && object === "accao") {
this.viewPublications(idObject)
} else if (service === "accoes" && object === "publicacao") {
this.viewPublicationDetail(idObject)
}
*/
@@ -177,11 +167,11 @@ export class HomePage implements OnInit {
/* },
);
},
);
}
*/
/* async localNotificationPresent(notification) {
async localNotificationPresent(notification) {
LocalNotificationAction.
@@ -200,9 +190,44 @@ export class HomePage implements OnInit {
}
]
});
} */
}
/* async viewExpedientDetail(serialNumber:any) {
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();
modal.onDidDismiss().then((res)=>{
if(res){
console.log(res);
//this.loadRangeEvents(this.rangeStartDate, this.rangeEndDate);
}
});
}
async viewExpedientDetail(serialNumber:any) {
console.log(this.profile);
const modal = await this.modalController.create({
@@ -244,12 +269,14 @@ export class HomePage implements OnInit {
component: ViewPublicationsPage,
/* enterAnimation,
leaveAnimation, */
/* componentProps: { */
/* item: folderId,
componentProps: {
item: folderId,
},
cssClass: 'new-action',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
} */
}
}