diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index f49a58816..a6cb6c8f5 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -8,10 +8,10 @@ import { EventList } from '../models/agenda/AgendaEventList'; import { ChangeProfileService } from './change-profile.service'; import { OfflineManagerService } from 'src/app/services/offline-manager.service'; import { catchError } from "rxjs/operators"; -import { Storage } from '@ionic/storage'; import { BackgroundService } from 'src/app/services/background.service'; import { SessionStore } from '../store/session.service'; import { calendarInterface } from '../models/user.model'; +import { Subscribe } from './subcribe'; @Injectable({ @@ -62,6 +62,8 @@ export class EventsService { myCalendarNames = {} hasAnyCalendar = false + onCalendarFinishLoad = new Subscribe({execute : false, deleteOnExecute: true}) + constructor( private http: HttpClient, public user: AuthService, @@ -255,37 +257,36 @@ export class EventsService { for (let sharedCalendar of SessionStore.user.SharedCalendars) { this.hasAnyCalendar = true if(sharedCalendar?.OwnerUserId) { - this.GetCalendarName(sharedCalendar.OwnerUserId).subscribe((e)=> { + const e = await this.GetCalendarName(sharedCalendar.OwnerUserId).toPromise() - this.calendarNames[sharedCalendar.CalendarId] = e.FullName - this.myCalendarNames[sharedCalendar.CalendarId] = e.FullName - - if(!this.calendarNamesAry.find(x => x.Role == e.Role)) { - - - let objectShared = { - "Fullname": e.FullName, - "Role": e.Role, - "OwnerUserId": sharedCalendar.OwnerUserId, - "RoleId": sharedCalendar.CalendarRoleId - } - - this.calendarNamesAry.push(objectShared) - - if(e.Role == 'Presidente da República') { - this.calendarNamesAryPR.push(objectShared) - } else { - this.calendarNamesAryNoPr.push(objectShared) - } - - this.calendarNamesType[e.FullName] = {} + this.calendarNames[sharedCalendar.CalendarId] = e.FullName + this.myCalendarNames[sharedCalendar.CalendarId] = e.FullName + + if(!this.calendarNamesAry.find(x => x.Role == e.Role)) { + + + let objectShared = { + "Fullname": e.FullName, + "Role": e.Role, + "OwnerUserId": sharedCalendar.OwnerUserId, + "RoleId": sharedCalendar.CalendarRoleId } + + this.calendarNamesAry.push(objectShared) - this.calendarNamesType[e.FullName][sharedCalendar.CalendarName] = true - this.calendarNamesType[e.FullName][sharedCalendar.CalendarName+'Id'] = sharedCalendar.CalendarId - this.calendarNamesType[e.FullName]['RoleId'] = sharedCalendar.CalendarRoleId - this.calendarNamesType[e.FullName]['OwnerId'] = sharedCalendar.OwnerUserId - }) + if(e.Role == 'Presidente da República') { + this.calendarNamesAryPR.push(objectShared) + } else { + this.calendarNamesAryNoPr.push(objectShared) + } + + this.calendarNamesType[e.FullName] = {} + } + + this.calendarNamesType[e.FullName][sharedCalendar.CalendarName] = true + this.calendarNamesType[e.FullName][sharedCalendar.CalendarName+'Id'] = sharedCalendar.CalendarId + this.calendarNamesType[e.FullName]['RoleId'] = sharedCalendar.CalendarRoleId + this.calendarNamesType[e.FullName]['OwnerId'] = sharedCalendar.OwnerUserId } } @@ -317,6 +318,8 @@ export class EventsService { this.calendarNamesAryReverse = this.calendarNamesAry.reverse(); + this.onCalendarFinishLoad.executor(); + (() => { const keys = {} diff --git a/src/app/services/subcribe.ts b/src/app/services/subcribe.ts new file mode 100644 index 000000000..5e3057b2a --- /dev/null +++ b/src/app/services/subcribe.ts @@ -0,0 +1,50 @@ +import { v4 as uuidv4 } from 'uuid' + +export class Subscribe { + + function: Function + callbacks: {} = {} + execute: boolean + deleteOnExecute: boolean + + constructor({execute = true, deleteOnExecute = false}) { + this.execute = execute + this.deleteOnExecute = deleteOnExecute + } + + executor() { + if(!this.execute) { + this.execute = true + for (let id in this.callbacks) { + this.callbacks[id].e() + if(this.deleteOnExecute) { + delete this.callbacks[id] + } + } + } else { + throw('already ben called') + } + } + + subscribe(e) { + const id = uuidv4(); + + let shadow + + if(!this.execute) { + this.callbacks[id] = {e} + shadow = e + } else { + e() + shadow = () => {} + } + + this.callbacks[id] = {e} + return { + unSubscribe: () => { + this.callbacks[id] = shadow + } + } + } + +} \ No newline at end of file diff --git a/version/git-version.ts b/version/git-version.ts index 09bbb38f3..2821a715f 100644 --- a/version/git-version.ts +++ b/version/git-version.ts @@ -1,12 +1,12 @@ export let versionData = { - "shortSHA": "f8f0d39be", - "SHA": "f8f0d39be994d847b5406eee2cf3aba5fe9b2c19", + "shortSHA": "f023501d9", + "SHA": "f023501d9ebf0d058430f9feaa43f47ab131bde5", "branch": "feature/gabinete-search", "lastCommitAuthor": "'Peter Maquiran'", - "lastCommitTime": "'Tue Jun 13 14:34:22 2023 +0100'", - "lastCommitMessage": "rollback", - "lastCommitNumber": "5012", - "change": "", - "changeStatus": "On branch feature/gabinete-search\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/pages/gabinete-digital/diplomas/diploma/diploma.page.html\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.html\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.ts\n\tmodified: src/app/pages/gabinete-digital/gabinete-digital.page.ts\n\tmodified: src/app/shared/agenda/event-list/event-list.page.html\n\tmodified: src/app/shared/agenda/event-list/event-list.page.ts\n\tmodified: src/app/shared/gabinete-digital/all-processes/all-processes.page.ts\n\tmodified: src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.html\n\tmodified: src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts\n\tmodified: src/global.scss", + "lastCommitTime": "'Tue Jun 13 20:37:23 2023 +0100'", + "lastCommitMessage": "fix issues", + "lastCommitNumber": "5013", + "change": "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\nindex 8fc46150d..0f7a466d0 100644\n--- a/src/app/pages/gabinete-digital/event-list/event-list.page.ts\n+++ b/src/app/pages/gabinete-digital/event-list/event-list.page.ts\n@@ -62,20 +62,25 @@ export class EventListPage implements OnInit {\n if(window.location.pathname.includes('gabinete-digital')) {\n this.showFilter = true\n }\n- \n- if(!this.segment) {\n- if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n- this.segment = 'Meu calendario';\n- } else {\n- this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ \n+\n+ this.eventService.onCalendarFinishLoad.subscribe(() => {\n+ if(!this.segment) {\n+ if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n+ this.segment = 'Meu calendario';\n+ } else {\n+ this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ }\n+ \n+ // select pr by default\n+ const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n+ if(pr) {\n+ this.segment = pr.OwnerUserId\n+ }\n }\n+ })\n+\n \n- // select pr by default\n- // const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n- // if(pr) {\n- // this.segment = pr.OwnerUserId\n- // }\n- }\n \n const location = window.location\n const pathname = location.pathname + location.search\ndiff --git a/src/app/shared/agenda/event-list/event-list.page.ts b/src/app/shared/agenda/event-list/event-list.page.ts\nindex 7e283262c..1913a9636 100644\n--- a/src/app/shared/agenda/event-list/event-list.page.ts\n+++ b/src/app/shared/agenda/event-list/event-list.page.ts\n@@ -49,18 +49,21 @@ export class EventListPage implements OnInit {\n }\n \n ngAfterViewInit(): void {\n- if(!this.segment) {\n- if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n- this.segment = 'Meu calendario';\n- } else {\n- this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ this.eventService.onCalendarFinishLoad.subscribe(() => {\n+ if(!this.segment) {\n+ if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n+ this.segment = 'Meu calendario';\n+ } else {\n+ this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ }\n+ \n+ // select pr by default\n+ const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n+ if(pr) {\n+ this.segment = pr.OwnerUserId\n+ }\n }\n-\n- // const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n- // if(pr) {\n- // this.segment = pr.OwnerUserId\n- // }\n- }\n+ })\n }\n \n ngOnInit() {\ndiff --git a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts\nindex 7aae316e9..60e63ef1b 100644\n--- a/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts\n+++ b/src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts\n@@ -62,18 +62,23 @@ export class EventsToApprovePage implements OnInit {\n {}\n \n ngOnInit() {\n- if(!this.segment) {\n- if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n- this.segment = 'Meu calendario';\n- } else {\n- this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ \n+ this.eventService.onCalendarFinishLoad.subscribe(() => {\n+ if(!this.segment) {\n+ if(this.eventService.calendarNamesAry.includes('Meu calendario')) {\n+ this.segment = 'Meu calendario';\n+ } else {\n+ this.segment = this.eventService.calendarNamesAry[0].OwnerUserId\n+ }\n+ \n+ // select pr by default\n+ const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n+ if(pr) {\n+ this.segment = pr.OwnerUserId\n+ }\n }\n+ })\n \n- // const pr = this.eventService.calendarNamesAry.find( e => e.Role == 'Presidente da República')\n- // if(pr) {\n- // this.segment = pr.OwnerUserId\n- // }\n- }\n this.LoadToApproveEvents()\n \n this.listSubscription = this.eventoaprovacaostore.registerCallback({", + "changeStatus": "On branch feature/gabinete-search\nChanges to be committed:\n (use \"git restore --staged ...\" to unstage)\n\tmodified: src/app/services/events.service.ts\n\tnew file: src/app/services/subcribe.ts\n\nChanges not staged for commit:\n (use \"git add ...\" to update what will be committed)\n (use \"git restore ...\" to discard changes in working directory)\n\tmodified: src/app/pages/gabinete-digital/event-list/event-list.page.ts\n\tmodified: src/app/shared/agenda/event-list/event-list.page.ts\n\tmodified: src/app/shared/gabinete-digital/events-to-approve/events-to-approve.page.ts", "changeAuthor": "peter.maquiran" } \ No newline at end of file