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

Hide inactive activities from roll call #1709

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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;
Expand Down
27 changes: 10 additions & 17 deletions src/app/core/entity/model/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -248,7 +241,7 @@ export class Entity {
*/
set isActive(isActive: boolean) {
this["active"] = isActive;
this["inactive"] = !isActive;
this.inactive = !isActive;
}

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

Expand Down