Skip to content
Snippets Groups Projects
Commit f71d9851 authored by François's avatar François
Browse files

ticket #49 : remaniement de GenericInputComponent

- ajout propriété isValid indiquant la validité de la valeur du modèle ou de la valeur saisie dans l'interface
- rapatriement de l'EventEmitter onChange
parent 84911b42
No related branches found
No related tags found
1 merge request!8Resolve "Calculettes : désactiver le bouton de calcul si un des champs est en erreur"
......@@ -26,43 +26,73 @@ export abstract class GenericInputComponent { //implements OnInit {
@Input('title')
private _title: string;
/**
* valeur dans le contrôle (saisie par l'utilisateur)
*/
// private _uiValue: string;
@Output()
protected onChange = new EventEmitter<string>();
/**
* valeur du modèle
* validité actuelle (false si erreur dûe à la saisie ou à la valeur du modèle)
*/
// private _modelValue: any;
private _isValid;
/**
* message d'erreur
*/
private _message: string;
/**
* événement de changement de la valeur du modèle
*/
private emitModelChanged() {
this.onChange.emit("value");
}
/**
* événement de changement de la valeur du modèle
*/
private emitValidChanged() {
this.onChange.emit("valid");
}
private get isDisabled(): boolean {
return this._inputDisabled;
}
public validateModel() {
protected validateModel(): boolean {
let { isValid, message } = this.validateModelValue(this.getModelValue());
this._message = message;
this.setValid(isValid);
return isValid;
}
public get isValid() {
return this._isValid;
}
private setValid(b: boolean) {
if (this._isValid != b) {
this._isValid = b;
this.emitValidChanged();
}
}
public get model(): any {
return this.getModelValue();
}
public set model(v: any) {
this.setModelValue(v);
this.validateModel()
if (this.model !== v) {
this.setModelValue(v);
this.emitModelChanged();
let { isValid, message } = this.validateModelValue(v);
this._message = message;
this.setValid(isValid);
}
}
private validateUI(ui: string) {
let { isValid, message } = this.validateUIValue(ui);
this._message = message;
this.setValid(isValid);
return isValid;
}
......@@ -75,13 +105,8 @@ export abstract class GenericInputComponent { //implements OnInit {
* @param event valeur du contrôle
*/
private setUIValue(ui: any) {
if (this.validateUI(ui)) {
const m = this.uiToModel(ui);
this.setModelValue(m);
//this.validateModel()
let { isValid, message } = this.validateModelValue(m);
this._message = message;
}
if (this.validateUI(ui))
this.model = this.uiToModel(ui);
}
/**
......
......@@ -20,15 +20,13 @@ export class NgParamMaxComponent extends GenericInputComponent {
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
constructor(private intlService: InternationalisationService) {
super();
}
public set refValue(v: Pair) {
this._refValue = v;
this.validateModel();
}
protected getModelValue(): any {
......@@ -37,7 +35,6 @@ export class NgParamMaxComponent extends GenericInputComponent {
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
......
......@@ -20,9 +20,6 @@ export class NgParamMinComponent extends GenericInputComponent {
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
public isInit: boolean;
constructor(private intlService: InternationalisationService) {
......@@ -31,6 +28,7 @@ export class NgParamMinComponent extends GenericInputComponent {
public set refValue(v: Pair) {
this._refValue = v;
this.validateModel();
}
protected getModelValue(): any {
......@@ -39,7 +37,6 @@ export class NgParamMinComponent extends GenericInputComponent {
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
......
......@@ -20,15 +20,13 @@ export class NgParamStepComponent extends GenericInputComponent {
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
constructor(private intlService: InternationalisationService) {
super();
}
public set refValue(v: Pair) {
this._refValue = v;
this.validateModel();
}
protected getModelValue(): any {
......@@ -37,7 +35,6 @@ export class NgParamStepComponent extends GenericInputComponent {
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
......
......@@ -15,9 +15,6 @@ import { NgParamStepComponent } from "./ngparam-step.component";
templateUrl: "../generic-input/generic-input.component.html"
})
export class ValueListComponent extends GenericInputComponent {
@Output()
private onChange = new EventEmitter<string>();
public _list: number[];
public isInit;
......@@ -38,7 +35,6 @@ export class ValueListComponent extends GenericInputComponent {
}
else
this._list = l;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
......@@ -158,7 +154,7 @@ export class ParamValuesComponent implements DoCheck {
this._valueModes.push({ "value": ParamValueMode.MINMAX, "label": "Min/max" });
this._valueModes.push({ "value": ParamValueMode.LISTE, "label": "Liste" });
}
private initMinMaxStep() {
// valeur pour min (celle déjà définie ou celle déduite du domaine de définition)
let min: number = this._param.minValue;
......@@ -207,9 +203,7 @@ export class ParamValuesComponent implements DoCheck {
this.updateStepComponentRef();
this._maxComponent.refValue = new Pair(this._minComponent.model, this._param.domain.maxValue);
this._maxComponent.validateModel();
if (this._minComponent.validateModel())
if (this._minComponent.isValid)
this._param.minValue = this._minComponent.model;
}
......@@ -217,19 +211,17 @@ export class ParamValuesComponent implements DoCheck {
this.updateStepComponentRef();
this._minComponent.refValue = new Pair(this._param.domain.minValue, this._maxComponent.model);
this._minComponent.validateModel();
if (this._maxComponent.validateModel())
if (this._maxComponent.isValid)
this._param.maxValue = this._maxComponent.model;
}
private onStepChanged(val: string) {
if (this._stepComponent.validateModel())
if (this._stepComponent.isValid)
this._param.stepValue = this._stepComponent.model;
}
private onListChanged(val: string) {
if (this._listComponent.validateModel())
if (this._listComponent.isValid)
this._param.valueList = this._listComponent.model;
}
......@@ -254,7 +246,6 @@ export class ParamValuesComponent implements DoCheck {
*/
private updateStepComponentRef() {
this._stepComponent.refValue = new Pair(1e-9, this._maxComponent.model - this._minComponent.model);
this._stepComponent.validateModel();
}
private get uitextValeurMini() {
......
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