Files
doneit-web/src/app/shared/gabinete-digital/despachos-pr/despachos-pr.page.ts
T
2023-09-21 10:06:08 +01:00

175 lines
4.1 KiB
TypeScript

import { Component, OnInit} from '@angular/core';
import { customTask} from '../../../models/dailyworktask.model';
import { LoginUserRespose } from 'src/app/models/user.model';
import { NavigationStart, Router } from '@angular/router';
import { DespachosprStore } from 'src/app/store/despachospr-store.service';
import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe';
import { SessionStore } from 'src/app/store/session.service';
import { environment } from 'src/environments/environment';
import { TaskService } from 'src/app/services/task.service'
import { ThemeService } from 'src/app/services/theme.service'
import { PermissionService } from 'src/app/services/permission.service';
@Component({
selector: 'app-despachos-pr',
templateUrl: './despachos-pr.page.html',
styleUrls: ['./despachos-pr.page.scss'],
})
export class DespachosPrPage implements OnInit {
customTaskPipe = new CustomTaskPipe()
skeletonLoader = false
loggeduser: LoginUserRespose;
despachosprstore = DespachosprStore;
environment = environment
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;
headerName = ''
constructor (
private router: Router,
public TaskService: TaskService,
public ThemeService: ThemeService,
public p: PermissionService,
) {
this.loggeduser = SessionStore.user;
if(!this.p.userRole('PR')) {
this.headerName = `Despachos ${ environment.despachoLabel }`
} else {
this.headerName = "Despachos criados por mim"
}
}
ngOnInit() {
this.LoadList()
this.dynamicSearch();
this.listSubscription = this.despachosprstore.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?despachospr=true')) {
if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
this.refreshing()
} else {
this.LoadList()
}
}
});
window['gabinete-aside-refresh'] = () => {
this.LoadList()
}
}
ngOnDestroy() {
this.listSubscription.delete()
this.routerSubscription?.unsubscribe();
}
changeFilterName(filterName) {
this.filterName = filterName
}
async LoadList() {
this.skeletonLoader = true;
await this.TaskService.loadDiplomas()
this.dynamicSearch()
this.skeletonLoader = false;
}
reorderList(orderBy: string) {
this.ordinance = orderBy;
this.dynamicSearch();
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
const list = this.despachosprstore.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.despachosprstore.list
this.list = this.TaskService.reorderList(this.ordinance, list)
}
}
openSearch() {
this.dynamicSearch()
}
async closeSearch() {
this.searchSubject = ''
this.dynamicSearch()
}
async basicSearch() {
this.dynamicSearch()
}
refreshing(){
setTimeout(() => {
this.LoadList();
}, 1000);
}
doRefresh(event) {
if (event) {
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
setTimeout(() => {
this.LoadList();
try {
event?.target?.complete();
} catch(error) {}
}, 1000);
}
goToDespacho({ SerialNumber } :customTask) {
this.router.navigate(['/home/gabinete-digital/despachos-pr',SerialNumber,'gabinete-digital']);
}
}