Skip to content

Commit

Permalink
refactor: remove custom implementation for activities-overview
Browse files Browse the repository at this point in the history
to reduce code duplication and parallel subscriptions on entity changes
  • Loading branch information
sleidig committed Nov 13, 2023
1 parent 976e149 commit ab9c5d0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 147 deletions.

This file was deleted.

Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { Component, Input, OnInit } from "@angular/core";
import { Component, OnInit } from "@angular/core";
import { RecurringActivity } from "../model/recurring-activity";
import { FormFieldConfig } from "../../../core/common-components/entity-form/entity-form/FormConfig";
import { EntityMapperService } from "../../../core/entity/entity-mapper/entity-mapper.service";
import { Entity } from "../../../core/entity/model/entity";
import { DynamicComponent } from "../../../core/config/dynamic-components/dynamic-component.decorator";
import { delay } from "rxjs";
import { RelatedEntitiesComponent } from "../../../core/entity-details/related-entities/related-entities.component";
import { EntitySubrecordComponent } from "../../../core/common-components/entity-subrecord/entity-subrecord/entity-subrecord.component";
import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
import { ColumnConfig } from "../../../core/common-components/entity-subrecord/entity-subrecord/entity-subrecord-config";

@UntilDestroy()
/**
* @deprecated configure a RelatedEntitiesComponent instead
*/
@DynamicComponent("ActivitiesOverview")
@Component({
selector: "app-activities-overview",
templateUrl: "./activities-overview.component.html",
styleUrls: ["./activities-overview.component.scss"],
templateUrl:
"../../../core/entity-details/related-entities/related-entities.component.html",
imports: [EntitySubrecordComponent],
standalone: true,
})
export class ActivitiesOverviewComponent implements OnInit {
export class ActivitiesOverviewComponent
extends RelatedEntitiesComponent<RecurringActivity>
implements OnInit
{
entityType = RecurringActivity.ENTITY_TYPE;
property = "linkedGroups";

titleColumn = {
id: "title",
edit: "EditTextWithAutocomplete",
Expand All @@ -27,49 +32,16 @@ export class ActivitiesOverviewComponent implements OnInit {
relevantValue: "",
},
};
@Input() columns: FormFieldConfig[] = [
_columns: ColumnConfig[] = [
this.titleColumn,
{ id: "type" },
{ id: "assignedTo" },
{ id: "linkedGroups" },
{ id: "excludedParticipants" },
"type",
"assignedTo",
"linkedGroups",
"excludedParticipants",
];

@Input() entity: Entity;
records: RecurringActivity[] = [];

constructor(private entityMapper: EntityMapperService) {}

async ngOnInit() {
this.titleColumn.additional.relevantValue = this.entity.getId();
await this.initLinkedActivities();

this.entityMapper
.receiveUpdates(RecurringActivity)
// using short delay to make sure the EntitySubrecord's `receiveUpdates` code is executed before this
.pipe(delay(0), untilDestroyed(this))
.subscribe((updateEntity) => {
if (updateEntity.type === "update") {
this.initLinkedActivities();
}
});
}

private async initLinkedActivities() {
this.records = await this.entityMapper
.loadType(RecurringActivity)
.then((activities) =>
activities.filter((activity) =>
activity.linkedGroups.includes(this.entity.getId()),
),
);
}

generateNewRecordFactory(): () => RecurringActivity {
return () => {
const newRecurringActivity = new RecurringActivity();
newRecurringActivity.linkedGroups.push(this.entity.getId());
return newRecurringActivity;
};
await super.ngOnInit();
}
}

0 comments on commit ab9c5d0

Please sign in to comment.