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

530 lines
15 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';
import { Event } from '../../../models/event.model';
import { EditEventPage } from '../edit-event/edit-event.page';
2021-08-25 12:34:02 +01:00
import { ActivatedRoute, Router } 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-09-21 06:09:41 +01:00
import { SqliteService } from 'src/app/services/sqlite.service';
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';
import { ExpedientTaskModalPage } from '../../gabinete-digital/expediente/expedient-task-modal/expedient-task-modal.page';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
2021-10-18 17:42:25 +01:00
import { BackgroundService } from 'src/app/services/background.service';
import { StorageService } from 'src/app/services/storage.service';
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-01-31 15:02:26 +01:00
import { Storage } from '@ionic/storage';
2022-04-02 14:13:37 +01:00
import { SessionStore } from 'src/app/store/session.service';
import { CalendarService } from 'src/app/store/calendar.service';
2021-10-22 15:43:57 +01:00
@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
constructor(
private modalController: ModalController,
2021-10-18 17:42:25 +01:00
/* private navParams: NavParams, */
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,
private router: Router,
2021-06-25 12:06:18 +01:00
private toastService: ToastService,
2021-09-21 06:09:41 +01:00
public platform: Platform,
2021-10-18 17:42:25 +01:00
private sqliteservice: SqliteService,
private backgroundservice: BackgroundService,
2021-10-22 15:43:57 +01:00
private storage: StorageService,
2022-01-06 14:47:22 +01:00
public ThemeService: ThemeService,
private RouteService: RouteService,
2022-04-02 14:13:37 +01:00
private ionicStorage: Storage,
2022-07-12 15:22:36 +01:00
private CalendarService: CalendarService,
2021-10-18 17:42:25 +01:00
) {
2022-07-12 15:22:36 +01:00
2022-05-27 13:36:37 +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();
this.backgroundservice.registerBackService('Online', () => {
this.storage.get('eventEdit').then((req) => {
JSON.parse(req).forEach(element => {
this.eventsService.editEvent(element, 2, 3).subscribe((res) => {
this.storage.remove('eventEdit')
2022-04-28 09:32:27 +01:00
})
});
})
this.storage.get('eventDelete').then((req) => {
JSON.parse(req).forEach(element => {
this.eventsService.editEvent(element, 2, 3).subscribe((res) => {
this.storage.remove('eventDelete')
2022-04-28 09:32:27 +01:00
})
});
})
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
2022-04-02 14:13:37 +01:00
getEventsFromDB () {
return new Promise((resolve, reject) => {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storage.get('agendaResponse').then((events) => {
resolve(events)
})
} else {
this.sqliteservice.getAllEvents().then((events: any[]) => {
resolve(events)
})
}
})
}
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();
}
2021-07-15 17:30:02 +01:00
loadEvent() {
2021-07-13 14:34:05 +01:00
const loader = this.toastService.loading();
2022-04-02 14:13:37 +01:00
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.getEvent(this.eventId).subscribe(res => {
this.loadedEvent = res;
this.addEventToDb(res);
2022-04-28 09:32:27 +01:00
2022-04-02 14:13:37 +01:00
loader.remove()
}, (error) => {
2022-04-28 09:32:27 +01:00
2022-04-02 14:13:37 +01:00
if (error.status === 0) {
this.getFromDb();
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
loader.remove()
this.modalController.dismiss('Eevent not Foud');
this.RouteService.goBack();
}
2021-10-18 17:42:25 +01:00
loader.remove()
2022-04-02 14:13:37 +01:00
});
} else {
2022-04-06 14:51:35 +01:00
2022-05-27 13:36:37 +01:00
if(this.CalendarId) {
this.eventsService.genericGetEvent(this.eventId, this.CalendarId).subscribe(res => {
2022-04-02 14:13:37 +01:00
this.loadedEvent = res;
this.addEventToDb(res);
2022-04-28 09:32:27 +01:00
2022-04-02 14:13:37 +01:00
loader.remove()
}, (error) => {
if (error.status === 0) {
this.getFromDb();
} else {
this.toastService.badRequest('Este evento já não existe na sua agenda')
loader.remove()
this.modalController.dismiss('Eevent not Foud');
this.RouteService.goBack();
}
loader.remove()
});
2021-09-15 09:33:13 +01:00
}
2022-04-02 14:13:37 +01:00
}
}
2021-04-06 11:28:46 +01:00
2021-10-18 17:42:25 +01:00
deleteEvent() {
2021-10-06 10:59:42 +01:00
const loader = this.toastService.loading()
2022-04-02 14:51:57 +01:00
if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') {
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () => {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(() => {
alert.dismiss();
}, 1500);
this.goBack();
this.toastService._successMessage('Evento apagado');
2022-04-02 14:51:57 +01:00
}, () => { },
() => {
loader.remove();
});
} else {
2022-04-06 14:51:35 +01:00
this.eventsService.genericDeleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName, this.loadedEvent.CalendarId).subscribe(async () => {
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(() => {
alert.dismiss();
}, 1500);
this.goBack();
this.toastService._successMessage('Evento apagado');
2022-04-06 14:51:35 +01:00
}, () => { },
() => {
loader.remove();
});
2022-04-02 14:51:57 +01:00
}
}
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',
});
await modal.present();
modal.onDidDismiss().then((res) => {
2022-04-28 09:32:27 +01:00
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;
}
});
}
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,
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) => {
2022-04-28 09:32:27 +01:00
2021-07-13 14:34:05 +01:00
2021-10-18 17:42:25 +01:00
if (res) {
2021-04-23 10:35:53 +01:00
setTimeout(() => {
/* this.loadEvent(); */
this.loadEvent()
}, 250);
this.isEventEdited = true;
}
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() {
2022-04-28 09:32:27 +01:00
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,
});
await modal.present();
modal.onDidDismiss().then((res) => {
2022-04-28 09:32:27 +01:00
2021-07-13 14:34:05 +01:00
2021-10-18 17:42:25 +01:00
if (res) {
setTimeout(() => {
/* this.loadEvent(); */
2021-04-14 12:10:53 +01:00
this.loadEvent()
}, 250);
this.isEventEdited = true;
}
});
}
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
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
2022-04-28 09:32:27 +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
});
await modal.present();
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
});
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
addEventToDb(data) {
2021-10-18 17:42:25 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
2022-01-31 15:02:26 +01:00
this.ionicStorage.set('eventDetails', data).then(() => {
2022-04-28 09:32:27 +01:00
2022-01-31 15:02:26 +01:00
})
2021-10-18 17:42:25 +01:00
} else {
let event = {
Attendees: JSON.stringify(data.Attendees) || JSON.stringify(''),
Body: JSON.stringify(data.Body) || JSON.stringify(''),
CalendarId: data.CalendarId,
CalendarName: data.CalendarName,
Category: data.Category,
EndDate: data.EndDate,
EventId: data.EventId,
EventRecurrence: JSON.stringify(data.EventRecurrence) || JSON.stringify(''),
EventType: data.EventType,
HasAttachments: data.HasAttachments,
IsAllDayEvent: data.IsAllDayEvent,
IsMeeting: data.IsMeeting,
IsRecurring: data.IsRecurring,
Location: data.Location,
Organizer: JSON.stringify(data.Organizer) || JSON.stringify(''),
StartDate: data.StartDate,
Subject: data.Subject,
TimeZone: data.TimeZone
}
2021-10-09 14:56:07 +01:00
2021-10-18 17:42:25 +01:00
this.sqliteservice.updateEvent(event);
}
2021-10-18 07:44:24 +01:00
}
2021-09-21 06:09:41 +01:00
2021-10-18 07:44:24 +01:00
getFromDb() {
2021-10-18 17:42:25 +01:00
const loader = this.toastService.loading();
2022-01-31 15:02:26 +01:00
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.ionicStorage.get('eventDetails').then((events) =>{
this.loadedEvent = events;
})
} else {
this.sqliteservice.getEventById(this.eventId).then((event) => {
let arrayevent = [];
2022-04-28 09:32:27 +01:00
2022-01-31 15:02:26 +01:00
let elemet = {
Attendees: (typeof JSON.parse(event[0].Attendees) === 'undefined') ? "" : JSON.parse(event[0].Attendees),
Body: JSON.parse(event[0].Body) || "",
CalendarId: event[0].CalendarId,
CalendarName: event[0].CalendarName,
Category: event[0].Category,
EndDate: event[0].EndDate,
EventId: event[0].EventId,
EventRecurrence: JSON.parse(event[0].EventRecurrence) || "",
EventType: event[0].EventType,
HasAttachments: event[0].HasAttachments,
IsAllDayEvent: event[0].IsAllDayEvent,
IsMeeting: event[0].IsMeeting,
IsRecurring: event[0].IsRecurring,
Location: event[0].Location,
Organizer: JSON.parse(event[0].Organizer) || "",
StartDate: event[0].StartDate,
Subject: event[0].Subject,
TimeZone: event[0].TimeZone
}
arrayevent.push(elemet);
this.loadedEvent = arrayevent[0];
2022-04-28 09:32:27 +01:00
2022-01-31 15:02:26 +01:00
})
}
2021-10-18 17:42:25 +01:00
loader.remove()
}
}