diff --git a/src/app/child-dev-project/attendance/attendance.service.ts b/src/app/child-dev-project/attendance/attendance.service.ts index 8a01e8fb82..b436866bc5 100644 --- a/src/app/child-dev-project/attendance/attendance.service.ts +++ b/src/app/child-dev-project/attendance/attendance.service.ts @@ -281,7 +281,9 @@ export class AttendanceService { const childIdPromises = linkedGroups.map((groupId) => this.childrenService .queryRelationsOf("school", groupId) - .then((relations) => relations.map((r) => r.childId)) + .then((relations) => + relations.map((r) => r.childId).filter((id) => !!id) + ) ); const allParticipants = await Promise.all(childIdPromises); // flatten and remove duplicates diff --git a/src/app/core/entity-components/entity-subrecord/entity-subrecord/entity-subrecord.component.ts b/src/app/core/entity-components/entity-subrecord/entity-subrecord/entity-subrecord.component.ts index b15022c4bc..60de0319e3 100644 --- a/src/app/core/entity-components/entity-subrecord/entity-subrecord/entity-subrecord.component.ts +++ b/src/app/core/entity-components/entity-subrecord/entity-subrecord/entity-subrecord.component.ts @@ -132,7 +132,7 @@ export class EntitySubrecordComponent if (changes.hasOwnProperty("columns")) { this.initFormGroups(); } - if (changes.hasOwnProperty("records") && this.records.length > 0) { + if (changes.hasOwnProperty("records")) { this.initFormGroups(); this.initDefaultSort(); if (this.columnsToDisplay.length < 2) { diff --git a/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts b/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts index aad7eb4089..3665c828c2 100644 --- a/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts +++ b/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts @@ -13,6 +13,7 @@ import { MatTableDataSource } from "@angular/material/table"; import { PageEvent } from "@angular/material/paginator"; import { MockSessionModule } from "../../../session/mock-session.module"; import { EntityMapperService } from "../../../entity/entity-mapper.service"; +import { User } from "../../../user/user"; describe("ListPaginatorComponent", () => { let component: ListPaginatorComponent; @@ -69,4 +70,27 @@ describe("ListPaginatorComponent", () => { expect(component.pageSize).toBe(20); expect(component.showingAll).toBeFalse(); }); + + it("should update pagination when the idForSavingPagination changed", fakeAsync(() => { + const userPaginationSettings = { + c1: 11, + c2: 12, + }; + component.user = ({ + paginatorSettingsPageSize: userPaginationSettings, + paginatorSettingsPageIndex: {}, + } as Partial) as User; + + component.idForSavingPagination = "c1"; + component.ngOnChanges({ idForSavingPagination: undefined }); + tick(); + expect(component.pageSize).toBe(userPaginationSettings.c1); + expect(component.paginator.pageSize).toBe(userPaginationSettings.c1); + + component.idForSavingPagination = "c2"; + component.ngOnChanges({ idForSavingPagination: undefined }); + tick(); + expect(component.pageSize).toBe(userPaginationSettings.c2); + expect(component.paginator.pageSize).toBe(userPaginationSettings.c2); + })); }); diff --git a/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.ts b/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.ts index 997c74dc64..b48f405151 100644 --- a/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.ts +++ b/src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.ts @@ -104,6 +104,7 @@ export class ListPaginatorComponent } else { this.pageSize = pageSize; } + this.paginator._changePageSize(this.pageSize); } this.currentPageIndex = this.user.paginatorSettingsPageIndex[this.idForSavingPagination] || diff --git a/src/app/core/user/user.ts b/src/app/core/user/user.ts index c3531d59a0..efa96c3346 100644 --- a/src/app/core/user/user.ts +++ b/src/app/core/user/user.ts @@ -32,13 +32,16 @@ export class User extends Entity { /** username used for login and identification */ @DatabaseField() name: string; - /** settings for the mat-paginator for tables + /** + * settings for the mat-paginator for tables. + * map of ids (uniquely identifying a table) to pageSize or pageIndex. + * * pageSizeOptions is set in the corresponding html of the component, * pageSize is stored persistently in the database and * pageIndex is saved only temporarily for the session */ - @DatabaseField() paginatorSettingsPageSize: any = {}; - public paginatorSettingsPageIndex: any = {}; + @DatabaseField() paginatorSettingsPageSize: { [id: string]: number } = {}; + public paginatorSettingsPageIndex: { [id: string]: number } = {}; /** password for webdav account (encrypted) */ @DatabaseField() private cloudPasswordEnc: any;