diff --git a/src/app/pages/agenda/edit-event/edit-event.page.ts b/src/app/pages/agenda/edit-event/edit-event.page.ts index 18db101f0..4646d9b17 100644 --- a/src/app/pages/agenda/edit-event/edit-event.page.ts +++ b/src/app/pages/agenda/edit-event/edit-event.page.ts @@ -14,6 +14,8 @@ import { SearchPage } from '../../search/search.page'; import { ThemeService } from 'src/app/services/theme.service'; import { NgxMatDateFormats } from '@angular-material-components/datetime-picker'; import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker'; +import { SessionStore } from 'src/app/store/session.service'; + const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -79,6 +81,8 @@ export class EditEventPage implements OnInit { public stepMinutes = [1, 5, 10, 15, 20, 25]; public stepSeconds = [1, 5, 10, 15, 20, 25]; + sesseionStora = SessionStore + constructor( private modalController: ModalController, private navParams: NavParams, @@ -249,29 +253,57 @@ export class EditEventPage implements OnInit { this.postEvent.EventRecurrence.Type = this.selectedRecurringType; - this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => { + if(this.sesseionStora.user.Profile == 'MDGPR' || this.sesseionStora.user.Profile == 'PR') { + this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => { - if(this.initCalendarName != this.postEvent.CalendarName) { - - let body = { - "EventId": this.postEvent.EventId, - "CalendarDestinationName": this.postEvent.CalendarName, + if(this.initCalendarName != this.postEvent.CalendarName) { + + let body = { + "EventId": this.postEvent.EventId, + "CalendarDestinationName": this.postEvent.CalendarName, + } + try { + await this.eventsService.changeAgenda(body).toPromise(); + } catch (error) {} + finally { + this.goBack(); + } + } - try { - await this.eventsService.changeAgenda(body).toPromise(); - } catch (error) {} - finally { - this.goBack(); + + this.toastService.successMessage(); + + }, error => { + if(error.status != 0) + this.toastService.badRequest() + }); + } else { + this.eventsService.editEvent(this.postEvent, 2, 3, this.postEvent.CalendarId).subscribe(async () => { + + if(this.initCalendarName != this.postEvent.CalendarName) { + + let body = { + "EventId": this.postEvent.EventId, + "CalendarDestinationName": this.postEvent.CalendarName, + } + try { + await this.eventsService.changeAgenda(body).toPromise(); + } catch (error) {} + finally { + this.goBack(); + } + } + + this.toastService.successMessage(); + + }, error => { + if(error.status != 0) + this.toastService.badRequest() + }); + } - } - - this.toastService.successMessage(); - - }, error => { - if(error.status != 0) - this.toastService.badRequest() - }); + this.isEventEdited = true; diff --git a/src/app/pages/agenda/new-event/new-event.page.ts b/src/app/pages/agenda/new-event/new-event.page.ts index 4313478c0..20a5c7b13 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -300,7 +300,7 @@ export class NewEventPage implements OnInit { - if(this.CalendarName == 'MDGPR') { + if(this.loggeduser.Profile == 'MDGPR') { console.log(this.loggeduser.Profile); console.log(this.postEvent); @@ -309,7 +309,7 @@ export class NewEventPage implements OnInit { console.log(eventId); } - else if(this.CalendarName == 'PR'){ + else if(this.loggeduser.Profile == 'PR') { console.log(this.loggeduser.Profile); eventId = await this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).toPromise(); diff --git a/src/app/pages/agenda/view-event/view-event.page.ts b/src/app/pages/agenda/view-event/view-event.page.ts index 3942b55af..4b521e372 100644 --- a/src/app/pages/agenda/view-event/view-event.page.ts +++ b/src/app/pages/agenda/view-event/view-event.page.ts @@ -99,13 +99,6 @@ export class ViewEventPage implements OnInit { } }); - /* this.activatedRoute.queryParams.subscribe(params => { - if(params["eventId"]) { - this.eventId = params["eventId"]; - console.log(params["eventId"]); - } - }); */ - } ngOnInit() { @@ -248,24 +241,46 @@ export class ViewEventPage implements OnInit { const loader = this.toastService.loading() - 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'); - }, () => { }, - () => { - loader.remove(); - }); - - loader.remove(); + 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'); + }, () => { }, + () => { + loader.remove(); + }); + + } else { + + 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'); + }, () => { }, + () => { + loader.remove(); + }); + + + + } } diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index 70e8d46cd..c3722c200 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -509,7 +509,7 @@ export class EventsService { return this.http.put(`${puturl}`, event, options) } - editEvent(event: Event, conflictResolutionMode: number, sendInvitationsOrCancellationsMode: number): Observable { + editEvent(event: Event, conflictResolutionMode: number, sendInvitationsOrCancellationsMode: number, CalendarId? ): Observable { let arrayReq = []; arrayReq.push(event); const puturl = environment.apiURL + 'calendar/PutEvent'; @@ -530,11 +530,18 @@ export class EventsService { this.headers = this.headersPrOficial; } else { - if(this.hasOwnCalendar) { - this.headers = this.headerOwnOficial - } else { - this.headers = this.headerSharedOficial - } + const headers = [ + this.headerSharedOficial, + this.headerSharedPessoal, + this.headerOwnPessoal, + this.headerOwnOficial + ] + + const header = headers.find((header)=> { + return header?.get('CalendarId')?.includes(CalendarId) + }) + + this.headers = header } } else { @@ -545,11 +552,18 @@ export class EventsService { this.headers = this.headersPrPessoal; } else { - if(this.hasSharedCalendar) { - this.headers = this.headerSharedPessoal - } else { - this.headers = this.headerOwnPessoal - } + const headers = [ + this.headerSharedOficial, + this.headerSharedPessoal, + this.headerOwnPessoal, + this.headerOwnOficial + ] + + const header = headers.find((header)=> { + return header?.get('CalendarId')?.includes(CalendarId) + }) + + this.headers = header } } diff --git a/src/app/shared/agenda/edit-event/edit-event.page.ts b/src/app/shared/agenda/edit-event/edit-event.page.ts index 35eda3874..2265c0592 100644 --- a/src/app/shared/agenda/edit-event/edit-event.page.ts +++ b/src/app/shared/agenda/edit-event/edit-event.page.ts @@ -275,7 +275,7 @@ export class EditEventPage implements OnInit { this.showLoader = false; this.toastService.successMessage() } else { - await this.eventsService.editEvent(this.postEvent, 2, 3).toPromise() + await this.eventsService.editEvent(this.postEvent, 2, 3, this.postEvent.CalendarId).toPromise() if(this.initCalendarName != this.postEvent.CalendarName) { let body = { "EventId": this.postEvent.EventId, diff --git a/src/app/shared/agenda/new-event/new-event.page.ts b/src/app/shared/agenda/new-event/new-event.page.ts index bd7e3d0ac..dd0935eef 100644 --- a/src/app/shared/agenda/new-event/new-event.page.ts +++ b/src/app/shared/agenda/new-event/new-event.page.ts @@ -413,7 +413,7 @@ export class NewEventPage implements OnInit { }); } - else if(this.CalendarName == 'PR') { + else if(this.loggeduser.Profile == 'PR') { console.log('PR - Aqui'); console.log(this.postEvent); this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe( diff --git a/src/app/shared/agenda/view-event/view-event.page.ts b/src/app/shared/agenda/view-event/view-event.page.ts index 8f7213a58..911384d6f 100644 --- a/src/app/shared/agenda/view-event/view-event.page.ts +++ b/src/app/shared/agenda/view-event/view-event.page.ts @@ -25,7 +25,7 @@ import { SessionStore } from 'src/app/store/session.service'; }) export class ViewEventPage implements OnInit { - loadedEvent: any; + loadedEvent: Event; isEventEdited: boolean; eventBody: EventBody; loadedAttachments:any; @@ -122,28 +122,25 @@ export class ViewEventPage implements OnInit { }); } else { - const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId) + + this.eventsService.genericGetEvent(this.eventId, this.loadedEvent.CalendarId).subscribe(res => { + this.loadedEvent = res; + this.today = new Date(res.StartDate); + this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]); + }, (error)=> { + + this.viewEventDetailDismiss.emit({ + type: 'close' + }) + + if(error.status == 0) { + this.toastService.badRequest('Não é possível visualizar este evento no modo offline') + } else { + this.toastService.badRequest('Este evento já não existe na sua agenda') + } + + }); - if(event?.CalendarId) { - this.eventsService.genericGetEvent(this.eventId, event.CalendarId).subscribe(res => { - console.log(res); - this.loadedEvent = res; - this.today = new Date(res.StartDate); - this.customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]); - }, (error)=> { - - this.viewEventDetailDismiss.emit({ - type: 'close' - }) - - if(error.status == 0) { - this.toastService.badRequest('Não é possível visualizar este evento no modo offline') - } else { - this.toastService.badRequest('Este evento já não existe na sua agenda') - } - - }); - } } @@ -193,17 +190,13 @@ export class ViewEventPage implements OnInit { loader.remove(); }); } else { - const event = this.CalendarService.eventSource.find((ele) => ele.id == this.eventId) - - if(event?.CalendarId) { - this.eventsService.genericDeleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName, event?.CalendarId).subscribe(async () => { - this.toastService.successMessage('Evento apagado'); - this.close(); - },()=>{}, - ()=>{ - loader.remove(); - }); - } + this.eventsService.genericDeleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName, this.loadedEvent.CalendarId).subscribe(async () => { + this.toastService.successMessage('Evento apagado'); + this.close(); + },()=>{}, + ()=>{ + loader.remove(); + }); } } @@ -254,7 +247,7 @@ export class ViewEventPage implements OnInit { workflowInstanceDataFields: { FolderID: '', Subject: selectedDoc.SourceName, - SourceSecFsID: selectedDoc.ApplicationId || selectedDoc.ApplicationID, + SourceSecFsID: selectedDoc.ApplicationId || selectedDoc['ApplicationID'], SourceType: 'DOC', SourceID: selectedDoc.SourceId, DispatchNumber: '' @@ -320,7 +313,7 @@ export class ViewEventPage implements OnInit { taskAction: taskAction, task: this.task, seachDocuments: this.loadedEvent.Attachments[ this.dicIndex], - aplicationId: this.loadedEvent.Attachments[ this.dicIndex].ApplicationId || this.loadedEvent.Attachments[ this.dicIndex].ApplicationID + aplicationId: this.loadedEvent.Attachments[ this.dicIndex].ApplicationId || this.loadedEvent.Attachments[ this.dicIndex]['ApplicationID'] }, cssClass: classs, });