From a987989de45f5239528af93775d13182791ad7f7 Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Fri, 16 Feb 2018 08:59:03 +0100
Subject: [PATCH]  #27 : simplification de la classe Field (suppression de
 l'enum FieldType)

---
 .../field-set/field-set.component.html        |  6 ++--
 .../field-set/field-set.component.ts          | 33 ++++++++++++++++---
 src/app/formulaire/check-field.ts             |  4 +--
 src/app/formulaire/field.ts                   | 18 +---------
 src/app/formulaire/input-field.ts             |  4 +--
 src/app/formulaire/select-field.ts            |  3 +-
 6 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html
index 32b9d79f5..361f044f6 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 7f40c3d06..eb2a8fefd 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 84555e23c..593a5ad1f 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 57caa7f5c..e55fc1fa1 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 414e2e6ea..3f89b88e7 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 a81404b11..bfdff8fbb 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();
     }
-- 
GitLab