From bf602f6c1d1a1741fcf0fd30a884d76c331394ff Mon Sep 17 00:00:00 2001 From: Sebastian Leidig Date: Thu, 27 Jul 2023 11:46:32 +0200 Subject: [PATCH 1/2] feat(core): EditDescriptionOnly field to display additional text in forms closes #1802 --- src/app/core/config/config-fix.ts | 5 ++- src/app/core/core-components.ts | 19 ++++++++---- .../edit-description-only.component.spec.ts | 26 ++++++++++++++++ .../edit-description-only.component.ts | 31 +++++++++++++++++++ 4 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts create mode 100644 src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts diff --git a/src/app/core/config/config-fix.ts b/src/app/core/config/config-fix.ts index 5887f767e8..e837fc8b7e 100644 --- a/src/app/core/config/config-fix.ts +++ b/src/app/core/config/config-fix.ts @@ -664,7 +664,10 @@ export const defaultJsonConfig = { "config": { "cols": [ ["health_bloodGroup"], - ["health_lastDentalCheckup"] + [ + { "id": "_description_health", "edit": "EditDescriptionOnly", "label": $localize`:description section:Health checkups are to be done regularly, at least every 6 months according to the program guidelines.`}, + "health_lastDentalCheckup" + ] ] } }, diff --git a/src/app/core/core-components.ts b/src/app/core/core-components.ts index decf964c2d..caa4865db2 100644 --- a/src/app/core/core-components.ts +++ b/src/app/core/core-components.ts @@ -26,7 +26,7 @@ export const coreComponents: ComponentTuple[] = [ "Form", () => import("./entity-components/entity-details/form/form.component").then( - (c) => c.FormComponent + (c) => c.FormComponent, ), ], [ @@ -113,6 +113,13 @@ export const coreComponents: ComponentTuple[] = [ "./entity-components/entity-utils/dynamic-form-components/edit-number/edit-number.component" ).then((c) => c.EditNumberComponent), ], + [ + "EditDescriptionOnly", + () => + import( + "./entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component" + ).then((c) => c.EditDescriptionOnlyComponent), + ], [ "DisplayCheckmark", () => @@ -173,21 +180,21 @@ export const coreComponents: ComponentTuple[] = [ "UserSecurity", () => import("./user/user-security/user-security.component").then( - (c) => c.UserSecurityComponent + (c) => c.UserSecurityComponent, ), ], [ "Dashboard", () => import("./dashboard/dashboard/dashboard.component").then( - (c) => c.DashboardComponent + (c) => c.DashboardComponent, ), ], [ "EntityList", () => import("./entity-components/entity-list/entity-list.component").then( - (c) => c.EntityListComponent + (c) => c.EntityListComponent, ), ], [ @@ -205,14 +212,14 @@ export const coreComponents: ComponentTuple[] = [ "ConfigImport", () => import("./config-setup/config-import/config-import.component").then( - (c) => c.ConfigImportComponent + (c) => c.ConfigImportComponent, ), ], [ "MarkdownPage", () => import("./markdown-page/markdown-page/markdown-page.component").then( - (c) => c.MarkdownPageComponent + (c) => c.MarkdownPageComponent, ), ], [ diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts new file mode 100644 index 0000000000..c017e11fbe --- /dev/null +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts @@ -0,0 +1,26 @@ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { EditDescriptionOnlyComponent } from "./edit-description-only.component"; +import { setupEditComponent } from "../edit-component.spec"; + +describe("EditDescriptionOnlyComponent", () => { + let component: EditDescriptionOnlyComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [EditDescriptionOnlyComponent], + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(EditDescriptionOnlyComponent); + component = fixture.componentInstance; + setupEditComponent(component); + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts new file mode 100644 index 0000000000..449c305072 --- /dev/null +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts @@ -0,0 +1,31 @@ +import { Component, OnInit } from "@angular/core"; +import { EditComponent } from "../edit-component"; +import { DynamicComponent } from "../../../../view/dynamic-components/dynamic-component.decorator"; +import { MatFormFieldModule } from "@angular/material/form-field"; +import { ReactiveFormsModule } from "@angular/forms"; +import { MatInputModule } from "@angular/material/input"; +import { ErrorHintComponent } from "../../error-hint/error-hint.component"; +import { NgIf } from "@angular/common"; + +@DynamicComponent("EditDescriptionOnly") +@Component({ + selector: "app-edit-description-only", + template: "{{label}}", + imports: [ + MatFormFieldModule, + ReactiveFormsModule, + MatInputModule, + ErrorHintComponent, + NgIf, + ], + standalone: true, +}) +export class EditDescriptionOnlyComponent + extends EditComponent + implements OnInit +{ + ngOnInit() { + // override base class on init because this does not have a valid formControl! + this.label = this.formFieldConfig?.label; + } +} From 3018f3db23a11fe91e1824f4ed53bc0a29c5d19b Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 31 Jul 2023 13:18:45 +0200 Subject: [PATCH 2/2] removed unnecessary code --- .../edit-description-only.component.spec.ts | 3 -- .../edit-description-only.component.ts | 28 ++++--------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts index c017e11fbe..1661e6a37f 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.spec.ts @@ -1,7 +1,5 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; - import { EditDescriptionOnlyComponent } from "./edit-description-only.component"; -import { setupEditComponent } from "../edit-component.spec"; describe("EditDescriptionOnlyComponent", () => { let component: EditDescriptionOnlyComponent; @@ -16,7 +14,6 @@ describe("EditDescriptionOnlyComponent", () => { beforeEach(() => { fixture = TestBed.createComponent(EditDescriptionOnlyComponent); component = fixture.componentInstance; - setupEditComponent(component); fixture.detectChanges(); }); diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts index 449c305072..b400107471 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-description-only/edit-description-only.component.ts @@ -1,31 +1,13 @@ -import { Component, OnInit } from "@angular/core"; -import { EditComponent } from "../edit-component"; +import { Component, Input } from "@angular/core"; import { DynamicComponent } from "../../../../view/dynamic-components/dynamic-component.decorator"; -import { MatFormFieldModule } from "@angular/material/form-field"; -import { ReactiveFormsModule } from "@angular/forms"; -import { MatInputModule } from "@angular/material/input"; -import { ErrorHintComponent } from "../../error-hint/error-hint.component"; -import { NgIf } from "@angular/common"; +import { FormFieldConfig } from "../../../entity-form/entity-form/FormConfig"; @DynamicComponent("EditDescriptionOnly") @Component({ selector: "app-edit-description-only", - template: "{{label}}", - imports: [ - MatFormFieldModule, - ReactiveFormsModule, - MatInputModule, - ErrorHintComponent, - NgIf, - ], + template: "{{formFieldConfig?.label}}", standalone: true, }) -export class EditDescriptionOnlyComponent - extends EditComponent - implements OnInit -{ - ngOnInit() { - // override base class on init because this does not have a valid formControl! - this.label = this.formFieldConfig?.label; - } +export class EditDescriptionOnlyComponent { + @Input() formFieldConfig: FormFieldConfig; }