From 0c14b9be979f22b13e627b978767be4a173d9768 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 21 Jun 2024 23:33:29 +0100 Subject: [PATCH] fix ownertype and category type --- .../agenda/edit-event/edit-event.page.html | 4 +- .../agenda/new-event/new-event.page.html | 2 +- .../pages/agenda/new-event/new-event.page.ts | 8 - .../event-list/event-list.page.html | 4 +- .../event-list/event-list.page.ts | 129 ++---- .../Agenda/agenda-data-repository.service.ts | 4 +- src/app/services/Repositorys/Agenda/utils.ts | 23 +- .../api-validate-schema.decorator.ts | 2 + src/app/services/task.service.ts | 16 +- .../agenda/event-list/event-list.page.html | 2 +- .../shared/agenda/new-event/new-event.page.ts | 413 +----------------- .../events-to-approve.page.html | 2 +- version/git-version.ts | 12 +- 13 files changed, 90 insertions(+), 531 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 c16071455..aa44f7f74 100644 --- a/src/app/pages/agenda/edit-event/edit-event.page.html +++ b/src/app/pages/agenda/edit-event/edit-event.page.html @@ -8,7 +8,7 @@
- Editar Evento[] + Editar Evento
@@ -34,7 +34,7 @@ -
+
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 a91a400d4..ab2df2fc3 100644 --- a/src/app/pages/agenda/new-event/new-event.page.html +++ b/src/app/pages/agenda/new-event/new-event.page.html @@ -31,7 +31,7 @@
Minha agenda
- + 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 366ad74bb..697c778b5 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -4,7 +4,6 @@ import { EventBody } from 'src/app/models/eventbody.model'; import { EventPerson } from 'src/app/models/eventperson.model'; import { SearchList } from 'src/app/models/search-document'; import { LoginUserRespose } from 'src/app/models/user.model'; -import { AttachmentsService } from 'src/app/services/attachments.service'; import { EventsService } from 'src/app/services/events.service'; import { ToastService } from 'src/app/services/toast.service'; import { Event } from '../../../models/event.model'; @@ -15,13 +14,11 @@ 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'; -import { ChatMethodsService } from 'src/app/services/chat/chat-methods.service'; import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'; import { environment } from 'src/environments/environment'; import { ProcessesService } from 'src/app/services/processes.service'; import { TaskService } from 'src/app/services/task.service' import { ContactsService } from 'src/app/services/contacts.service'; -import { DomSanitizerService } from 'src/app/services/DomSanitizer.service'; import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, ThemePalette } from '@angular/material/core'; import { MomentDateAdapter } from '@angular/material-moment-adapter'; import { AgendaDataRepositoryService } from 'src/app/services/Repositorys/Agenda/agenda-data-repository.service'; @@ -127,17 +124,13 @@ export class NewEventPage implements OnInit { private modalController: ModalController, private navParams: NavParams, public eventService: EventsService, - private attachmentsService: AttachmentsService, private toastService: ToastService, public ThemeService: ThemeService, private platform: Platform, - private chatMethodService: ChatMethodsService, private hhtpErrorHandle: HttpErrorHandle, private processeService: ProcessesService, public TaskService: TaskService, private contactsService: ContactsService, - private domSanitazerService: DomSanitizerService, - private dateAdapter: DateAdapter, private agendaDataRepository: AgendaDataRepositoryService, public RoleIdService: RoleIdService, ) { @@ -495,7 +488,6 @@ export class NewEventPage implements OnInit { return false } - const calendar = await this.agendaDataRepository.getCalendarByUserId(this.selectedUserCalendar) if(calendar.isOk()) { const loader = this.toastService.loading() diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.html b/src/app/pages/gabinete-digital/event-list/event-list.page.html index f1d06cb2f..0f398a75b 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.html +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.html @@ -8,7 +8,7 @@
- +
@@ -56,7 +56,7 @@
- + diff --git a/src/app/pages/gabinete-digital/event-list/event-list.page.ts b/src/app/pages/gabinete-digital/event-list/event-list.page.ts index bf54385ee..bcdb5a6c0 100644 --- a/src/app/pages/gabinete-digital/event-list/event-list.page.ts +++ b/src/app/pages/gabinete-digital/event-list/event-list.page.ts @@ -34,7 +34,6 @@ export class EventListPage implements OnInit { // [desktop] event list to approve profile: string; - segment: any; showLoader: boolean; eventPerson: EventPerson; eventBody: EventBody; @@ -62,7 +61,6 @@ export class EventListPage implements OnInit { selectedUserCalendar:any; constructor( - private processes: ProcessesService, private modalController: ModalController, private router: Router, private sortService: SortService, @@ -83,26 +81,6 @@ export class EventListPage implements OnInit { } - this.eventService.onCalendarFinishLoad.subscribe(() => { - if(!this.segment) { - if(this.eventService.calendarNamesAry.includes('Meu calendario')) { - this.segment = 'Meu calendario'; - } else { - this.segment = this.eventService.calendarNamesAry[0].OwnerUserId - } - - // select pr by default - const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República') - if(pr) { - this.segment = pr.OwnerUserId - } - - this.dynamicSearch() - } else { - this.dynamicSearch() - } - }) - this.listSubscription = this.eventoaprovacaostore.registerCallback({ id: import.meta.url, funx:() => { @@ -140,26 +118,8 @@ export class EventListPage implements OnInit { } }; - - // 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.AgendaDataRepositoryService.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.eventService.onCalendarFinishLoad.subscribe(async() => { - this.setCalendarByDefault() - }) + this.sharedCalendar = this.AgendaDataRepositoryService.getShareCalendarItemsLiveWithOrder() + this.setCalendarByDefault(); } @@ -173,6 +133,9 @@ export class EventListPage implements OnInit { } else { this.selectedUserCalendar = SessionStore.user.UserId } + + + this.LoadToApproveEvents() } ngOnDestroy() { @@ -180,10 +143,7 @@ export class EventListPage implements OnInit { } - ngAfterViewInit(): void { - - - } + ngAfterViewInit(): void {} reorderList(orderBy: string) { @@ -197,7 +157,7 @@ export class EventListPage implements OnInit { if(this.showSearch && this.searchSubject) { - const list = this.eventoaprovacaostore.get(this.segment).filter((task) => { + const list = this.eventoaprovacaostore.get(this.selectedUserCalendar).filter((task) => { let subject = task.Folio || task.Subject || task.workflowInstanceDataFields.Subject subject = subject.toLowerCase(); return subject.includes(this.searchSubject.toLowerCase()) @@ -205,7 +165,7 @@ export class EventListPage implements OnInit { this.list = this.TaskService.reorderList(this.ordinance, list) } else { - const list = this.eventoaprovacaostore.get(this.segment) + const list = this.eventoaprovacaostore.get(this.selectedUserCalendar) this.list = this.TaskService.reorderList(this.ordinance, list) } @@ -221,52 +181,59 @@ export class EventListPage implements OnInit { async LoadToApproveEvents(tracing?: TracingType) { console.log('aprove event') this.showLoader = true; - this.skeletonLoader = true - const segment: any = this.segment - let userId; - if(this.segment == 'Meu calendario') { - if(SessionStore.user.Profile == 'PR') { + const segment = this.selectedUserCalendar + + if(segment) { + let userId; + + if(this.selectedUserCalendar == SessionStore.user.UserId) { + // color + if(SessionStore.user.Profile == 'PR') { + this.color = 'pr' + } else { + this.color = 'mdgpr' + } + userId = SessionStore.user.UserId + + } else if(segment) { this.color = 'pr' - } else { - this.color = 'mdgpr' + userId = this.selectedUserCalendar } - userId = SessionStore.user.UserId - - } else if(segment) { - this.color = 'pr' - userId = segment - } - let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({ - userId, - status: EEventFilterStatus.Pending - }, tracing) + this.skeletonLoader = true - if(allEvents.isOk()) { - tracing.setAttribute('outcome', 'success') + let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({ + userId, + status: EEventFilterStatus.Pending + }, tracing) - if(allEvents.value.length >= 1) { - const eventsList = this.sortService.sortArrayByDate(allEvents.value).reverse(); - this.eventoaprovacaostore.save(segment, eventsList) - } else { + if(allEvents.isOk()) { + tracing.setAttribute('outcome', 'success') + + if(allEvents.value.length >= 1) { + const eventsList = this.sortService.sortArrayByDate(allEvents.value).reverse(); + this.eventoaprovacaostore.save(segment, eventsList) + } else { + this.eventoaprovacaostore.save(segment, []) + } + } else { + + tracing.setAttribute('outcome', 'failed') + tracing.bugFlag() + if(!isHttpError(allEvents.error)) { + this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #4') + } this.eventoaprovacaostore.save(segment, []) + // this.showLoader = false; } - } else { - tracing.setAttribute('outcome', 'failed') - tracing.bugFlag() - if(!isHttpError(allEvents.error)) { - this.toastService._badRequest('Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico. #4') - } - this.eventoaprovacaostore.save(segment, []) - // this.showLoader = false; + this.showLoader = false; + this.skeletonLoader = false } - this.showLoader = false; - this.skeletonLoader = false } 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 dbdb55028..7df11b795 100644 --- a/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts +++ b/src/app/services/Repositorys/Agenda/agenda-data-repository.service.ts @@ -157,7 +157,7 @@ export class AgendaDataRepositoryService { } createEvent(eventData: Event, documents, calendar: TableSharedCalendar) { - console.log('create repository 1',eventData) + console.log('create repository 1',eventData, calendar) let eventInput = { userId: calendar.wxUserId, @@ -211,6 +211,8 @@ export class AgendaDataRepositoryService { } } + console.log({eventData}) + return this.agendaDataService.updateEvent(eventId, eventInput) } diff --git a/src/app/services/Repositorys/Agenda/utils.ts b/src/app/services/Repositorys/Agenda/utils.ts index d065821a1..9e6d3cca3 100644 --- a/src/app/services/Repositorys/Agenda/utils.ts +++ b/src/app/services/Repositorys/Agenda/utils.ts @@ -26,13 +26,13 @@ export class Utils { } } - selectedCalendarOwner(CalendarName) { - let selectedCalendar = this.findRoleIdByUserId(this.eventService.calendarNamesAry, CalendarName); - console.log('selected', selectedCalendar ) - if (selectedCalendar) { - if (selectedCalendar == "Presidente da República") { + selectedCalendarOwner(roleDescription) { + + console.log('roleDescription', roleDescription) + if (roleDescription) { + if (roleDescription == "Presidente da República") { return 1; - } else if (selectedCalendar == "Ministro e Director do Gabinete do PR") { + } else if (roleDescription == "Ministro e Director do Gabinete do PR") { return 2 } else { return 3 @@ -50,7 +50,7 @@ export class Utils { return 'other'; } } - + } @@ -60,6 +60,11 @@ export class Utils { 'Oficial': 1, 'Pessoal': 2 } + + if(calendarName != 'Pessoal' && calendarName != 'Oficial') { + throw('bad logic') + } + return selectedCalendar[calendarName]; } @@ -180,11 +185,11 @@ export class Utils { addOneHourToIsoString(isoDateString) { let date = new Date(isoDateString); - + const tzOffset = -date.getTimezoneOffset(); // in minutes const diff = tzOffset >= 0 ? '+' : '-'; const pad = (n: number) => (n < 10 ? '0' : '') + n; - + return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + diff --git a/src/app/services/decorator/api-validate-schema.decorator.ts b/src/app/services/decorator/api-validate-schema.decorator.ts index f919677bf..c13ebd204 100644 --- a/src/app/services/decorator/api-validate-schema.decorator.ts +++ b/src/app/services/decorator/api-validate-schema.decorator.ts @@ -22,6 +22,7 @@ export function APIReturn(schema: z.ZodTypeAny, path: string) { console.error('unexpected data structure', path) // Capture the Zod validation error with additional context console.error('Validation failed:', error.errors); + console.log(result.value) } else { // Throw any other unexpected errors // throw error; @@ -53,6 +54,7 @@ export function APINODReturn(schema: z.ZodTypeAny, data , path: string, tracing? console.error('unexpected data structure', path) // Capture the Zod validation error with additional context console.error('Validation failed:', error.errors); + console.log(data) tracing?.setAttribute('APIReturn.error', 'true') diff --git a/src/app/services/task.service.ts b/src/app/services/task.service.ts index 12db62b38..92879dd43 100644 --- a/src/app/services/task.service.ts +++ b/src/app/services/task.service.ts @@ -320,19 +320,13 @@ export class TaskService { // PR dont have event to approve /* if(this.SessionStore.user.Profile != 'PR') { */ try { - for(let calendar of this.eventService.calendarNamesAry) { - let userId; + const list = await this.AgendaDataRepositoryService.geCalendars() - if(calendar == 'Meu calendario') { - userId = SessionStore.user.UserId - - } else { - userId = calendar.OwnerUserId - } + for(let calendar of list) { let allEvents = await this.AgendaDataRepositoryService.eventToApproveList({ - userId, + userId: calendar.wxUserId, status: EEventFilterStatus.Pending }, tracing) @@ -342,9 +336,9 @@ export class TaskService { let eventsList = [] if(allEvents.value.length >= 1) { eventsList = this.sortService.sortArrayByDate(allEvents.value).reverse(); - this.eventoaprovacaostore.save(userId, eventsList) + this.eventoaprovacaostore.save(calendar.wxUserId as any, eventsList) } else { - this.eventoaprovacaostore.save(userId, []) + this.eventoaprovacaostore.save(calendar.wxUserId as any, []) } } else { diff --git a/src/app/shared/agenda/event-list/event-list.page.html b/src/app/shared/agenda/event-list/event-list.page.html index 1917e7073..fd1c5f3f3 100644 --- a/src/app/shared/agenda/event-list/event-list.page.html +++ b/src/app/shared/agenda/event-list/event-list.page.html @@ -1,7 +1,7 @@
-
Eventos para Aprovação
+
Eventos para aprovação