Dev Horror Stories: Angular Madness

“May chaos take the world!” – shouted by Frenzied Flame enemies.

Screenshot From 2025-10-02 18-20-08.webp

  private googleCalendarSelect(profileId:string, serviceEventId:string): Observable<any> {

    return forkJoin([this.getGoogleCalendar(profileId,true), this.getGoogleCalendarListApi(profileId)]).pipe(
          map(v=>v[1].data.items.map(itm=>({id:itm.id, title:itm.summary,
              alreadySelected: v[0].connections.some(c=>c.calendarId==itm.id && c.serviceEvent == serviceEventId),
              remove: false,
              selected: v[0].connections.some(c=>c.calendarId==itm.id && c.serviceEvent == serviceEventId) }))),
          switchMap(v=>this.commonDialogService.openDialogRx(SelectCalendarComponent, { i18nKey: "calendarSync.select" , calendarData:v}, 'calendar-select')),
          switchMap(v=>v?of(v):EMPTY),
          switchMap(x=>x.some(itm=>!itm.remove)?of(x):
                 this.commonDialogService.openConfirmRx("calendarSync.confirmRemoveSync").pipe(
                     switchMap(v=>v==1?of(v):EMPTY),
                     switchMap(v=>forkJoin([of({})].concat(x.filter(itm=>itm.alreadySelected)
                       .map(v=>this.disconnectGoogleCalendarWithServiceEventApi(profileId, {serviceEvent:serviceEventId, calendarId: v.id}))
                       ))),
                     switchMap(v=>this.removeGoogleCalendarApi(profileId).pipe(
                         tap(v=>{this.connectedCalendar.google=false; this.connectedCalendar.def=false;
                                 this.hasCalendar.google = false ; this.hasCalendar.def = false; })
                      )),
                     //switchMap(v=>this.waitIndicator(7000)),
                     switchMap(v=>EMPTY)
               )),
          switchMap(v=>
            forkJoin([].concat(v.filter(itm=>!itm.selected && itm.alreadySelected && !itm.remove)
             .map(v=>this.disconnectGoogleCalendarWithServiceEventApi(profileId, {serviceEvent:serviceEventId, calendarId: v.id})),
              v.filter(itm=>itm.selected && !itm.alreadySelected)
              .map(v=>this.connectGoogleCalendarWithServiceEventApi(profileId, {serviceEvent:serviceEventId, calendarId: v.id})))
             ).pipe(
                tap(x=>{this.hasCalendar.google = v.some(itm=>itm.selected); this.hasCalendar.def = this.hasCalendar.google;
                        }),
                //switchMap(v=>this.waitIndicator(7000))
                )
           )
    );
  }