Skip to content
Snippets Groups Projects
Commit ede1823b authored by mathias.chouet's avatar mathias.chouet
Browse files

Résolution bug: les paramètres liés sont récupérés correctement

+ nettoyage code (tslint)
parent da4051b4
No related branches found
No related tags found
No related merge requests found
Showing
with 124 additions and 123 deletions
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
--> -->
<ng-template ngFor let-p [ngForOf]="fields"> <ng-template ngFor let-p [ngForOf]="fields">
<param-field-line *ngIf="isInputField(p)" [param]=p (onRadio)=onRadioClick($event) (onValid)=onParamLineValid() (inputChange)=onInputChange()> <param-field-line *ngIf="isInputField(p)" [param]=p (onRadio)=onRadioClick($event) (valid)=onParamLineValid() (inputChange)=onInputChange()>
</param-field-line> </param-field-line>
<select-field-line *ngIf="isSelectField(p)" [_select]=p> <select-field-line *ngIf="isSelectField(p)" [_select]=p>
......
...@@ -49,10 +49,10 @@ export class FieldSetComponent implements DoCheck { ...@@ -49,10 +49,10 @@ export class FieldSetComponent implements DoCheck {
} }
public get title(): string { public get title(): string {
if (this._fieldSet == undefined) { if (! this._fieldSet) {
return "fs undefined"; return "fs undefined";
} }
if (this._fieldSet.label == undefined) { if (! this._fieldSet.label) { // @TODO allow "" ?
return "label undefined"; return "label undefined";
} }
return this._fieldSet.label; return this._fieldSet.label;
...@@ -234,7 +234,7 @@ export class FieldSetComponent implements DoCheck { ...@@ -234,7 +234,7 @@ export class FieldSetComponent implements DoCheck {
private updateValidity() { private updateValidity() {
this._isValid = false; this._isValid = false;
if (this._paramComponents != undefined) { if (this._paramComponents) {
this._isValid = this._paramComponents.reduce( this._isValid = this._paramComponents.reduce(
// callback // callback
( (
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<h4 class="col">{{ title }}</h4> <h4 class="col">{{ title }}</h4>
</div> </div>
<field-set *ngFor="let fs of fieldsets" [fieldSet]=fs (onRadio)=onRadioClick($event) (onValid)=onFieldsetValid() (inputChange)=onInputChange() <field-set *ngFor="let fs of fieldsets" [fieldSet]=fs (onRadio)=onRadioClick($event) (valid)=onFieldsetValid() (inputChange)=onInputChange()
(addFieldset)=onAddFieldset($event) (removeFieldset)=onRemoveFieldset($event) (moveFieldsetUp)=onMoveFieldsetUp($event) (addFieldset)=onAddFieldset($event) (removeFieldset)=onRemoveFieldset($event) (moveFieldsetUp)=onMoveFieldsetUp($event)
(moveFieldsetDown)=onMoveFieldsetDown($event)> (moveFieldsetDown)=onMoveFieldsetDown($event)>
</field-set> </field-set>
......
// cf. https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html // cf. https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
import { Component, Input, forwardRef, OnInit, DoCheck, ChangeDetectorRef } from "@angular/core"; import { Component, ChangeDetectorRef, OnDestroy } from "@angular/core";
import { ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl } from "@angular/forms";
import { NumericalString, Message, Observer } from "jalhyd"; import { NumericalString, Message, Observer } from "jalhyd";
...@@ -13,7 +12,7 @@ import { GenericInputComponent } from "../generic-input/generic-input.component" ...@@ -13,7 +12,7 @@ import { GenericInputComponent } from "../generic-input/generic-input.component"
selector: "ngparam-input", selector: "ngparam-input",
templateUrl: "../generic-input/generic-input.component.html" templateUrl: "../generic-input/generic-input.component.html"
}) })
export class NgParamInputComponent extends GenericInputComponent implements Observer { export class NgParamInputComponent extends GenericInputComponent implements Observer, OnDestroy {
/** /**
* paramètre géré * paramètre géré
*/ */
...@@ -35,7 +34,7 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse ...@@ -35,7 +34,7 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
* appelé avant le changement de modèle * appelé avant le changement de modèle
*/ */
protected beforeSetModel() { protected beforeSetModel() {
if (this._paramDef != undefined) { if (this._paramDef) {
this._paramDef.removeObserver(this); this._paramDef.removeObserver(this);
} }
} }
...@@ -44,7 +43,7 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse ...@@ -44,7 +43,7 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
* appelé après le changement de modèle * appelé après le changement de modèle
*/ */
protected afterSetModel() { protected afterSetModel() {
if (this._paramDef != undefined) { if (this._paramDef) {
if (this._paramDef.isDefined) { if (this._paramDef.isDefined) {
this._tmp = this._paramDef.getValue(); this._tmp = this._paramDef.getValue();
} }
...@@ -66,10 +65,10 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse ...@@ -66,10 +65,10 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
} }
protected validateModelValue(v: any): { isValid: boolean, message: string } { protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg; let msg: string;
let valid = false; let valid = false;
if (this._paramDef == undefined) { if (! this._paramDef) {
msg = "internal error, model undefined"; msg = "internal error, model undefined";
} else { } else {
try { try {
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</div> </div>
<!-- composant pour gérer le cas "paramètre à varier" (min-max/liste de valeurs) --> <!-- composant pour gérer le cas "paramètre à varier" (min-max/liste de valeurs) -->
<param-values *ngIf="isRadioVarChecked" [param]="_param" (onValid)=onParamValuesValid($event)></param-values> <param-values *ngIf="isRadioVarChecked" [param]="param" (valid)=onParamValuesValid($event)></param-values>
<!-- composant pour gérer le cas "paramètre lié" --> <!-- composant pour gérer le cas "paramètre lié" -->
<param-link *ngIf="isRadioLinkChecked" [param]="_param" (onValid)=onParamValuesValid($event)></param-link> <param-link *ngIf="isRadioLinkChecked" [param]="param" (valid)=onParamValuesValid($event)></param-link>
\ No newline at end of file \ No newline at end of file
...@@ -33,17 +33,17 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -33,17 +33,17 @@ export class ParamFieldLineComponent implements OnChanges {
constructor() { constructor() {
this.intlService = ServiceFactory.instance.internationalisationService; this.intlService = ServiceFactory.instance.internationalisationService;
this._formService = ServiceFactory.instance.formulaireService; this._formService = ServiceFactory.instance.formulaireService;
this.onValid = new EventEmitter(); this.valid = new EventEmitter();
this.inputChange = new EventEmitter(); this.inputChange = new EventEmitter();
} }
public get title(): string { public get title(): string {
let t = ""; let t = "";
if (this._param.label != undefined) { if (this.param.label !== undefined) {
t = this._param.label; t = this.param.label;
} }
if (this._param.unit != undefined && this._param.unit != "") { if (this.param.unit !== undefined && this.param.unit !== "") {
t = t + " (" + this._param.unit + ")"; t = t + " (" + this.param.unit + ")";
} }
return t; return t;
} }
...@@ -68,7 +68,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -68,7 +68,7 @@ export class ParamFieldLineComponent implements OnChanges {
* Parameter symbol (Q, Ks, B, ...) input attribute * Parameter symbol (Q, Ks, B, ...) input attribute
*/ */
private get symbol(): string { private get symbol(): string {
return this._param.symbol; return this.param.symbol;
} }
/** /**
...@@ -89,7 +89,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -89,7 +89,7 @@ export class ParamFieldLineComponent implements OnChanges {
* calcule l'état du radio "paramètre à calculer" * calcule l'état du radio "paramètre à calculer"
*/ */
private get radioCalCheck(): string { private get radioCalCheck(): string {
if (this._param.radioState == ParamRadioConfig.CAL) { if (this.param.radioState === ParamRadioConfig.CAL) {
return "checked"; return "checked";
} }
return undefined; return undefined;
...@@ -99,7 +99,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -99,7 +99,7 @@ export class ParamFieldLineComponent implements OnChanges {
* calcule l'état du radio "paramètre lié" * calcule l'état du radio "paramètre lié"
*/ */
private get radioLinkCheck(): string { private get radioLinkCheck(): string {
if (this._param.radioState == ParamRadioConfig.LINK) { if (this.param.radioState === ParamRadioConfig.LINK) {
return "checked"; return "checked";
} }
return undefined; return undefined;
...@@ -109,39 +109,40 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -109,39 +109,40 @@ export class ParamFieldLineComponent implements OnChanges {
* retourne l'état du radio "paramètre fixé" sous forme booléenne * retourne l'état du radio "paramètre fixé" sous forme booléenne
*/ */
public get isRadioFixChecked(): boolean { public get isRadioFixChecked(): boolean {
return this._param.radioState == ParamRadioConfig.FIX; return this.param.radioState === ParamRadioConfig.FIX;
} }
/** /**
* retourne l'état du radio "paramètre à varier" sous forme booléenne * retourne l'état du radio "paramètre à varier" sous forme booléenne
*/ */
public get isRadioVarChecked(): boolean { public get isRadioVarChecked(): boolean {
return this._param.radioState == ParamRadioConfig.VAR; return this.param.radioState === ParamRadioConfig.VAR;
} }
/** /**
* retourne l'état du radio "paramètre lié" sous forme booléenne * retourne l'état du radio "paramètre lié" sous forme booléenne
*/ */
public get isRadioLinkChecked(): boolean { public get isRadioLinkChecked(): boolean {
return this._param.radioState == ParamRadioConfig.LINK; return this.param.radioState === ParamRadioConfig.LINK;
} }
/** /**
* désactivation de tous les boutons radio si paramètre par défaut à "CAL" * désactivation de tous les boutons radio si paramètre par défaut à "CAL"
*/ */
private get isDisabled(): boolean { private get isDisabled(): boolean {
return this._param.isDefault && this._param.radioState == ParamRadioConfig.CAL; return this.param.isDefault && this.param.radioState === ParamRadioConfig.CAL;
} }
/** /**
* désactivation du champ de saisie * désactivation du champ de saisie
*/ */
public get isInputDisabled(): boolean { public get isInputDisabled(): boolean {
return this._param.radioState != ParamRadioConfig.FIX; return this.param.radioState !== ParamRadioConfig.FIX;
} }
private get radioFixClass(): string { private get radioFixClass(): string {
if (this.on) { if (this.on) {
return this.radioFixCheck == undefined ? this.offClass : this.onClass; return this.radioFixCheck ? this.onClass : this.offClass;
} }
return ""; return "";
} }
...@@ -151,7 +152,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -151,7 +152,7 @@ export class ParamFieldLineComponent implements OnChanges {
*/ */
private get radioVarClass(): string { private get radioVarClass(): string {
if (this.on) { if (this.on) {
return this.radioVarCheck == undefined ? this.offClass : this.onClass; return this.radioVarCheck ? this.onClass : this.offClass;
} }
return ""; return "";
} }
...@@ -161,7 +162,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -161,7 +162,7 @@ export class ParamFieldLineComponent implements OnChanges {
*/ */
private get radioCalClass(): string { private get radioCalClass(): string {
if (this.on) { if (this.on) {
return this.radioCalCheck == undefined ? this.offClass : this.onClass; return this.radioCalCheck ? this.onClass : this.offClass;
} }
return ""; return "";
} }
...@@ -171,7 +172,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -171,7 +172,7 @@ export class ParamFieldLineComponent implements OnChanges {
*/ */
private get radioLinkClass(): string { private get radioLinkClass(): string {
if (this.on) { if (this.on) {
return this.radioLinkCheck == undefined ? this.offClass : this.onClass; return this.radioLinkCheck ? this.onClass : this.offClass;
} }
return ""; return "";
} }
...@@ -180,7 +181,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -180,7 +181,7 @@ export class ParamFieldLineComponent implements OnChanges {
* validité des saisies du composant * validité des saisies du composant
*/ */
public get isValid(): boolean { public get isValid(): boolean {
switch (this._param.radioState) { switch (this.param.radioState) {
case ParamRadioConfig.FIX: case ParamRadioConfig.FIX:
return this._isInputValid; return this._isInputValid;
...@@ -195,8 +196,9 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -195,8 +196,9 @@ export class ParamFieldLineComponent implements OnChanges {
public get formHasResults(): boolean { public get formHasResults(): boolean {
return ServiceFactory.instance.formulaireService.currentFormHasResults; return ServiceFactory.instance.formulaireService.currentFormHasResults;
} }
@Input("param")
private _param: NgParameter; @Input()
private param: NgParameter;
@ViewChild(NgParamInputComponent) @ViewChild(NgParamInputComponent)
private _ngParamInputComponent: NgParamInputComponent; private _ngParamInputComponent: NgParamInputComponent;
...@@ -205,7 +207,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -205,7 +207,7 @@ export class ParamFieldLineComponent implements OnChanges {
private _paramLinkComponent: ParamLinkComponent; private _paramLinkComponent: ParamLinkComponent;
@Output() @Output()
private onValid: EventEmitter<void>; private valid: EventEmitter<void>;
@Output() @Output()
private inputChange: EventEmitter<void>; private inputChange: EventEmitter<void>;
...@@ -244,7 +246,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -244,7 +246,7 @@ export class ParamFieldLineComponent implements OnChanges {
* calcule la présence du radio "paramètre fixé" * calcule la présence du radio "paramètre fixé"
*/ */
public hasRadioFix(): boolean { public hasRadioFix(): boolean {
switch (this._param.radioConfig) { switch (this.param.radioConfig) {
case ParamRadioConfig.FIX: case ParamRadioConfig.FIX:
return this.hasRadioLink(); return this.hasRadioLink();
...@@ -257,7 +259,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -257,7 +259,7 @@ export class ParamFieldLineComponent implements OnChanges {
* calcule la présence du radio "paramètre à varier" * calcule la présence du radio "paramètre à varier"
*/ */
public hasRadioVar(): boolean { public hasRadioVar(): boolean {
switch (this._param.radioConfig) { switch (this.param.radioConfig) {
case ParamRadioConfig.VAR: case ParamRadioConfig.VAR:
case ParamRadioConfig.CAL: case ParamRadioConfig.CAL:
return true; return true;
...@@ -271,7 +273,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -271,7 +273,7 @@ export class ParamFieldLineComponent implements OnChanges {
* calcule la présence du radio "paramètre à calculer" * calcule la présence du radio "paramètre à calculer"
*/ */
public hasRadioCal(): boolean { public hasRadioCal(): boolean {
switch (this._param.radioConfig) { switch (this.param.radioConfig) {
case ParamRadioConfig.CAL: case ParamRadioConfig.CAL:
return true; return true;
...@@ -287,14 +289,14 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -287,14 +289,14 @@ export class ParamFieldLineComponent implements OnChanges {
if (this._formService.formulaires.length > 0) { if (this._formService.formulaires.length > 0) {
// au moins 2 calculettes ouvertes // au moins 2 calculettes ouvertes
if (this._formService.formulaires.length > 1) { if (this._formService.formulaires.length > 1) {
return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; return this._formService.filterLinkableValues(this._formService.getLinkableValues(this.param)).length > 0;
} }
// ou une seule calculette "ouvrages parallèles" // ou une seule calculette "ouvrages parallèles"
if (this._formService.formulaires[0].calculatorType == CalculatorType.ParallelStructure) { if (this._formService.formulaires[0].calculatorType === CalculatorType.ParallelStructure) {
const ps: ParallelStructure = this._formService.formulaires[0].currentSessionNub.nub as ParallelStructure; const ps: ParallelStructure = this._formService.formulaires[0].currentSessionNub.nub as ParallelStructure;
if (ps.structures.length > 1) { if (ps.structures.length > 1) {
return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; return this._formService.filterLinkableValues(this._formService.getLinkableValues(this.param)).length > 0;
} }
} }
...@@ -303,30 +305,30 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -303,30 +305,30 @@ export class ParamFieldLineComponent implements OnChanges {
} }
private onRadioClick(option: string) { private onRadioClick(option: string) {
const oldValue = this._param.valueMode; const oldValue = this.param.valueMode;
switch (option) { switch (option) {
case "fix": case "fix":
const oldValueMode = this._param.valueMode; const oldValueMode = this.param.valueMode;
this._param.valueMode = ParamValueMode.SINGLE; this.param.valueMode = ParamValueMode.SINGLE;
this._param.setValue(this, this._param.paramDefinition.paramValues.singleValue); this.param.setValue(this, this.param.paramDefinition.paramValues.singleValue);
break; break;
case "var": case "var":
this._param.valueMode = ParamValueMode.MINMAX; // min/max par défaut this.param.valueMode = ParamValueMode.MINMAX; // min/max par défaut
break; break;
case "cal": case "cal":
this._param.valueMode = ParamValueMode.CALCUL; this.param.valueMode = ParamValueMode.CALCUL;
break; break;
case "link": case "link":
this._param.valueMode = ParamValueMode.LINK; this.param.valueMode = ParamValueMode.LINK;
break; break;
} }
this.onRadio.emit({ this.onRadio.emit({
"param": this._param, "param": this.param,
"oldValueMode": oldValue "oldValueMode": oldValue
}); });
...@@ -338,7 +340,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -338,7 +340,7 @@ export class ParamFieldLineComponent implements OnChanges {
* émission d'un événement de validité * émission d'un événement de validité
*/ */
private emitValidity() { private emitValidity() {
this.onValid.emit(); this.valid.emit();
} }
/** /**
...@@ -366,7 +368,7 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -366,7 +368,7 @@ export class ParamFieldLineComponent implements OnChanges {
} }
public ngOnChanges() { public ngOnChanges() {
this._ngParamInputComponent.model = this._param; this._ngParamInputComponent.model = this.param;
this._ngParamInputComponent.showError = this.isRadioFixChecked; this._ngParamInputComponent.showError = this.isRadioFixChecked;
} }
......
...@@ -2,9 +2,8 @@ import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy } from "@a ...@@ -2,9 +2,8 @@ import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy } from "@a
import { NgParameter } from "../../formulaire/ngparam"; import { NgParameter } from "../../formulaire/ngparam";
import { ServiceFactory } from "../../services/service-factory"; import { ServiceFactory } from "../../services/service-factory";
import { ParamValueMode, Observer, ParamDefinition } from "jalhyd"; import { ParamValueMode, Observer } from "jalhyd";
import { FormulaireService } from "../../services/formulaire/formulaire.service"; import { FormulaireService } from "../../services/formulaire/formulaire.service";
import { FormulaireDefinition } from "../../formulaire/definition/form-definition";
@Component({ @Component({
selector: "param-link", selector: "param-link",
...@@ -12,14 +11,14 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio ...@@ -12,14 +11,14 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio
}) })
export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
// paramètre géré (qui sera lié à une valeur, cad qui importe cette valeur) // paramètre géré (qui sera lié à une valeur, cad qui importe cette valeur)
@Input("param") @Input()
private _param: NgParameter; private param: NgParameter;
@Output() @Output()
private onValid: EventEmitter<boolean>; private valid: EventEmitter<boolean>;
/** /**
* indice actuel du paramètre sélectionné dans la lsite * indice actuel du paramètre sélectionné dans la liste
*/ */
private _currentIndex = -1; private _currentIndex = -1;
...@@ -49,7 +48,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -49,7 +48,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
private _formService: FormulaireService; private _formService: FormulaireService;
constructor() { constructor() {
this.onValid = new EventEmitter(); this.valid = new EventEmitter();
this._formService = ServiceFactory.instance.formulaireService; this._formService = ServiceFactory.instance.formulaireService;
this._formService.addObserver(this); this._formService.addObserver(this);
} }
...@@ -66,7 +65,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -66,7 +65,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
* envoi d'un événement de validité * envoi d'un événement de validité
*/ */
private emitValidity() { private emitValidity() {
// this.onValid.emit(this._validList); // this.valid.emit(this._validList);
} }
/** /**
...@@ -74,14 +73,15 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -74,14 +73,15 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
*/ */
public onSelectLinkableParam(event: any) { public onSelectLinkableParam(event: any) {
const next = event.target.value; const next = event.target.value;
if (next !== undefined && next !== "") { // opening the dropdown returns ""
let i = 0; let i = 0;
for (const e of this._linkableParams) { for (const e of this._linkableParams) {
if (this._linkableParams[i].value.uid == next.value.uid) { if (this._linkableParams[i].value.uid === next.value.uid) {
this.linkTo(i); this.linkTo(i);
break; break;
} else { } else {
i++; i++;
}
} }
} }
} }
...@@ -101,18 +101,6 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -101,18 +101,6 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
return undefined; return undefined;
} }
// // le paramètre est il déjà lié à une valeur ? si oui laquelle ?
// if(this._currentIndex === -1 && this._param.valueMode == ParamValueMode.LINK && this._linkableParams !== undefined) {
// let i = 0;
// for (const e of this._linkableParams)
// if (e.param.uid === this._param.paramDefinition.re) {
// this._currentIndex = i;
// break;
// }
// else
// i++;
// }
/** /**
* attribut "label" d'une entrée du select des paramètres * attribut "label" d'une entrée du select des paramètres
*/ */
...@@ -164,24 +152,36 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -164,24 +152,36 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
this._currentIndex = index; this._currentIndex = index;
const lp = this._linkableParams[index]; const lp = this._linkableParams[index];
this._param.linkToParameter(lp.nub, lp.name); this.param.linkToParameter(lp.nub, lp.name);
} }
} }
public updateParamList() { public updateParamList() {
// liste des paramètres liables // liste des paramètres liables
if (this._param.valueMode === ParamValueMode.LINK) { if (this.param.valueMode === ParamValueMode.LINK) {
this._linkableParams = this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)); this._linkableParams = this._formService.filterLinkableValues(this._formService.getLinkableValues(this.param));
} else { } else {
this._linkableParams = []; this._linkableParams = [];
} }
// initialisation de l'indice courant // initialisation de l'indice courant
if (this._linkableParams.length > 0) { if (this._linkableParams.length > 0) {
if (this._currentIndex === -1) { if (this._currentIndex === -1) {
this.linkTo(0); // le paramètre est il déjà lié à une valeur ? si oui laquelle ?
if (this.param.valueMode === ParamValueMode.LINK && this._linkableParams !== undefined) {
let i = 0;
for (const e of this._linkableParams) {
if (this.param.paramDefinition.paramValues.referencedNub
&& e.nub.uid === this.param.paramDefinition.paramValues.referencedNub["_uid"]) {
this._currentIndex = i;
break;
} else {
i++;
}
}
}
this.linkTo(Math.max(this._currentIndex, 0)); // might still be -1
} }
this._message = undefined; this._message = undefined;
} else { } else {
...@@ -191,16 +191,16 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -191,16 +191,16 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
} }
public ngOnChanges() { public ngOnChanges() {
if (this._param !== undefined) { if (this.param !== undefined) {
this._param.removeObserver(this); this.param.removeObserver(this);
} }
this._param.addObserver(this); this.param.addObserver(this);
this.updateParamList(); this.updateParamList();
} }
public ngOnDestroy() { public ngOnDestroy() {
this._param.removeObserver(this); this.param.removeObserver(this);
} }
// interface Observer // interface Observer
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<ngparam-max [title]="uitextValeurMaxi" (onChange)="onMaxChanged($event)"></ngparam-max> <ngparam-max [title]="uitextValeurMaxi" (onChange)="onMaxChanged($event)"></ngparam-max>
</div> </div>
<div *ngIf="isMinMax" class="col-12 col-sm-3"> <div *ngIf="isMinMax" class="col-12 col-sm-3">
<ngparam-step [title]="uitextPasVariation" [param]=_param (onChange)="onStepChanged($event)"></ngparam-step> <ngparam-step [title]="uitextPasVariation" [param]="param" (onChange)="onStepChanged($event)"></ngparam-step>
</div> </div>
<div *ngIf="isList" class="col-12 col-sm-6"> <div *ngIf="isList" class="col-12 col-sm-6">
......
...@@ -31,8 +31,8 @@ import { ValueListComponent } from "./value-list.component"; ...@@ -31,8 +31,8 @@ import { ValueListComponent } from "./value-list.component";
] ]
}) })
export class ParamValuesComponent extends BaseComponent implements AfterViewChecked { export class ParamValuesComponent extends BaseComponent implements AfterViewChecked {
@Input("param") @Input()
private _param: NgParameter; private param: NgParameter;
private _valueModes = []; private _valueModes = [];
...@@ -113,30 +113,30 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -113,30 +113,30 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
this._doInitMinmax = false; this._doInitMinmax = false;
// valeur pour min : celle déjà définie ou celle déduite de la valeur saisie // valeur pour min : celle déjà définie ou celle déduite de la valeur saisie
let min: number = this._param.minValue; let min: number = this.param.minValue;
if (min == undefined) { if (min == undefined) {
min = this._param.getValue() / 2; min = this.param.getValue() / 2;
} }
// valeur pour max : celle déjà définie ou celle déduite de la valeur saisie // valeur pour max : celle déjà définie ou celle déduite de la valeur saisie
let max: number = this._param.maxValue; let max: number = this.param.maxValue;
if (max == undefined) { if (max == undefined) {
max = this._param.getValue() * 2; max = this.param.getValue() * 2;
} }
this._param.minValue = min; this.param.minValue = min;
this._minComponent.model = this._param; this._minComponent.model = this.param;
this._param.maxValue = max; this.param.maxValue = max;
this._maxComponent.model = this._param; this._maxComponent.model = this.param;
// valeur du pas // valeur du pas
let step = this._param.stepValue; let step = this.param.stepValue;
if (step == undefined) { if (step == undefined) {
step = (max - min) / 20; step = (max - min) / 20;
} }
this._param.stepValue = step; this.param.stepValue = step;
this._stepComponent.model = this._param; this._stepComponent.model = this.param;
this.validateAll(); this.validateAll();
...@@ -155,17 +155,17 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -155,17 +155,17 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
private initList() { private initList() {
if (this._doInitList && this._listComponent != undefined) { if (this._doInitList && this._listComponent != undefined) {
this._doInitList = false; this._doInitList = false;
let l = this._param.valueList; let l = this.param.valueList;
if (l == undefined) { if (l == undefined) {
if (this._param.isDefined) { if (this.param.isDefined) {
l = [this._param.getValue()]; l = [this.param.getValue()];
} else { } else {
l = []; l = [];
} }
} }
this._param.valueList = l; this.param.valueList = l;
this._listComponent.model = this._param; this._listComponent.model = this.param;
} }
} }
...@@ -191,7 +191,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -191,7 +191,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
* envoi d'un événement de validité * envoi d'un événement de validité
*/ */
private emitValidity() { private emitValidity() {
switch (this._param.valueMode) { switch (this.param.valueMode) {
case ParamValueMode.LISTE: case ParamValueMode.LISTE:
this.onValid.emit(this._validList); this.onValid.emit(this._validList);
break; break;
...@@ -290,28 +290,28 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -290,28 +290,28 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
* true si mode "liste de valeurs" * true si mode "liste de valeurs"
*/ */
public get isList(): boolean { public get isList(): boolean {
return this._param.valueMode === ParamValueMode.LISTE; return this.param.valueMode === ParamValueMode.LISTE;
} }
/** /**
* true si mode "lié" * true si mode "lié"
*/ */
public get isLink(): boolean { public get isLink(): boolean {
return this._param.valueMode === ParamValueMode.LINK; return this.param.valueMode === ParamValueMode.LINK;
} }
/** /**
* true si mode "min/max/pas" * true si mode "min/max/pas"
*/ */
public get isMinMax(): boolean { public get isMinMax(): boolean {
return this._param.valueMode === ParamValueMode.MINMAX; return this.param.valueMode === ParamValueMode.MINMAX;
} }
/** /**
* valeur courante affichée dans le select min-max/list * valeur courante affichée dans le select min-max/list
*/ */
public get currentModeSelectLabel(): string { public get currentModeSelectLabel(): string {
return ParamValueMode[this._param.valueMode]; return ParamValueMode[this.param.valueMode];
} }
/** /**
...@@ -335,7 +335,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec ...@@ -335,7 +335,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec
throw new Error("valeur " + next + " de ParamValueMode non prise en charge"); throw new Error("valeur " + next + " de ParamValueMode non prise en charge");
} }
this._param.valueMode = next; this.param.valueMode = next;
} }
public get valueModes() { public get valueModes() {
......
...@@ -22,14 +22,14 @@ export class ValueListComponent extends GenericInputComponent { ...@@ -22,14 +22,14 @@ export class ValueListComponent extends GenericInputComponent {
} }
protected getModelValue(): any { protected getModelValue(): any {
if (this._param == undefined) { if (this._param === undefined || this._param === null) {
return undefined; return undefined;
} }
return this._param.valueList; return this._param.valueList;
} }
protected setModelValue(sender: any, l: any) { protected setModelValue(sender: any, l: any) {
if (typeof (l) == "number") { if (typeof (l) === "number") {
this._param.valueList = []; this._param.valueList = [];
this._param.valueList.push(l); this._param.valueList.push(l);
} else { } else {
...@@ -62,9 +62,9 @@ export class ValueListComponent extends GenericInputComponent { ...@@ -62,9 +62,9 @@ export class ValueListComponent extends GenericInputComponent {
protected modelToUI(v: any): string { protected modelToUI(v: any): string {
let res = ""; let res = "";
if (v != undefined) { if (v !== undefined && v !== null) {
for (const e of v) { for (const e of v) {
if (res != "") { if (res !== "") {
res += ";"; res += ";";
} }
res += String(e); res += String(e);
...@@ -80,7 +80,7 @@ export class ValueListComponent extends GenericInputComponent { ...@@ -80,7 +80,7 @@ export class ValueListComponent extends GenericInputComponent {
const tmp: string[] = ui.split(";"); const tmp: string[] = ui.split(";");
let res = true; let res = true;
for (const v of tmp) { for (const v of tmp) {
const isnum = v != "" && (+v == +v); const isnum = v !== "" && (+v === +v);
res = res && isnum; res = res && isnum;
if (!res) { if (!res) {
break; break;
......
...@@ -148,19 +148,18 @@ export class FormDefFixedVar { ...@@ -148,19 +148,18 @@ export class FormDefFixedVar {
break; break;
} }
} }
if (newCal != undefined) { if (newCal) {
break; break;
} }
} }
if (newCal != undefined) { if (newCal) {
newCal.valueMode = ParamValueMode.CALCUL; newCal.valueMode = ParamValueMode.CALCUL;
} }
} }
} }
private logParams() { private logParams() {
console.log("----");
for (const fe of this._formBase.allFormElements) { for (const fe of this._formBase.allFormElements) {
if (fe instanceof NgParameter) { if (fe instanceof NgParameter) {
console.log(`${fe.paramDefinition.symbol} : ${ParamValueMode[fe.paramDefinition.valueMode]}`); console.log(`${fe.paramDefinition.symbol} : ${ParamValueMode[fe.paramDefinition.valueMode]}`);
......
import { CalculatorType, ComputeNodeType, Nub, ParamDefinition, SessionNub, Props, NubFactory, Observer } from "jalhyd"; import { CalculatorType, ComputeNodeType, ParamDefinition, SessionNub, Props, Observer } from "jalhyd";
import { FormulaireElement } from "../formulaire-element"; import { FormulaireElement } from "../formulaire-element";
import { NgParameter, ParamRadioConfig } from "../ngparam"; import { NgParameter, ParamRadioConfig } from "../ngparam";
......
...@@ -55,7 +55,7 @@ export class NgParameter extends InputField implements Observer { ...@@ -55,7 +55,7 @@ export class NgParameter extends InputField implements Observer {
this._confId = id; this._confId = id;
} }
private get _paramValues() { public get _paramValues() { // @TODO remettre en private ! (debug)
return this._paramDef.paramValues; return this._paramDef.paramValues;
} }
...@@ -232,6 +232,7 @@ export class NgParameter extends InputField implements Observer { ...@@ -232,6 +232,7 @@ export class NgParameter extends InputField implements Observer {
} }
this.valueMode = ParamValueMode.LINK; this.valueMode = ParamValueMode.LINK;
// changement de lien
this._paramDef.defineReference(n, ref); this._paramDef.defineReference(n, ref);
o = asObservable(this._paramDef.referencedObject); o = asObservable(this._paramDef.referencedObject);
......
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