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

178 lines
4.9 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { ProcessesService } from 'src/app/services/processes.service';
import { ToastService } from 'src/app/services/toast.service';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
import { SqliteService } from 'src/app/services/sqlite.service';
import { Platform } from '@ionic/angular';
import { BackgroundService } from '../../../services/background.service';
import { ThemeService } from 'src/app/services/theme.service'
import { SortService } from 'src/app/services/functions/sort.service';
import { Storage } from '@ionic/storage';
import { EventTrigger } from 'src/app/services/eventTrigger.service';
import { TaskDeadlineService } from 'src/app/services/task-deadline.service'
import { TaskService } from 'src/app/services/task.service'
import { RouteService } from 'src/app/services/route.service';
@Component({
selector: 'app-expediente',
templateUrl: './expediente.page.html',
styleUrls: ['./expediente.page.scss'],
})
export class ExpedientePage implements OnInit {
segment: string;
skeletonLoader = true
//profile:string;
showLoader: boolean;
serialNumber: string;
//expedienteGdStore = ExpedienteGdStore;
expedientegbstore = ExpedienteGdStore
expedienteTaskPipe = new ExpedienteTaskPipe()
onlinecheck: boolean;
showSearch = false
searchSubject = ''
list = []
ordinance: string = 'old'
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
constructor(
private processes: ProcessesService,
private router: Router,
private toastService: ToastService,
public platform: Platform,
private sqliteservice: SqliteService,
private backgroundservice: BackgroundService,
public ThemeService: ThemeService,
private sortService: SortService,
private storage: Storage,
private eventTriger: EventTrigger,
public TaskDeadlineService: TaskDeadlineService,
public TaskService: TaskService,
private RouteService: RouteService,
) {
this.eventTriger.getObservable().subscribe((event) => {
if(event.notification == "recive") {
this.refreshing();
}
// console.log(event)
})
}
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()
}
reorderList(orderBy: string) {
this.ordinance = orderBy;
this.dynamicSearch();
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
const searchedList = this.expedientegbstore.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.expedientegbstore.list
this.list = this.TaskService.reorderList(this.ordinance, list)
}
}
LoadList() {
this.processes.GetTaskListExpediente(false).subscribe(async res => {
(async ()=> {
await this.TaskService.loadExpedientes()
this.dynamicSearch()
})()
this.skeletonLoader = true
const result = res
let taskslist = new Array();
let ress = result.filter((data: any) => data.workflowInstanceDataFields.Status == "" || data.workflowInstanceDataFields.Status == "Active");
ress.forEach((element: any) => {
let task = this.expedienteTaskPipe.transform(element)
taskslist.push(task);
// this.addProcessTODb(task);
});
taskslist = taskslist.filter(function(item) {
return item.activityInstanceName != 'Retificar Expediente'
})
this.expedientegbstore.reset(taskslist);
this.skeletonLoader = false;
}, (error) => {
// this.getEventsFromLocalDb();
})
}
async refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
doRefresh(event) {
this.LoadList();
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 1000);
}
goBack() {
this.RouteService.goBack();
}
goToExpediente(serialNumber: any) {
//
this.router.navigate(['/home/gabinete-digital/expediente', serialNumber, 'gabinete-digital']);
}
}