Files
doneit-web/src/app/shared/gabinete-digital/expedients/expedients.page.ts
T
Peter Maquiran 2688b1e012 performance
2023-06-11 20:17:10 +01:00

191 lines
4.5 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { ProcessesService } from 'src/app/services/processes.service';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
import { ThemeService } from 'src/app/services/theme.service'
import { SortService } from 'src/app/services/functions/sort.service';
import { Storage } from '@ionic/storage';
import { EventTrigger } from 'src/app/services/eventTrigger.service';
import { TaskService } from 'src/app/services/task.service'
@Component({
selector: 'app-expedients',
templateUrl: './expedients.page.html',
styleUrls: ['./expedients.page.scss'],
})
export class ExpedientsPage implements OnInit {
segment: string;
serialNumber: string;
@Input() profile: string;
skeletonLoader = false
expedientegbstore = ExpedienteGdStore
expedienteTaskPipe = new ExpedienteTaskPipe()
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 router: Router,
public ThemeService: ThemeService,
private sortService: SortService,
private eventTriger: EventTrigger,
public TaskService: TaskService
) {
this.profile = 'mdgpr';
this.eventTriger.getObservable().subscribe((event) => {
if(event.expedienteDetail == "update") {
this.LoadList();
}
})
}
ngOnInit() {
//Inicializar segment
this.segment = "expedientes";
this.LoadList()
this.listSubscription = this.expedientegbstore.registerCallback({
id: import.meta.url,
funx:() => {
this.dynamicSearch()
}
})
this.routerSubscription = this.router.events.subscribe((event) => {
if (event instanceof NavigationStart &&
event.url.startsWith('/home/gabinete-digital?expedientes=true')) {
this.LoadList()
}
});
window['gabinete-aside-refresh'] = () => {
this.LoadList()
}
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.expedientegbstore.list.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.expedientegbstore.list
this.list = this.TaskService.reorderList(this.ordinance, list)
}
}
openSearch() {
this.dynamicSearch()
}
async closeSearch() {
this.searchSubject = ''
this.dynamicSearch()
}
async basicSearch() {
this.dynamicSearch()
}
segmentChanged() {
this.LoadList();
}
LoadList() {
this.skeletonLoader = true
this.processes.GetTaskListExpediente(false).subscribe(result => {
let taskslist = [];
this.skeletonLoader = false
let res = result.filter(data => data.workflowInstanceDataFields.Status == "" || data.workflowInstanceDataFields.Status == "Active");
taskslist = res.map((e) => this.expedienteTaskPipe.transform(e))
taskslist = this.sortService.sortDate(taskslist, 'CreateDate')
// this.addProcessTODb(taskslist);
taskslist = taskslist.filter(function(item) {
return item.activityInstanceName != 'Retificar Expediente'
})
this.expedientegbstore.reset(taskslist);
this.dynamicSearch()
}, (error) => {
this.skeletonLoader = false
// this.getEventsFromLocalDb();
}, () =>{
this.skeletonLoader = false
});
}
doRefresh(event) {
if (event) {
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
setTimeout(() => {
this.LoadList();
}, 1000)
}
goToExpediente({SerialNumber}) {
this.router.navigate(['/home/gabinete-digital/expediente', SerialNumber, 'gabinete-digital']);
}
}