Commit c2a3bb4b authored by Grand Francois's avatar Grand Francois
Browse files

ajout du composant CheckFieldLineComponent

Showing with 105 additions and 8 deletions
+105 -8
...@@ -11,6 +11,7 @@ import { ParamInputComponent } from './components/param-input/param-input.compon ...@@ -11,6 +11,7 @@ import { ParamInputComponent } from './components/param-input/param-input.compon
import { FieldSetComponent } from './components/field-set/field-set.component'; import { FieldSetComponent } from './components/field-set/field-set.component';
import { ParamFieldLineComponent } from './components/param-field-line/param-field-line.component'; import { ParamFieldLineComponent } from './components/param-field-line/param-field-line.component';
import { SelectFieldLineComponent } from './components/select-field-line/select-field-line.component'; import { SelectFieldLineComponent } from './components/select-field-line/select-field-line.component';
import { CheckFieldLineComponent } from './components/check-field-line/check-field-line.component';
import { CondDistriComponent } from './calculators/cond_distri/conddistri.component'; import { CondDistriComponent } from './calculators/cond_distri/conddistri.component';
import { LechaptCalmonComponent } from './calculators/lechapt-calmon/lechaptcalmon.component'; import { LechaptCalmonComponent } from './calculators/lechapt-calmon/lechaptcalmon.component';
import { SectionParametreeComponent } from './calculators/section-param/section-param.component'; import { SectionParametreeComponent } from './calculators/section-param/section-param.component';
...@@ -38,7 +39,7 @@ import { SectionCanvasComponent } from './components/section-canvas/section-canv ...@@ -38,7 +39,7 @@ import { SectionCanvasComponent } from './components/section-canvas/section-canv
AppComponent, AppComponent,
ParamInputComponent, ParamInputComponent,
FieldSetComponent, FieldSetComponent,
ParamFieldLineComponent, SelectFieldLineComponent, ParamFieldLineComponent, SelectFieldLineComponent, CheckFieldLineComponent,
CondDistriComponent, LechaptCalmonComponent, SectionParametreeComponent, GenericCalculatorComponent, RegimeUniformeComponent, CondDistriComponent, LechaptCalmonComponent, SectionParametreeComponent, GenericCalculatorComponent, RegimeUniformeComponent,
AlertDialog, AlertDialog,
CalculatorResultsComponent, SectionResultsComponent, CalculatorResultsComponent, SectionResultsComponent,
......
...@@ -16,8 +16,8 @@ export class FormulaireDefinition { ...@@ -16,8 +16,8 @@ export class FormulaireDefinition {
private _config = {}; private _config = {};
/** /**
* symbole du paramètre à calculer par défaut (cf config "idCal") * symbole du paramètre à calculer par défaut (cf config "idCal")
*/ */
private _defaultCalculatedParam: string; private _defaultCalculatedParam: string;
private _fieldSets: FieldSet[] = []; private _fieldSets: FieldSet[] = [];
...@@ -227,6 +227,18 @@ export class FormulaireDefinition { ...@@ -227,6 +227,18 @@ export class FormulaireDefinition {
} }
} }
private parse_check(node_type: ComputeNodeType, field: {}): CheckField {
let id = field["id"];
let res: CheckField = new CheckField(node_type, id);
let value = field["value"];
res.setValue(value == "true");
this.parse_dependencies(res, field);
return res;
}
private parse_select(node_type: ComputeNodeType, field: {}): SelectField { private parse_select(node_type: ComputeNodeType, field: {}): SelectField {
let id = field["id"]; let id = field["id"];
let res: SelectField = new SelectField(node_type, id); let res: SelectField = new SelectField(node_type, id);
...@@ -279,6 +291,9 @@ export class FormulaireDefinition { ...@@ -279,6 +291,9 @@ export class FormulaireDefinition {
} else if (field["type"] === "select") { } else if (field["type"] === "select") {
let param = this.parse_select(node_type, field); let param = this.parse_select(node_type, field);
res.addField(param); res.addField(param);
} else if (field["type"] === "check") {
let param = this.parse_check(node_type, field);
res.addField(param);
} }
} }
...@@ -445,7 +460,7 @@ export abstract class FormulaireElement { ...@@ -445,7 +460,7 @@ export abstract class FormulaireElement {
} }
export enum FieldType { export enum FieldType {
Input, Select Input, Select, Check
} }
export abstract class Field extends FormulaireElement { export abstract class Field extends FormulaireElement {
...@@ -461,6 +476,10 @@ export abstract class Field extends FormulaireElement { ...@@ -461,6 +476,10 @@ export abstract class Field extends FormulaireElement {
return this._fieldType == FieldType.Select; return this._fieldType == FieldType.Select;
} }
public get isCheck(): boolean {
return this._fieldType == FieldType.Check;
}
public abstract getValue(): any; public abstract getValue(): any;
public abstract setValue(val: any): void; public abstract setValue(val: any): void;
} }
...@@ -582,6 +601,31 @@ export class SelectField extends Field { ...@@ -582,6 +601,31 @@ export class SelectField extends Field {
} }
} }
export class CheckField extends Field {
private _value: boolean;
constructor(nodeType: ComputeNodeType, id: string) {
super(nodeType, id, FieldType.Check);
this._value = false;
}
public getValue(): boolean {
return this._value;
}
public setValue(val: boolean) {
this._value = val;
}
protected verifyDependency(d: Dependency): boolean {
throw "CheckField.verifyDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge";
}
public updateLocalisation(loc: StringMap) {
this.label = loc[this.id];
}
}
export abstract class InputField extends Field { export abstract class InputField extends Field {
private _value: any; private _value: any;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
"id": "select_section_circ" "id": "select_section_circ"
}, },
{ {
"id": "select_section_para" "id": "select_section_puiss"
} }
] ]
} }
......
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CheckField } from '../../calculators/generic/formulaire';
import { FormulaireService } from '../../services/formulaire/formulaire.service';
@Component({
selector: 'check-field-line',
templateUrl: "./check-field-line.html",
})
export class CheckFieldLineComponent {
private _check: CheckField;
private _currentValue: boolean;
constructor(private formulaireService: FormulaireService) {
}
/**
* id input attribute
*/
private _id: string;
@Input()
private set id(s: string) {
this._id = s;
this._check = this.formulaireService.getCheckField(this._id);
}
private onChange(event: any) {
this._check.setValue(event);
}
}
<tr>
<td align="right">{{_check.label}}</td>
<td colspan="3">
<!--
<input type="checkbox" >
-->
<input type="checkbox" [(ngModel)]=_currentValue (ngModelChange)="onChange($event)">
</td>
</tr>
\ No newline at end of file
...@@ -15,5 +15,6 @@ ...@@ -15,5 +15,6 @@
<td colspan="5"> <td colspan="5">
<param-field-line *ngIf="p.isInput" [computeNodeType]=_fieldSet.computeNodeType [symbol]=p.symbol (onRadio)=onRadioClick($event)></param-field-line> <param-field-line *ngIf="p.isInput" [computeNodeType]=_fieldSet.computeNodeType [symbol]=p.symbol (onRadio)=onRadioClick($event)></param-field-line>
<select-field-line *ngIf="p.isSelect" [id]=p.id (onSelectChange)=onSelectChanged($event)></select-field-line> <select-field-line *ngIf="p.isSelect" [id]=p.id (onSelectChange)=onSelectChanged($event)></select-field-line>
<check-field-line *ngIf="p.isCheck" [id]=p.id></check-field-line>
</td> </td>
</tr> </tr>
...@@ -7,7 +7,7 @@ import { ParamsSectionRectang, cSnRectang, ParamsSectionCirc, cSnCirc, ParamsSec ...@@ -7,7 +7,7 @@ import { ParamsSectionRectang, cSnRectang, ParamsSectionCirc, cSnCirc, ParamsSec
import { ParamService } from '../param/param.service'; import { ParamService } from '../param/param.service';
import { HttpService } from '../../services/http/http.service'; import { HttpService } from '../../services/http/http.service';
import { FormulaireDefinition, FormulaireElement, CalculatorType, SelectField } from '../../calculators/generic/formulaire'; import { FormulaireDefinition, FormulaireElement, CalculatorType, SelectField, CheckField } from '../../calculators/generic/formulaire';
import { StringMap } from '../../stringmap'; import { StringMap } from '../../stringmap';
@Injectable() @Injectable()
...@@ -44,10 +44,9 @@ export class FormulaireService { ...@@ -44,10 +44,9 @@ export class FormulaireService {
if (ct == undefined) if (ct == undefined)
throw "FormulaireService.getFormulaire() : invalid undefined CalculatorType" throw "FormulaireService.getFormulaire() : invalid undefined CalculatorType"
for (let f of this._formulaires) { for (let f of this._formulaires)
if (f.type == ct) if (f.type == ct)
return f; return f;
}
throw "FormulaireService.getFormulaire() : type '" + ct + "' form is not loaded"; throw "FormulaireService.getFormulaire() : type '" + ct + "' form is not loaded";
} }
...@@ -72,6 +71,17 @@ export class FormulaireService { ...@@ -72,6 +71,17 @@ export class FormulaireService {
return undefined; return undefined;
} }
public getCheckField(id: string): CheckField {
for (let f of this._formulaires) {
let s = f.getFormulaireElementById(id);
if (s != undefined)
if (!(s instanceof CheckField))
throw "Form element with id '" + id + "' is not a checkbox";
return <CheckField>s;
}
return undefined;
}
public updateLocalisation(localisation: StringMap) { public updateLocalisation(localisation: StringMap) {
for (let loc_id in localisation) { for (let loc_id in localisation) {
let fe = this.getFormulaireElementById(loc_id); let fe = this.getFormulaireElementById(loc_id);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment