import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import {NavigationEnd, NavigationExtras, Router } from '@angular/router'; import { UserSession } from 'src/app/models/user.model'; import { ExpedientsPage } from 'src/app/shared/gabinete-digital/expedients/expedients.page'; import { PendentesPage } from 'src/app/shared/gabinete-digital/pendentes/pendentes.page'; import { EventsToApprovePage } from 'src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page'; import { WaitForDomService } from 'src/app/services/dom/wait-for-dom.service'; import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe'; import { PermissionService } from 'src/app/services/permission.service'; import { ThemeService } from 'src/app/services/theme.service'; import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe'; import { SessionStore } from 'src/app/store/session.service'; import { NotificationsService } from 'src/app/services/notifications.service' import { environment } from 'src/environments/environment'; import { TaskService } from 'src/app/services/task.service' @Component({ selector: 'app-gabinete-digital', templateUrl: './gabinete-digital.page.html', styleUrls: ['./gabinete-digital.page.scss'], }) export class GabineteDigitalPage implements OnInit { segment: string; segmentVista: string; public profile: string; allProcessesList: any = new Array(); skeletonLoader: boolean; selectedElement = ""; desktopComponent: any = { showEventList: false, showExpediente: false, } showAllProcesses = false; showEventsToApprove = false; showEmptyContainer = false; showExpedients = false; showExpedientesPr = false; showPedidos = false; showDespachos = false; showDespachosPr = false; showPendentes = false; showDiplomas = false; showDiplomasAssinar = false; showExpedientDetail = false; showSignedDiploma = false; emptyTextDescription = 'Sem opção selecionada'; serialNumber: string; loggeduser: UserSession; mdgpr = "MDGPR"; pr = "PR"; hideRefreshBtn = true; hideInMobile = true; showDiplomasGerar = false // // pipe SessionStore = SessionStore expedienteTaskPipe = new ExpedienteTaskPipe(); customTaskPipe = new CustomTaskPipe() permissions = { Agenda: 530 } // workerList : Worker environment = environment @ViewChild(ExpedientsPage) expedientesPage: ExpedientsPage; @ViewChild(PendentesPage) pendentesListPage: PendentesPage; @ViewChild(EventsToApprovePage) eventsToApprove: EventsToApprovePage; filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos' hideSearchBtn: boolean = false; showSearch = true; searchSubject: string = ''; AllProcess = [] ordinance: string = 'old' refresh = true @ViewChild('scroll') scroll: ElementRef; constructor( private router: Router, public waitForDomService: WaitForDomService, public ThemeService: ThemeService, public p: PermissionService, public NotificationsService: NotificationsService, public TaskService: TaskService ) { window.onresize = (event) => { if (window.innerWidth < 701) { this.hideRefreshBtn = false; this.hideInMobile = false; this.segmentVista = "listview"; } else { this.hideRefreshBtn = true; this.hideInMobile = true; this.segmentVista = "boxview"; } } // fix with many timeout } closeAllDesktopComponent() { this.desktopComponent = { showEventList: false, showExpediente: false } } openSearch() { this.dynamicSearch() } async closeSearch() { this.searchSubject = '' this.dynamicSearch() } async basicSearch() { this.dynamicSearch() } reorderList(orderBy: string) { this.changeTab() this.ordinance = orderBy; this.dynamicSearch(); } 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()) }) if(ordinance == this.ordinance) { this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess) .filter( task => this.TaskService.filter(task, this.filterName)) } } else { const AllProcess = this.TaskService.AllProcess.filter( task => this.TaskService.filter(task, this.filterName)) if(ordinance == this.ordinance) { this.AllProcess = this.TaskService.reorderList(this.ordinance, AllProcess) .filter( task => this.TaskService.filter(task, this.filterName)) } } } ngOnInit() { if (window.innerWidth < 701) { this.segmentVista = "listview"; } else { this.segmentVista = "boxview" } this.hideRefreshButton(); (async () => { await this.loadAllProcesses() this.TaskService.registerCallback({ id: import.meta.url, funx:() => { this.dynamicSearch() } }) })(); this.checkFilter(); this.checkRoutes(); this.dynamicSearch() const pathname = '/home/gabinete-digital' this.router.events.forEach((event) => { if (event instanceof NavigationEnd && event.url.includes(pathname) && !event.url.includes('/home/gabinete-digital/')) { this.waitForDomService.selector({ selector: 'app-gabinete-digital ion-content .aside-wrapper', callback: () => { this.loadAllProcesses() if(this.NotificationsService.active === false) { this.checkRoutes(); // this.LoadCounts(); this.checkFilter() } else { this.checkRoutes(); // this.LoadCounts(); this.checkFilter() } this.mobile() } }) } }); } ngAfterViewInit(): void { try { // We can access the TestComponent now that this portion of the view tree has been initiated. const element = this.scroll.nativeElement this.scroll.nativeElement.addEventListener("scroll", (e)=> { this.changeTab() }); } catch(error) { } } functionTimer1 = null; changeTab() { clearTimeout(this.functionTimer1); this.functionTimer1 = setTimeout(() => { const element = this.scroll.nativeElement if(element.scrollTop == 0 ) { this.refresh = true } else { this.refresh = false } }, 100); } checkFilter() { const currentFilter = this.filterName 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' } if(currentFilter != this.filterName) { this.dynamicSearch() } // console.log('this.filterName', this.filterName) } goto(url) { this.router.navigate([url]) } 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' && SessionStore.user.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 == "Expediente") { 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`) } } checkUser() { if(SessionStore.user.Profile != 'PR') { this.selectedElement = 'Correspondence' let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showExpedients = true; } else if(SessionStore.user.Profile == 'PR') { this.selectedElement = 'ExpedientesPr' let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showExpedientesPr = true; } } hideRefreshButton() { if (window.innerWidth < 701) { this.hideRefreshBtn = false; this.hideInMobile = false; this.segmentVista = "listview"; } else { this.hideRefreshBtn = true; this.hideInMobile = true; this.segmentVista = "boxview"; } } mobile() { if (window.innerWidth < 701 && this.router.url.includes('filter=')) { this.hideRefreshBtn = false; this.hideInMobile = false; this.segmentVista = "listview"; } this.checkFilter(); } checkRoutes() { this.closeAllDesktopComponents(); // console.log(this.router.url, this.router.url.includes('processes=true')) // alert('hello')s if (this.router.url.includes('processes=true')) { this.openAllProcessesPage(); this.checkUser() } if (this.router.url == '/home/gabinete-digital?eventos=true') { this.openEventsToApprovePage(); this.selectedElement = 'approval'; } else if (this.router.url == '/home/gabinete-digital?expedientes=true') { this.openExpedientListPage(); if (SessionStore.user.Profile == 'MDGPR') { this.selectedElement = 'Correspondence'; } else { this.selectedElement = 'Expediente Presidente' } } else if (this.router.url == '/home/gabinete-digital?pendentes=true') { this.openPendentesPage(''); this.selectedElement = 'Pending'; } else if (this.router.url == '/home/gabinete-digital?despachos=true') { this.openDespachosPage(''); this.selectedElement = 'Dispatches'; } else if (this.router.url == '/home/gabinete-digital?pedidos=true') { this.openPedidosPage('parecer'); this.selectedElement = 'RequestsForOpinion'; } else if (this.router.url == '/home/gabinete-digital?expedientespr=true') { this.openExpedientesPrPage(); this.selectedElement = 'Expediente Presidente' } else if (this.router.url == '/home/gabinete-digital?despachospr=true') { this.openDespachosPrPage(''); this.selectedElement = 'showDespachosPr' } else if (this.router.url == '/home/gabinete-digital?diplomas=assinados') { this.openDiplomasPage('assinados'); } else if (this.router.url == '/home/gabinete-digital?diplomas=validar') { this.openDiplomasPage('validar'); } else if (this.router.url == '/home/gabinete-digital?diplomasassinar=true') { this.openDiplomasAssinarPage(); this.selectedElement = 'DiplomasParaAssinar'; } else if (this.router.url == '/home/gabinete-digital?parecer=true') { this.openPedidosPage('parecer') } else if (this.router.url == '/home/gabinete-digital?deferimento=true') { this.openPedidosPage('deferimento') } else { this.checkUser(); } } closeAllDesktopComponents() { this.showEmptyContainer = false; this.showAllProcesses = false; this.showEventsToApprove = false; this.showExpedients = false; this.showPedidos = false; this.showDespachos = false; this.showDespachosPr = false; this.showPendentes = false; this.showDiplomas = false; this.showDiplomasAssinar = false; this.showExpedientesPr = false; this.showExpedientDetail = false; this.showSignedDiploma = false this.showDiplomasGerar = false } functionTimer = null loadProcess = {} get getloadKeys() { return Object.keys(this.loadProcess) } async loadAllProcesses() { this.skeletonLoader = true try { await this.TaskService.LoadTask(); this.dynamicSearch(); } catch (e) {} this.skeletonLoader = false } doRefreshAside() { try { window['gabinete-aside-refresh']() } catch(error) {} setTimeout(() => { this.loadAllProcesses(); }, 1000) } doRefresh(event) { this.loadAllProcesses(); if (event) { setTimeout(() => { try { try { event?.target?.complete(); } catch(error) {} } catch(error) {} }, 2000); } else { } } selectedElementF(element: string) { if (window.innerWidth > 701) { return element == this.selectedElement } return false; } openAllProcessesPage() { this.closeAllDesktopComponents(); let navigationExtras: NavigationExtras = { queryParams: { "processes": true, } }; if (window.innerWidth < 701) { // this.router.navigate(['/home/gabinete-digital']); } else { // this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showAllProcesses = true; this.selectedElement = "allProcessesTag"; } } openEventsToApprovePage() { this.closeAllDesktopComponents(); let navigationExtras: NavigationExtras = { queryParams: { "eventos": true, } }; if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/event-list']); } else { this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showEventsToApprove = true; } } openExpedientListPage() { this.closeAllDesktopComponents(); if(SessionStore.user.Profile != 'PR') { if (window.innerWidth < 701) { //this.openExpedientList(); this.router.navigate(['/home/gabinete-digital/expediente']); } else { this.selectedElement = 'Correspondence' let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showExpedients = true; } } else if(SessionStore.user.Profile == 'PR') { if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/expedientes-pr']); } else { this.selectedElement = 'ExpedientesPr' let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showExpedientesPr = true; } } } openPedidosPage(segment: string) { this.closeAllDesktopComponents(); let navigationExtras: NavigationExtras; if (segment == 'deferimento') { navigationExtras = { queryParams: { "deferimento": true, } }; this.segment = 'deferimento' } else if (segment == 'parecer') { navigationExtras = { queryParams: { "parecer": true, } }; this.segment = 'parecer' } if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/pedidos'], navigationExtras); } else { this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showPedidos = true; this.selectedElement = 'RequestForApproval' if (segment == 'deferimento') { this.selectedElement = 'RequestForApproval' } else if (segment == 'parecer') { this.selectedElement = 'RequestsForOpinion' } } } openDespachosPage(segment?: string) { this.closeAllDesktopComponents(); if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/despachos']); } else { let navigationExtras: NavigationExtras = { queryParams: { "despachos": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showDespachos = true; } } openDespachosPrPage(segment?: string) { this.closeAllDesktopComponents(); if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/despachos-pr']); } else { let navigationExtras: NavigationExtras = { queryParams: { "despachospr": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showDespachosPr = true; } } openPendentesPage(segment?: string) { this.closeAllDesktopComponents(); if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/pendentes']); } else { let navigationExtras: NavigationExtras = { queryParams: { "pendentes": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showPendentes = true; } } openExpedientesPrPage(segment?: string) { this.closeAllDesktopComponents(); if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/expedientes-pr']); } else { this.selectedElement = 'ExpedientesPr' let navigationExtras: NavigationExtras = { queryParams: { "expedientespr": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showExpedientesPr = true; } } openDiplomasPage(segment: string) { let navigationExtras: NavigationExtras; if (segment == 'validar') { navigationExtras = { queryParams: { "diplomas": 'validar', } }; this.selectedElement = 'DiplomasPorValidar'; } else if (segment == 'assinados') { this.selectedElement = 'DiplomasAssinados'; navigationExtras = { queryParams: { "diplomas": 'assinados', } }; } this.segment = segment; if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/diplomas'], navigationExtras); } else { this.closeAllDesktopComponents(); this.router.navigate(['/home/gabinete-digital'], navigationExtras); setTimeout(() => { this.showDiplomas = true; }, 10) } } openDiplomaPorElaborar(segment: string) { this.segment = segment; if (window.innerWidth < 701) { let navigationExtras: NavigationExtras = { queryParams: { "gerarDiplomas": true }} this.router.navigate(['/home/gabinete-digital/diplomas-gerar'], navigationExtras); } else { this.closeAllDesktopComponents(); this.segment = segment; let navigationExtras: NavigationExtras = { queryParams: { "gerarDiplomas": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showDiplomasGerar = true } } openDiplomasAssinarPage() { this.closeAllDesktopComponents(); if (window.innerWidth < 701) { this.router.navigate(['/home/gabinete-digital/diplomas-assinar']); } else { let navigationExtras: NavigationExtras = { queryParams: { "diplomasassinar": true, } }; this.router.navigate(['/home/gabinete-digital'], navigationExtras); this.showDiplomasAssinar = true; } } onDragOver(event) { // do something event.preventDefault(); } onDragLeave(event) { // do something event.preventDefault(); } }