Files
doneit-web/src/app/pages/agenda/event-actions-popover/event-actions-popover.page.ts
T

175 lines
4.2 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2022-04-26 16:53:10 +01:00
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
2020-11-09 14:00:10 +01:00
import { ProcessesService } from 'src/app/services/processes.service';
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
import { EditEventToApproveComponent } from 'src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page';
2021-06-18 17:02:32 +01:00
import { EmendMessageModalPage } from '../emend-message-modal/emend-message-modal.page';
2021-10-25 15:31:43 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2022-01-06 14:47:22 +01:00
import { RouteService } from 'src/app/services/route.service';
@Component({
selector: 'app-event-actions-popover',
templateUrl: './event-actions-popover.page.html',
styleUrls: ['./event-actions-popover.page.scss'],
})
export class EventActionsPopoverPage implements OnInit {
serialNumber:string;
instanceId: string;
2022-06-03 16:53:50 +01:00
activityInstanceName: string
constructor(
private navParams: NavParams,
2020-11-09 14:00:10 +01:00
private processes:ProcessesService,
private modalController: ModalController,
2021-06-08 15:59:06 +01:00
private popoverController: PopoverController,
2021-08-25 09:38:13 +01:00
private toastService: ToastService,
2022-01-06 14:47:22 +01:00
private RouteService: RouteService,
2021-10-25 15:31:43 +01:00
public ThemeService: ThemeService) {
this.serialNumber = this.navParams.get('serialNumber');
this.instanceId = this.navParams.get('InstanceId');
2022-06-03 16:53:50 +01:00
this.activityInstanceName = this.navParams.get('InstanceId');
}
ngOnInit() {
window.onresize = (event) => {
if( window.innerWidth >= 800){
this.popoverController.dismiss();
}
};
}
2021-06-17 16:12:56 +01:00
2021-08-25 09:38:13 +01:00
goBack() {
2021-06-17 16:12:56 +01:00
this.closePopover();
2021-06-18 17:02:32 +01:00
2022-01-06 14:47:22 +01:00
this.RouteService.goBack()
2021-06-17 16:12:56 +01:00
}
2021-08-25 09:38:13 +01:00
closePopover() {
this.popoverController.dismiss();
}
2021-06-17 16:12:56 +01:00
2021-07-16 19:32:13 +01:00
async approveTask() {
2021-06-03 15:36:15 +01:00
let body = { "serialNumber": this.serialNumber, "action": "Aprovar" }
2022-04-28 09:32:27 +01:00
2021-06-17 16:12:56 +01:00
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-06-08 16:56:48 +01:00
try {
2021-07-16 19:32:13 +01:00
await this.processes.PostTaskAction(body).toPromise()
2021-07-12 11:13:29 +01:00
2021-06-17 16:12:56 +01:00
this.toastService.successMessage();
this.goBack();
2021-05-28 15:13:50 +01:00
} catch (error) {
2021-07-12 11:13:29 +01:00
2021-06-15 15:09:20 +01:00
this.toastService.badRequest()
2021-05-28 15:13:50 +01:00
}
2021-07-12 11:13:29 +01:00
finally {
loader.remove()
}
}
2021-06-17 16:12:56 +01:00
2022-06-03 16:53:50 +01:00
async ReenviarTask() {
let body = { "serialNumber": this.serialNumber, "action": "Reenviar" }
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise()
this.toastService.successMessage();
this.goBack();
} catch (error) {
this.toastService.badRequest()
}
finally {
loader.remove()
}
}
2021-06-18 17:02:32 +01:00
async emendarTask() {
2021-06-22 11:43:09 +01:00
this.closePopover();
2021-06-18 17:02:32 +01:00
const modal = await this.modalController.create({
component: EmendMessageModalPage,
componentProps:{
},
cssClass: 'emend-message-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss()
.then( async (res) => {
2022-04-28 09:32:27 +01:00
2021-06-18 17:02:32 +01:00
2022-06-17 16:02:32 +01:00
if(res.data.note !== ''){
2021-06-18 17:02:32 +01:00
let body = { "serialNumber": this.serialNumber,
"action": "Emendar",
"dataFields": {
"ReviewUserComment": res.data,
}
}
2022-04-28 09:32:27 +01:00
2021-06-18 17:02:32 +01:00
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-06-18 17:02:32 +01:00
try {
await this.processes.PostTaskAction(body).toPromise();
this.toastService.successMessage('Pedido enviado');
this.goBack();
} catch (error) {
this.toastService.badRequest();
}
2021-07-12 11:13:29 +01:00
finally {
loader.remove()
}
2021-06-18 17:02:32 +01:00
}
else{
2022-06-03 16:53:50 +01:00
2021-06-18 17:02:32 +01:00
}
});
}
2022-06-03 16:53:50 +01:00
async rejeitar() {
2021-06-17 16:12:56 +01:00
let body = { "serialNumber": this.serialNumber, "action": "Rejeitar" }
2021-07-12 11:13:29 +01:00
2022-06-03 16:53:50 +01:00
const loader = this.toastService.loading();
2021-06-17 16:12:56 +01:00
try {
2021-07-16 19:32:13 +01:00
await this.processes.PostTaskAction(body).toPromise();
2021-06-17 16:12:56 +01:00
await this.toastService.successMessage('Processo rejeitado');
this.goBack();
} catch (error) {
2022-06-03 16:53:50 +01:00
this.toastService.badRequest();
2021-06-17 16:12:56 +01:00
}
2021-07-12 11:13:29 +01:00
finally {
2022-06-03 16:53:50 +01:00
loader.remove();
2021-07-12 11:13:29 +01:00
}
}
2021-06-17 16:12:56 +01:00
async editTask() {
2021-06-22 11:43:09 +01:00
this.closePopover();
const modal = await this.modalController.create({
component: EditEventToApproveComponent,
componentProps: {
serialNumber: this.serialNumber,
InstanceId: this.instanceId
},
cssClass: 'modal modal-desktop',
// backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(res => {
});
2022-06-03 16:53:50 +01:00
}
}