Files
doneit-web/src/app/pages/gabinete-digital/event-list/approve-event/approve-event.page.ts
T
Eudes Inácio 46387d4977 to many changes
2023-02-27 17:39:10 +01:00

436 lines
12 KiB
TypeScript

import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { AnimationController, MenuController, ModalController, PopoverController } from '@ionic/angular';
import { Event } from 'src/app/models/event.model';
import { ProcessesService } from 'src/app/services/processes.service';
import { EmendMessageModalPage } from 'src/app/pages/agenda/emend-message-modal/emend-message-modal.page';
import { EventActionsPopoverPage } from 'src/app/pages/agenda/event-actions-popover/event-actions-popover.page';
import { EditEventToApproveComponent } from 'src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page';
import { ToastService } from 'src/app/services/toast.service';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { SqliteService } from '../../../../services/sqlite.service';
import { BackgroundService } from '../../../../services/background.service';
import { Platform } from '@ionic/angular';
import { ThemeService } from 'src/app/services/theme.service'
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
import { RouteService } from 'src/app/services/route.service';
import { Storage } from '@ionic/storage';
import config from 'capacitor.config';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
@Component({
selector: 'app-approve-event',
templateUrl: './approve-event.page.html',
styleUrls: ['./approve-event.page.scss'],
})
export class ApproveEventPage implements OnInit {
event: Event;
loadedEvent: any = false
loadedAttachments: any;
customDate: any;
today: any;
show: boolean = false;
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
serialNumber: string;
caller: string;
attachments: any;
@Input() InstanceId: string;
@Output() approveEventDismiss = new EventEmitter<any>();
@Output() closeEventToApprove = new EventEmitter<any>();
@Output() AproveEventEditEvent = new EventEmitter<any>();
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private modalController: ModalController,
private processes: ProcessesService,
private popoverController: PopoverController,
private menu: MenuController,
private toastService: ToastService,
private RouteService: RouteService,
private sqliteservice: SqliteService,
private platform: Platform,
private backgroundservice: BackgroundService,
public ThemeService: ThemeService,
private offlineManager: OfflineManagerService,
private storage: Storage,
private httpErrorHandle: HttpErrorHandle
) {
this.activatedRoute.paramMap.subscribe(params => {
//
if (params["params"].serialNumber) {
this.serialNumber = params["params"].serialNumber;
}
if (params["params"].caller) {
this.caller = params["params"].caller;
}
});
}
toDateString(e) {
return new Date(e).toDateString()
}
ngOnInit() {
this.getTask();
this.backgroundservice.registerBackService('Online', () => {
this.getTask();
});
}
goBack() {
this.RouteService.goBack();
/* let navigationExtras: NavigationExtras = {
queryParams: {
"eventos": true,
}
};
if( window.innerWidth < 801) {
this.router.navigate(['/home',this.caller, 'event-list']);
} else {
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
} */
}
addProcessToDB(data) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.set('approve_event_detils', data).then(() => {
})
} else {
this.sqliteservice.updateProcess(data);
}
}
getProcessFromDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('approve_event_detils').then((event) => {
this.loadedEvent = event
try {
this.today = new Date(this.loadedEvent.workflowInstanceDataFields.StartDate);
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
} catch(error) {
console.log(this.loadedEvent)
throw(error)
}
this.loadedAttachments = this.loadedEvent.Documents;
})
} else {
this.platform.ready().then(() => {
this.sqliteservice.getProcessById(this.serialNumber).then((process) => {
var doc;
var action = [];
var origi = [];
var wordafi = {};
if (process[0].Documents === "null" || process[0].Documents === "undefined") {
doc = []
} else {
doc = JSON.parse(process[0].Documents)
}
if (process[0].actions === "null" || process[0].actions === "undefined") {
action = []
} else {
action = JSON.parse(process[0].Documents)
}
if (process[0].originator === "null" || process[0].originator === "undefined") {
origi = []
} else {
origi = JSON.parse(process[0].Documents)
}
if (process[0].workflowInstanceDataFields === "null" || process[0].workflowInstanceDataFields === "undefined") {
wordafi = []
} else {
wordafi = JSON.parse(process[0].workflowInstanceDataFields)
}
let task = {
"Documents": doc,
"actions": action,
"activityInstanceName": process[0].activityInstanceName,
"formURL": process[0].formURL,
"originator": origi,
"serialNumber": process[0].serialNumber,
"taskStartDate": process[0].taskStartDate,
"totalDocuments": process[0].totalDocuments,
"workflowDisplayName": process[0].workflowDisplayName,
"workflowID": process[0].workflowID,
"workflowInstanceDataFields": wordafi,
"workflowInstanceFolio": process[0].workflowInstanceFolio,
"workflowInstanceID": process[0].workflowInstanceID,
"workflowName": process[0].workflowInstanceID
}
this.loadedEvent = task
this.loadedAttachments = this.loadedEvent.Documents;
try {
this.today = new Date(this.loadedEvent.workflowInstanceDataFields.StartDate);
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
} catch(error) {
console.log(this.loadedEvent)
throw(error)
}
})
})
}
}
async getTask() {
this.processes.GetTask(this.serialNumber).subscribe(async res => {
this.loadedEvent = res
this.addProcessToDB(this.loadedEvent)
try {
this.today = new Date(this.loadedEvent.workflowInstanceDataFields.StartDate);
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
} catch(error) {
console.log(this.loadedEvent)
throw(error)
}
}, (error) => {
if(error.status == 0) {
this.getProcessFromDB();
} else {
this.httpErrorHandle.httpStatusHandle(error)
}
})
}
async approveTask(serialNumber: string) {
let body = { "serialNumber": serialNumber, "action": "Aprovar" }
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise()
this.goBack();
this.httpErrorHandle.httpsSucessMessagge('Evento aprovação')
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async emendTask(serialNumber: string) {
const modal = await this.modalController.create({
component: EmendMessageModalPage,
componentProps: {
},
cssClass: 'emend-message-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss()
.then(async (res) => {
if(res.data.option == 'save') {
if (res.data !== '') {
let body = {
"serialNumber": serialNumber,
"action": "Emendar",
"dataFields": {
"ReviewUserComment": res.data,
}
}
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise()
.catch(() => {
this.offlineManager.storeRequestData('event-listRever', body);
});
this.httpErrorHandle.httpsSucessMessagge('Rever')
this.goBack();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
else {
this.toastService._badRequest('É necessário adicionar uma nota');
}
}
});
}
async rejeitar(serialNumber: string) {
let body = { "serialNumber": serialNumber, "action": "Descartar" }
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise();
this.httpErrorHandle.httpsSucessMessagge('Rejeitar')
this.goBack();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async viewDocument(DocId: string, Document) {
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: Document.Assunto,
url: '',
title_link: '',
},
Document,
applicationId: Document.ApplicationId,
docId: Document.DocId || Document.SourceId,
folderId: this.loadedEvent.FolderId,
task: this.loadedEvent
},
cssClass: 'modal modal-desktop'
});
await modal.present();
}
async openOptions(ev: any) {
const popover = await this.popoverController.create({
component: EventActionsPopoverPage,
cssClass: 'events-options',
event: ev,
translucent: true,
componentProps: {
serialNumber: ev.serialNumber,
InstanceId: ev.workflowInstanceDataFields.InstanceId,
activityInstanceName: this.loadedEvent.activityInstanceName
},
});
return await popover.present();
}
openMenu() {
this.menu.open();
}
async openEmendMessageModal(serialNumber: string) {
const modal = await this.modalController.create({
component: EmendMessageModalPage,
componentProps: {
},
cssClass: 'emend-message-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(async (res) => {
if(res.data.option == 'save') {
if (res.data.note !== '') {
let body = {
"serialNumber": serialNumber,
"action": "Emendar",
"dataFields": {
"ReviewUserComment": res.data,
}
}
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise();
this.goBack();
this.httpErrorHandle.httpsSucessMessagge('Rever')
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
else {
this.toastService._badRequest('É necessário adicionar uma nota');
}
} else {
}
});
}
goToEventsToApprove() {
let navigationExtras: NavigationExtras = {
queryParams: {
"eventos": true,
}
};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
async editar(serialNumber: string) {
const modal = await this.modalController.create({
component: EditEventToApproveComponent,
componentProps: {
serialNumber: serialNumber,
InstanceId: this.InstanceId
},
cssClass: 'modal modal-desktop'
});
await modal.present();
modal.onDidDismiss().then(res => {
this.getTask();
});
}
}