diff --git a/src/app/presence-control/services/presence-control-state.service.spec.ts b/src/app/presence-control/services/presence-control-state.service.spec.ts index 3b061fbdb..6c22b3622 100644 --- a/src/app/presence-control/services/presence-control-state.service.spec.ts +++ b/src/app/presence-control/services/presence-control-state.service.spec.ts @@ -258,6 +258,8 @@ describe('PresenceControlStateService', () => { ) ) ); + expectLoadOtherTeachersAbsencesRequest([], person.Id, [66]); + resetCallbackSpies(); service.updateLessonPresencesTypes([ @@ -273,6 +275,8 @@ describe('PresenceControlStateService', () => { expect(entries[0].lessonPresence.Type).toBe('Abwesend'); expect(entries[0].presenceType).toBe(absent); + expectLoadOtherTeachersAbsencesRequest([], person.Id, [66]); + expectCstRequest(); }); }); @@ -353,9 +357,13 @@ describe('PresenceControlStateService', () => { function expectLoadOtherTeachersAbsencesRequest( response = otherAbsences, - personId: number + personId: number, + students?: number[] ): void { - const url = `https://eventotest.api/LessonTeachers/except/${personId}/LessonAbsences?expand=LessonRef`; + let url = `https://eventotest.api/LessonTeachers/except/${personId}/LessonAbsences?expand=LessonRef`; + if (students && students.length > 0) { + url = url.concat('&filter.StudentRef=;', students.join(';')); + } httpTestingController .expectOne(url) .flush(t.array(LessonAbsence).encode(response)); diff --git a/src/app/presence-control/services/presence-control-state.service.ts b/src/app/presence-control/services/presence-control-state.service.ts index 6271d2685..0d8c3c2b1 100644 --- a/src/app/presence-control/services/presence-control-state.service.ts +++ b/src/app/presence-control/services/presence-control-state.service.ts @@ -18,6 +18,7 @@ import { takeUntil, mergeAll, filter, + startWith, } from 'rxjs/operators'; import { isEqual, uniq } from 'lodash-es'; import { format } from 'date-fns'; @@ -110,9 +111,26 @@ export class PresenceControlStateService .getAbsenceConfirmationStates() .pipe(shareReplay(1)); - otherTeachersAbsences$ = this.personsService.getMyself().pipe( - switchMap((person) => - this.lessonTeacherService.loadOtherTeachersLessonAbsences(person.Id) + selectedLessonStudentIds$ = combineLatest([ + this.selectLesson$, + this.lessonPresences$, + ]).pipe( + map(([lesson, presences]) => { + return presences.filter((i) => i.LessonRef.Id === Number(lesson?.id)); + }), + map((p) => p.map((i) => i.StudentRef.Id)), + shareReplay(1) + ); + + otherTeachersAbsences$ = combineLatest([ + this.personsService.getMyself(), + this.selectedLessonStudentIds$.pipe(startWith([])), + ]).pipe( + switchMap(([person, students]) => + this.lessonTeacherService.loadOtherTeachersLessonAbsences( + person.Id, + students + ) ), shareReplay(1) ); diff --git a/src/app/shared/services/lesson-teachers-rest.service.ts b/src/app/shared/services/lesson-teachers-rest.service.ts index 2ddfbbbc1..cc49c89cd 100644 --- a/src/app/shared/services/lesson-teachers-rest.service.ts +++ b/src/app/shared/services/lesson-teachers-rest.service.ts @@ -18,17 +18,19 @@ export class LessonTeachersRestService extends RestService< } /** - * Returns all lesson absences for all teachers expect for the given teacher + * Returns all lesson absences for all teachers expect for the given teacher for the current lesson corresponding students */ loadOtherTeachersLessonAbsences( personId: number, + students: number[], params?: HttpParams | Dict ): Observable> { + let url = `${this.baseUrl}/except/${personId}/LessonAbsences?expand=LessonRef`; + if (students && students.length > 0) { + url = url.concat('&filter.StudentRef=;' + students.join(';')); + } return this.http - .get( - `${this.baseUrl}/except/${personId}/LessonAbsences?expand=LessonRef`, - { params } - ) + .get(url, { params }) .pipe(switchMap(decodeArray(LessonAbsence))); } }