mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
273 lines
7.1 KiB
TypeScript
273 lines
7.1 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
import { ProcessesService } from 'src/app/services/processes.service';
|
|
import { ModalController } from '@ionic/angular';
|
|
import { ApproveEventModalPage } from './approve-event-modal/approve-event-modal.page';
|
|
import { NavigationStart, Router } from '@angular/router';
|
|
import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.service';
|
|
import { TaskService } from 'src/app/services/task.service'
|
|
import { BackgroundService } from '../../../services/background.service';
|
|
import { SortService } from 'src/app/services/functions/sort.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { RouteService } from 'src/app/services/route.service';
|
|
import { EventsService } from 'src/app/services/events.service';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { environment } from 'src/environments/environment';
|
|
|
|
@Component({
|
|
selector: 'app-event-list',
|
|
templateUrl: './event-list.page.html',
|
|
styleUrls: ['./event-list.page.scss'],
|
|
})
|
|
export class EventListPage implements OnInit {
|
|
// [desktop] event list to approve
|
|
|
|
profile: string;
|
|
segment: any;
|
|
showLoader: boolean;
|
|
eventPerson: EventPerson;
|
|
eventBody: EventBody;
|
|
categories: string[];
|
|
serialnumber: string;
|
|
|
|
skeletonLoader = true
|
|
eventoaprovacaostore = EventoAprovacaoStore;
|
|
color: 'pr' | 'mdgpr'
|
|
environment = environment
|
|
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
|
|
showFilter = false
|
|
|
|
showSearch = false
|
|
searchSubject = ''
|
|
list = []
|
|
ordinance: string = 'old'
|
|
|
|
listSubscription : {
|
|
delete(): void;
|
|
}
|
|
|
|
constructor(
|
|
private processes: ProcessesService,
|
|
private modalController: ModalController,
|
|
private router: Router,
|
|
private sortService: SortService,
|
|
private backgroundservice: BackgroundService,
|
|
public ThemeService: ThemeService,
|
|
private RouteService: RouteService,
|
|
public eventService: EventsService,
|
|
public TaskService: TaskService,
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
|
|
if(window.location.pathname.includes('gabinete-digital')) {
|
|
this.showFilter = true
|
|
}
|
|
|
|
|
|
this.eventService.onCalendarFinishLoad.subscribe(() => {
|
|
if(!this.segment) {
|
|
if(this.eventService.calendarNamesAry.includes('Meu calendario')) {
|
|
this.segment = 'Meu calendario';
|
|
} else {
|
|
this.segment = this.eventService.calendarNamesAry[0].OwnerUserId
|
|
}
|
|
|
|
// select pr by default
|
|
const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')
|
|
if(pr) {
|
|
this.segment = pr.OwnerUserId
|
|
}
|
|
}
|
|
})
|
|
|
|
this.listSubscription = this.eventoaprovacaostore.registerCallback({
|
|
id: import.meta.url,
|
|
funx:() => {
|
|
|
|
this.dynamicSearch()
|
|
|
|
}
|
|
})
|
|
|
|
|
|
|
|
const location = window.location
|
|
const pathname = location.pathname + location.search
|
|
|
|
this.LoadToApproveEvents()
|
|
|
|
this.router.events.forEach((event) => {
|
|
if (event instanceof NavigationStart && event.url.startsWith(pathname)) {
|
|
if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
|
|
this.refreshing()
|
|
} else {
|
|
this.LoadToApproveEvents()
|
|
}
|
|
}
|
|
});
|
|
|
|
this.backgroundservice.registerBackService('Online', () => {
|
|
this.LoadToApproveEvents();
|
|
});
|
|
|
|
window.onresize = (event) => {
|
|
// if not mobile remove all component
|
|
if (window.innerWidth < 701) {
|
|
this.modalController.dismiss();
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
|
|
ngOnDestroy() {
|
|
this.listSubscription.delete()
|
|
}
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
|
|
}
|
|
|
|
reorderList(orderBy: string) {
|
|
|
|
this.ordinance = orderBy;
|
|
|
|
this.dynamicSearch();
|
|
}
|
|
|
|
|
|
async dynamicSearch() {
|
|
|
|
if(this.showSearch && this.searchSubject) {
|
|
|
|
const list = this.eventoaprovacaostore.get(this.segment).filter((task) => {
|
|
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
|
|
subject = subject.toLowerCase();
|
|
return subject.includes(this.searchSubject.toLowerCase())
|
|
})
|
|
|
|
this.list = this.TaskService.reorderList(this.ordinance, list)
|
|
} else {
|
|
const list = this.eventoaprovacaostore.get(this.segment)
|
|
|
|
this.list = this.TaskService.reorderList(this.ordinance, list)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
segmentChanged(ev: any) {
|
|
this.LoadToApproveEvents();
|
|
}
|
|
|
|
async LoadToApproveEvents() {
|
|
this.showLoader = true;
|
|
this.skeletonLoader = true
|
|
|
|
const segment = this.segment
|
|
|
|
if(this.segment == 'Meu calendario') {
|
|
// color
|
|
if(SessionStore.user.Profile == 'PR') {
|
|
this.color = 'pr'
|
|
} else {
|
|
this.color = 'mdgpr'
|
|
}
|
|
|
|
let eventsList
|
|
let genericEvents = await this.processes.eventsToApprove(SessionStore.user.UserId,'mobile agenda').toPromise()
|
|
try {
|
|
eventsList = this.sortService.sortArrayByDate(genericEvents).reverse();
|
|
} catch (error) {
|
|
this.skeletonLoader = false
|
|
eventsList = [];
|
|
}
|
|
|
|
this.eventoaprovacaostore.save(segment, eventsList as any)
|
|
this.dynamicSearch()
|
|
|
|
} else if(segment) {
|
|
|
|
this.color = 'pr'
|
|
let eventsList = []
|
|
let allEvents = await this.processes.eventsToApprove(segment,'mobile agenda').toPromise()
|
|
try {
|
|
eventsList = this.sortService.sortArrayByDate(allEvents).reverse();
|
|
} catch(error) {
|
|
this.skeletonLoader = false
|
|
eventsList = []
|
|
}
|
|
|
|
this.showLoader = false;
|
|
this.eventoaprovacaostore.save(segment, eventsList)
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
this.showLoader = false;
|
|
this.skeletonLoader = false
|
|
|
|
}
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
async openApproveModal(eventSerialNumber, event) {
|
|
const modal = await this.modalController.create({
|
|
component: ApproveEventModalPage,
|
|
componentProps: {
|
|
serialNumber: eventSerialNumber,
|
|
},
|
|
cssClass: 'event-list cal-modal modal modal-desktop',
|
|
backdropDismiss: false
|
|
});
|
|
await modal.present();
|
|
}
|
|
|
|
goToEventToApproveDetail(serialNumber: string) {
|
|
|
|
|
|
/* let navigationExtras: NavigationExtras = {
|
|
queryParams: {
|
|
"serialNumber": serialNumber,
|
|
}
|
|
}; */
|
|
|
|
if (this.router.url == '/home/agenda/event-list') {
|
|
this.router.navigate(['/home/agenda/event-list/approve-event', serialNumber, 'agenda'])
|
|
}
|
|
else if (this.router.url == '/home/gabinete-digital/event-list') {
|
|
this.router.navigate(['/home/gabinete-digital/event-list/approve-event', serialNumber, 'gabinete-digital'])
|
|
}
|
|
|
|
//this.router.navigate(['/home/gabinete-digital/event-list/approve-event'], navigationExtras)
|
|
}
|
|
|
|
refreshing() {
|
|
setTimeout(() => {
|
|
this.LoadToApproveEvents();
|
|
}, 1000);
|
|
}
|
|
|
|
doRefresh(event) {
|
|
|
|
setTimeout(() => {
|
|
this.LoadToApproveEvents();
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 1000);
|
|
}
|
|
|
|
|
|
goBack() {
|
|
this.RouteService.goBack()
|
|
}
|
|
|
|
|
|
}
|