From 37c2e3f7ee315e76361ea2307416ebac6a55cc2a Mon Sep 17 00:00:00 2001 From: Simon <33730997+TheSlimvReal@users.noreply.github.com> Date: Fri, 6 May 2022 19:06:31 +0200 Subject: [PATCH] fix: Initial values are correctly display in select component (#1248) fixes: #1244 Co-authored-by: Sebastian --- .../attendance-status-select.component.html | 10 +++++++--- .../attendance-status-select.component.ts | 16 +++------------- .../attendance/attendance.module.ts | 2 ++ .../note-details/note-details.component.html | 8 +++++++- .../notes/note-details/note-details.component.ts | 2 ++ .../edit-configurable-enum.component.html | 2 +- .../edit-configurable-enum.component.ts | 2 ++ src/app/utils/utils.ts | 8 ++++++++ 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.html b/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.html index 0dfd01d561..ddd34320f3 100644 --- a/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.html +++ b/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.html @@ -1,9 +1,13 @@
  - - - + +   {{ s.label }} diff --git a/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.ts b/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.ts index 09954827de..6ce715bc65 100644 --- a/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.ts +++ b/src/app/child-dev-project/attendance/attendance-status-select/attendance-status-select.component.ts @@ -1,14 +1,10 @@ import { Component, EventEmitter, Input, Output } from "@angular/core"; -import { ConfigService } from "../../../core/config/config.service"; -import { - CONFIGURABLE_ENUM_CONFIG_PREFIX, - ConfigurableEnumConfig, -} from "../../../core/configurable-enum/configurable-enum.interface"; import { ATTENDANCE_STATUS_CONFIG_ID, AttendanceStatusType, NullAttendanceStatusType, } from "../model/attendance-status"; +import { compareEnums } from "../../../utils/utils"; @Component({ selector: "app-attendance-status-select", @@ -19,12 +15,6 @@ export class AttendanceStatusSelectComponent { @Input() value: AttendanceStatusType = NullAttendanceStatusType; @Input() disabled: boolean = false; @Output() valueChange = new EventEmitter(); - - statusValues: AttendanceStatusType[]; - - constructor(private configService: ConfigService) { - this.statusValues = this.configService.getConfig< - ConfigurableEnumConfig - >(CONFIGURABLE_ENUM_CONFIG_PREFIX + ATTENDANCE_STATUS_CONFIG_ID); - } + statusID = ATTENDANCE_STATUS_CONFIG_ID; + compareFn = compareEnums; } diff --git a/src/app/child-dev-project/attendance/attendance.module.ts b/src/app/child-dev-project/attendance/attendance.module.ts index aeeeee415f..9951c150d6 100644 --- a/src/app/child-dev-project/attendance/attendance.module.ts +++ b/src/app/child-dev-project/attendance/attendance.module.ts @@ -61,6 +61,7 @@ import { FontAwesomeModule } from "@fortawesome/angular-fontawesome"; import { MatPaginatorModule } from "@angular/material/paginator"; import { ViewModule } from "../../core/view/view.module"; import { AttendanceSummaryComponent } from "./attendance-summary/attendance-summary.component"; +import { ConfigurableEnumModule } from "../../core/configurable-enum/configurable-enum.module"; @NgModule({ declarations: [ @@ -111,6 +112,7 @@ import { AttendanceSummaryComponent } from "./attendance-summary/attendance-summ DashboardModule, MatPaginatorModule, ViewModule, + ConfigurableEnumModule, ], exports: [ ActivityCardComponent, diff --git a/src/app/child-dev-project/notes/note-details/note-details.component.html b/src/app/child-dev-project/notes/note-details/note-details.component.html index d910fbbdee..570a509ce1 100644 --- a/src/app/child-dev-project/notes/note-details/note-details.component.html +++ b/src/app/child-dev-project/notes/note-details/note-details.component.html @@ -74,7 +74,12 @@

{{ entity.date | date }}: {{ entity.subject }}

Status - + {{ entity.date | date }}: {{ entity.subject }} name="type" [(ngModel)]="entity.category" [disabled]="formDialogWrapper.readonly" + [compareWith]="compareFn" > { readonly User: EntityConstructor = User; readonly INTERACTION_TYPE_CONFIG = INTERACTION_TYPE_CONFIG_ID; + readonly compareFn = compareEnums; includeInactiveChildren: boolean = false; /** export format for notes to be used for downloading the individual details */ diff --git a/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.html b/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.html index 4936ae2af0..19bd9d8565 100644 --- a/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.html +++ b/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.html @@ -2,7 +2,7 @@ {{ label }} - + {{ o.label }} diff --git a/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.ts b/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.ts index 1cd7c6f768..ab661a2d89 100644 --- a/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.ts +++ b/src/app/core/configurable-enum/edit-configurable-enum/edit-configurable-enum.component.ts @@ -6,6 +6,7 @@ import { import { ConfigurableEnumValue } from "../configurable-enum.interface"; import { DynamicComponent } from "../../view/dynamic-components/dynamic-component.decorator"; import { arrayEntitySchemaDatatype } from "../../entity/schema-datatypes/datatype-array"; +import { compareEnums } from "../../../utils/utils"; @DynamicComponent("EditConfigurableEnum") @Component({ @@ -16,6 +17,7 @@ import { arrayEntitySchemaDatatype } from "../../entity/schema-datatypes/datatyp export class EditConfigurableEnumComponent extends EditComponent { enumId: string; multi = false; + compareFun = compareEnums; onInitFromDynamicConfig(config: EditPropertyConfig) { super.onInitFromDynamicConfig(config); diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index 0eadadfc49..999ce3fcca 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -3,6 +3,7 @@ * @param date The date to be checked */ import { Router } from "@angular/router"; +import { ConfigurableEnumValue } from "../core/configurable-enum/configurable-enum.interface"; export function isValidDate(date: any): boolean { return ( @@ -89,3 +90,10 @@ export function readFile(file: Blob): Promise { fileReader.readAsText(file); }); } + +export function compareEnums( + a: ConfigurableEnumValue, + b: ConfigurableEnumValue +): boolean { + return a?.id === b?.id; +}