From a0f8c40920864a0df79319874acde882f4125491 Mon Sep 17 00:00:00 2001 From: Sebastian Leidig Date: Tue, 1 Mar 2022 20:23:37 +0100 Subject: [PATCH 1/7] fix: safeguard against errors in case of incomplete group membership entries prevent "null" participants in events if invalid ChildSchoolRelation entities exist in the database fixes #1051 --- src/app/child-dev-project/attendance/attendance.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/child-dev-project/attendance/attendance.service.ts b/src/app/child-dev-project/attendance/attendance.service.ts index 8a01e8fb82..e32a988206 100644 --- a/src/app/child-dev-project/attendance/attendance.service.ts +++ b/src/app/child-dev-project/attendance/attendance.service.ts @@ -281,7 +281,7 @@ 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((r) => !!r)) ); const allParticipants = await Promise.all(childIdPromises); // flatten and remove duplicates From 59edd5fef99955c400e4051aedc3c3af96f1ffd5 Mon Sep 17 00:00:00 2001 From: Sebastian Leidig Date: Tue, 1 Mar 2022 21:08:55 +0100 Subject: [PATCH 2/7] fix: correctly load lists for full pagination size fixes #1107 --- .../list-paginator.component.spec.ts | 24 +++++++++++++++++++ .../list-paginator.component.ts | 1 + src/app/core/user/user.ts | 9 ++++--- 3 files changed, 31 insertions(+), 3 deletions(-) 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..21aebbfb79 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: {} as any }); + tick(); + expect(component.pageSize).toBe(userPaginationSettings.c1); + expect(component.paginator.pageSize).toBe(userPaginationSettings.c1); + + component.idForSavingPagination = "c2"; + component.ngOnChanges({ idForSavingPagination: {} as any }); + 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; From d3ffce33c09910580692094638cc97c994383098 Mon Sep 17 00:00:00 2001 From: Simon <33730997+TheSlimvReal@users.noreply.github.com> Date: Wed, 2 Mar 2022 10:57:45 +0100 Subject: [PATCH 3/7] Update src/app/child-dev-project/attendance/attendance.service.ts --- src/app/child-dev-project/attendance/attendance.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/child-dev-project/attendance/attendance.service.ts b/src/app/child-dev-project/attendance/attendance.service.ts index e32a988206..d7519af03c 100644 --- a/src/app/child-dev-project/attendance/attendance.service.ts +++ b/src/app/child-dev-project/attendance/attendance.service.ts @@ -281,7 +281,7 @@ export class AttendanceService { const childIdPromises = linkedGroups.map((groupId) => this.childrenService .queryRelationsOf("school", groupId) - .then((relations) => relations.map((r) => r.childId).filter((r) => !!r)) + .then((relations) => relations.map((r) => r.childId).filter((id) => !!id)) ); const allParticipants = await Promise.all(childIdPromises); // flatten and remove duplicates From aaf02ca8f8d046a5155039fcaf6cdaa1f80804fc Mon Sep 17 00:00:00 2001 From: Simon <33730997+TheSlimvReal@users.noreply.github.com> Date: Wed, 2 Mar 2022 10:57:51 +0100 Subject: [PATCH 4/7] Update src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts --- .../list-paginator/list-paginator.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 21aebbfb79..9e47d8a7a0 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 @@ -82,7 +82,7 @@ describe("ListPaginatorComponent", () => { } as Partial) as User; component.idForSavingPagination = "c1"; - component.ngOnChanges({ idForSavingPagination: {} as any }); + component.ngOnChanges({ idForSavingPagination: undefined }); tick(); expect(component.pageSize).toBe(userPaginationSettings.c1); expect(component.paginator.pageSize).toBe(userPaginationSettings.c1); From 7dbe0120b51fcf677a0043350dab95d178f02cc6 Mon Sep 17 00:00:00 2001 From: Simon <33730997+TheSlimvReal@users.noreply.github.com> Date: Wed, 2 Mar 2022 10:57:56 +0100 Subject: [PATCH 5/7] Update src/app/core/entity-components/entity-subrecord/list-paginator/list-paginator.component.spec.ts --- .../list-paginator/list-paginator.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9e47d8a7a0..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 @@ -88,7 +88,7 @@ describe("ListPaginatorComponent", () => { expect(component.paginator.pageSize).toBe(userPaginationSettings.c1); component.idForSavingPagination = "c2"; - component.ngOnChanges({ idForSavingPagination: {} as any }); + component.ngOnChanges({ idForSavingPagination: undefined }); tick(); expect(component.pageSize).toBe(userPaginationSettings.c2); expect(component.paginator.pageSize).toBe(userPaginationSettings.c2); From 318b2c8fbe1d1642968d70437f9ba23a447cc419 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 2 Mar 2022 11:15:28 +0100 Subject: [PATCH 6/7] fix: table is updated if filters return no data --- .../entity-subrecord/entity-subrecord.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { From 80a2e1ddedbe403b6abdff1e4dab1bec45a46fad Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 2 Mar 2022 11:16:33 +0100 Subject: [PATCH 7/7] refactor: fix lint error --- src/app/child-dev-project/attendance/attendance.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/child-dev-project/attendance/attendance.service.ts b/src/app/child-dev-project/attendance/attendance.service.ts index d7519af03c..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).filter((id) => !!id)) + .then((relations) => + relations.map((r) => r.childId).filter((id) => !!id) + ) ); const allParticipants = await Promise.all(childIdPromises); // flatten and remove duplicates