Files
doneit-web/src/app/shared/popover/deploma-options/deploma-options.page.ts
T
Peter Maquiran 11f1fedcc9 Improve messages
2021-06-09 10:49:37 +01:00

215 lines
5.3 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AnimationController, ModalController, PopoverController } from '@ionic/angular';
import { AddNotePage } from 'src/app/modals/add-note/add-note.page';
import { BookMeetingModalPage } from 'src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page';
import { ProcessesService } from 'src/app/services/processes.service';
import { BadRequestPage } from '../bad-request/bad-request.page';
import { SuccessMessagePage } from '../success-message/success-message.page';
@Component({
selector: 'app-deploma-options',
templateUrl: './deploma-options.page.html',
styleUrls: ['./deploma-options.page.scss'],
})
export class DeplomaOptionsPage implements OnInit {
serialnumber: string;
profile: string;
task: any
fulltask: any
constructor(public popoverController: PopoverController,
private modalController: ModalController,
private activatedRoute: ActivatedRoute,
private processes: ProcessesService,
private animationController: AnimationController) {
this.activatedRoute.queryParams.subscribe(params => {
if(params["serialNumber"]) {
this.serialnumber = params["serialNumber"];
console.log(params["serialNumber"]);
}
});
}
ngOnInit() {
}
async openAddNoteModal(actionName:string) {
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop'
}
const modal = await this.modalController.create({
component: AddNotePage,
componentProps:{
},
cssClass: classs,
backdropDismiss: true
});
await modal.present();
modal.onDidDismiss().then(res => {
if(res.data){
const DocumentToSave = res.data.documents.map((e) => {
return {
ApplicationId: e.ApplicationType,
SourceId: e.Id,
}
});
let docs = {
ProcessInstanceID: "",
Attachments: DocumentToSave,
}
if(actionName == 'Solicitar assinatura'){
this.askSignature(res.data.note, docs);
this.goBack();
}
else if(actionName == 'Solicitar alteração'){
this.askToChange(res.data.note, docs);
this.goBack();
}
}
});
}
async askToChange(note:string, documents:any){
let body = {
"serialNumber": this.serialnumber,
"action": "Retificar",
"ActionTypeId": 99999841,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
try {
await this.processes.CompleteTask(body).toPromise()
this.close();
this.successMessage()
} catch (error) {
this.badRequest()
}
}
async openBookMeetingModal(task: any) {
let classs;
if( window.innerWidth <= 800){
classs = 'book-meeting-modal modal modal-desktop'
} else {
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: BookMeetingModalPage,
componentProps: {
task: this.task,
},
cssClass: classs,
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
async askSignature(note:string, documents:any) {
let body = {
"serialNumber": this.serialnumber,
"action": "Aprovar",
"ActionTypeId": 99999840,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
try {
await this.processes.CompleteTask(body).toPromise()
this.close();
this.successMessage()
} catch (error) {
this.badRequest()
}
}
async successMessage(message?: string) {
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
const modal = await this.modalController.create({
enterAnimation,
leaveAnimation,
component: SuccessMessagePage,
componentProps: {
message: message || 'Processo efetuado' ,
},
cssClass: 'notification-modal'
});
modal.present()
setTimeout(()=>{
modal.dismiss()
},7000)
}
async badRequest(message?: string) {
const modal = await this.modalController.create({
component: BadRequestPage,
componentProps: {
message: message || 'Processo efetuado' ,
},
cssClass: 'notification-modal'
});
modal.present()
setTimeout(()=>{
modal.dismiss()
},7000)
}
goBack() {
this.close()
}
close(){}
}