Files
doneit-web/src/app/pages/events/events.page.ts
T

409 lines
10 KiB
TypeScript
Raw Normal View History

2022-07-12 14:57:02 +01:00
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import { EventsService } from 'src/app/services/events.service';
2021-03-31 16:47:14 +01:00
import { NavigationExtras, Router } from '@angular/router';
import { ActivatedRoute, NavigationEnd } from '@angular/router';
2021-08-17 09:53:06 +01:00
import { ModalController, Platform } from '@ionic/angular';
2020-11-24 13:46:13 +01:00
import { EventDetailPage } from './event-detail/event-detail.page';
2021-01-04 10:37:13 +01:00
import { ProcessesService } from '../../services/processes.service';
2021-09-21 06:09:41 +01:00
import { ToDayEventStorage } from 'src/app/store/to-day-event-storage.service';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
2021-10-18 17:42:25 +01:00
import { BackgroundService } from 'src/app/services/background.service';
2023-03-04 07:21:33 +01:00
import { ThemeService } from 'src/app/services/theme.service';
2022-01-31 15:02:26 +01:00
import { Storage } from '@ionic/storage';
2022-03-30 15:08:23 +01:00
import { PermissionService } from 'src/app/services/permission.service';
2022-06-29 16:30:28 +01:00
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
import { ChangeProfileService } from 'src/app/services/change-profile.service';
2022-10-12 17:01:09 +01:00
import { SessionStore } from 'src/app/store/session.service';
2023-07-11 10:25:16 +01:00
import { TaskService } from 'src/app/services/task.service';
@Component({
selector: 'app-events',
templateUrl: './events.page.html',
styleUrls: ['./events.page.scss'],
})
export class EventsPage implements OnInit {
2020-08-21 16:18:37 +01:00
today = new Date();
2021-07-29 14:37:09 +01:00
2020-08-21 16:18:37 +01:00
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
2021-09-21 06:09:41 +01:00
customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
2020-08-21 16:18:37 +01:00
grettings = ["Bom dia", "Boa tarde", "Boa noite"];
2021-09-21 06:09:41 +01:00
greetting = '';
2020-08-21 16:18:37 +01:00
timeDate = this.today.getHours() + ":" + this.today.getMinutes();
2022-07-12 14:57:02 +01:00
2021-09-21 06:09:41 +01:00
segment: string;
public profile: string;
2021-01-05 13:58:15 +01:00
currentEvent: any;
2021-06-24 11:07:53 +01:00
maxSubjectLength = 30;
2020-11-20 10:55:51 +01:00
customText = false;
2021-09-21 06:09:41 +01:00
totalEvent = 0;
2021-08-31 09:00:33 +01:00
currentHoursMinutes: Date | string;
2020-08-28 11:45:50 +01:00
showLoader: boolean;
2021-07-29 14:37:09 +01:00
2021-09-21 06:09:41 +01:00
expedientList: any;
hideSearchBtn: boolean = false;
2021-07-20 19:22:56 +01:00
// shared data
toDayEventStorage = ToDayEventStorage
expedienteGdStore = ExpedienteGdStore
2021-09-15 10:48:32 +01:00
2021-09-29 16:47:58 +01:00
listToPresent = [];
2021-09-21 10:04:42 +01:00
expedienteTaskPipe = new ExpedienteTaskPipe()
2021-07-20 19:22:56 +01:00
2021-09-21 06:09:41 +01:00
@Output() openExpedientListPage: EventEmitter<any> = new EventEmitter<any>();
2021-03-31 13:52:40 +01:00
2022-12-21 11:05:05 +01:00
sessoStore = SessionStore;
2021-05-21 10:38:55 +01:00
2022-12-21 12:46:10 +01:00
showAgendaLoader = false
showCorrespondenciasLoader = false
2023-05-25 16:24:18 +01:00
loadingAllTask = false
2022-12-21 12:46:10 +01:00
2023-08-08 09:43:26 +01:00
agendaColor = ''
2023-06-10 14:17:41 +01:00
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Não lidos'
showSearch = true;
searchSubject: string = '';
AllProcess = []
ordinance: string = 'old'
2023-06-11 20:17:10 +01:00
listSubscription : {
delete(): void;
}
2023-06-10 14:17:41 +01:00
2021-06-10 23:24:42 +01:00
constructor(
2021-07-29 14:37:09 +01:00
private eventService: EventsService,
private router: Router,
public activatedRoute: ActivatedRoute,
2021-09-21 06:09:41 +01:00
private processes: ProcessesService,
private modalController: ModalController,
2021-08-17 09:53:06 +01:00
public platform: Platform,
2021-10-18 17:42:25 +01:00
private backgroundservice: BackgroundService,
2022-01-31 15:02:26 +01:00
public ThemeService: ThemeService,
2022-03-30 15:08:23 +01:00
private storage: Storage,
public p: PermissionService,
private changeProfileService: ChangeProfileService,
2023-04-17 14:11:30 +01:00
public TaskService: TaskService
2021-09-21 06:09:41 +01:00
) {
2023-05-25 16:24:18 +01:00
2022-12-22 12:45:26 +01:00
window['zipPhoneCallback'] = function (zipphone) {
var frame = document.getElementById('home-iframe');
if(frame) {
frame['contentWindow']['postMessage']({call:'cookies', value: { cookies: {} }});
}
}
2021-01-04 11:34:43 +01:00
2022-12-22 12:45:26 +01:00
this.changeProfileService.registerCallback(() => {
this.listToPresent = [];
})
2023-08-08 09:43:26 +01:00
if(this.agendaColor != "PR") {
this.agendaColor = "MDGPR"
}
2023-06-11 20:17:10 +01:00
}
ngAfterViewInit(): void {
this.loadAllTask();
this.listSubscription = this.TaskService.registerCallback({
2023-06-10 14:17:41 +01:00
id: import.meta.url,
funx:() => {
this.dynamicSearch()
}
})
2023-06-11 20:17:10 +01:00
this.dynamicSearch()
}
2023-06-10 14:17:41 +01:00
2023-06-11 20:17:10 +01:00
ngOnDestroy() {
this.listSubscription.delete()
2021-09-21 06:09:41 +01:00
}
2020-08-21 16:18:37 +01:00
ngOnInit() {
2021-08-18 12:52:51 +01:00
2022-12-22 12:45:26 +01:00
this.showGreeting();
2022-12-19 17:04:21 +01:00
2022-12-22 12:45:26 +01:00
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == '/home/events') {
2023-05-19 12:00:51 +01:00
this.getEventsFromLocalDb()
2022-12-22 12:45:26 +01:00
this.RefreshEvents();
setTimeout(() => {
this.LoadList();
}, 1500)
}
});
this.hideSearch();
2022-12-19 17:04:21 +01:00
2022-12-22 12:45:26 +01:00
this.backgroundservice.registerBackService('Online', () => {
this.showGreeting();
this.RefreshEvents();
this.LoadList();
this.hideSearch();
});
2021-10-18 17:42:25 +01:00
2021-07-30 14:11:19 +01:00
}
2023-06-10 14:17:41 +01:00
async dynamicSearch() {
const ordinance = this.ordinance
if(this.showSearch && this.searchSubject) {
const AllProcess = this.TaskService.AllProcess.filter((task) => {
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
subject = subject.toLowerCase();
return subject.includes(this.searchSubject.toLowerCase())
}).filter( task => this.TaskService.filter(task, this.filterName))
if(ordinance == this.ordinance) {
this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess)
}
} else {
const AllProcess = this.TaskService.AllProcess
if(ordinance == this.ordinance) {
this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess)
.filter( task => this.TaskService.filter(task, this.filterName))
}
}
}
2023-05-26 14:23:37 +01:00
async loadAllTask() {
this.loadingAllTask = true
await this.TaskService.LoadTask()
2023-06-11 20:17:10 +01:00
this.dynamicSearch()
2023-05-26 14:23:37 +01:00
this.loadingAllTask = false
}
2021-09-21 06:09:41 +01:00
hideSearch() {
2022-12-22 12:45:26 +01:00
if (this.router.url == '/home/events') {
this.hideSearchBtn = true;
}
}
2023-02-02 10:37:17 +01:00
doRefresh(event) {
if (event) {
setTimeout(() => {
2023-02-09 16:05:36 +01:00
try {
2023-03-04 07:21:33 +01:00
event?.target?.complete();
} catch(error) {}
2023-02-02 10:37:17 +01:00
}, 2000);
}
2023-05-26 14:23:37 +01:00
2022-12-22 12:45:26 +01:00
this.RefreshEvents();
this.LoadList();
2023-05-26 14:23:37 +01:00
this.loadAllTask();
}
2021-07-20 19:22:56 +01:00
onSegmentChange() {
2023-02-02 10:37:17 +01:00
this.RefreshEvents();
this.LoadList();
}
2021-08-17 09:53:06 +01:00
2021-07-20 19:22:56 +01:00
async RefreshEvents() {
2022-12-22 12:45:26 +01:00
2021-04-01 10:34:41 +01:00
this.currentEvent = "";
this.showLoader = true;
2022-12-21 12:46:10 +01:00
this.showAgendaLoader = true;
2021-02-10 03:26:26 +01:00
2021-02-09 15:39:39 +01:00
let date = new Date();
let month = date.getMonth() + 1;
let start = date.getFullYear() + "-" + month + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
let end = date.getFullYear() + "-" + month + "-" + date.getDate() + " 23:59:59";
2022-12-21 11:05:05 +01:00
if(SessionStore.user) {
let onwEvent:any = await this.eventService.getAllOwnEvents(start, end).catch((error) => {
2023-02-27 18:34:42 +01:00
this.showLoader = false;
2022-12-21 12:46:10 +01:00
this.showAgendaLoader = false;
2022-12-21 11:05:05 +01:00
console.error(error)
})
this.listToPresent = onwEvent;
2022-12-26 17:04:20 +01:00
if(onwEvent?.length) {
this.totalEvent = onwEvent.length;
}
2021-06-16 13:29:57 +01:00
2023-05-19 12:00:51 +01:00
this.storage.set('events', this.listToPresent)
2023-02-27 18:34:42 +01:00
}
2023-03-04 07:21:33 +01:00
2023-02-27 18:34:42 +01:00
this.showLoader = false;
this.showAgendaLoader = false;
}
2020-08-21 16:18:37 +01:00
2021-10-20 11:06:00 +01:00
2021-09-21 06:09:41 +01:00
getEventsFromLocalDb() {
2022-12-22 12:45:26 +01:00
let date = new Date();
let month = date.getMonth() + 1;
//date.setMonth(date.getMonth() + 1);
let dateToday = date.getFullYear() + "-" + month + "-" + date.getDate();
2023-05-19 12:00:51 +01:00
this.storage.get('events').then((events: any[] = []) => {
//
2022-12-22 12:45:26 +01:00
2023-05-19 12:00:51 +01:00
if(Array.isArray(events)) {
this.listToPresent = events
this.totalEvent = this.listToPresent.length
2023-05-19 15:02:02 +01:00
try {
this.currentEvent = this.listToPresent[0].Subject
} catch (error) {}
try {
this.currentHoursMinutes = this.listToPresent[0].StartDate
} catch (error) {}
2023-05-19 12:00:51 +01:00
}
//
})
2022-12-22 12:45:26 +01:00
2023-05-19 12:00:51 +01:00
this.showLoader = false;
2022-12-22 12:45:26 +01:00
2021-09-21 06:09:41 +01:00
}
2020-08-21 16:18:37 +01:00
2021-09-21 06:09:41 +01:00
showGreeting() {
2022-12-22 12:45:26 +01:00
if (this.today.getHours() >= 6 && this.today.getHours() < 12) {
this.greetting = this.grettings[0];
}
else if (this.today.getHours() >= 12 && this.today.getHours() < 18) {
this.greetting = this.grettings[1];
}
else /* if(this.today.getHours() < 6 && this.today.getHours() >= 18) */ {
this.greetting = this.grettings[2];
}
}
2021-09-21 06:09:41 +01:00
gotTo() {
2020-08-21 16:18:37 +01:00
this.router.navigate(['/home/events']);
}
2021-09-21 06:09:41 +01:00
changeProfile() {
2022-12-22 12:45:26 +01:00
if (this.profile == "mdgpr") {
//
this.profile = "pr";
this.RefreshEvents();
}
else {
//
this.profile = "mdgpr";
this.RefreshEvents();
}
2020-08-28 15:28:38 +01:00
}
2021-09-21 06:09:41 +01:00
async openEventDetail1(id: any) {
2022-04-28 09:32:27 +01:00
//
2021-07-29 14:37:09 +01:00
2020-11-24 13:46:13 +01:00
const modal = await this.modalController.create({
component: EventDetailPage,
2021-09-21 06:09:41 +01:00
componentProps: {
2020-11-24 13:46:13 +01:00
eventId: id,
},
cssClass: 'event-detail',
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2020-11-24 13:46:13 +01:00
modal.onDidDismiss();
2023-07-15 11:01:09 +01:00
await modal.present();
2020-11-24 13:46:13 +01:00
}
2022-06-29 16:30:28 +01:00
async openEventDetail(id: any) {
//
const modal = await this.modalController.create({
component: ViewEventPage,
componentProps: {
eventId: id,
},
cssClass: 'view-event',
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2022-06-29 16:30:28 +01:00
modal.onDidDismiss();
2023-07-15 11:01:09 +01:00
await modal.present();
2022-06-29 16:30:28 +01:00
}
2023-06-05 10:14:48 +01:00
firstEnter = false
2021-07-20 19:22:56 +01:00
LoadList() {
2023-06-05 10:14:48 +01:00
if(this.firstEnter) {
this.showCorrespondenciasLoader = true
2022-04-19 17:10:08 +01:00
2023-08-10 16:46:55 +01:00
this.getEventsFromLocalDb();
2023-06-05 10:14:48 +01:00
}
this.firstEnter = true
2023-08-08 16:32:57 +01:00
if(window['all-process-gabinete']) {
window['all-process-gabinete']()
}
2023-06-05 10:14:48 +01:00
}
2021-01-19 08:52:43 +01:00
2021-09-21 06:09:41 +01:00
sortArrayISODate(myArray: any) {
return myArray.sort(function (a, b) {
2021-01-19 08:52:43 +01:00
return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0);
});
}
2021-01-19 16:44:39 +01:00
2022-12-17 16:19:23 +01:00
goToEvent(event: any) {
let navigationExtras: NavigationExtras = { queryParams: { CalendarId: event.CalendarId } }
this.router.navigate(['/home/events', event.EventId, 'agenda'], navigationExtras);
2021-01-31 16:14:42 +01:00
}
2023-04-17 14:57:08 +01:00
goToAllTaskFilter(event: any) {
let navigationExtras: NavigationExtras = { queryParams: {
filter: event,
processes: true
} }
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2021-05-24 11:37:50 +01:00
2021-09-29 16:47:58 +01:00
viewExpedientListPage() {
2022-10-13 14:50:52 +01:00
2022-12-21 16:19:06 +01:00
if (this.sessoStore.user.Profile == 'PR') {
2021-09-29 16:47:58 +01:00
if (window.innerWidth < 701) {
2022-10-13 14:50:52 +01:00
this.router.navigate(['/home/gabinete-digital/expedientes-pr']);
2021-07-01 15:53:48 +01:00
}
2021-09-21 06:09:41 +01:00
else {
2022-10-13 14:50:52 +01:00
let navigationExtras: NavigationExtras = { queryParams: { "expedientes-pr": true, } };
2021-07-01 15:53:48 +01:00
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2022-10-13 14:50:52 +01:00
} else {
2022-10-13 15:09:58 +01:00
2021-09-29 16:47:58 +01:00
if (window.innerWidth < 701) {
2022-10-13 14:50:52 +01:00
this.router.navigate(['/home/gabinete-digital/expediente']);
2021-07-01 15:53:48 +01:00
}
2021-09-21 06:09:41 +01:00
else {
2022-10-13 14:50:52 +01:00
let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } };
2021-07-01 15:53:48 +01:00
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2021-03-31 13:52:40 +01:00
}
}
2021-07-29 14:37:09 +01:00
2022-12-22 11:01:58 +01:00
}