Files
doneit-web/src/app/pages/gabinete-digital/despachos/despachos.page.ts
T
Peter Maquiran e991ba5f4e add domain layer
2023-06-23 11:47:20 +01:00

143 lines
3.3 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { DespachoService } from 'src/app/Rules/despacho.service';
import { DespachoStore } from 'src/app/store/despacho-store.service';
import { RouteService } from 'src/app/services/route.service';
import { BackgroundService } from 'src/app/services/background.service';
import { ThemeService } from 'src/app/services/theme.service'
import { TaskService } from 'src/app/services/task.service'
@Component({
selector: 'app-despachos',
templateUrl: './despachos.page.html',
styleUrls: ['./despachos.page.scss'],
})
export class DespachosPage implements OnInit {
despachoStore = DespachoStore;
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
showSearch = false
searchSubject = ''
list = []
hideSearchBtn: boolean = false;
ordinance: string = 'old'
constructor(
private router: Router,
private despachoRule: DespachoService,
private backgroundservice: BackgroundService,
public ThemeService: ThemeService,
public TaskService: TaskService,
private RouteService: RouteService,
) {}
ngOnInit() {
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.refreshing()
} else {
this.LoadList()
}
}
});
this.backgroundservice.registerBackService('Online', () => {
this.LoadList();
});
this.dynamicSearch()
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
const searchedList = this.TaskService.despachoStore.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, searchedList)
} else {
const list = this.despachoStore.list
this.list = this.TaskService.reorderList(this.ordinance, list)
}
}
openSearch() {
this.dynamicSearch()
}
async closeSearch() {
this.searchSubject = ''
this.dynamicSearch()
}
async basicSearch() {
this.dynamicSearch()
}
reorderList(orderBy: string) {
this.ordinance = orderBy;
this.dynamicSearch();
}
async refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
segmentChanged(ev: any) {
this.LoadList();
}
async LoadList() {
await this.despachoRule.getList({ updateStore: true }).then((pre) => {
//
this.dynamicSearch()
}).catch(() => {
})
}
get skeletonLoader(): boolean {
return this.despachoRule.LoaderService.loading
}
doRefresh(event) {
this.LoadList();
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
async GoToDespacho(serialNumber: any) {
this.router.navigate(['/home/gabinete-digital/despachos', serialNumber, 'gabinete-digital']);
}
goBack() {
this.RouteService.goBack();
}
}