Files
doneit-web/src/app/shared/popover/despachos-options/despachos-options.page.ts
T

316 lines
8.2 KiB
TypeScript
Raw Normal View History

2021-05-27 14:33:17 +01:00
import { Component, OnInit } from '@angular/core';
import { ProcessesService } from 'src/app/services/processes.service';
2021-07-07 08:39:54 +01:00
import { ActivatedRoute, Router } from '@angular/router';
2021-07-01 11:08:04 +01:00
import { AnimationController, ModalController, NavParams, PopoverController } from '@ionic/angular';
2021-05-27 14:33:17 +01:00
import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page';
import { DelegarPage } from 'src/app/modals/delegar/delegar.page';
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 { DiscartExpedientModalPage } from 'src/app/pages/gabinete-digital/discart-expedient-modal/discart-expedient-modal.page';
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-08-19 11:32:08 +01:00
import { customTask, fullTask } from 'src/app/models/dailyworktask.model';
2021-09-30 15:56:04 +01:00
import { PermissionService } from 'src/app/services/worker/permission.service';
2021-10-25 15:31:43 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2021-05-27 14:33:17 +01:00
@Component({
selector: 'app-despachos-options',
templateUrl: './despachos-options.page.html',
styleUrls: ['./despachos-options.page.scss'],
})
export class DespachosOptionsPage implements OnInit {
2021-08-19 11:32:08 +01:00
task: customTask
fulltask: fullTask;
serialNumber: string;
2021-05-27 14:33:17 +01:00
constructor(private activateRoute: ActivatedRoute,
private processes: ProcessesService,
private router: Router,
private modalController: ModalController,
public popoverController: PopoverController,
2021-06-15 15:09:20 +01:00
private navParams: NavParams,
2021-07-07 08:39:54 +01:00
private toastService: ToastService,
2021-08-24 14:07:27 +01:00
public p: PermissionService,
2021-10-25 15:31:43 +01:00
public ThemeService: ThemeService
2021-07-07 08:39:54 +01:00
) {
2021-06-14 14:16:16 +01:00
this.task = this.navParams.get('task')
this.fulltask = this.navParams.get('fulltask')
2021-08-19 11:32:08 +01:00
this.serialNumber = this.task.SerialNumber
2021-06-14 14:16:16 +01:00
}
2021-05-27 14:33:17 +01:00
ngOnInit() {
}
close () {
this.goBack()
}
2021-07-01 12:36:37 +01:00
async openTaskProcessModal(taskAction: any, task: any) {
2021-06-22 11:43:09 +01:00
this.popoverController.dismiss();
2021-05-27 14:33:17 +01:00
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
2021-07-07 08:39:54 +01:00
} else {
2021-05-27 14:33:17 +01:00
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: CreateProcessPage,
componentProps: {
taskAction: taskAction,
task: task,
2021-08-13 16:39:28 +01:00
fulltask: this.fulltask
2021-05-27 14:33:17 +01:00
},
cssClass: classs,
});
await modal.present();
2021-08-23 14:17:32 +01:00
modal.onDidDismiss().then( res => {
2021-07-01 12:36:37 +01:00
this.goBack();
2021-05-27 14:33:17 +01:00
});
}
sendExpedienteToPending(){
2021-07-01 11:08:04 +01:00
this.popoverController.dismiss();
this.processes.SetTaskToPending(this.task.SerialNumber).subscribe(res=>{
2021-11-09 15:37:59 +01:00
this.toastService._successMessage()
2021-05-27 14:33:17 +01:00
console.log(res);
this.close();
2021-07-17 21:22:03 +01:00
},()=>{
2021-11-09 15:37:59 +01:00
this.toastService._badRequest('Processo não encontrado')
2021-05-27 14:33:17 +01:00
});
}
async distartExpedientModal(){
2021-06-22 11:43:09 +01:00
this.popoverController.dismiss();
2021-05-27 14:33:17 +01:00
console.log(this.fulltask);
const modal = await this.modalController.create({
component: DiscartExpedientModalPage,
componentProps: {
serialNumber: this.fulltask.serialNumber,
folderId: this.fulltask.workflowInstanceDataFields.FolderID,
action: 'complete',
},
cssClass: 'discart-expedient-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(res=>{
if(res['data']=='close'){
this.close();
}
});
}
async openBookMeetingModal(task: any) {
2021-06-22 11:43:09 +01:00
this.popoverController.dismiss();
2021-05-27 14:33:17 +01:00
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 openDelegarModal(task: any) {
2021-07-01 16:15:40 +01:00
this.popoverController.dismiss();
2021-05-27 14:33:17 +01:00
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: DelegarPage,
componentProps: {
task: this.task,
},
cssClass: classs,
backdropDismiss: false
});
await modal.present();
2021-07-01 16:15:40 +01:00
modal.onDidDismiss().then(res=>{
this.goBack();
});
2021-05-27 14:33:17 +01:00
}
async generateDiploma(note:string, documents:any){
let body = {
2021-08-19 11:32:08 +01:00
"serialNumber": this.serialNumber,
2021-05-27 14:33:17 +01:00
"action": "Reencaminhar",
"ActionTypeId": 99999839,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-27 14:33:17 +01:00
try {
2021-05-28 15:45:41 +01:00
await this.processes.CompleteTask(body).toPromise()
2021-11-09 15:37:59 +01:00
this.toastService._successMessage()
2021-05-27 14:33:17 +01:00
this.close();
} catch (error) {
2021-11-09 15:37:59 +01:00
this.toastService._badRequest()
2021-07-12 11:13:29 +01:00
} finally {
loader.remove()
2021-05-27 14:33:17 +01:00
}
}
async openAddNoteModal(actionName:string) {
2021-08-19 11:32:08 +01:00
2021-06-22 16:18:14 +01:00
this.popoverController.dismiss();
2021-05-27 14:33:17 +01:00
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
} else {
classs = 'modal modal-desktop'
}
const modal = await this.modalController.create({
component: AddNotePage,
2021-08-19 11:32:08 +01:00
componentProps: {
showAttachmentBtn: true
2021-05-27 14:33:17 +01:00
},
cssClass: classs,
backdropDismiss: true
});
await modal.present();
2021-07-16 19:32:13 +01:00
modal.onDidDismiss().then(async (res) => {
2021-05-27 14:33:17 +01:00
console.log(res);
2021-06-15 11:39:59 +01:00
if(res.data) {
2021-05-27 14:33:17 +01:00
const DocumentToSave = res.data.documents.map((e) => {
return {
ApplicationId: e.ApplicationType,
SourceId: e.Id,
}
});
let docs = {
ProcessInstanceID: "",
Attachments: DocumentToSave,
}
if(actionName == 'Executado'){
2021-07-16 19:32:13 +01:00
await this.executado(res.data.note, docs);
2021-05-27 14:33:17 +01:00
}
else if(actionName == 'Arquivar'){
2021-07-16 19:32:13 +01:00
await this.arquivar(res.data.note, docs);
2021-05-27 14:33:17 +01:00
}
else if(actionName == 'Gerar Diploma'){
2021-07-16 19:32:13 +01:00
await this.generateDiploma(res.data.note, docs);
2021-05-27 14:33:17 +01:00
}
else if(actionName == 'Concluido'){
//this.concluir(res.data.note, docs);
}
else if(actionName == 'Reexecução'){
2021-07-16 19:32:13 +01:00
await this.reexecutar(res.data.note, docs);
2021-05-27 14:33:17 +01:00
}
this.goBack();
}
});
}
2021-06-15 11:39:59 +01:00
async arquivar(note:string, documents:any) {
2021-05-27 14:33:17 +01:00
let body = {
2021-08-19 11:32:08 +01:00
"serialNumber": this.serialNumber,
2021-05-27 14:33:17 +01:00
"action": "Arquivo",
"ActionTypeId": 95,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-27 14:33:17 +01:00
try {
2021-05-28 15:45:41 +01:00
await this.processes.CompleteTask(body).toPromise()
2021-11-09 15:37:59 +01:00
this.toastService._successMessage('Processo arquivado')
2021-05-27 14:33:17 +01:00
this.close();
} catch (error) {
2021-11-09 15:37:59 +01:00
this.toastService._badRequest('Processo não arquivado')
2021-07-12 11:13:29 +01:00
} finally {
loader.remove()
2021-05-27 14:33:17 +01:00
}
2021-07-12 11:13:29 +01:00
2021-05-27 14:33:17 +01:00
}
async executado(note:string, documents:any){
let body = {
2021-08-19 11:32:08 +01:00
"serialNumber": this.serialNumber,
2021-05-27 14:33:17 +01:00
"action": "Conhecimento",
"ActionTypeId": 104,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-27 14:33:17 +01:00
try {
2021-05-28 15:45:41 +01:00
await this.processes.CompleteTask(body).toPromise()
2021-05-27 14:33:17 +01:00
this.close();
2021-11-09 15:37:59 +01:00
this.toastService._successMessage()
2021-05-27 14:33:17 +01:00
} catch(error) {
2021-11-09 15:37:59 +01:00
this.toastService._badRequest()
2021-07-12 11:13:29 +01:00
} finally {
loader.remove()
2021-05-27 14:33:17 +01:00
}
2021-07-12 11:13:29 +01:00
2021-05-27 14:33:17 +01:00
}
2021-06-17 09:13:48 +01:00
2021-05-27 14:33:17 +01:00
async reexecutar(note:string, documents:any){
let body = {
2021-08-19 11:32:08 +01:00
"serialNumber": this.serialNumber,
2021-05-27 14:33:17 +01:00
"action": "Reexecutar",
"ActionTypeId": 100000010,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-07-12 11:13:29 +01:00
const loader = this.toastService.loading()
2021-05-27 14:33:17 +01:00
try {
2021-05-28 15:45:41 +01:00
await this.processes.CompleteTask(body).toPromise()
2021-11-09 15:37:59 +01:00
this.toastService._successMessage()
2021-05-27 14:33:17 +01:00
this.close();
} catch (error) {
2021-11-09 15:37:59 +01:00
this.toastService._badRequest()
2021-07-12 11:13:29 +01:00
} finally {
loader.remove()
2021-05-27 14:33:17 +01:00
}
}
goBack() {
2021-07-01 12:36:37 +01:00
this.router.navigate(['/home/gabinete-digital/despachos']);
2021-05-27 14:33:17 +01:00
}
}