mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
244 lines
6.0 KiB
TypeScript
244 lines
6.0 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 { NavigationStart, Router } from '@angular/router';
|
|
import { EventoAprovacaoStore } from 'src/app/store/eventoaprovacao-store.service';
|
|
import { SortService } from 'src/app/services/functions/sort.service';
|
|
import { Storage } from '@ionic/storage';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { EventsService } from 'src/app/services/events.service';
|
|
import { environment } from 'src/environments/environment';
|
|
import { TaskService } from 'src/app/services/task.service'
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
|
|
@Component({
|
|
selector: 'app-events-to-approve',
|
|
templateUrl: './events-to-approve.page.html',
|
|
styleUrls: ['./events-to-approve.page.scss'],
|
|
})
|
|
export class EventsToApprovePage implements OnInit {
|
|
|
|
showLoader: boolean;
|
|
eventsPRList: any = [];
|
|
eventsMDGPRList: any = [];
|
|
eventPerson: EventPerson;
|
|
eventBody: EventBody;
|
|
categories: string[];
|
|
serialnumber:string;
|
|
segment:any;
|
|
eventaprovacaostore = EventoAprovacaoStore;
|
|
|
|
eventsList: any = []
|
|
color: 'pr' | 'mdgpr'
|
|
eventoaprovacaostore = EventoAprovacaoStore;
|
|
environment = environment
|
|
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
|
|
|
|
|
|
//
|
|
showSearch = false
|
|
searchSubject = ''
|
|
list = []
|
|
hideSearchBtn: boolean = false;
|
|
ordinance: string = 'old'
|
|
listSubscription : {
|
|
delete(): void;
|
|
}
|
|
routerSubscription;
|
|
|
|
|
|
constructor(
|
|
private processes:ProcessesService,
|
|
private modalController: ModalController,
|
|
private router: Router,
|
|
private sortService: SortService,
|
|
private storage: Storage,
|
|
public eventService: EventsService,
|
|
public TaskService: TaskService,
|
|
public ThemeService: ThemeService,
|
|
)
|
|
{}
|
|
|
|
ngOnInit() {
|
|
if(!this.segment) {
|
|
if(this.eventService.calendarNamesAry.includes('Meu calendario')) {
|
|
this.segment = 'Meu calendario';
|
|
} else {
|
|
this.segment = this.eventService.calendarNamesAry[0].OwnerUserId
|
|
}
|
|
}
|
|
this.LoadToApproveEvents()
|
|
|
|
this.listSubscription = this.eventoaprovacaostore.registerCallback({
|
|
id: import.meta.url,
|
|
funx:() => {
|
|
|
|
this.dynamicSearch()
|
|
|
|
}
|
|
})
|
|
|
|
this.routerSubscription = this.router.events.subscribe((event) => {
|
|
if (event instanceof NavigationStart &&
|
|
'/home/gabinete-digital?eventos=true'.startsWith(event.url)) {
|
|
|
|
if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
|
|
this.LoadToApproveEvents()
|
|
} else {
|
|
this.LoadToApproveEvents()
|
|
}
|
|
}
|
|
});
|
|
window['gabinete-aside-refresh'] = () => {
|
|
this.LoadToApproveEvents()
|
|
}
|
|
|
|
|
|
|
|
this.dynamicSearch();
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.listSubscription.delete()
|
|
|
|
this.routerSubscription?.unsubscribe();
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
}
|
|
|
|
|
|
openSearch() {
|
|
this.dynamicSearch()
|
|
}
|
|
async closeSearch() {
|
|
this.searchSubject = ''
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
async basicSearch() {
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
|
|
|
|
segmentChanged(ev: any) {
|
|
this.LoadToApproveEvents();
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
async LoadToApproveEvents() {
|
|
this.showLoader = true;
|
|
const segment = this.segment
|
|
|
|
if(SessionStore.user.Profile == 'PR') {
|
|
return false
|
|
}
|
|
|
|
|
|
if(this.segment == 'Meu calendario') {
|
|
// color
|
|
this.color = 'mdgpr'
|
|
|
|
let genericEvents = await this.processes.eventsToApprove(SessionStore.user.UserId,'mobile agenda').toPromise()
|
|
try {
|
|
this.eventsList = this.sortService.sortArrayByDate(genericEvents).reverse();
|
|
} catch (error) {
|
|
this.eventsList = [];
|
|
}
|
|
|
|
this.eventoaprovacaostore.save(segment, this.eventsList)
|
|
this.dynamicSearch()
|
|
} else {
|
|
|
|
|
|
this.color = 'pr'
|
|
let allEvents = await this.processes.eventsToApprove(segment, 'gabinete').toPromise()
|
|
try {
|
|
this.eventsList = this.sortService.sortArrayByDate(allEvents).reverse();
|
|
} catch(error) {
|
|
this.eventsList = []
|
|
}
|
|
|
|
this.eventsList = this.eventsList
|
|
this.eventsList = this.eventsList
|
|
this.showLoader = false;
|
|
this.eventoaprovacaostore.save(segment, this.eventsList)
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
this.showLoader = false;
|
|
}
|
|
|
|
|
|
getFromDB() {
|
|
this.storage.get('event-to-aproveMD').then((events = []) => {
|
|
this.eventsMDGPRList = events
|
|
})
|
|
|
|
this.storage.get('event-to-aprovePR').then((events) => {
|
|
this.eventsPRList = events
|
|
})
|
|
}
|
|
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
goToEventDetail(event) {
|
|
this.router.navigate(['/home/gabinete-digital/event-list/approve-event',event.serialNumber, 'gabinete-digital'])
|
|
}
|
|
|
|
doRefresh(event) {
|
|
if (event) {
|
|
setTimeout(() => {
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 2000);
|
|
}
|
|
|
|
setTimeout(()=>{
|
|
this.LoadToApproveEvents();
|
|
}, 1000)
|
|
|
|
}
|
|
close() {
|
|
this.modalController.dismiss(null);
|
|
|
|
|
|
|
|
// this.RouteService.goBack('/home/gabinetedigital')
|
|
}
|
|
|
|
|
|
}
|