Files
doneit-web/src/app/shared/gabinete-digital/diplomas/diplomas.page.ts
T
Peter Maquiran ef882e8ff1 fix
2023-05-08 10:52:54 +01:00

145 lines
3.6 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { DailyWorkTask } from '../../../models/dailyworktask.model';
import { ProcessesService } from 'src/app/services/processes.service';
import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe';
import { DeplomasStore } from 'src/app/store/deplomas.service';
import { ThemeService } from 'src/app/services/theme.service'
import { SortService } from 'src/app/services/functions/sort.service';
import { PermissionService } from 'src/app/services/permission.service';
import { TaskService } from 'src/app/services/task.service'
@Component({
selector: 'app-diplomas',
templateUrl: './diplomas.page.html',
styleUrls: ['./diplomas.page.scss'],
})
export class DiplomasPage implements OnInit {
diplomasList:DailyWorkTask[] = [];
diplomasAssinadoList:DailyWorkTask[] = [];
showLoader: boolean;
serialNumber:string;
skeletonLoader = false
@Input() segment:string;
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
deplomasStore = DeplomasStore
customTaskPipe = new CustomTaskPipe()
showSearch = false
searchSubject = ''
listDiplomasPorValidar = []
listDiplomasAssinadosPR = []
hideSearchBtn: boolean = false;
constructor(
private processes:ProcessesService,
private router: Router,
public ThemeService: ThemeService,
private sortService: SortService,
public p: PermissionService,
public TaskService: TaskService
) {}
ngOnInit() {
// update list
this.LoadList()
this.router.events.forEach((event) => {
if (event instanceof NavigationStart && '/home/gabinete-digital?diplomas=true'.startsWith(event.url)) {
if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
this.LoadList()
} else {
this.LoadList()
}
}
});
this.dynamicSearch();
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
this.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.listDiplomasPorValidar = this.deplomasStore.diplomasReviewList.filter((task) => {
let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject
subject = subject.toLowerCase();
return subject.includes(this.searchSubject.toLowerCase())
})
} else {
this.listDiplomasAssinadosPR = this.deplomasStore.diplomasAssinadoList
this.listDiplomasPorValidar = this.deplomasStore.diplomasReviewList
}
}
openSearch() {
this.dynamicSearch()
}
async closeSearch() {
this.searchSubject = ''
this.dynamicSearch()
}
async basicSearch() {
this.dynamicSearch()
}
segmentChanged(ev: any) {
this.LoadList();
}
goToDiploma(serialNumber:any){
this.router.navigate(['/home/gabinete-digital/diplomas', serialNumber, 'gabinete-digital']);
}
async LoadList() {
this.skeletonLoader = true;
await this.TaskService.loadDiplomas()
this.dynamicSearch()
this.showLoader = false;
this.skeletonLoader = false
}
async refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
doRefresh(event) {
if (event) {
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
this.LoadList();
}
}