diff --git a/src/app/core/entity-components/entity-form/entity-form/entity-form.stories.ts b/src/app/core/entity-components/entity-form/entity-form/entity-form.stories.ts index 6a1ccc8ae0..33606a960c 100644 --- a/src/app/core/entity-components/entity-form/entity-form/entity-form.stories.ts +++ b/src/app/core/entity-components/entity-form/entity-form/entity-form.stories.ts @@ -84,6 +84,7 @@ const cols = [ label: "Assigned school(s)", }, ], + ["school"], ]; Child.schema.set("has_rationCard", { @@ -91,6 +92,13 @@ Child.schema.set("has_rationCard", { innerDataType: "document-status", }); Child.schema.set("assignedTo", { dataType: "array", innerDataType: "string" }); +Child.schema.set("school", { + dataType: "string", + label: "Assigned School", + additional: School.ENTITY_TYPE, + viewComponent: "DisplayEntity", + editComponent: "EditSingleEntity", +}); const Template: Story = (args: EntityFormComponent) => ({ component: EntityFormComponent, diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.html b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.html index 25a2970a49..f4a6733beb 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.html +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.html @@ -3,7 +3,6 @@ -
+
-
diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.scss b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.scss index f989381131..93ceccce02 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.scss +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.scss @@ -3,3 +3,8 @@ .block-wrapper { @include entity-block-border; } + +.wrapper-readonly { + margin-top: 7px; + margin-bottom: 16px; +} diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.spec.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.spec.ts index aa40619766..5dcb305846 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.spec.ts +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.spec.ts @@ -16,6 +16,9 @@ import { School } from "../../../../../child-dev-project/schools/model/school"; import { EntityUtilsModule } from "../../entity-utils.module"; import { Child } from "../../../../../child-dev-project/children/model/child"; import { TypedFormControl } from "../edit-component"; +import { ChangeDetectorRef } from "@angular/core"; +import { FontAwesomeTestingModule } from "@fortawesome/angular-fontawesome/testing"; +import { RouterTestingModule } from "@angular/router/testing"; import { EntityRegistry, entityRegistry, @@ -31,7 +34,12 @@ describe("EditSingleEntityComponent", () => { mockEntityMapper.loadType.and.resolveTo([]); await TestBed.configureTestingModule({ - imports: [EntityUtilsModule, NoopAnimationsModule], + imports: [ + EntityUtilsModule, + NoopAnimationsModule, + FontAwesomeTestingModule, + RouterTestingModule, + ], declarations: [EditSingleEntityComponent], providers: [ EntityFormService, @@ -41,6 +49,10 @@ describe("EditSingleEntityComponent", () => { provide: EntityRegistry, useValue: entityRegistry, }, + { + provide: ChangeDetectorRef, + useValue: jasmine.createSpyObj(["detectChanges"]), + }, ], }).compileComponents(); }); diff --git a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.ts b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.ts index 1f8017486f..40d7ff149e 100644 --- a/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.ts +++ b/src/app/core/entity-components/entity-utils/dynamic-form-components/edit-single-entity/edit-single-entity.component.ts @@ -1,4 +1,9 @@ -import { Component, ElementRef, ViewChild } from "@angular/core"; +import { + ChangeDetectorRef, + Component, + ElementRef, + ViewChild, +} from "@angular/core"; import { EditComponent, EditPropertyConfig } from "../edit-component"; import { Entity } from "../../../../entity/model/entity"; import { Observable } from "rxjs"; @@ -25,7 +30,10 @@ export class EditSingleEntityComponent extends EditComponent { @ViewChild("inputElement") input: ElementRef; - constructor(private entityMapperService: EntityMapperService) { + constructor( + private changeDetection: ChangeDetectorRef, + private entityMapperService: EntityMapperService + ) { super(); this.filteredEntities = this.entityNameFormControl.valueChanges.pipe( untilDestroyed(this), @@ -47,6 +55,7 @@ export class EditSingleEntityComponent extends EditComponent { async onInitFromDynamicConfig(config: EditPropertyConfig) { super.onInitFromDynamicConfig(config); + this.connectFormControlDisabledStatus(); this.placeholder = $localize`:Placeholder for input to set an entity|context Select User:Select ${this.label}`; const entityType: string = config.formFieldConfig.additional || config.propertySchema.additional; @@ -66,6 +75,20 @@ export class EditSingleEntityComponent extends EditComponent { } else { this.entityNameFormControl.setValue(""); } + this.changeDetection.detectChanges(); + } + + private connectFormControlDisabledStatus() { + if (this.formControl.disabled) { + this.entityNameFormControl.disable(); + } + this.formControl.registerOnDisabledChange((isDisabled) => { + if (isDisabled) { + this.entityNameFormControl.disable(); + } else { + this.entityNameFormControl.enable(); + } + }); } select(entityName: string) {