mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
366 lines
9.9 KiB
TypeScript
366 lines
9.9 KiB
TypeScript
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
|
|
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
|
|
import { MenuController, ModalController, PopoverController } from '@ionic/angular';
|
|
import { Event } from 'src/app/models/event.model';
|
|
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';
|
|
import { EditEventToApproveComponent } from 'src/app/shared/gabinete-digital/edit-event-to-approve/edit-event.page';
|
|
import { ToastService } from 'src/app/services/toast.service';
|
|
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
|
|
|
|
import { BackgroundService } from '../../../../services/background.service';
|
|
import { ThemeService } from 'src/app/services/theme.service'
|
|
import { OfflineManagerService } from 'src/app/services/offline-manager.service';
|
|
import { RouteService } from 'src/app/services/route.service';
|
|
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
|
|
import { TaskService } from 'src/app/services/task.service'
|
|
|
|
|
|
@Component({
|
|
selector: 'app-approve-event',
|
|
templateUrl: './approve-event.page.html',
|
|
styleUrls: ['./approve-event.page.scss'],
|
|
})
|
|
export class ApproveEventPage implements OnInit {
|
|
event: Event;
|
|
loadedEvent: any = false
|
|
loadedAttachments: any;
|
|
customDate: any;
|
|
today: any;
|
|
show: boolean = false;
|
|
|
|
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"];
|
|
|
|
serialNumber: string;
|
|
caller: string;
|
|
attachments: any;
|
|
|
|
@Input() InstanceId: string;
|
|
|
|
@Output() approveEventDismiss = new EventEmitter<any>();
|
|
@Output() closeEventToApprove = new EventEmitter<any>();
|
|
@Output() AproveEventEditEvent = new EventEmitter<any>();
|
|
|
|
constructor(
|
|
private router: Router,
|
|
private activatedRoute: ActivatedRoute,
|
|
private modalController: ModalController,
|
|
private processes: ProcessesService,
|
|
private popoverController: PopoverController,
|
|
private menu: MenuController,
|
|
private toastService: ToastService,
|
|
private RouteService: RouteService,
|
|
private backgroundservice: BackgroundService,
|
|
public ThemeService: ThemeService,
|
|
private offlineManager: OfflineManagerService,
|
|
private httpErrorHandle: HttpErrorHandle,
|
|
public TaskService: TaskService
|
|
) {
|
|
this.activatedRoute.paramMap.subscribe(params => {
|
|
//
|
|
|
|
if (params["params"].serialNumber) {
|
|
this.serialNumber = params["params"].serialNumber;
|
|
}
|
|
if (params["params"].caller) {
|
|
this.caller = params["params"].caller;
|
|
}
|
|
});
|
|
|
|
window['approve-event-getTask'] = () => {
|
|
this.getTask1()
|
|
}
|
|
}
|
|
|
|
toDateString(e) {
|
|
return new Date(e).toDateString()
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.getTask();
|
|
this.backgroundservice.registerBackService('Online', () => {
|
|
this.getTask();
|
|
});
|
|
|
|
}
|
|
|
|
goBack() {
|
|
this.RouteService.goBack();
|
|
|
|
}
|
|
|
|
addProcessToDB(data) {
|
|
|
|
}
|
|
|
|
getProcessFromDB() {
|
|
|
|
|
|
}
|
|
|
|
getTask1 = () => {
|
|
this.processes.GetTask(this.serialNumber).subscribe(async res => {
|
|
|
|
this.loadedEvent = res
|
|
this.addProcessToDB(this.loadedEvent)
|
|
|
|
try {
|
|
this.today = new Date(this.loadedEvent.workflowInstanceDataFields.StartDate);
|
|
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
|
|
|
|
} catch(error) {
|
|
// console.log(this.loadedEvent)
|
|
throw(error)
|
|
}
|
|
|
|
}, (error) => {
|
|
if(error.status == 0) {
|
|
this.getProcessFromDB();
|
|
} else {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
}
|
|
})
|
|
}
|
|
|
|
async getTask () {
|
|
this.processes.GetTask(this.serialNumber).subscribe(async res => {
|
|
|
|
this.loadedEvent = res
|
|
this.addProcessToDB(this.loadedEvent)
|
|
|
|
try {
|
|
this.today = new Date(this.loadedEvent.workflowInstanceDataFields.StartDate);
|
|
this.customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
|
|
|
|
} catch(error) {
|
|
// console.log(this.loadedEvent)
|
|
throw(error)
|
|
}
|
|
|
|
}, (error) => {
|
|
if(error.status == 0) {
|
|
this.getProcessFromDB();
|
|
} else {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
}
|
|
})
|
|
}
|
|
|
|
async approveTask(serialNumber: string) {
|
|
let body = { "serialNumber": serialNumber, "action": "Aprovar" }
|
|
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
try {
|
|
await this.processes.PostTaskAction(body).toPromise()
|
|
this.goBack();
|
|
this.httpErrorHandle.httpsSucessMessagge('Evento aprovação')
|
|
this.TaskService.loadEventosParaAprovacao();
|
|
|
|
} catch (error) {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
}
|
|
finally {
|
|
loader.remove()
|
|
}
|
|
|
|
}
|
|
|
|
async emendTask(serialNumber: string) {
|
|
|
|
|
|
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 !== '') {
|
|
let body = {
|
|
"serialNumber": serialNumber,
|
|
"action": "Emendar",
|
|
"dataFields": {
|
|
"ReviewUserComment": res.data,
|
|
}
|
|
}
|
|
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
try {
|
|
await this.processes.PostTaskAction(body).toPromise()
|
|
.catch(() => {
|
|
|
|
this.offlineManager.storeRequestData('event-listRever', body);
|
|
});
|
|
this.httpErrorHandle.httpsSucessMessagge('Rever')
|
|
this.TaskService.loadEventosParaAprovacao();
|
|
this.goBack();
|
|
} catch (error) {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
} finally {
|
|
loader.remove()
|
|
}
|
|
|
|
}
|
|
else {
|
|
this.toastService._badRequest('É necessário adicionar uma nota');
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
async rejeitar(serialNumber: string) {
|
|
let body = { "serialNumber": serialNumber, "action": "Descartar" }
|
|
|
|
const loader = this.toastService.loading()
|
|
try {
|
|
await this.processes.PostTaskAction(body).toPromise();
|
|
this.httpErrorHandle.httpsSucessMessagge('Rejeitar')
|
|
this.TaskService.loadEventosParaAprovacao();
|
|
this.goBack();
|
|
} catch (error) {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
}
|
|
finally {
|
|
loader.remove()
|
|
}
|
|
}
|
|
|
|
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'
|
|
});
|
|
await modal.present();
|
|
|
|
}
|
|
|
|
async openOptions(ev: any) {
|
|
const popover = await this.popoverController.create({
|
|
component: EventActionsPopoverPage,
|
|
cssClass: 'events-options',
|
|
event: ev,
|
|
translucent: true,
|
|
componentProps: {
|
|
serialNumber: ev.serialNumber,
|
|
InstanceId: ev.workflowInstanceDataFields.InstanceId,
|
|
activityInstanceName: this.loadedEvent.activityInstanceName
|
|
},
|
|
});
|
|
return await popover.present().then(() => {
|
|
this.TaskService.loadEventosParaAprovacao()
|
|
})
|
|
}
|
|
|
|
openMenu() {
|
|
this.menu.open();
|
|
}
|
|
|
|
async openEmendMessageModal(serialNumber: string) {
|
|
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": serialNumber,
|
|
"action": "Emendar",
|
|
"dataFields": {
|
|
"ReviewUserComment": res.data,
|
|
}
|
|
}
|
|
|
|
|
|
const loader = this.toastService.loading()
|
|
|
|
try {
|
|
await this.processes.PostTaskAction(body).toPromise();
|
|
this.goBack();
|
|
this.httpErrorHandle.httpsSucessMessagge('Rever')
|
|
this.TaskService.loadEventosParaAprovacao();
|
|
} catch (error) {
|
|
this.httpErrorHandle.httpStatusHandle(error)
|
|
} finally {
|
|
loader.remove()
|
|
}
|
|
|
|
}
|
|
else {
|
|
this.toastService._badRequest('É necessário adicionar uma nota');
|
|
}
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
});
|
|
}
|
|
|
|
goToEventsToApprove() {
|
|
let navigationExtras: NavigationExtras = {
|
|
queryParams: {
|
|
"eventos": true,
|
|
}
|
|
};
|
|
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
|
|
}
|
|
|
|
async editar(serialNumber: string) {
|
|
|
|
const modal = await this.modalController.create({
|
|
component: EditEventToApproveComponent,
|
|
componentProps: {
|
|
serialNumber: serialNumber,
|
|
InstanceId: this.InstanceId
|
|
},
|
|
cssClass: 'modal modal-desktop'
|
|
});
|
|
|
|
await modal.present();
|
|
|
|
modal.onDidDismiss().then(res => {
|
|
this.getTask();
|
|
this.TaskService.loadEventosParaAprovacao();
|
|
});
|
|
|
|
}
|
|
|
|
}
|