-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(attendance): manage activities directly from team/school details…
… view (#1314) see #713 Co-authored-by: Simon <therealslimv@yahoo.de> Co-authored-by: Sebastian <sebastian.leidig@gmail.com>
- Loading branch information
1 parent
feaea34
commit 0e2b5e9
Showing
7 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/app/child-dev-project/schools/activities-overview/activities-overview.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<app-entity-subrecord | ||
[records]="records" | ||
[columns]="columns" | ||
[getBackgroundColor]="null" | ||
[newRecordFactory]="generateNewRecordFactory()" | ||
[editable]="true" | ||
></app-entity-subrecord> |
Empty file.
74 changes: 74 additions & 0 deletions
74
src/app/child-dev-project/schools/activities-overview/activities-overview.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { RecurringActivity } from "app/child-dev-project/attendance/model/recurring-activity"; | ||
import { EntityMapperService } from "app/core/entity/entity-mapper.service"; | ||
import { | ||
mockEntityMapper, | ||
MockEntityMapperService, | ||
} from "app/core/entity/mock-entity-mapper-service"; | ||
import { UpdatedEntity } from "app/core/entity/model/entity-update"; | ||
import { Subject } from "rxjs"; | ||
import { School } from "../model/school"; | ||
|
||
import { ActivitiesOverviewComponent } from "./activities-overview.component"; | ||
|
||
describe("ActivitiesOverviewComponent", () => { | ||
let component: ActivitiesOverviewComponent; | ||
let fixture: ComponentFixture<ActivitiesOverviewComponent>; | ||
|
||
let entityMapper: MockEntityMapperService; | ||
|
||
beforeEach(async () => { | ||
entityMapper = mockEntityMapper(); | ||
await TestBed.configureTestingModule({ | ||
declarations: [ActivitiesOverviewComponent], | ||
providers: [{ provide: EntityMapperService, useValue: entityMapper }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ActivitiesOverviewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it("should fetch all and only recurring activities having the selected school as a linkedGroup", async () => { | ||
const school1 = new School("school1"); | ||
const activity1 = new RecurringActivity(); | ||
activity1.linkedGroups = ["school1"]; | ||
const activity2 = new RecurringActivity(); | ||
activity2.linkedGroups = ["school1", "school2"]; | ||
const activity3 = new RecurringActivity(); | ||
activity3.linkedGroups = ["school3"]; | ||
entityMapper.addAll([activity1, activity2, activity3]); | ||
|
||
await component.onInitFromDynamicConfig({ entity: school1 }); | ||
expect(component.records).toEqual([activity1, activity2]); | ||
}); | ||
|
||
it("should create a new recurring activity having the current school as a linkedGroup", () => { | ||
component.entity = new School("school1"); | ||
const newRecurringActivity = component.generateNewRecordFactory(); | ||
expect(newRecurringActivity().linkedGroups).toEqual(["school1"]); | ||
}); | ||
|
||
it("should remove the recurring activity from the table view if the current school is removed as a group of this recurring activity", async () => { | ||
const school1 = new School("school1"); | ||
const activity1 = new RecurringActivity(); | ||
activity1.linkedGroups = ["school1"]; | ||
const activity2 = new RecurringActivity(); | ||
activity1.linkedGroups = ["school1", "school2", "school3"]; | ||
entityMapper.addAll([activity1, activity2]); | ||
const subject = new Subject<UpdatedEntity<RecurringActivity>>(); | ||
spyOn(entityMapper, "receiveUpdates").and.returnValue(subject); | ||
await component.onInitFromDynamicConfig({ entity: school1 }); | ||
|
||
activity2.linkedGroups = ["school2", "school3"]; | ||
subject.next({ entity: activity2, type: "update" }); | ||
|
||
expect(component.records).toEqual([activity1]); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
src/app/child-dev-project/schools/activities-overview/activities-overview.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Component } from "@angular/core"; | ||
import { RecurringActivity } from "app/child-dev-project/attendance/model/recurring-activity"; | ||
import { FormFieldConfig } from "app/core/entity-components/entity-form/entity-form/FormConfig"; | ||
import { EntityListConfig } from "app/core/entity-components/entity-list/EntityListConfig"; | ||
import { EntityMapperService } from "app/core/entity/entity-mapper.service"; | ||
import { Entity } from "app/core/entity/model/entity"; | ||
import { DynamicComponent } from "app/core/view/dynamic-components/dynamic-component.decorator"; | ||
import { OnInitDynamicComponent } from "app/core/view/dynamic-components/on-init-dynamic-component.interface"; | ||
|
||
@DynamicComponent("ActivitiesOverview") | ||
@Component({ | ||
selector: "app-activities-overview", | ||
templateUrl: "./activities-overview.component.html", | ||
styleUrls: ["./activities-overview.component.scss"], | ||
}) | ||
export class ActivitiesOverviewComponent implements OnInitDynamicComponent { | ||
columns: FormFieldConfig[] = [ | ||
{ id: "title" }, | ||
{ id: "type" }, | ||
{ id: "assignedTo" }, | ||
{ id: "linkedGroups" }, | ||
]; | ||
|
||
entity: Entity; | ||
records: RecurringActivity[] = []; | ||
listConfig: EntityListConfig; | ||
activityConstructor = RecurringActivity; | ||
|
||
constructor(private entityMapper: EntityMapperService) {} | ||
|
||
async onInitFromDynamicConfig(config: any) { | ||
if (config?.config?.columns) { | ||
this.columns = config.config.columns; | ||
} | ||
|
||
this.entity = config.entity; | ||
this.records = ( | ||
await this.entityMapper.loadType<RecurringActivity>(RecurringActivity) | ||
).filter((activity) => activity.linkedGroups.includes(this.entity.getId())); | ||
this.entityMapper | ||
.receiveUpdates(RecurringActivity) | ||
.subscribe((updateEntity) => { | ||
if (updateEntity.type === "update") { | ||
this.records = this.records.filter((activity) => | ||
activity.linkedGroups.includes(this.entity.getId()) | ||
); | ||
} | ||
}); | ||
} | ||
|
||
generateNewRecordFactory(): () => RecurringActivity { | ||
return () => { | ||
const newRecurringActivity = new RecurringActivity(); | ||
newRecurringActivity.linkedGroups.push(this.entity.getId()); | ||
return newRecurringActivity; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters