Skip to content
Snippets Groups Projects
Commit a987989d authored by francois.grand's avatar francois.grand
Browse files

#27 : simplification de la classe Field (suppression de l'enum FieldType)

parent 2dc8e8a1
No related branches found
No related tags found
1 merge request!12Resolve "Ajout de la calculette "Ouvrages hydrauliques""
......@@ -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
......@@ -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);
......
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;
}
......
......@@ -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;
......
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() {
......
......@@ -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();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment