Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #1127

Merged
merged 9 commits into from
Mar 2, 2022
4 changes: 3 additions & 1 deletion src/app/child-dev-project/attendance/attendance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class EntitySubrecordComponent<T extends Entity>
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
Expand Down Expand Up @@ -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<User>) 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);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class ListPaginatorComponent<E>
} else {
this.pageSize = pageSize;
}
this.paginator._changePageSize(this.pageSize);
}
this.currentPageIndex =
this.user.paginatorSettingsPageIndex[this.idForSavingPagination] ||
Expand Down
9 changes: 6 additions & 3 deletions src/app/core/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down