diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html index 32b9d79f5f47cb32a09cd3f37a8da8f166e4c9f3..361f044f68001f0ecd2ad26d2a211fef5615628b 100644 --- a/src/app/components/field-set/field-set.component.html +++ b/src/app/components/field-set/field-set.component.html @@ -15,11 +15,11 @@ --> <ng-template ngFor let-p [ngForOf]="fields"> - <param-field-line *ngIf="p.isInput" [param]=p (onRadio)=onRadioClick($event) (onValid)=onParamLineValid()> + <param-field-line *ngIf="isInputField(p)" [param]=p (onRadio)=onRadioClick($event) (onValid)=onParamLineValid()> </param-field-line> - <select-field-line *ngIf="p.isSelect" [param]=p (selectChange)=onSelectChanged($event)> + <select-field-line *ngIf="isSelectField(p)" [param]=p (selectChange)=onSelectChanged($event)> </select-field-line> - <check-field-line *ngIf="p.isCheck" [param]=p></check-field-line> + <check-field-line *ngIf="isCheckField(p)" [param]=p></check-field-line> </ng-template> \ No newline at end of file diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index 7f40c3d060a45dfaa4ccbb3abc69f139b06efaff..eb2a8fefdfa10e0a5e38794374be6a7eb5e2c392 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -7,6 +7,10 @@ import { FieldSet } from "../../formulaire/fieldset"; import { ParamFieldLineComponent } from "../param-field-line/param-field-line.component"; import { BaseComponent } from "../base/base.component"; import { SelectEntry } from "../../formulaire/select-entry"; +import { Field } from "../../formulaire/field"; +import { InputField } from "../../formulaire/input-field"; +import { SelectField } from "../../formulaire/select-field"; +import { CheckField } from "../../formulaire/check-field"; @Component({ selector: "field-set", @@ -96,11 +100,32 @@ export class FieldSetComponent extends BaseComponent { return this._fieldSet.label; } + /** + * détermine si un Field est du type InputField + */ + private isInputField(f: Field): boolean { + return f instanceof InputField; + } + + /** + * détermine si un Field est du type SelectField + */ + private isSelectField(f: Field): boolean { + return f instanceof SelectField; + } + + /** + * détermine si un Field est du type CheckField + */ + private isCheckField(f: Field): boolean { + return f instanceof CheckField; + } + /* - * gestion des événements clic sur les radios : - * réception d'un message du composant enfant (param-field) - * cf. https://angular.io/guide/component-interaction#parent-listens-for-child-event - */ + * gestion des événements clic sur les radios : + * réception d'un message du composant enfant (param-field) + * cf. https://angular.io/guide/component-interaction#parent-listens-for-child-event + */ private onRadioClick(info: string) { // on renvoie l'info au parent this.onRadio.emit(info); diff --git a/src/app/formulaire/check-field.ts b/src/app/formulaire/check-field.ts index 84555e23c6a81ffce9a719229678b0e0753d7884..593a5ad1f6bd794d7d51661afebe9d119e20df01 100644 --- a/src/app/formulaire/check-field.ts +++ b/src/app/formulaire/check-field.ts @@ -1,6 +1,6 @@ import { ComputeNodeType } from "jalhyd"; -import { Field, FieldType } from "./field"; +import { Field } from "./field"; import { Dependency } from "./dependency"; import { DependencyConditionType } from "./dependency-condition"; @@ -8,7 +8,7 @@ export class CheckField extends Field { private _value: boolean; constructor(nodeType: ComputeNodeType, id: string, formId: number) { - super(nodeType, id, FieldType.Check, formId); + super(nodeType, id, formId); this._value = false; } diff --git a/src/app/formulaire/field.ts b/src/app/formulaire/field.ts index 57caa7f5c2757b8efa11ed36693ee6ac187c462e..e55fc1fa1ad270a9ecd3caa1ba85382441bbc5a3 100644 --- a/src/app/formulaire/field.ts +++ b/src/app/formulaire/field.ts @@ -2,27 +2,11 @@ import { ComputeNodeType } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; -export enum FieldType { - Input, Select, Check -} - export abstract class Field extends FormulaireElement { - constructor(nodeType: ComputeNodeType, id: string, private _fieldType: FieldType, formId: number) { + constructor(nodeType: ComputeNodeType, id: string, formId: number) { super(nodeType, id, formId); } - public get isInput(): boolean { - return this._fieldType == FieldType.Input; - } - - public get isSelect(): boolean { - return this._fieldType == FieldType.Select; - } - - public get isCheck(): boolean { - return this._fieldType == FieldType.Check; - } - public abstract get isValid(); public abstract getValue(): any; diff --git a/src/app/formulaire/input-field.ts b/src/app/formulaire/input-field.ts index 414e2e6ea92619fee6b656598bab450019ae1e7e..3f89b88e7e40e9ee257040fbcd2b0a9fc6ee8bb8 100644 --- a/src/app/formulaire/input-field.ts +++ b/src/app/formulaire/input-field.ts @@ -1,13 +1,13 @@ import { ComputeNodeType } from "jalhyd"; -import { Field, FieldType } from "./field" +import { Field } from "./field" export abstract class InputField extends Field { private _value: any; constructor(type: ComputeNodeType, id: string, formId: number) { - super(type, id, FieldType.Input, formId); + super(type, id, formId); } public getValue() { diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts index a81404b11fff15d2f7963cd7e14ccbc7d34a1c2f..bfdff8fbbdda845f3f543866d43eeddce57f064e 100644 --- a/src/app/formulaire/select-field.ts +++ b/src/app/formulaire/select-field.ts @@ -2,7 +2,6 @@ import { ComputeNodeType } from "jalhyd"; import { Field } from "./field"; import { SelectEntry } from "./select-entry"; -import { FieldType } from "./field"; import { Dependency } from "./dependency"; import { DependencyConditionType } from "./dependency-condition"; import { ValueDependencyCondition } from "./value-dependency-condition"; @@ -18,7 +17,7 @@ export class SelectField extends Field implements IObservable { private _observable: Observable; constructor(nodeType: ComputeNodeType, id: string, formId: number) { - super(nodeType, id, FieldType.Select, formId); + super(nodeType, id, formId); this._entries = []; this._observable = new Observable(); }