From 6153864321008ff692fecddc3dbd97b287d74a98 Mon Sep 17 00:00:00 2001 From: Mathis Hofer Date: Mon, 25 Nov 2024 17:34:24 +0100 Subject: [PATCH] Add weekday filter to edit absences #714 --- .../edit-absences-header.component.html | 10 ++++++++++ .../edit-absences-header.component.spec.ts | 1 + .../edit-absences-header.component.ts | 10 ++++++++++ .../edit-absences-list.component.spec.ts | 1 + .../edit-absences-list.component.ts | 1 + .../services/edit-absences-state.service.ts | 14 +++++++++++--- .../models/presence-control-entry.model.ts | 4 ++-- .../multiselect/multiselect.component.ts | 7 +++++-- .../services/drop-down-items-rest.service.ts | 6 ++++++ .../services/lesson-presences-rest.service.spec.ts | 4 +++- .../services/lesson-presences-rest.service.ts | 7 +++++++ src/assets/locales/de-CH.json | 1 + src/assets/locales/fr-CH.json | 1 + 13 files changed, 59 insertions(+), 8 deletions(-) diff --git a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.html b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.html index 8ad371c0c..575c05df9 100644 --- a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.html +++ b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.html @@ -54,6 +54,16 @@ }} + +
+ + +
diff --git a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.spec.ts b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.spec.ts index 9508f92cd..dd137216a 100644 --- a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.spec.ts +++ b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.spec.ts @@ -16,6 +16,7 @@ describe("EditAbsencesHeaderComponent", () => { { provide: EditAbsencesStateService, useValue: { + weekdays$: of([]), absenceConfirmationStates$: of([]), presenceTypes$: of([]), selected: [{ lessonIds: [1, 2, 3], personIds: [4, 5, 6] }], diff --git a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.ts b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.ts index e46e24d7c..3a6235bb3 100644 --- a/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.ts +++ b/src/app/edit-absences/components/edit-absences-header/edit-absences-header.component.ts @@ -64,6 +64,7 @@ export class EditAbsencesHeaderComponent { teacher: null, dateFrom: null, dateTo: null, + weekdays: null, presenceTypes: null, confirmationStates: null, incidentTypes: null, @@ -71,6 +72,15 @@ export class EditAbsencesHeaderComponent { @Output() filterChange = new EventEmitter(); + weekdaysGrouped$ = this.state.weekdays$.pipe( + map((weekdays) => + addGroupToDropdownItem( + weekdays, + this.translate.instant("shared.multiselect.all-option"), + ), + ), + ); + absenceConfirmationStatesGrouped$ = this.state.absenceConfirmationStates$.pipe( map((i) => diff --git a/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.spec.ts b/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.spec.ts index 81479bd99..5399efcff 100644 --- a/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.spec.ts +++ b/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.spec.ts @@ -22,6 +22,7 @@ describe("EditAbsencesListComponent", () => { setFilter: jasmine.createSpy("setFilter"), isFilterValid$: of(true), validFilter$: of({}), + weekdays$: of([]), presenceTypes$: of([]), absenceConfirmationStates$: of([]), } as unknown as EditAbsencesStateService; diff --git a/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.ts b/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.ts index 6ed9d7e98..f143d6e4d 100644 --- a/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.ts +++ b/src/app/edit-absences/components/edit-absences-list/edit-absences-list.component.ts @@ -117,6 +117,7 @@ function createFilterFromParams(params: Params): EditAbsencesFilter { teacher: params["teacher"] ?? null, dateFrom: params["dateFrom"] ? parseISOLocalDate(params["dateFrom"]) : null, dateTo: params["dateTo"] ? parseISOLocalDate(params["dateTo"]) : null, + weekdays: params["weekdays"] ? params["weekdays"].split(",") : null, presenceTypes: params["presenceTypes"] ? params["presenceTypes"].split(",").map(Number) : null, diff --git a/src/app/edit-absences/services/edit-absences-state.service.ts b/src/app/edit-absences/services/edit-absences-state.service.ts index 32f35cdf9..5afad63e9 100644 --- a/src/app/edit-absences/services/edit-absences-state.service.ts +++ b/src/app/edit-absences/services/edit-absences-state.service.ts @@ -30,9 +30,10 @@ export interface EditAbsencesFilter { teacher: Option; dateFrom: Option; dateTo: Option; - presenceTypes: Option; - confirmationStates: Option; - incidentTypes: Option; + weekdays: Option>; + presenceTypes: Option>; + confirmationStates: Option>; + incidentTypes: Option>; } @Injectable() @@ -42,6 +43,7 @@ export class EditAbsencesStateService { confirmBackLinkParams?: Params; + weekdays$ = this.loadWeekdays().pipe(shareReplay(1)); presenceTypes$ = this.loadPresenceTypes().pipe(shareReplay(1)); absenceConfirmationStates$ = this.loadAbsenceConfirmationStates().pipe( map(sortDropDownItemsByValue), @@ -96,6 +98,7 @@ export class EditAbsencesStateService teacher: null, dateFrom: null, dateTo: null, + weekdays: null, presenceTypes: null, confirmationStates: null, incidentTypes: null, @@ -110,6 +113,7 @@ export class EditAbsencesStateService filterValue.teacher || filterValue.dateFrom || filterValue.dateTo || + filterValue.weekdays || filterValue.presenceTypes || filterValue.confirmationStates || filterValue.incidentTypes, @@ -135,6 +139,10 @@ export class EditAbsencesStateService return buildParamsFromAbsenceFilter(filterValue); } + private loadWeekdays(): Observable> { + return this.loadingService.load(this.dropDownItemsService.getWeekdays()); + } + private loadPresenceTypes(): Observable> { return this.loadingService.load( this.presenceTypesService.activePresenceTypes$, diff --git a/src/app/presence-control/models/presence-control-entry.model.ts b/src/app/presence-control/models/presence-control-entry.model.ts index 677505e32..087181eea 100644 --- a/src/app/presence-control/models/presence-control-entry.model.ts +++ b/src/app/presence-control/models/presence-control-entry.model.ts @@ -41,8 +41,8 @@ export class PresenceControlEntry { this.studentFullName = lessonPresence.StudentFullName; } - get id(): number { - return this.lessonPresence.StudentRef.Id; + get id(): string { + return `${this.lessonPresence.LessonRef.Id}-${this.lessonPresence.StudentRef.Id}`; } get presenceCategory(): PresenceCategory { diff --git a/src/app/shared/components/multiselect/multiselect.component.ts b/src/app/shared/components/multiselect/multiselect.component.ts index a48012c26..67526c95b 100644 --- a/src/app/shared/components/multiselect/multiselect.component.ts +++ b/src/app/shared/components/multiselect/multiselect.component.ts @@ -3,6 +3,7 @@ import { FormsModule } from "@angular/forms"; import { NgSelectModule } from "@ng-select/ng-select"; import { TranslateModule } from "@ngx-translate/core"; import { DropDownGroupedItem } from "../../models/drop-down-grouped-item.model"; +import { DropDownItem } from "../../models/drop-down-item.model"; @Component({ selector: "bkd-multiselect", @@ -13,8 +14,10 @@ import { DropDownGroupedItem } from "../../models/drop-down-grouped-item.model"; }) export class MultiselectComponent { @Input() options: ReadonlyArray = []; - @Input() values: Option = []; - @Output() valuesChange = new EventEmitter>(); + @Input() values: Option> = []; + @Output() valuesChange = new EventEmitter< + Option> + >(); constructor() {} diff --git a/src/app/shared/services/drop-down-items-rest.service.ts b/src/app/shared/services/drop-down-items-rest.service.ts index 3f7f7e10d..08b1d10cd 100644 --- a/src/app/shared/services/drop-down-items-rest.service.ts +++ b/src/app/shared/services/drop-down-items-rest.service.ts @@ -15,6 +15,12 @@ export class DropDownItemsRestService { @Inject(SETTINGS) private settings: Settings, ) {} + getWeekdays(): Observable> { + return this.http + .get(`${this.baseUrl}/Weekdays`) + .pipe(switchMap(decodeArray(DropDownItem)), shareReplay(1)); + } + getAbsenceConfirmationStates(): Observable> { return this.http .get(`${this.baseUrl}/AbsenceConfirmationStates`) diff --git a/src/app/shared/services/lesson-presences-rest.service.spec.ts b/src/app/shared/services/lesson-presences-rest.service.spec.ts index caa188a97..9caf8639d 100644 --- a/src/app/shared/services/lesson-presences-rest.service.spec.ts +++ b/src/app/shared/services/lesson-presences-rest.service.spec.ts @@ -398,6 +398,7 @@ describe("LessonPresencesRestService", () => { teacher: null, dateFrom: null, dateTo: null, + weekdays: null, presenceTypes: null, confirmationStates: null, incidentTypes: null, @@ -429,11 +430,12 @@ describe("LessonPresencesRestService", () => { filter.teacher = "Bandi Victor"; filter.dateFrom = new Date(2000, 0, 23); filter.dateTo = new Date(2000, 0, 25); + filter.weekdays = ["1"]; filter.presenceTypes = [888]; filter.confirmationStates = [999]; const url = - "https://eventotest.api/LessonPresences/?filter.StudentRef==123&filter.EventRef==333&filter.StudyClassRef==678&filter.TeacherInformation=~*Bandi%20Victor*&filter.LessonDateTimeFrom=%3E2000-01-22&filter.LessonDateTimeTo=%3C2000-01-26&filter.ConfirmationStateId=;999&filter.TypeRef=;888&offset=0&limit=1000"; + "https://eventotest.api/LessonPresences/?filter.StudentRef==123&filter.EventRef==333&filter.StudyClassRef==678&filter.TeacherInformation=~*Bandi%20Victor*&filter.LessonDateTimeFrom=%3E2000-01-22&filter.LessonDateTimeTo=%3C2000-01-26&filter.WeekdayId=;1&filter.ConfirmationStateId=;999&filter.TypeRef=;888&offset=0&limit=1000"; service .getFilteredList(filter, 0) diff --git a/src/app/shared/services/lesson-presences-rest.service.ts b/src/app/shared/services/lesson-presences-rest.service.ts index ad3a87dfd..4fc31e690 100644 --- a/src/app/shared/services/lesson-presences-rest.service.ts +++ b/src/app/shared/services/lesson-presences-rest.service.ts @@ -252,6 +252,13 @@ export class LessonPresencesRestService extends RestService< } } + if (absencesFilter.weekdays) { + params = params.set( + "filter.WeekdayId", + `;${absencesFilter.weekdays.join(";")}`, + ); + } + if (absencesFilter.confirmationStates) { params = params.set( "filter.ConfirmationStateId", diff --git a/src/assets/locales/de-CH.json b/src/assets/locales/de-CH.json index 9a4361bec..16a989e44 100644 --- a/src/assets/locales/de-CH.json +++ b/src/assets/locales/de-CH.json @@ -171,6 +171,7 @@ "teacher": "Lehrperson", "date-from": "Datum von", "date-to": "Datum bis", + "weekdays": "Tag", "presence-type": "Grund", "confirmation-state": "Status", "incident": "Vorfall", diff --git a/src/assets/locales/fr-CH.json b/src/assets/locales/fr-CH.json index d66ea371a..8c2428e32 100644 --- a/src/assets/locales/fr-CH.json +++ b/src/assets/locales/fr-CH.json @@ -171,6 +171,7 @@ "teacher": "Enseignant-e", "date-from": "Date du", "date-to": "Date au", + "weekdays": "Jour", "presence-type": "Motif", "confirmation-state": "Statut", "incident": "Incident",