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

Fix #186

parent 77de25ff
No related branches found
No related tags found
1 merge request!40Resolve "Amélioration du système de paramètres liés"
...@@ -92,8 +92,8 @@ export class NgBaseParam extends Observable { ...@@ -92,8 +92,8 @@ export class NgBaseParam extends Observable {
templateUrl: "../generic-input/generic-input.component.html", templateUrl: "../generic-input/generic-input.component.html",
}) })
export class BaseParamInputComponent extends GenericInputComponent { export class BaseParamInputComponent extends GenericInputComponent {
constructor(private intlService: I18nService, cdRef: ChangeDetectorRef) { constructor(intlService: I18nService, cdRef: ChangeDetectorRef) {
super(cdRef); super(cdRef, intlService);
} }
/** /**
......
import { Component, Input } from "@angular/core"; import { Component } from "@angular/core";
import { GenericInputComponent } from "../generic-input/generic-input.component"; import { GenericInputComponent } from "../generic-input/generic-input.component";
import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
@Component({ @Component({
selector: "calc-name", selector: "calc-name",
...@@ -11,8 +12,8 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio ...@@ -11,8 +12,8 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio
}) })
export class CalculatorNameComponent extends GenericInputComponent { export class CalculatorNameComponent extends GenericInputComponent {
constructor() { constructor(intlService: I18nService) {
super(null); super(null, intlService);
} }
/** /**
...@@ -39,41 +40,27 @@ export class CalculatorNameComponent extends GenericInputComponent { ...@@ -39,41 +40,27 @@ export class CalculatorNameComponent extends GenericInputComponent {
this.updateAndValidateUI(); this.updateAndValidateUI();
} }
/**
* valide une valeur de modèle : est ce une valeur acceptable ? (par ex, nombre dans un intervalle, valeur dans une liste, ...)
* @param v valide la valeur du modèle
* @returns isValid : true si la valeur est valide, false sinon
* @returns message : message d'erreur
*/
protected validateModelValue(v: any): { isValid: boolean, message: string } { protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg; // no model validation for a simple string
let valid = false; return { isValid: true, message: undefined };
if (!(typeof (v) === "string") || v.length < 1) {
msg = "Veuillez entrer un nom";
} else {
valid = true;
}
return { isValid: valid, message: msg };
} }
/**
* valide une valeur saisie dans l'UI (forme de la saisie : est ce bien une date, un nombre, ...)
* @param ui valide la valeur saisie
* @returns isValid : true si la valeur est valide, false sinon
* @returns message : message d'erreur
*/
protected validateUIValue(ui: string): { isValid: boolean, message: string } { protected validateUIValue(ui: string): { isValid: boolean, message: string } {
let valid = false; let valid = false;
let msg: string; let msg: string;
if (ui === undefined || ui.length < 1) { if (ui === undefined || ui.length < 1) {
msg = "Veuillez entrer un nom"; msg = "Veuillez entrer un nom tralala";
} else { } else {
valid = true; valid = true;
} }
return { isValid: valid, message: msg }; return { isValid: valid, message: msg };
} }
public updateModelFromUI() {
if (this.validateUI()) {
this.setAndValidateModel(this, this.uiValue); // do NOT cast UI value to Number
}
}
} }
...@@ -4,6 +4,7 @@ import { BaseComponent } from "../base/base.component"; ...@@ -4,6 +4,7 @@ import { BaseComponent } from "../base/base.component";
import { isNumeric } from "jalhyd"; import { isNumeric } from "jalhyd";
import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition";
import { NgParameter } from "../../formulaire/ngparam"; import { NgParameter } from "../../formulaire/ngparam";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
/** /**
* classe de gestion générique d'un champ de saisie avec titre, validation et message d'erreur * classe de gestion générique d'un champ de saisie avec titre, validation et message d'erreur
...@@ -88,7 +89,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC ...@@ -88,7 +89,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC
@ViewChild("inputControl") inputField: NgModel; @ViewChild("inputControl") inputField: NgModel;
constructor(private cdRef: ChangeDetectorRef) { constructor(private cdRef: ChangeDetectorRef, protected intlService: I18nService) {
super(); super();
} }
...@@ -129,7 +130,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC ...@@ -129,7 +130,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC
} }
} }
private validateUI() { protected validateUI() {
const { isValid, message } = this.validateUIValue(this._uiValue); const { isValid, message } = this.validateUIValue(this._uiValue);
this._errorMessageUI = message; this._errorMessageUI = message;
this.detectChanges(); this.detectChanges();
...@@ -185,7 +186,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC ...@@ -185,7 +186,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC
this.change.emit({ "action": "model", "value": this.getModelValue() }); this.change.emit({ "action": "model", "value": this.getModelValue() });
} }
private setAndValidateModel(sender: any, v: any) { protected setAndValidateModel(sender: any, v: any) {
this.setModelValue(sender, v); this.setModelValue(sender, v);
this.emitModelChanged(); this.emitModelChanged();
...@@ -281,7 +282,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC ...@@ -281,7 +282,7 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC
let msg: string; let msg: string;
if (! isNumeric(ui)) { if (! isNumeric(ui)) {
msg = "Veuillez entrer une valeur numérique"; msg = this.intlService.localizeText("ERROR_PARAM_MUST_BE_A_NUMBER");
} else { } else {
valid = true; valid = true;
} }
......
...@@ -29,8 +29,8 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse ...@@ -29,8 +29,8 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
*/ */
private _tmp: number; private _tmp: number;
constructor(private intlService: I18nService, cdRef: ChangeDetectorRef) { constructor(intlService: I18nService, cdRef: ChangeDetectorRef) {
super(cdRef); super(cdRef, intlService);
} }
/** /**
......
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