Files
doneit-web/src/app/ui/agenda/modal/view-event/view-event.page.ts
T

485 lines
12 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2021-09-21 06:09:41 +01:00
import { AlertController, ModalController, PopoverController, Platform } from '@ionic/angular';
import { EventBody } from 'src/app/models/eventbody.model';
import { EventsService } from 'src/app/services/events.service';
2024-10-18 12:12:55 +01:00
import { Event } from '../../../../models/event.model';
import { EditEventPage } from '../edit-event/edit-event.page';
2023-06-12 10:05:59 +01:00
import { ActivatedRoute } from '@angular/router';
2021-06-25 12:06:18 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-07-20 19:22:11 +01:00
import { EliminateEventPage } from 'src/app/modals/eliminate-event/eliminate-event.page';
2021-10-08 19:29:21 +01:00
import { ExpedientTaskModalPageNavParamsTask } from 'src/app/models/ExpedientTaskModalPage';
import { DocumentSetUpMeetingPage } from 'src/app/modals/document-set-up-meeting/document-set-up-meeting.page';
2024-10-18 12:12:55 +01:00
import { ExpedientTaskModalPage } from '../../../../pages/gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page';
2021-10-08 19:29:21 +01:00
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-10-22 15:43:57 +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';
2022-04-02 14:13:37 +01:00
import { SessionStore } from 'src/app/store/session.service';
2024-06-04 09:38:11 +01:00
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'
2024-07-31 11:29:26 +01:00
import { AgendaDataRepositoryService } from 'src/app/module/agenda/data/repository/agenda-data-repository.service';
2024-06-18 09:14:22 +01:00
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
import { isHttpError } from 'src/app/services/http.service';
import { PermissionService } from 'src/app/services/permission.service';
2024-07-09 12:36:46 +01:00
import { DeleteEventRecurrencePage, EventDeleteRecurrenceComponentReturn } from 'src/app/modals/delete-event-recurrence/delete-event-recurrence.page';
@Component({
selector: 'app-view-event',
templateUrl: './view-event.page.html',
styleUrls: ['./view-event.page.scss'],
})
2021-04-06 11:28:46 +01:00
export class ViewEventPage implements OnInit {
loadedEvent: Event;
isEventEdited: boolean;
eventBody: EventBody;
2021-10-18 17:42:25 +01:00
loadedAttachments: any;
pageId: string;
showLoader: boolean;
minDate: Date;
2021-10-18 17:42:25 +01:00
profile: string;
eventId: string;
2022-05-27 13:36:37 +01:00
CalendarId: string;
2021-10-18 17:42:25 +01:00
caller: string;
customDate: any;
today: any;
2021-07-13 14:34:05 +01:00
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"];
2021-07-13 14:34:05 +01:00
dicIndex = 0;
2021-07-26 11:34:46 +01:00
isModal = false
2021-08-25 12:34:02 +01:00
header = true
2021-10-08 19:29:21 +01:00
task: ExpedientTaskModalPageNavParamsTask;
2021-10-18 17:42:25 +01:00
LoadedDocument: any = null;
2022-04-02 14:13:37 +01:00
sesseionStora = SessionStore
2022-05-27 13:36:37 +01:00
TimeZoneString = ''
constructor(
private modalController: ModalController,
2022-04-21 16:45:17 +01:00
public eventsService: EventsService,
public alertController: AlertController,
2021-06-10 15:38:08 +01:00
public popoverController: PopoverController,
2021-06-10 23:24:42 +01:00
private activatedRoute: ActivatedRoute,
2021-06-25 12:06:18 +01:00
private toastService: ToastService,
2021-09-21 06:09:41 +01:00
public platform: Platform,
2022-01-06 14:47:22 +01:00
public ThemeService: ThemeService,
private RouteService: RouteService,
2023-06-09 15:29:03 +01:00
private httpErrorHandle: HttpErrorHandle,
private agendaDataRepository: AgendaDataRepositoryService,
public p: PermissionService,
2021-10-18 17:42:25 +01:00
) {
2022-07-12 15:22:36 +01:00
this.isEventEdited = false;
this.loadedEvent = new Event();
2021-10-18 17:42:25 +01:00
this.eventBody = { BodyType: "1", Text: "" };
this.loadedEvent.Body = this.eventBody;
2022-05-27 13:36:37 +01:00
2021-10-18 17:42:25 +01:00
this.activatedRoute.paramMap.subscribe(params => {
2021-06-29 10:50:05 +01:00
this.eventId = params['params'].eventId;
2022-05-27 13:36:37 +01:00
const urlParams = new URLSearchParams(window.location.search);
this.CalendarId = urlParams.get('CalendarId');
this.eventId = this.eventId.replace(' ', '')
2021-10-18 17:42:25 +01:00
if (params["params"].caller) {
2021-06-29 10:50:05 +01:00
this.caller = (params["params"].caller);
}
2021-07-26 11:34:46 +01:00
2021-10-18 17:42:25 +01:00
if (params["params"].isModal) {
2021-07-26 11:34:46 +01:00
this.isModal = params["params"].isModal
}
2021-08-25 12:34:02 +01:00
2021-10-18 17:42:25 +01:00
if (params["params"].header) {
2021-08-25 12:34:02 +01:00
this.header = params["params"].header
}
2021-06-10 15:38:08 +01:00
});
2021-06-10 23:24:42 +01:00
}
ngOnInit() {
2021-10-18 17:42:25 +01:00
this.loadEvent();
2021-02-24 20:23:15 +01:00
window.onresize = (event) => {
// if not mobile remove all component
2021-10-18 17:42:25 +01:00
if (window.innerWidth >= 1024) {
2021-02-24 20:23:15 +01:00
this.modalController.dismiss(this.isEventEdited);
}
};
2021-07-13 14:34:05 +01:00
}
2021-04-06 11:28:46 +01:00
2021-10-18 17:42:25 +01:00
close() {
2021-07-13 14:34:05 +01:00
this.modalController.dismiss(this.isEventEdited);
}
2021-06-10 23:24:42 +01:00
goBack() {
2021-07-26 11:34:46 +01:00
2021-10-18 17:42:25 +01:00
if (this.isModal) {
2021-07-26 11:34:46 +01:00
this.close()
} else {
2021-10-18 17:42:25 +01:00
this.activatedRoute.paramMap.subscribe(params => {
if (params["params"].caller == 'expediente') {
window.history.back();
}
else {
// this.router.navigate(['/home', params["params"].caller]);
this.RouteService.goBack();
2021-10-18 17:42:25 +01:00
}
2021-08-05 11:47:09 +01:00
});
2021-07-26 11:34:46 +01:00
}
2021-06-10 23:24:42 +01:00
}
2021-10-18 17:42:25 +01:00
doRefresh(ev) {
2021-09-15 16:20:59 +01:00
this.loadEvent();
ev.target.complete();
}
setTimeZone() {
2024-06-03 13:28:18 +01:00
this.TimeZoneString = this.loadedEvent.TimeZone
}
2024-06-23 21:47:34 +01:00
@XTracerAsync({name:'mobile/loadEventDetails', bugPrint: true})
2024-06-18 09:14:22 +01:00
async loadEvent(tracing?: TracingType) {
2021-07-13 14:34:05 +01:00
const loader = this.toastService.loading();
2024-06-18 09:14:22 +01:00
let res = await this.agendaDataRepository.getEventById(this.eventId, tracing)
2024-06-04 09:38:11 +01:00
if (res.isOk()) {
2024-06-18 09:14:22 +01:00
tracing.setAttribute('outcome', 'success')
2024-05-31 13:59:51 +01:00
console.log('Loaded Event', res.value)
loader.remove()
2024-06-12 16:04:27 +01:00
/* let changeDate = this.dateService.fixDate(res.value as any) as any */
this.loadedEvent = res.value as any;
2024-05-31 13:59:51 +01:00
this.setTimeZone()
2022-04-02 14:13:37 +01:00
} else {
2024-06-18 09:14:22 +01:00
tracing.setAttribute('eventId', this.eventId)
if(!isHttpError(res.error)) {
this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #13')
console.log(res.error)
} else if (isHttpError(res.error)) {
if(res.error.status == 404) {
this.toastService._badRequest('Este evento já não existe')
} else {
this.httpErrorHandle.httpStatusHandle(res.error)
}
}
tracing.setAttribute('outcome', 'failed')
// this.toastService.badRequest('Este evento já não existe na sua agenda')
2024-05-31 13:59:51 +01:00
this.RouteService.goBack();
2022-04-02 14:13:37 +01:00
}
2024-06-18 09:14:22 +01:00
loader.remove()
2024-05-31 13:59:51 +01:00
}
2021-04-06 11:28:46 +01:00
2024-07-09 12:36:46 +01:00
async deleteYesOrNo() {
2024-06-11 11:23:38 +01:00
if (this.loadedEvent.IsRecurring) {
2024-06-18 09:14:22 +01:00
2024-07-09 12:36:46 +01:00
const modal = await this.modalController.create({
component: DeleteEventRecurrencePage,
componentProps: {},
cssClass: 'event-recurrence-modal',
});
modal.onDidDismiss().then((res) => {
const data: EventDeleteRecurrenceComponentReturn = res.data
if(data =='DeleteAll') {
this.deleteEvent(true);
} else if (data == 'DeleteOne') {
this.deleteEvent(false);
} else if(data == 'Cancel') {
this.close()
} else {
this.close()
}
2024-06-11 11:23:38 +01:00
});
2024-07-09 12:36:46 +01:00
await modal.present();
2024-06-11 11:23:38 +01:00
} else {
this.alertController.create({
header: 'Eliminar evento?',
message: '',
buttons: [
{
text: 'Sim',
handler: (data) => {
this.deleteEvent(false);
}
},
{
text: 'Não',
handler: () => {
// sconsole.log('Let me think');
}
}
]
}).then(res => {
res.present();
});
}
2024-06-18 09:14:22 +01:00
}
2024-07-09 12:36:46 +01:00
async deleteEvent(deleteAll) {
2021-10-06 10:59:42 +01:00
const loader = this.toastService.loading()
2024-06-04 09:38:11 +01:00
console.log(this.loadedEvent.EventId)
2024-07-09 12:36:46 +01:00
const result = await this.agendaDataRepository.deleteEvent(this.loadedEvent.EventId,deleteAll)//.subscribe(async () => {
if(result.isOk()) {
2024-06-04 09:38:11 +01:00
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(() => {
alert.dismiss();
}, 1500);
this.goBack();
this.httpErrorHandle.httpsSucessMessagge('delete event')
2024-07-09 12:36:46 +01:00
} else {
console.log('delete event error: ', result.error)
this.httpErrorHandle.httpStatusHandle(result.error)
}
2024-06-04 09:38:11 +01:00
2024-07-09 12:36:46 +01:00
loader.remove();
}
2021-07-20 19:22:11 +01:00
async OpenDeleteEventModal() {
2021-09-15 09:33:13 +01:00
2021-07-20 19:22:11 +01:00
const modal = await this.modalController.create({
component: EliminateEventPage,
componentProps: {
eventId: this.loadedEvent.EventId,
caller: this.caller,
},
cssClass: 'discart-expedient-modal',
});
2023-07-15 11:01:09 +01:00
2021-07-20 19:22:11 +01:00
modal.onDidDismiss().then((res) => {
2021-07-20 19:22:11 +01:00
2021-10-18 17:42:25 +01:00
if (res) {
2021-07-20 19:22:11 +01:00
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
}, 250);
this.isEventEdited = true;
}
});
2023-07-15 11:01:09 +01:00
await modal.present();
2021-07-20 19:22:11 +01:00
}
toDateString(e) {
return new Date(e).toDateString()
}
2021-04-05 15:00:14 +01:00
async editEventDetail() {
const modal = await this.modalController.create({
2021-04-06 09:26:31 +01:00
component: EditEventPage,
2021-04-05 15:00:14 +01:00
componentProps: {
eventId: this.loadedEvent.EventId,
2021-06-29 10:50:05 +01:00
caller: this.caller,
closeModal: true
2021-04-05 15:00:14 +01:00
},
2021-04-14 12:02:43 +01:00
cssClass: 'modal modal-desktop',
2021-04-23 10:35:53 +01:00
});
await modal.present();
modal.onDidDismiss().then((res) => {
2024-06-19 15:56:39 +01:00
if (res.data?.action == 'cancel') {
console.log('res', res)
} else {
this.loadEvent()
2021-04-23 10:35:53 +01:00
this.isEventEdited = true;
2024-06-19 15:56:39 +01:00
// if (res.data.Attendees?.length >= 1) {
// this.loadedEvent.HasAttachments = true
// // this.getAttachments()
// }
2024-06-19 15:56:39 +01:00
console.log('res', res)
2021-04-23 10:35:53 +01:00
}
2024-06-19 15:56:39 +01:00
2021-04-05 15:00:14 +01:00
});
2021-04-06 11:28:46 +01:00
2021-04-05 15:00:14 +01:00
}
2021-07-13 14:34:05 +01:00
async editEvent() {
2021-04-01 15:06:05 +01:00
let classs;
2021-10-18 17:42:25 +01:00
if (window.innerWidth <= 800) {
2021-04-14 12:02:43 +01:00
classs = 'modal modal-desktop'
2021-10-18 17:42:25 +01:00
} else {
2021-04-01 15:06:05 +01:00
classs = 'modal modal-desktop showAsideOptions'
}
2021-07-13 14:34:05 +01:00
const modal = await this.modalController.create({
component: EditEventPage,
2021-10-18 17:42:25 +01:00
componentProps: {
event: this.loadedEvent,
2021-06-29 10:50:05 +01:00
caller: this.caller,
},
2021-04-01 15:06:05 +01:00
cssClass: classs,
});
2023-07-15 11:01:09 +01:00
modal.onDidDismiss().then((res) => {
2021-07-13 14:34:05 +01:00
2024-03-02 12:21:00 +01:00
if (res.data?.action == 'cancel') {
console.log('res', res)
} else {
2024-06-19 15:56:39 +01:00
this.loadEvent()
this.isEventEdited = true;
2023-06-13 12:27:27 +01:00
// if (res.data.Attendees?.length >= 1) {
// this.loadedEvent.HasAttachments = true
// // this.getAttachments()
// }
// console.log('res', res)
}
2023-06-10 10:26:47 +01:00
});
2023-07-15 11:01:09 +01:00
await modal.present();
}
2021-04-01 15:06:05 +01:00
2021-10-18 17:42:25 +01:00
docIndex(index: number) {
2021-10-08 19:29:21 +01:00
this.dicIndex = index
}
2021-07-13 14:34:05 +01:00
2023-06-09 15:29:03 +01:00
2021-10-08 19:29:21 +01:00
async LoadDocumentDetails() {
2021-10-18 17:42:25 +01:00
const docId = this.loadedEvent.Attachments[this.dicIndex].SourceId
const applicationId: any = this.loadedEvent.Attachments[this.dicIndex].ApplicationId
const selectedDoc = this.loadedEvent.Attachments[this.dicIndex]
2021-10-09 18:43:17 +01:00
2021-10-09 18:43:17 +01:00
this.task = {
serialNumber: '',
taskStartDate: '',
isEvent: true,
workflowInstanceDataFields: {
FolderID: '',
Subject: selectedDoc.SourceName,
SourceSecFsID: selectedDoc.ApplicationId || selectedDoc['ApplicationID'],
SourceType: 'DOC',
SourceID: selectedDoc.SourceId,
DispatchNumber: ''
2021-10-08 19:29:21 +01:00
}
2021-10-09 18:43:17 +01:00
}
2021-10-08 19:29:21 +01:00
2021-07-13 14:34:05 +01:00
2021-10-09 18:43:17 +01:00
const modal = await this.modalController.create({
component: ViewDocumentPage,
componentProps: {
trustedUrl: '',
file: {
title: this.task.workflowInstanceDataFields.Subject,
url: '',
title_link: '',
2021-10-08 19:29:21 +01:00
},
2021-10-18 17:42:25 +01:00
Document: this.loadedEvent.Attachments[this.dicIndex],
2021-10-09 18:43:17 +01:00
applicationId: this.task.workflowInstanceDataFields.SourceSecFsID,
docId: selectedDoc.SourceId,
folderId: '',
task: this.task
},
cssClass: 'modal modal-desktop'
2021-04-05 14:56:40 +01:00
});
2021-10-09 18:43:17 +01:00
await modal.present();
2021-02-01 13:21:41 +01:00
}
2021-10-08 19:29:21 +01:00
async openBookMeetingModal() {
2021-10-08 19:29:21 +01:00
let classs;
2021-10-18 17:42:25 +01:00
if (window.innerWidth < 701) {
2021-10-08 19:29:21 +01:00
classs = 'book-meeting-modal modal modal-desktop'
2021-10-18 17:42:25 +01:00
} else {
2021-10-08 19:29:21 +01:00
classs = 'modal modal-desktop showAsideOptions'
}
2021-10-08 19:29:21 +01:00
const modal = await this.modalController.create({
component: DocumentSetUpMeetingPage,
2021-04-23 10:35:53 +01:00
componentProps: {
2021-10-08 19:29:21 +01:00
subject: this.task.workflowInstanceDataFields.Subject,
2021-10-18 17:42:25 +01:00
document: this.loadedEvent.Attachments[this.dicIndex],
2021-04-23 10:35:53 +01:00
},
2021-10-08 19:29:21 +01:00
cssClass: classs,
backdropDismiss: false
});
2023-07-15 11:01:09 +01:00
2021-10-18 17:42:25 +01:00
modal.onDidDismiss().then(res => {
2022-01-06 14:47:22 +01:00
//this.RouteService.goBack();
2021-04-23 10:35:53 +01:00
});
2023-07-15 11:01:09 +01:00
await modal.present();
2021-05-12 15:52:10 +01:00
}
2021-04-23 10:35:53 +01:00
2021-10-08 19:29:21 +01:00
// efetuar despacho
2021-10-18 17:42:25 +01:00
async openExpedientActionsModal(taskAction: any) {
2021-04-23 10:35:53 +01:00
2021-10-08 19:29:21 +01:00
let classs;
2021-10-18 17:42:25 +01:00
if (window.innerWidth < 701) {
2021-10-08 19:29:21 +01:00
classs = 'modal modal-desktop'
2021-10-18 17:42:25 +01:00
} else {
2021-10-08 19:29:21 +01:00
classs = 'modal modal-desktop showAsideOptions'
}
const modal = await this.modalController.create({
component: ExpedientTaskModalPage,
componentProps: {
taskAction: taskAction,
task: this.task,
2021-10-18 17:42:25 +01:00
seachDocuments: this.loadedEvent.Attachments[this.dicIndex],
aplicationId: this.loadedEvent.Attachments[this.dicIndex].ApplicationId || this.loadedEvent.Attachments[this.dicIndex]['ApplicationID']
2021-10-08 19:29:21 +01:00
},
cssClass: classs,
});
await modal.present();
2021-10-18 17:42:25 +01:00
modal.onDidDismiss().then(async (res) => { });
2021-04-23 10:35:53 +01:00
}
2021-10-18 17:42:25 +01:00
2021-10-18 07:44:24 +01:00
getFromDb() {
2023-04-12 14:39:26 +01:00
2021-10-18 17:42:25 +01:00
}
2024-06-10 10:56:11 +01:00
stringToNumber(number: string) {
return parseInt(number)
}
2021-10-18 17:42:25 +01:00
}