Files
doneit-web/src/app/pages/gabinete-digital/expediente/expediente.page.ts
T
Peter Maquiran b15396e480 improve
2022-05-30 15:52:20 +01:00

168 lines
4.7 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';
@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;
taskslist = [];
serialNumber: string;
//expedienteGdStore = ExpedienteGdStore;
expedientegbstore = ExpedienteGdStore
expedienteTaskPipe = new ExpedienteTaskPipe()
onlinecheck: boolean;
listToPresent= []
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
) { }
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();
});
}
LoadList() {
this.processes.GetTaskListExpediente(false).subscribe(async res => {
this.skeletonLoader = true
const result = res
this.taskslist = new Array();
let ress = result.filter((data: any) => data.workflowInstanceDataFields.Status == "Active");
ress.forEach((element: any) => {
let task = this.expedienteTaskPipe.transform(element)
this.taskslist.push(task);
this.addProcessTODb(task);
});
this.taskslist = this.taskslist.filter(function(item) {
return item.activityInstanceName != 'Retificar Expediente'
})
this.listToPresent = this.sortService.sortDate(this.taskslist, 'taskStartDate')
this.skeletonLoader = false;
}, (error) => {
this.getEventsFromLocalDb();
})
}
async refreshing() {
setTimeout(() => {
this.LoadList();
}, 1000);
}
doRefresh(event) {
this.LoadList();
setTimeout(() => {
event.target.complete();
}, 1000);
}
goBack() {
this.router.navigate(['/home/gabinete-digital']);
}
goToExpediente(serialNumber: any) {
//
this.router.navigate(['/home/gabinete-digital/expediente', serialNumber, 'gabinete-digital']);
}
addProcessTODb(task) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.set('gabinete-expediente',task).then(() => {
})
} else {
this.sqliteservice.addProcess(task);
}
}
getEventsFromLocalDb() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('gabinete-expediente').then((expediente) => {
this.listToPresent = expediente
})
} else {
this.taskslist = new Array();
this.sqliteservice.getprocessByworkflow("Expediente").then((expediente: any[]) => {
expediente.forEach((element) => {
var workflow = JSON.parse(element.workflowInstanceDataFields);
let exped = {
"CreateDate": element.taskStartDate,
"DocumentsQty": element.totalDocuments,
"Senders": workflow.Senders,
"SerialNumber": element.serialNumber,
"Status": workflow.Status,
"Subject": workflow.Subject,
"WorkflowName": element.workflowDisplayName,
"activityInstanceName": element.activityInstanceName
}
this.taskslist.push(exped)
});
this.taskslist = this.taskslist.filter(function(item) {
return item.activityInstanceName != 'Retificar Expediente'
})
this.listToPresent = this.taskslist
})
}
}
}