From c28d17fa64fe0727053f1c5400efb93f93eb37ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 10 Jun 2024 09:55:23 +0100 Subject: [PATCH] recurence added --- .../agenda/edit-event/edit-event.page.html | 62 +++++++++++++ .../agenda/edit-event/edit-event.page.ts | 7 +- .../agenda/new-event/new-event.page.html | 91 +++++++++++++++---- .../pages/agenda/new-event/new-event.page.ts | 50 +++++++++- .../Agenda/agenda-data-repository.service.ts | 69 +++++++------- .../Agenda/mapper/EventDetailsMapper.ts | 4 +- .../Agenda/model/eventDTOOutput.ts | 16 +++- src/app/services/Repositorys/Agenda/utils.ts | 11 +++ .../agenda/edit-event/edit-event.page.html | 63 +++++++++++++ .../agenda/edit-event/edit-event.page.ts | 5 +- src/environments/suport/doneIt.ts | 11 ++- 11 files changed, 322 insertions(+), 67 deletions(-) diff --git a/src/app/pages/agenda/edit-event/edit-event.page.html b/src/app/pages/agenda/edit-event/edit-event.page.html index a1f401c00..fc4b52f8f 100644 --- a/src/app/pages/agenda/edit-event/edit-event.page.html +++ b/src/app/pages/agenda/edit-event/edit-event.page.html @@ -144,6 +144,68 @@ +
+
+
+ +
+
+ + + + + + Nunca + + + Diário + + + Semanalmente + + + Mensal + + + Anual + + + + +
+
+
+ +
+
+
+ +
+ +
+ + + + + + + + +
+
+
+
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 095fa092b..12a0ef7a1 100644 --- a/src/app/pages/agenda/edit-event/edit-event.page.ts +++ b/src/app/pages/agenda/edit-event/edit-event.page.ts @@ -20,6 +20,7 @@ import { environment } from 'src/environments/environment'; import { ContactsService } from 'src/app/services/contacts.service'; import { DomSanitizerService } from 'src/app/services/DomSanitizer.service'; import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; +import { Utils } from 'src/app/services/Repositorys/Agenda/utils'; const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -105,7 +106,8 @@ export class EditEventPage implements OnInit { private httpErrorHandle: HttpErrorHandle, private contactsService: ContactsService, private domSanitazerService: DomSanitizerService, - private agendaDataRepository: AgendaDataRepositoryService + private agendaDataRepository: AgendaDataRepositoryService, + private utils: Utils ) { /* this.postEvent = new Event(); */ @@ -154,7 +156,7 @@ export class EditEventPage implements OnInit { }) } - if (this.postEvent.IsRecurring == false) { + if (this.postEvent.EventRecurrence.frequency == 'never') { this.isRecurring = "Não se repete"; } else { @@ -168,6 +170,7 @@ export class EditEventPage implements OnInit { } ngOnInit() { + this.postEvent.EventRecurrence.frequency = this.utils.recurenceTypeSeleted(this.postEvent.EventRecurrence.frequency) console.log(this.postEvent?.Attachments) console.log(this.loadedEventAttachments) window.onresize = (event) => { diff --git a/src/app/pages/agenda/new-event/new-event.page.html b/src/app/pages/agenda/new-event/new-event.page.html index bc2b566e7..5fc62850f 100644 --- a/src/app/pages/agenda/new-event/new-event.page.html +++ b/src/app/pages/agenda/new-event/new-event.page.html @@ -19,7 +19,7 @@
-
+
@@ -29,22 +29,15 @@ - - -
{{ environment.agendaPR}}
-
{{ environment.agendaVP}}
-
Agenda do {{calendars.Fullname}}
-
- + + +
PR
+
AGENDA DO MDGPR
+
Agenda do {{calendars.wxFullName}}
+
Minha agenda -
+
+
@@ -120,6 +113,68 @@
+ +
+
+
+ +
+
+ + + + + + Nunca + + + Diário + + + Semanalmente + + + Mensal + + + Anual + + + + +
+
+
+ +
+
+
+ +
+ +
+ + + + + + + + +
+
+
@@ -259,7 +314,7 @@
-
+
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 8bbd453fe..b0442dcbd 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -29,6 +29,10 @@ import { MatDatepickerModule } from '@angular/material/datepicker'; import { MomentDateAdapter } from '@angular/material-moment-adapter'; import { EventInputDTO } from '../../../services/Repositorys/Agenda/agendaDataModels'; import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; +import { Observable } from 'rxjs'; +import { TableSharedCalendar } from 'src/app/services/Repositorys/Agenda/agenda-local-data-source.service'; +import { map } from 'rxjs/operators'; +import { RoleIdService } from 'src/app/services/role-id.service' const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { parse: { @@ -116,6 +120,9 @@ export class NewEventPage implements OnInit { eventPersons: EventPerson[]; contacts: EventPerson[]; allDayCheck: boolean = false; + eventRecurence = 'never'; + sharedCalendar: Observable + selectedUserCalendar:any; constructor( @@ -133,7 +140,8 @@ export class NewEventPage implements OnInit { private contactsService: ContactsService, private domSanitazerService: DomSanitizerService, private dateAdapter: DateAdapter, - private agendaDataRepository: AgendaDataRepositoryService + private agendaDataRepository: AgendaDataRepositoryService, + public RoleIdService: RoleIdService, ) { this.loggeduser = SessionStore.user; this.postEvent = new Event(); @@ -146,6 +154,40 @@ export class NewEventPage implements OnInit { this.selectedDate = this.navParams.get('eventSelectedDate'); this.taskParticipants = this.navParams.get('attendees'); this.CalendarDate = this.navParams.get('CalendarDate') + + // Define the role priorities + const rolePriorities: { [key: number]: number } = { + 100000014: 1, // Presidente da República + 100000011: 2, // Vice Presidente (example role ID) + // Add other roles with their priorities here + }; + + this.sharedCalendar = this.agendaDataRepository.getShareCalendarItemsLive().pipe( + map(data => data.sort((a, b) => { + console.log('Raw data:', data); // Debug line + const priorityA = rolePriorities[a.roleId] || Infinity; + const priorityB = rolePriorities[b.roleId] || Infinity; + return priorityA - priorityB; + })) + ) + + + this.setCalendarByDefault(true) + } + + async setCalendarByDefault(force) { + if (!this.selectedUserCalendar || force) { + + const data = await this.agendaDataRepository.geCalendars() + + const prObject = data.find(e => e?.roleId == 100000014) + if(prObject) { + this.selectedUserCalendar = prObject.wxUserId + } else { + this.selectedUserCalendar = SessionStore.user.UserId + } + + } } ngOnInit() { @@ -187,7 +229,8 @@ export class NewEventPage implements OnInit { Organizer: '', Category: 'Reunião', HasAttachments: false, - EventRecurrence: { Type: '-1', LastOccurrence: this.autoEndTime }, + EventRecurrence: { frequency: this.eventRecurence, until: this.autoEndTime, + Type: '' }, }; } else { @@ -209,7 +252,8 @@ export class NewEventPage implements OnInit { Organizer: '', Category: 'Reunião', HasAttachments: false, - EventRecurrence: { Type: '-1', LastOccurrence: this.autoEndTime }, + EventRecurrence: { frequency: this.eventRecurence, until: this.autoEndTime, + Type: '' }, }; } diff --git a/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts b/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts index 65bc20414..c8f0acc5d 100644 --- a/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts +++ b/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts @@ -21,7 +21,7 @@ export class AgendaDataRepositoryService { private agendaDataService: AgendaDataService, private utils: Utils, private agendaLocalDataSourceService: AgendaLocalDataSourceService - ) {} + ) { } createOwnCalendar() { const currentUserCalendar = { @@ -39,14 +39,14 @@ export class AgendaDataRepositoryService { async getEventById(id: string) { try { - const result = await this.agendaDataService.getEvent(id).pipe( + const result = await this.agendaDataService.getEvent(id).pipe( map((response) => { - console.log('Response',response.data) - console.log('Output',EventMapper.toDomain(response.data)) + console.log('Response', response.data) + console.log('Output', EventMapper.toDomain(response.data)) return EventMapper.toDomain(response.data) }) ).toPromise() - return ok (result) + return ok(result) } catch (e) { return err(e as HttpErrorResponse) } @@ -55,42 +55,42 @@ export class AgendaDataRepositoryService { async getEventToApproveById(id: string) { try { - const result = await this.agendaDataService.getEvent(id).pipe( + const result = await this.agendaDataService.getEvent(id).pipe( map((response) => { return EventToApproveDetailsMapper.toDomain(response.data) }) ).toPromise() - return ok (result) + return ok(result) } catch (e) { return err(e as HttpErrorResponse) } } - async EventList({userId, startDate , endDate , status= 2, category= null, type= null, calendarOwnerName = ''}) { + async EventList({ userId, startDate, endDate, status = 2, category = null, type = null, calendarOwnerName = '' }) { try { - const result = await this.agendaDataService.getEvents(userId, startDate, endDate, status, category, type).pipe( + const result = await this.agendaDataService.getEvents(userId, startDate, endDate, status, category, type).pipe( map((response) => { return ListEventMapper.toDomain(response.data, calendarOwnerName, userId) } - )).toPromise() - return ok (result) + )).toPromise() + return ok(result) } catch (e) { return err(e as HttpErrorResponse) } } - async eventToApproveList({userId, startDate = null, endDate = null, status = 0, category= null, type= null, calendarOwnerName = ''}) { + async eventToApproveList({ userId, startDate = null, endDate = null, status = 0, category = null, type = null, calendarOwnerName = '' }) { try { - const result = await this.agendaDataService.getEvents(userId, startDate = null, endDate = null, status, category= null, type= null).pipe( + const result = await this.agendaDataService.getEvents(userId, startDate = null, endDate = null, status, category = null, type = null).pipe( map((response) => { return EventListToApproveMapper.toDomain(response.data, calendarOwnerName, userId) } - )).toPromise() + )).toPromise() - return ok (result) + return ok(result) } catch (e) { return err(e as HttpErrorResponse) } @@ -122,9 +122,6 @@ export class AgendaDataRepositoryService { } updateEvent(eventId, eventData) { - console.log(eventData.StartDate) - console.log(eventData.EndDate) - let eventInput = { subject: eventData.Subject, body: eventData.Body.Text || eventData.Body, @@ -133,39 +130,41 @@ export class AgendaDataRepositoryService { endDate: eventData.EndDate, isAllDayEvent: eventData.IsAllDayEvent, updateAllEvents: false, + type: this.utils.calendarTypeSeleted(eventData.Category), + category: this.utils.calendarCategorySeleted(eventData.CalendarName), recurrence: { - frequency: 0, - occurrences: 0 + frequency: this.utils.eventRecurence(eventData.EventRecurrence.frequency), + until: eventData.EventRecurrence.until } } return this.agendaDataService.updateEvent(eventId, eventInput) } - addEventAttendee(id,attendeeData,) { + addEventAttendee(id, attendeeData,) { console.log(attendeeData) console.log(this.utils.attendeesEdit(attendeeData)) - return this.agendaDataService.addEventAttendee(id,{ attendees: this.utils.attendeesAdded(attendeeData) }); + return this.agendaDataService.addEventAttendee(id, { attendees: this.utils.attendeesAdded(attendeeData) }); } - addEventAttachment(id,attachmentData) { + addEventAttachment(id, attachmentData) { console.log(attachmentData) - console.log('post attachment',this.utils.documentAdded(attachmentData)) - return this.agendaDataService.addEventAttachment(id,{ attachments: this.utils.documentAdded(attachmentData) }); + console.log('post attachment', this.utils.documentAdded(attachmentData)) + return this.agendaDataService.addEventAttachment(id, { attachments: this.utils.documentAdded(attachmentData) }); } deleteEvent(eventId) { return this.agendaDataService.deleteEvent(eventId, false) } - removeEventAttachment(eventId,attachmentData) { - return this.agendaDataService.removeEventAttachment(eventId,attachmentData); + removeEventAttachment(eventId, attachmentData) { + return this.agendaDataService.removeEventAttachment(eventId, attachmentData); } async deleteEvent1(eventId) { try { - const result = await this.agendaDataService.deleteEvent(eventId,false).toPromise() - return ok (result) + const result = await this.agendaDataService.deleteEvent(eventId, false).toPromise() + return ok(result) } catch (e) { return err(e as HttpErrorResponse) } @@ -177,20 +176,20 @@ export class AgendaDataRepositoryService { status: this.utils.statusEventAproval(status), comment: "" } - return this.agendaDataService.updateEventStatus(eventId,statusObject) + return this.agendaDataService.updateEventStatus(eventId, statusObject) } - getDocumentAttachments(applicationId,userId,subject,pageNumber,pageSize) { - return this.agendaDataService.getDocumentAttachment(applicationId,userId,subject,pageNumber,pageSize) + getDocumentAttachments(applicationId, userId, subject, pageNumber, pageSize) { + return this.agendaDataService.getDocumentAttachment(applicationId, userId, subject, pageNumber, pageSize) } async getSharedCalendar() { const result = await this.agendaDataService.getSharedCalendar() - if(result.isOk()) { + if (result.isOk()) { - if(result.value?.data) { + if (result.value?.data) { await this.agendaLocalDataSourceService.clearSharedCalendar() await this.createOwnCalendar() @@ -206,7 +205,7 @@ export class AgendaDataRepositoryService { } async clearSharedCalendar() { - return await this.agendaLocalDataSourceService.clearSharedCalendar() + return await this.agendaLocalDataSourceService.clearSharedCalendar() } getShareCalendarItemsLive() { diff --git a/src/app/services/Repositorys/Agenda/mapper/EventDetailsMapper.ts b/src/app/services/Repositorys/Agenda/mapper/EventDetailsMapper.ts index 640f6fbee..d5ef3d23b 100644 --- a/src/app/services/Repositorys/Agenda/mapper/EventDetailsMapper.ts +++ b/src/app/services/Repositorys/Agenda/mapper/EventDetailsMapper.ts @@ -66,7 +66,9 @@ export class EventMapper { "Day": null, "DayOfWeek": null, "Month": null, - "LastOccurrence": null + "LastOccurrence": null, + "frequency": dto.eventRecurrence.frequency, + "until": dto.eventRecurrence.until }, "Attachments": dto.attachments.map( e => ({ "Id": e.id, diff --git a/src/app/services/Repositorys/Agenda/model/eventDTOOutput.ts b/src/app/services/Repositorys/Agenda/model/eventDTOOutput.ts index afd7e2eb1..9e12523f3 100644 --- a/src/app/services/Repositorys/Agenda/model/eventDTOOutput.ts +++ b/src/app/services/Repositorys/Agenda/model/eventDTOOutput.ts @@ -37,6 +37,16 @@ const OrganizerSchema = z.object({ userPhoto: z.string(), }); +const EventRecurrenceSchema = z.object({ + Type: z.number(), + Day: null, + DayOfWeek: null, + Month: null, + LastOccurrence: null, + frequency: z.number(), + until: z.string() +}); + export const EventOutputDTOSchema = z.object({ id: z.string(), owner: OwnerSchema, @@ -47,12 +57,12 @@ export const EventOutputDTOSchema = z.object({ startDate: z.string(), endDate: z.string(), type: z.string(), - category: z.enum(['Oficial','Pessoal']), + category: z.enum(['Oficial', 'Pessoal']), attendees: z.array(AttendeeSchema), isRecurring: z.boolean(), - eventRecurrence: z.null(), + eventRecurrence: EventRecurrenceSchema, hasAttachments: z.boolean(), - attachments:z.array(AttachmentInputDTOSchema), + attachments: z.array(AttachmentInputDTOSchema), comments: z.array(CommentSchema), isPrivate: z.boolean(), isAllDayEvent: z.boolean(), diff --git a/src/app/services/Repositorys/Agenda/utils.ts b/src/app/services/Repositorys/Agenda/utils.ts index 1b833ec6f..c8e158bf7 100644 --- a/src/app/services/Repositorys/Agenda/utils.ts +++ b/src/app/services/Repositorys/Agenda/utils.ts @@ -165,4 +165,15 @@ export class Utils { } return selectedType[type]; } + + recurenceTypeSeleted(recurenceType) { + var selectedType = { + 0: 'never', + 1: 'daily', + 2: 'weekly', + 3: 'monthly', + 4: 'yearly' + } + return selectedType[recurenceType]; + } } diff --git a/src/app/shared/agenda/edit-event/edit-event.page.html b/src/app/shared/agenda/edit-event/edit-event.page.html index 50a635cdf..5fec344da 100644 --- a/src/app/shared/agenda/edit-event/edit-event.page.html +++ b/src/app/shared/agenda/edit-event/edit-event.page.html @@ -132,6 +132,69 @@
+ +
+
+
+ +
+
+ + + + + + Nunca + + + Diário + + + Semanalmente + + + Mensal + + + Anual + + + + +
+
+
+ +
+
+
+ +
+ +
+ + + + + + + + +
+
+
+
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 fdaf28021..f5f0523f1 100644 --- a/src/app/shared/agenda/edit-event/edit-event.page.ts +++ b/src/app/shared/agenda/edit-event/edit-event.page.ts @@ -18,6 +18,7 @@ import { ContactsService } from 'src/app/services/contacts.service' import { DomSanitizerService } from 'src/app/services/DomSanitizer.service'; import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; import { SearchList_v2 } from 'src/app/models/search-document'; +import { Utils } from 'src/app/services/Repositorys/Agenda/utils'; @Component({ selector: 'app-edit-event', @@ -108,7 +109,8 @@ export class EditEventPage implements OnInit { private httpErrorHandle: HttpErrorHandle, private contactsService: ContactsService, private domSanitizeService: DomSanitizerService, - private agendaDataRepository: AgendaDataRepositoryService + private agendaDataRepository: AgendaDataRepositoryService, + private utils: Utils ) { } @@ -117,6 +119,7 @@ export class EditEventPage implements OnInit { this.loadedEventAttachments = this.postEvent.Attachments console.log(this.postEvent) this._postEvent = this.postEvent + this._postEvent.EventRecurrence.frequency = this.utils.recurenceTypeSeleted(this.postEvent.EventRecurrence.frequency) this.allDayCheck = this.postEvent.IsAllDayEvent; if (!this.restoreTemporaryData()) { // clear diff --git a/src/environments/suport/doneIt.ts b/src/environments/suport/doneIt.ts index 7432faf61..18754d009 100644 --- a/src/environments/suport/doneIt.ts +++ b/src/environments/suport/doneIt.ts @@ -3,10 +3,12 @@ import { Environment } from './../../app/models/envarioment'; export const environment: Environment = { id:'1', - apiURL: 'https://gdapi-dev.dyndns.info/api/', + apiURL: 'http://gpr-dev-01:83/jwt/api/', + /* apiURL: 'https://gdapi-dev-0.dyndns.info/jwt/api/', */ apiChatUrl: 'https://gdchat-dev.dyndns.info/api/v1/', apiWsChatUrl: 'wss://gdchat-dev.dyndns.info/websocket', - apiPCURL: 'https://gdcmapi-dev.dyndns.info/api/', + apiPCURL: 'http://gpr-dev-01:86/api/', + /* apiPCURL: 'https://gdcmapi-dev.dyndns.info/api/', */ /* apiURL: 'https://API.DONEIT.CO.AO/api/', apiChatUrl: 'https://CHAT.DONEIT.CO.AO/api/v1/', apiWsChatUrl: 'wss://CHAT.DONEIT.CO.AO/websocket', @@ -34,10 +36,11 @@ export const environment: Environment = { export const doneITDev: Environment = { id:'1', - apiURL: 'https://gdapi-dev.dyndns.info/api/', + apiURL: 'http://gpr-dev-01:83/jwt/api/', + /* apiURL: 'https://gdapi-dev-0.dyndns.info/jwt/api/', */ apiChatUrl: 'https://gdchat-dev.dyndns.info/api/v1/', apiWsChatUrl: 'wss://gdchat-dev.dyndns.info/websocket', - apiPCURL: 'https://gdcmapi-dev.dyndns.info/api/', + apiPCURL: 'http://gpr-dev-01:86/api/', /* apiURL: 'https://API.DONEIT.CO.AO/api/', apiChatUrl: 'https://CHAT.DONEIT.CO.AO/api/v1/', apiWsChatUrl: 'wss://CHAT.DONEIT.CO.AO/websocket',