mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
216 lines
5.9 KiB
TypeScript
216 lines
5.9 KiB
TypeScript
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
import { NavigationStart, Router } from '@angular/router';
|
|
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
|
|
import { customTask} from '../../../models/dailyworktask.model';
|
|
import { ProcessesService } from 'src/app/services/processes.service';
|
|
import { PendentesStore } from 'src/app/store/pendestes-store.service';
|
|
import { LoginUserRespose } from 'src/app/models/user.model';
|
|
import { CustomTaskPipe } from 'src/app/pipes/custom-task.pipe';
|
|
import { SortService } from 'src/app/services/functions/sort.service';
|
|
import { Storage } from '@ionic/storage';
|
|
import { SessionStore } from 'src/app/store/session.service';
|
|
import { TaskService } from 'src/app/services/task.service'
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
|
|
@Component({
|
|
selector: 'app-pendentes',
|
|
templateUrl: './pendentes.page.html',
|
|
styleUrls: ['./pendentes.page.scss'],
|
|
})
|
|
export class PendentesPage implements OnInit {
|
|
|
|
skeletonLoader: boolean = false;
|
|
pendentesstore = PendentesStore;
|
|
customTaskPipe = new CustomTaskPipe()
|
|
loggeduser: LoginUserRespose;
|
|
listToPresent = [];
|
|
|
|
@Input() profile:string;
|
|
segment:string;
|
|
@Output() openExpedientDetail:EventEmitter<any> = new EventEmitter<any>();
|
|
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;
|
|
|
|
constructor(
|
|
private processes:ProcessesService,
|
|
private router: Router,
|
|
private sortService: SortService,
|
|
private storage: Storage,
|
|
public TaskService: TaskService,
|
|
public ThemeService: ThemeService) {
|
|
this.loggeduser = SessionStore.user;
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.LoadList()
|
|
|
|
this.listSubscription = this.pendentesstore.registerCallback({
|
|
id: import.meta.url,
|
|
funx:() => {
|
|
|
|
this.dynamicSearch()
|
|
}
|
|
})
|
|
this.dynamicSearch();
|
|
|
|
this.routerSubscription = this.router.events.subscribe((event) => {
|
|
if (event instanceof NavigationStart &&
|
|
event.url.startsWith('/home/gabinete-digital?pendentes=true')) {
|
|
if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
|
|
this.LoadList()
|
|
} else {
|
|
this.LoadList()
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
window['gabinete-aside-refresh'] = () => {
|
|
this.LoadList()
|
|
}
|
|
|
|
}
|
|
|
|
|
|
ngOnDestroy() {
|
|
this.listSubscription.delete()
|
|
this.routerSubscription?.unsubscribe();
|
|
}
|
|
|
|
reorderList(orderBy: string) {
|
|
|
|
this.ordinance = orderBy;
|
|
|
|
this.dynamicSearch();
|
|
}
|
|
|
|
|
|
async dynamicSearch() {
|
|
|
|
if(this.showSearch && this.searchSubject) {
|
|
|
|
const list = this.pendentesstore.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.pendentesstore.list
|
|
|
|
this.list = this.TaskService.reorderList(this.ordinance, list)
|
|
}
|
|
|
|
}
|
|
|
|
openSearch() {
|
|
this.dynamicSearch()
|
|
}
|
|
async closeSearch() {
|
|
this.searchSubject = ''
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
async basicSearch() {
|
|
this.dynamicSearch()
|
|
}
|
|
|
|
|
|
async LoadList(){
|
|
this.skeletonLoader = true;
|
|
this.processes.GetPendingTasks(false).subscribe(async (pendentes) => {
|
|
this.skeletonLoader = false;
|
|
|
|
let pendentesList = [];
|
|
|
|
pendentes.forEach(element => {
|
|
let task: customTask = this.customTaskPipe.transform(element);
|
|
pendentesList.push(task);
|
|
});
|
|
|
|
pendentesList = removeDuplicate( pendentesList)
|
|
pendentesList = this.sortService.sortDate(pendentesList, 'CreateDate')
|
|
|
|
this.listToPresent = pendentesList
|
|
this.pendentesstore.reset(pendentesList);
|
|
this.storage.set('pendente-list',pendentesList).then(() => {
|
|
|
|
})
|
|
|
|
this.dynamicSearch()
|
|
|
|
}, (error) => {
|
|
this.skeletonLoader = false;
|
|
if(error.status == 0){
|
|
this.getFromDb();
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
getFromDb() {
|
|
this.storage.get('pendente-list').then((pendentes) => {
|
|
this.listToPresent =pendentes
|
|
})
|
|
}
|
|
|
|
doRefresh(event) {
|
|
if (event) {
|
|
setTimeout(() => {
|
|
try {
|
|
event?.target?.complete();
|
|
} catch(error) {}
|
|
}, 2000);
|
|
}
|
|
|
|
setTimeout(()=>{
|
|
this.LoadList();
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
async viewTaskDetails({ SerialNumber, WorkflowName, activityInstanceName }:customTask) {
|
|
|
|
//
|
|
|
|
if(WorkflowName == 'Despacho') {
|
|
this.router.navigate(['/home/gabinete-digital/despachos',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else if (WorkflowName == 'Despacho do Presidente da República') {
|
|
this.router.navigate(['/home/gabinete-digital/despachos-pr', SerialNumber, 'gabinete-digital']);
|
|
}
|
|
else if(WorkflowName == 'Pedido de Parecer' || WorkflowName == 'Pedido de Deferimento' || WorkflowName == 'Pedido de Parecer do Presidente') {
|
|
this.router.navigate(['/home/gabinete-digital/pedidos',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else if(WorkflowName == 'Expediente') {
|
|
this.router.navigate(['/home/gabinete-digital/expediente',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else if(WorkflowName == 'Expediente' && this.loggeduser.Profile == 'PR') {
|
|
this.router.navigate(['/home/gabinete-digital/expedientes-pr',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else if (activityInstanceName == "Tarefa de Parecer") {
|
|
this.router.navigate(['/home/gabinete-digital/pedidos',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else if(activityInstanceName == "Tarefa de Despacho") {
|
|
this.router.navigate(['/home/gabinete-digital/despachos',SerialNumber,'gabinete-digital']);
|
|
}
|
|
else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|