Skip to content

Commit

Permalink
fix: inactive activities are hidden from roll call setup (#1709)
Browse files Browse the repository at this point in the history
closes #1707

Co-authored-by: Sebastian Leidig <sebastian.leidig@gmail.com>
TheSlimvReal and sleidig authored Feb 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1119bb3 commit 99a5290
Showing 5 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}));
});
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 12 additions & 1 deletion src/app/core/config/config-fix.ts
Original file line number Diff line number Diff line change
@@ -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"]
]
}
27 changes: 10 additions & 17 deletions src/app/core/entity/model/entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}

/**
Original file line number Diff line number Diff line change
@@ -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([]);
}));

0 comments on commit 99a5290

Please sign in to comment.