import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; import { NavigationEnd, Router } from '@angular/router'; import { LoginUserRespose } from 'src/app/models/user.model'; import { ThemeService } from 'src/app/services/theme.service'; import { TaskService } from 'src/app/services/task.service'; @Component({ selector: 'app-all-processes', templateUrl: './all-processes.page.html', styleUrls: ['./all-processes.page.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) export class AllProcessesPage implements OnInit { skeletonLoader = false; loggeduser: LoginUserRespose; hideSearchBtn: boolean = false; showSearch = false; searchSubject: string = ''; filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos' /* miniSearch = new MiniSearch({ fields: ['Folio', 'Senders'], // fields to index for full-text search idField: 'DocId' }) */ AllProcess = [] ordinance: string = 'old' /** * @description Update List subcription */ listSubscription : { delete(): void; } routerSubscription; constructor( private router: Router, public ThemeService: ThemeService, public TaskService: TaskService, private cdr: ChangeDetectorRef ) {} ngOnInit() { // this.updateAllProcess() this.checkFilter(); this.listSubscription = this.TaskService.registerCallback({ id: import.meta.url, funx:() => { this.dynamicSearch() } }) if(window['all-process-gabinete']) { window['all-process-gabinete']() } } ngAfterViewInit(): void { this.dynamicSearch(); this.routerSubscription = this.router.events.subscribe((event) => { if (event instanceof NavigationEnd && event.url.includes('/home/gabinete-digital')) { // this.refreshing(); this.checkFilter(); } }); } ngOnDestroy() { this.listSubscription.delete() this.routerSubscription?.unsubscribe(); } openSearch() { // this.dynamicSearch() } async closeSearch() { this.searchSubject = '' this.dynamicSearch() this.cdr.markForCheck() } async basicSearch() { // this.dynamicSearch() } reorderList(orderBy: string) { this.ordinance = orderBy; this.cdr.markForCheck() this.dynamicSearch(); } async dynamicSearch() { 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()) }) this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess) } else { const AllProcess = this.TaskService.AllProcess this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess) } this.cdr.markForCheck() } checkFilter() { if(this.router.url.includes('ForToDay')) { this.filterName = 'Para hoje' } else if (this.router.url.includes('OverdueTasks')) { this.filterName = 'OverdueTasks' } else if (this.router.url.includes('New')) { this.filterName = 'Novos' } else if (this.router.url.includes('unread')) { this.filterName = 'Não lidos' } this.cdr.markForCheck() } goToProcess(serialNumber: string, workflowName: string, activityName: string) { if (workflowName == 'Despacho') { if (activityName == 'Tarefa de Despacho' || activityName == 'Concluir Despacho' || activityName == 'Reexecutar Despacho') { this.router.navigate(['/home/gabinete-digital/despachos', serialNumber, 'gabinete-digital']); } } else if (workflowName == 'Despacho do Presidente da República') { if (activityName == 'Tarefa de Despacho' || activityName == 'Concluir Despacho') { this.router.navigate(['/home/gabinete-digital/despachos-pr', serialNumber, 'gabinete-digital']); } else if (activityName == 'Revisar Diploma' || activityName == 'Diploma Assinado') { this.router.navigate(['/home/gabinete-digital/diplomas', serialNumber, 'gabinete-digital']); } else if ( activityName == 'Assinar Diploma') { this.router.navigate(['/home/gabinete-digital/diplomas-assinar', serialNumber, 'gabinete-digital']); } else { throw('Bug!'); } } else if (workflowName == 'Pedido de Parecer' || workflowName == 'Pedido de Deferimento') { this.router.navigate(['/home/gabinete-digital/pedidos', serialNumber, 'gabinete-digital']); } else if (workflowName == 'Expediente') { this.router.navigate(['/home/gabinete-digital/expediente', serialNumber, 'gabinete-digital']); } else if (workflowName == 'Expediente' && this.loggeduser.Profile == 'PR') { this.router.navigate(['/home/gabinete-digital/expedientes-pr', serialNumber, 'gabinete-digital']); } else if (workflowName == "Pedido de Parecer do Presidente") { this.router.navigate(['/home/gabinete-digital/pedidos', serialNumber, 'gabinete-digital']); } else if (workflowName == 'Agenda Pessoal PR' || workflowName == 'Agenda Oficial PR' || workflowName == 'Agenda Oficial MDGPR' || workflowName == 'Agenda Pessoal MDGPR' || activityName == "Aprovar Evento" || workflowName == "Agendar Evento") { this.router.navigate(['/home/gabinete-digital/event-list/approve-event', serialNumber, 'gabinete-digital']); } else { throw(`${workflowName} && ${activityName} no route`) } this.cdr.markForCheck() } }