Files
doneit-web/src/app/pages/gabinete-digital/diplomas/diplomas.page.ts
T
Peter Maquiran a61ee6c07e improve
2023-07-14 18:57:07 +01:00

198 lines
5.1 KiB
TypeScript

import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
import { ProcessesService } from 'src/app/services/processes.service';
import { BackgroundService } from 'src/app/services/background.service';
import { ThemeService } from 'src/app/services/theme.service'
import { PermissionService } from 'src/app/services/permission.service';
import { DeplomasStore } from 'src/app/store/deplomas.service';
import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe';
import { TaskService } from 'src/app/services/task.service'
import { RouteService } from 'src/app/services/route.service';
@Component({
selector: 'app-diplomas',
templateUrl: './diplomas.page.html',
styleUrls: ['./diplomas.page.scss'],
})
export class DiplomasPage implements OnInit, OnDestroy {
showLoader: boolean;
totalDocs: any;
serialNumber: string;
headerName = "Diplomas"
segment: string;
skeletonLoader = true
deplomasStore = DeplomasStore
customTaskPipe = new CustomTaskPipe()
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
showSearch = false
searchSubject = ''
listDiplomasPorValidar = [];
listDiplomasAssinadosPR = [];
hideSearchBtn: boolean = false;
ordinance: string = 'old';
constructor(
private processes: ProcessesService,
private router: Router,
private activatedRoute: ActivatedRoute,
private backgroundservice: BackgroundService,
public ThemeService: ThemeService,
public p: PermissionService,
public TaskService: TaskService,
private RouteService: RouteService,
) {
//Inicializar segment
}
ngOnInit() {
//this.segment = 'validar';
this.activatedRoute.queryParams.subscribe(params => {
if (params['segment'] == 'validar') {
this.segment = 'validar';
} else if (params['segment'] == 'assinados') {
this.segment = 'assinados';
} else if (params['diplomas']=='assinados') {
this.segment = 'assinados';
} else if (params['diplomas']== 'validar') {
this.segment = 'validar';
}
});
const location = window.location
const pathname = location.pathname + location.search
this.LoadList()
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.LoadList()
} else {
this.LoadList()
}
}
});
this.backgroundservice.registerBackService('Online', () => {
this.LoadList();
});
this.dynamicSearch()
}
openSearch() {
this.dynamicSearch()
}
async closeSearch() {
this.searchSubject = ''
this.dynamicSearch()
}
async basicSearch() {
this.dynamicSearch()
}
reorderList(orderBy: string) {
this.ordinance = orderBy;
this.dynamicSearch();
}
changeFilterName(filterName) {
this.filterName = filterName
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
const listDiplomasAssinadosPR = this.deplomasStore.diplomasAssinadoList.filter((task) => {
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
subject = subject.toLowerCase();
return subject.includes(this.searchSubject.toLowerCase())
})
this.listDiplomasAssinadosPR = this.TaskService.reorderList(this.ordinance, listDiplomasAssinadosPR)
const listDiplomasPorValidar = this.deplomasStore.diplomasReviewList.filter((task) => {
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
subject = subject.toLowerCase();
return subject.includes(this.searchSubject.toLowerCase())
})
this.listDiplomasPorValidar = this.TaskService.reorderList(this.ordinance, listDiplomasPorValidar)
} else {
const listDiplomasAssinadosPR = this.deplomasStore.diplomasAssinadoList
const listDiplomasPorValidar = this.deplomasStore.diplomasReviewList
this.listDiplomasPorValidar = this.TaskService.reorderList(this.ordinance, listDiplomasPorValidar)
this.listDiplomasAssinadosPR = this.TaskService.reorderList(this.ordinance, listDiplomasAssinadosPR)
}
}
async getTotalDocs(DocId: any) {
let res = await this.processes.GetDocumentDetails(DocId, '361').toPromise();
return res.DocumentsTotal;
}
ngOnDestroy(): void {
}
segmentChanged(ev: any) {
this.LoadList();
}
goToDiploma(serialNumber: any) {
this.router.navigate(['/home/gabinete-digital/diplomas', serialNumber, 'gabinete-digital']);
}
async LoadList() {
try {
this.skeletonLoader = true
await this.TaskService.loadDiplomas()
this.dynamicSearch()
this.skeletonLoader = false
} catch(error) {
this.skeletonLoader = false
}
}
async refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
async doRefresh(event) {
setTimeout(() => {
this.LoadList();
}, 1000);
}
goBack() {
this.RouteService.goBack();
}
}