Files
doneit-web/src/app/pages/gabinete-digital/expedientes-pr/expedientes-pr.page.ts
T
Peter Maquiran eba2b7f9ce commit
2023-07-15 11:01:09 +01:00

174 lines
4.8 KiB
TypeScript

import { Component, EventEmitter, OnInit, Output, ViewChild } from '@angular/core';
import { NavigationStart, Router } from '@angular/router';
import { CalendarComponent } from 'ionic2-calendar';
import { ProcessesService } from 'src/app/services/processes.service';
import { ModalController } from '@ionic/angular';
import { ExpedienteDetailPage } from 'src/app/pages/gabinete-digital/expediente/expediente-detail/expediente-detail.page';
import { LoginUserRespose } from 'src/app/models/user.model';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
import { ThemeService } from 'src/app/services/theme.service'
import { SortService } from 'src/app/services/functions/sort.service';
import { RouteService } from 'src/app/services/route.service';
import { SessionStore } from 'src/app/store/session.service';
import { TaskService } from 'src/app/services/task.service';
@Component({
selector: 'app-expedientes-pr',
templateUrl: './expedientes-pr.page.html',
styleUrls: ['./expedientes-pr.page.scss'],
})
export class ExpedientesPrPage implements OnInit {
@ViewChild(CalendarComponent) myCal: CalendarComponent;
taskslist= [];
serialNumber:string;
showLoader:boolean;
loggeduser: LoginUserRespose;
@Output() openExpedientDetail:EventEmitter<any> = new EventEmitter<any>();
skeletonLoader = true
expedienteGdStore = ExpedienteGdStore;
expedienteTaskPipe = new ExpedienteTaskPipe()
filterName: 'Para hoje' | 'Novos'| 'Lidos'| 'Não lidos'| 'OverdueTasks' | 'Todos' = 'Todos'
showSearch = false
searchSubject = ''
list = []
ordinance: string = 'old'
headerName = "Expediente"
constructor(
private processes:ProcessesService,
private modalController: ModalController,
private router: Router,
private RouteService: RouteService,
public ThemeService: ThemeService,
private sortService: SortService,
public TaskService: TaskService
) {
this.loggeduser = SessionStore.user;
}
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.dynamicSearch()
}
reorderList(orderBy: string) {
this.ordinance = orderBy;
this.dynamicSearch();
}
changeFilterName(filterName) {
this.filterName = filterName
}
async dynamicSearch() {
if(this.showSearch && this.searchSubject) {
const list = this.expedienteGdStore.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.expedienteGdStore.list
this.list = this.TaskService.reorderList(this.ordinance, list)
}
}
LoadList() {
this.skeletonLoader = true
this.processes.GetTaskListExpediente(false).subscribe(result => {
this.skeletonLoader = false
this.showLoader =false
this.taskslist = new Array();
let res = result.reverse().filter(data => data.workflowInstanceDataFields.Status == "" || data.workflowInstanceDataFields.Status == "Active");
this.taskslist = res.map((element) => this.expedienteTaskPipe.transform(element));
this.taskslist = this.sortService.sortDate(this.taskslist, 'CreateDate')
this.expedienteGdStore.reset(this.taskslist);
this.skeletonLoader = false
this.dynamicSearch()
})
}
refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
doRefresh(event) {
this.LoadList();
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
goToExpediente({SerialNumber}){
this.router.navigate(['/home/gabinete-digital/expediente', SerialNumber, 'gabinete-digital']);
}
async viewExpedientDetail(serialNumber:any) {
const modal = await this.modalController.create({
component: ExpedienteDetailPage,
componentProps:{
enterAnimation: "",
serialNumber: serialNumber,
profile: this.loggeduser.Profile,
},
cssClass: 'modal modal-desktop',
});
modal.onDidDismiss().then((res)=>{
this.LoadList();
}, (error) => {
console.log(error)
});
await modal.present();
}
goBack() {
this.RouteService.goBack();
}
}