Commit 6fb6e01c authored by Grand Francois's avatar Grand Francois
Browse files

#45 déplacement vers BaseParam depuis ngHyd (NgParameter) des méthodes de...

 #45 déplacement vers BaseParam depuis ngHyd (NgParameter) des méthodes de validation des valeurs (checkMin, checkMax, isMinMaxValid, checkStep, isValueValid, isRangeValid, isValid)
Showing with 101 additions and 0 deletions
+101 -0
......@@ -145,6 +145,107 @@ export class BaseParam extends JalhydObject implements IObjectReference, Iterabl
}
}
/**
* vérifie si un min/max est valide par rapport au domaine de définition
*/
private isMinMaxDomainValid(v: number): boolean {
if (v == undefined)
return false;
if (this._paramValues.valueMode == ParamValueMode.MINMAX)
try {
this.checkValue(v);
}
catch (e) {
return false;
}
return true;
}
public checkMin(min: number): boolean {
return this.isMinMaxDomainValid(min) && (min < this._paramValues.max);
}
public checkMax(max: number): boolean {
return this.isMinMaxDomainValid(max) && (this._paramValues.min < max);
}
private checkMinMax(min: number, max: number): boolean {
return this.isMinMaxDomainValid(min) && this.isMinMaxDomainValid(max) && (min < max);
}
public get isMinMaxValid(): boolean {
return this.checkMinMax(this._paramValues.min, this._paramValues.max);
}
public checkStep(step: number): boolean {
return this.isMinMaxValid && this._paramValues.stepRefValue.intervalHasValue(step);
}
public get isValueValid(): boolean {
try {
const v = this.getValue();
this.checkValue(v);
return true;
}
catch (e) {
return false;
}
}
private get isListValid(): boolean {
if (this._paramValues.valueList == undefined)
return false;
for (let v of this._paramValues.valueList)
try {
this.checkValue(v);
}
catch (e) {
return false;
}
return true;
}
public get isRangeValid(): boolean {
switch (this._paramValues.valueMode) {
case ParamValueMode.LISTE:
return this.isListValid;
case ParamValueMode.MINMAX:
return this.checkStep(this._paramValues.step);
}
throw new Error(`"BaseParam.isRangeValid() : valeur ${ParamValueMode[this._paramValues.valueMode]} de ParamValueMode non prise en compte`);
}
public get isValid() {
switch (this._paramValues.valueMode) {
case ParamValueMode.SINGLE:
return this.isValueValid;
case ParamValueMode.MINMAX:
case ParamValueMode.LISTE:
return this.isRangeValid;
case ParamValueMode.CALCUL:
return true;
case ParamValueMode.LINK:
try {
for (const v of this.valuesIterator)
this.checkValue(v);
return true
}
catch (e) {
return false;
}
}
throw new Error(`"BaseParam.isValid() : valeur de ParamValueMode '${ParamValueMode[this._paramValues.valueMode]}' non prise en charge`);
}
public get valueMode() {
return this._paramValues.valueMode;
}
......
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