From 99a5290cea05292159197e9abfd3cd764df0dfba Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 7 Feb 2023 15:19:37 +0100 Subject: [PATCH] fix: inactive activities are hidden from roll call setup (#1709) closes #1707 Co-authored-by: Sebastian Leidig --- .../roll-call-setup.component.spec.ts | 14 ++++++++++ .../roll-call-setup.component.ts | 4 ++- src/app/core/config/config-fix.ts | 13 ++++++++- src/app/core/entity/model/entity.ts | 27 +++++++------------ .../data-import/data-import.component.spec.ts | 4 +-- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.spec.ts b/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.spec.ts index 588b0f74a3..26c65a7784 100644 --- a/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.spec.ts +++ b/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.spec.ts @@ -67,4 +67,18 @@ describe("RollCallSetupComponent", () => { expect(component.existingEvents[0].authors).toEqual([TEST_USER]); expect(component.existingEvents[1].authors).toEqual([TEST_USER]); })); + + it("should only show active activities", fakeAsync(() => { + const active = new RecurringActivity(); + const inactive = new RecurringActivity(); + inactive["active"] = false; + mockAttendanceService.createEventForActivity.and.resolveTo(new EventNote()); + const entityMapper = TestBed.inject(EntityMapperService); + spyOn(entityMapper, "loadType").and.resolveTo([active, inactive]); + + component.ngOnInit(); + flush(); + + expect(component.existingEvents).toHaveSize(1); + })); }); diff --git a/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.ts b/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.ts index a3d0f898be..d78262bd50 100644 --- a/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.ts +++ b/src/app/child-dev-project/attendance/add-day-attendance/roll-call-setup/roll-call-setup.component.ts @@ -98,7 +98,9 @@ export class RollCallSetupComponent implements OnInit { } private async loadActivities() { - this.allActivities = await this.entityMapper.loadType(RecurringActivity); + this.allActivities = await this.entityMapper + .loadType(RecurringActivity) + .then((res) => res.filter((a) => a.isActive)); if (this.showingAll) { this.visibleActivities = this.allActivities; diff --git a/src/app/core/config/config-fix.ts b/src/app/core/config/config-fix.ts index 7d9dca7b1b..169f2bda6c 100644 --- a/src/app/core/config/config-fix.ts +++ b/src/app/core/config/config-fix.ts @@ -784,6 +784,17 @@ export const defaultJsonConfig = { "type", "assignedTo" ], + "filters": [ + { + "id": "isActive", + "type": "boolean", + "default": "true", + "label": $localize`Status`, + "true": $localize`:Active records filter label - true case:Active`, + "false": $localize`:Active records filter label - false case:Inactive`, + "all": $localize`:Active records unselect option:All` + }, + ], "exportConfig": [ {label: "Title", query: "title"}, {label: "Type", query: "type"}, @@ -804,7 +815,7 @@ export const defaultJsonConfig = { "config": { "cols": [ ["title"], - ["type"], + ["type", "inactive"], ["assignedTo"] ] } diff --git a/src/app/core/entity/model/entity.ts b/src/app/core/entity/model/entity.ts index 23696c72ff..54c7aa1aa2 100644 --- a/src/app/core/entity/model/entity.ts +++ b/src/app/core/entity/model/entity.ts @@ -170,6 +170,12 @@ export class Entity { /** internal database doc revision, used to detect conflicts by PouchDB/CouchDB */ @DatabaseField() _rev: string; + @DatabaseField({ + label: $localize`:Label of checkbox:Inactive`, + description: $localize`:Description of checkbox:Ticking this box will archive the record. No data will be lost but the record will be hidden.`, + }) + inactive: boolean; + /** whether this entity object is newly created and not yet saved to database */ get isNew(): boolean { return !this._rev; @@ -215,29 +221,16 @@ export class Entity { /** * Check, if this entity is considered active. - * This is either taken from the (not configured) property "active". + * This is either taken from the property "inactive" (configured) or "active" (not configured). * If the property doesn't exist, the default is `true`. * Subclasses may overwrite this functionality. - * - * To have a simple boolean indicating if an entity is active or not, add the following schema: - * ```json - * { - * "name": "active", - * "schema": { - * "dataType": "boolean", - * "label": "Active", - * "defaultValue": true - * } - * } - * ``` - * alternatively you can store the inverted, as name "inactive" */ get isActive(): boolean { if (this["active"] !== undefined) { return this["active"]; } - if (this["inactive"] !== undefined) { - return !this["inactive"]; + if (this.inactive !== undefined) { + return !this.inactive; } return true; } @@ -248,7 +241,7 @@ export class Entity { */ set isActive(isActive: boolean) { this["active"] = isActive; - this["inactive"] = !isActive; + this.inactive = !isActive; } /** diff --git a/src/app/features/data-import/data-import/data-import.component.spec.ts b/src/app/features/data-import/data-import/data-import.component.spec.ts index b9e825705e..fce1084906 100644 --- a/src/app/features/data-import/data-import/data-import.component.spec.ts +++ b/src/app/features/data-import/data-import/data-import.component.spec.ts @@ -74,11 +74,11 @@ describe("DataImportComponent", () => { component.entityForm.patchValue({ entity: "Child" }); component.entitySelectionChanged(); - component.processChange("na"); + component.processChange("nam"); expect(component.filteredProperties.value).toEqual(["name"]); component.columnMappingForm.addControl("Name", new FormControl("name")); - component.processChange("na"); + component.processChange("nam"); expect(component.filteredProperties.value).toEqual([]); }));