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

180 lines
4.6 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, PopoverController } from '@ionic/angular';
import { ProcessesService } from 'src/app/services/processes.service';
import { ToastService } from 'src/app/services/toast.service';
import { EditEventToApproveComponent } from 'src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page';
import { EmendMessageModalPage } from '../emend-message-modal/emend-message-modal.page';
import { ThemeService } from 'src/app/services/theme.service'
import { RouteService } from 'src/app/services/route.service';
import { HttpErrorHandle } from 'src/app/services/http-error-handle.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;
activityInstanceName: string
constructor(
private navParams: NavParams,
private processes:ProcessesService,
private modalController: ModalController,
private popoverController: PopoverController,
private toastService: ToastService,
private RouteService: RouteService,
private httpErrorHandle: HttpErrorHandle,
public ThemeService: ThemeService) {
this.serialNumber = this.navParams.get('serialNumber');
this.instanceId = this.navParams.get('InstanceId');
this.activityInstanceName = this.navParams.get('InstanceId');
}
ngOnInit() {
window.onresize = (event) => {
if( window.innerWidth >= 800){
this.popoverController.dismiss();
}
};
}
goBack() {
this.closePopover();
this.RouteService.goBack()
}
closePopover() {
this.popoverController.dismiss();
}
async approveTask() {
let body = { "serialNumber": this.serialNumber, "action": "Aprovar" }
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise()
this.httpErrorHandle.httpsSucessMessagge('Evento aprovação')
this.goBack();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async ReenviarTask() {
let body = { "serialNumber": this.serialNumber, "action": "Reenviar" }
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise()
this.httpErrorHandle.httpsSucessMessagge('Rever')
this.goBack();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
async emendarTask() {
this.closePopover();
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": this.serialNumber,
"action": "Emendar",
"dataFields": {
"ReviewUserComment": res.data,
}
}
const loader = this.toastService.loading()
try {
await this.processes.PostTaskAction(body).toPromise();
this.httpErrorHandle.httpsSucessMessagge('Rever')
this.goBack();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
}
finally {
loader.remove()
}
}
else {
this.toastService._badRequest('É necessário adicionar uma nota');
}
} else {
}
});
}
async rejeitar() {
let body = { "serialNumber": this.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 editTask() {
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 => {
});
}
}