Files
doneit-web/src/app/shared/agenda/approve-event/approve-event.page.ts
T

226 lines
6.1 KiB
TypeScript
Raw Normal View History

2021-02-26 15:29:05 +01:00
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
2021-04-07 14:08:05 +01:00
import { NavigationExtras, Router } from '@angular/router';
2021-06-30 10:24:23 +01:00
import { ModalController, PopoverController } from '@ionic/angular';
2021-02-26 15:29:05 +01:00
import { Event } from 'src/app/models/event.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
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';
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-10-25 13:21:48 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2021-02-26 15:29:05 +01:00
@Component({
selector: 'app-approve-event',
2021-06-03 14:10:16 +01:00
templateUrl: './approve-event.page.html',
styleUrls: ['./approve-event.page.scss'],
2021-02-26 15:29:05 +01:00
})
2021-06-03 14:10:16 +01:00
export class ApproveEventPage implements OnInit {
2021-02-26 15:29:05 +01:00
event: Event;
2021-07-26 15:19:03 +01:00
@Input() loadedEvent:any;
2021-02-26 15:29:05 +01:00
loadedAttachments:any;
customDate:any;
today:any;
2021-03-25 15:46:43 +01:00
show: boolean = false;
2021-02-26 15:29:05 +01:00
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"];
@Input() serialNumber:string;
2021-07-26 15:19:03 +01:00
@Input() showComponent:string;
@Input() componentTransparent: any
2021-05-03 13:08:57 +01:00
@Input() InstanceId:string;
2021-03-25 15:46:43 +01:00
@Input() showAside:boolean;
2021-02-26 15:29:05 +01:00
@Output() approveEventDismiss = new EventEmitter<any>();
@Output() closeEventToApprove = new EventEmitter<any>();
2021-03-03 10:15:44 +01:00
@Output() AproveEventEditEvent = new EventEmitter<any>();
2021-02-26 15:29:05 +01:00
2021-06-29 14:15:56 +01:00
@Output() EditApproveEventDismiss = new EventEmitter<any>();
2021-02-26 15:29:05 +01:00
constructor(
2022-06-03 16:53:50 +01:00
private router: Router,
2021-02-26 15:29:05 +01:00
private modalController: ModalController,
2022-06-03 16:53:50 +01:00
private processes: ProcessesService,
2021-02-26 15:29:05 +01:00
private attachmentsService: AttachmentsService,
private popoverController: PopoverController,
2021-10-25 13:21:48 +01:00
private toastService: ToastService,
public ThemeService: ThemeService
2021-06-30 10:24:23 +01:00
) {
// Event to approve list
2021-06-10 11:20:41 +01:00
2021-05-03 13:08:57 +01:00
}
2021-02-26 15:29:05 +01:00
2021-07-17 22:42:02 +01:00
toDateString(e) {
return new Date(e).toDateString()
}
2021-02-26 15:29:05 +01:00
ngOnInit() {
this.getTask();
this.getAttachments();
2021-07-26 15:19:03 +01:00
}
2021-02-26 15:29:05 +01:00
2021-05-24 16:49:25 +01:00
close() {
2021-02-26 15:29:05 +01:00
this.closeEventToApprove.emit();
2021-03-25 15:46:43 +01:00
this.modalController.dismiss();
2021-02-26 15:29:05 +01:00
}
2021-05-24 16:49:25 +01:00
getTask() {
2021-02-26 15:29:05 +01:00
this.processes.GetTask(this.serialNumber).subscribe(res => {
2022-04-28 09:32:27 +01:00
2021-02-26 15:29:05 +01:00
this.loadedEvent = res;
2022-06-29 15:51:28 +01:00
// console.log(this.loadedEvent);
2021-02-26 15:29:05 +01:00
this.today = new Date(res.workflowInstanceDataFields.StartDate);
2022-04-28 09:32:27 +01:00
//
2021-02-26 15:29:05 +01:00
this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
2021-02-26 15:29:05 +01:00
})
}
2021-05-24 16:49:25 +01:00
2021-06-30 09:45:56 +01:00
async approveTask(serialNumber:string) {
2021-04-06 09:26:31 +01:00
let body = { "serialNumber": serialNumber, "action": "Aprovar" }
2021-05-24 16:49:25 +01:00
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-24 16:49:25 +01:00
try {
2021-05-28 15:45:41 +01:00
await this.processes.PostTaskAction(body).toPromise()
2021-05-24 16:49:25 +01:00
this.modalController.dismiss(serialNumber);
2022-06-10 14:08:30 +01:00
this.toastService._successMessage()
2021-05-24 16:49:25 +01:00
} catch (error) {
2022-06-10 14:08:30 +01:00
this.toastService._badRequest()
2022-06-03 16:53:50 +01:00
} finally {
2021-07-26 15:19:03 +01:00
this.close()
2021-07-12 11:13:29 +01:00
loader.remove()
2021-05-24 16:49:25 +01:00
}
2021-02-26 15:29:05 +01:00
}
2021-05-28 15:45:41 +01:00
async rejectTask(serialNumber:string) {
2021-02-26 15:29:05 +01:00
let body = { "serialNumber": serialNumber, "action": "Rejeitar" }
2022-04-28 09:32:27 +01:00
2021-05-24 16:49:25 +01:00
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-24 16:49:25 +01:00
try {
2021-05-28 15:13:50 +01:00
await this.processes.PostTaskAction(body).toPromise()
2022-06-10 14:08:30 +01:00
this.toastService._successMessage('Evento rejeitado')
2021-05-24 16:49:25 +01:00
} catch (error) {
2022-06-10 14:08:30 +01:00
this.toastService._badRequest('Processo não efectuado')
2021-07-26 15:19:03 +01:00
} finally {
2021-07-12 11:13:29 +01:00
loader.remove()
2021-07-26 15:19:03 +01:00
this.close()
2021-05-24 16:49:25 +01:00
}
2021-02-26 15:29:05 +01:00
}
2021-06-30 09:45:56 +01:00
async getAttachments() {
2021-05-03 13:08:57 +01:00
this.loadedAttachments = await this.attachmentsService.getAttachmentsById(this.InstanceId).toPromise();
}
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'
2021-02-26 15:29:05 +01:00
});
await modal.present();
2021-02-26 15:29:05 +01:00
}
async openOptions(ev:any) {
const popover = await this.popoverController.create({
component: EventActionsPopoverPage,
2022-06-03 16:53:50 +01:00
componentProps: {
activityInstanceName: this.loadedEvent.activityInstanceName
},
2021-02-26 15:29:05 +01:00
cssClass: 'event-actions-popover',
event: ev,
translucent: true
});
return await popover.present();
}
2021-05-24 16:49:25 +01:00
2021-06-30 09:45:56 +01:00
async emendTask(serialNumber:string) {
2022-04-28 09:32:27 +01:00
2021-02-26 15:29:05 +01:00
const modal = await this.modalController.create({
component: EmendMessageModalPage,
componentProps:{
},
cssClass: 'emend-message-modal',
backdropDismiss: false
2021-06-22 12:59:28 +01:00
});
2021-02-26 15:29:05 +01:00
await modal.present();
2021-06-22 12:59:28 +01:00
modal.onDidDismiss()
.then( async (res) => {
2022-04-28 09:32:27 +01:00
2022-06-17 16:02:32 +01:00
if(res.data.note !== '') {
let body = { "serialNumber": serialNumber,
2021-02-26 15:29:05 +01:00
"action": "Emendar",
2021-05-03 13:08:57 +01:00
"dataFields": {
2021-06-14 15:34:34 +01:00
"ReviewUserComment": res.data,
2021-05-03 13:08:57 +01:00
}
2021-02-26 15:29:05 +01:00
}
2022-04-28 09:32:27 +01:00
2022-06-03 16:53:50 +01:00
const loader = this.toastService.loading();
2021-06-22 12:59:28 +01:00
try {
2021-06-22 12:59:28 +01:00
await this.processes.PostTaskAction(body).toPromise();
2022-06-10 14:08:30 +01:00
this.toastService._successMessage('Pedido enviado');
2021-06-22 12:59:28 +01:00
this.close();
} catch (error) {
2022-06-10 14:08:30 +01:00
this.toastService._badRequest();
2021-07-12 11:13:29 +01:00
} finally {
loader.remove()
2021-06-22 12:59:28 +01:00
}
2021-02-26 15:29:05 +01:00
}
2022-06-17 16:02:32 +01:00
else {
if(res.data.option == 'save') {
this.toastService._badRequest('É necessário adicionar uma nota');
}
2022-06-13 15:27:28 +01:00
}
2021-02-26 15:29:05 +01:00
});
2021-02-26 15:29:05 +01:00
}
2021-06-30 09:45:56 +01:00
goToEventsToApprove() {
2021-07-28 14:18:02 +01:00
if(window.location.pathname.startsWith('/home/agenda')) {
this.close()
} else {
let navigationExtras: NavigationExtras = {
queryParams: {
2021-05-21 10:05:59 +01:00
"eventos": true,
2021-07-28 14:18:02 +01:00
}
};
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
2021-04-07 14:08:05 +01:00
}
2021-05-04 13:55:28 +01:00
2021-06-30 09:45:56 +01:00
/** @description edit event to aprove */
2021-05-04 13:55:28 +01:00
async editar(serialNumber: string) {
2021-06-30 09:45:56 +01:00
this.EditApproveEventDismiss.emit();
2021-05-24 16:49:25 +01:00
2021-06-30 09:45:56 +01:00
}
2021-02-26 15:29:05 +01:00
}