Skip to content

Commit

Permalink
Add weekday filter to edit absences #714
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Nov 27, 2024
1 parent 46a4de4 commit 8458847
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
}}</label>
<bkd-date-select [(value)]="filter.dateTo"></bkd-date-select>
</div>

<div class="col-md-6 col-lg-3">
<label class="form-label">{{
"edit-absences.header.weekdays" | translate
}}</label>
<bkd-multiselect
[options]="weekdaysGrouped$ | async"
[(values)]="filter.weekdays"
></bkd-multiselect>
</div>
</div>

<div class="row g-3 align-items-end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("EditAbsencesHeaderComponent", () => {
{
provide: EditAbsencesStateService,
useValue: {
weekdays$: of([]),
absenceConfirmationStates$: of([]),
presenceTypes$: of([]),
selected: [{ lessonIds: [1, 2, 3], personIds: [4, 5, 6] }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,23 @@ export class EditAbsencesHeaderComponent {
teacher: null,
dateFrom: null,
dateTo: null,
weekdays: null,
presenceTypes: null,
confirmationStates: null,
incidentTypes: null,
};

@Output() filterChange = new EventEmitter<EditAbsencesFilter>();

weekdaysGrouped$ = this.state.weekdays$.pipe(
map((weekdays) =>
addGroupToDropdownItem(
weekdays,
this.translate.instant("shared.multiselect.all-option"),
),
),
);

absenceConfirmationStatesGrouped$ =
this.state.absenceConfirmationStates$.pipe(
map((i) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions src/app/edit-absences/services/edit-absences-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export interface EditAbsencesFilter {
teacher: Option<string>;
dateFrom: Option<Date>;
dateTo: Option<Date>;
presenceTypes: Option<number[]>;
confirmationStates: Option<number[]>;
incidentTypes: Option<number[]>;
weekdays: Option<ReadonlyArray<string>>;
presenceTypes: Option<ReadonlyArray<number>>;
confirmationStates: Option<ReadonlyArray<number>>;
incidentTypes: Option<ReadonlyArray<number>>;
}

@Injectable()
Expand All @@ -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),
Expand Down Expand Up @@ -96,6 +98,7 @@ export class EditAbsencesStateService
teacher: null,
dateFrom: null,
dateTo: null,
weekdays: null,
presenceTypes: null,
confirmationStates: null,
incidentTypes: null,
Expand All @@ -110,6 +113,7 @@ export class EditAbsencesStateService
filterValue.teacher ||
filterValue.dateFrom ||
filterValue.dateTo ||
filterValue.weekdays ||
filterValue.presenceTypes ||
filterValue.confirmationStates ||
filterValue.incidentTypes,
Expand All @@ -135,6 +139,10 @@ export class EditAbsencesStateService
return buildParamsFromAbsenceFilter(filterValue);
}

private loadWeekdays(): Observable<ReadonlyArray<DropDownItem>> {
return this.loadingService.load(this.dropDownItemsService.getWeekdays());
}

private loadPresenceTypes(): Observable<ReadonlyArray<PresenceType>> {
return this.loadingService.load(
this.presenceTypesService.activePresenceTypes$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -13,8 +14,10 @@ import { DropDownGroupedItem } from "../../models/drop-down-grouped-item.model";
})
export class MultiselectComponent {
@Input() options: ReadonlyArray<DropDownGroupedItem> = [];
@Input() values: Option<number[]> = [];
@Output() valuesChange = new EventEmitter<Option<number[]>>();
@Input() values: Option<ReadonlyArray<DropDownItem["Key"]>> = [];
@Output() valuesChange = new EventEmitter<
Option<ReadonlyArray<DropDownItem["Key"]>>
>();

constructor() {}

Expand Down
6 changes: 6 additions & 0 deletions src/app/shared/services/drop-down-items-rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export class DropDownItemsRestService {
@Inject(SETTINGS) private settings: Settings,
) {}

getWeekdays(): Observable<ReadonlyArray<DropDownItem>> {
return this.http
.get<unknown>(`${this.baseUrl}/Weekdays`)
.pipe(switchMap(decodeArray(DropDownItem)), shareReplay(1));
}

getAbsenceConfirmationStates(): Observable<ReadonlyArray<DropDownItem>> {
return this.http
.get<unknown>(`${this.baseUrl}/AbsenceConfirmationStates`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ describe("LessonPresencesRestService", () => {
teacher: null,
dateFrom: null,
dateTo: null,
weekdays: null,
presenceTypes: null,
confirmationStates: null,
incidentTypes: null,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/app/shared/services/lesson-presences-rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/assets/locales/de-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"teacher": "Lehrperson",
"date-from": "Datum von",
"date-to": "Datum bis",
"weekdays": "Tag",
"presence-type": "Grund",
"confirmation-state": "Status",
"incident": "Vorfall",
Expand Down
1 change: 1 addition & 0 deletions src/assets/locales/fr-CH.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8458847

Please sign in to comment.