From b83574b8dd24edde1ccecc0e548f8d2798a79bb2 Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Fri, 7 Jul 2017 14:04:19 +0200 Subject: [PATCH] composant param-input : ajout des messages d'erreur sous la zone de saisie --- src/app/app.component.ts | 3 +- .../param-input/param-input.component.html | 6 +- src/app/param-input/param-input.component.ts | 61 +++++++++++++++++-- src/app/param-input/param.service.js | 21 ------- src/app/param-input/param.service.js.map | 1 - 5 files changed, 64 insertions(+), 28 deletions(-) delete mode 100644 src/app/param-input/param.service.js delete mode 100644 src/app/param-input/param.service.js.map diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c13c59c1d..8a85a6876 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -8,7 +8,8 @@ import { ParamService } from './param-service/param.service'; <h1>{{title}}</h1> <param-input symbol="Q"></param-input> <param-input symbol="Ks"></param-input> - <param-input symbol="Q"></param-input> + <!-- + --> `, providers: [ParamService] }) diff --git a/src/app/param-input/param-input.component.html b/src/app/param-input/param-input.component.html index ac16dbe77..b034821a1 100644 --- a/src/app/param-input/param-input.component.html +++ b/src/app/param-input/param-input.component.html @@ -1,3 +1,7 @@ <md-input-container> + <input mdInput placeholder="{{_paramDef.symbol}}" [(ngModel)]="_value"> + <md-hint>{{_hint}}</md-hint> +</md-input-container> +<!-- <input mdInput placeholder="{{_paramDef.symbol}}" [(ngModel)]="_paramDef.v"> -</md-input-container> \ No newline at end of file +--> \ No newline at end of file diff --git a/src/app/param-input/param-input.component.ts b/src/app/param-input/param-input.component.ts index a55e89311..9dbf100f2 100644 --- a/src/app/param-input/param-input.component.ts +++ b/src/app/param-input/param-input.component.ts @@ -1,4 +1,5 @@ -import { Component, Input, OnInit } from '@angular/core'; +// import { Component, Input, OnInit, DoCheck, OnChanges } from '@angular/core'; +import { Component, Input, OnInit, DoCheck } from '@angular/core'; import { ParamDefinition } from 'jalhyd'; @@ -8,17 +9,69 @@ import { ParamService } from '../param-service/param.service'; selector: "param-input[symbol]", templateUrl: "./param-input.component.html", }) -export class ParamInputComponent implements OnInit { +// export class ParamInputComponent implements OnInit, DoCheck, OnChanges { +export class ParamInputComponent implements OnInit, DoCheck { /** * Parameter symbol (Q, Ks, B, ...) attribute */ @Input('symbol') private _paramSymbol: string; + // private static _idGen: number = 0; + // private _id: number; + + /** + * managed parameter + */ private _paramDef: ParamDefinition; - constructor(private paramService: ParamService) { } + /** + * currently displayed value + */ + private _value: string; + + /** + * hint message + */ + private _hint: string; + + constructor(private paramService: ParamService) { + // this._id = ParamInputComponent._idGen++; + } ngOnInit(): void { + // retrieve parameter from symbol this._paramDef = this.paramService.getParameter(this._paramSymbol); + + this._value = String(this._paramDef.v); + } + + ngDoCheck(): void { + // let sValue: string = (this._value == undefined) ? "undef" : this._value; + // let sParam: string = (this._paramDef.v == undefined) ? "undef" : String(this._paramDef.v); + // // console.log("ngDoCheck STA " + this._paramDef.symbol + "(" + this._id + ") old=" + this._old + " value=" + sValue + " param=" + this._paramDef.v); + // console.log("ngDoCheck STA " + this._paramDef.symbol + "(" + this._id + ") value=" + sValue + " param=" + sParam); + + if (this._value == undefined || this._value.trim() == "" || isNaN(+this._value)) + this._hint = "Please enter a number"; + else { + this._hint = undefined; + let v: number = +this._value; + try { + this._paramDef.checkValue(v); // throws exception if something wrong + this._paramDef.v = v; + this._value = String(v); + } + catch (e) { + this._hint = e; + } + } + // // console.log("ngDoCheck END " + this._paramDef.symbol + "(" + this._id + ") old=" + this._old + " value=" + sValue + " param=" + this._paramDef.v); + // let sValue = (this._value == undefined) ? "undef" : this._value; + // let sParam = (this._paramDef.v == undefined) ? "undef" : String(this._paramDef.v); + // console.log("ngDoCheck END " + this._paramDef.symbol + "(" + this._id + ") value=" + sValue + " param=" + sParam); } -} + + // ngOnChanges() { + // console.log("ngOnChanges " + this._id); + // } +} \ No newline at end of file diff --git a/src/app/param-input/param.service.js b/src/app/param-input/param.service.js deleted file mode 100644 index 5a04bf621..000000000 --- a/src/app/param-input/param.service.js +++ /dev/null @@ -1,21 +0,0 @@ -//import { Injectable } from '@angular/core'; -"use strict"; -var jalhyd_1 = require("jalhyd"); -//@Injectable() -var ParamService = (function () { - function ParamService() { - this._params = [new jalhyd_1.ParamDefinition('Q', jalhyd_1.ParamDomainValue.POS_NULL, 0), - new jalhyd_1.ParamDefinition('Ks', jalhyd_1.ParamDomainValue.POS, 1)]; - } - ParamService.prototype.getParameter = function (s) { - for (var _i = 0, _a = this._params; _i < _a.length; _i++) { - var p = _a[_i]; - if (p.symbol == s) - return p; - } - return undefined; - }; - return ParamService; -}()); -exports.ParamService = ParamService; -//# sourceMappingURL=param.service.js.map \ No newline at end of file diff --git a/src/app/param-input/param.service.js.map b/src/app/param-input/param.service.js.map deleted file mode 100644 index b800abded..000000000 --- a/src/app/param-input/param.service.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"param.service.js","sourceRoot":"","sources":["param.service.ts"],"names":[],"mappings":"AAAA,6CAA6C;;AAE7C,iCAA2D;AAE3D,eAAe;AACf;IAGI;QACI,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,wBAAe,CAAC,GAAG,EAAE,yBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC;YACtE,IAAI,wBAAe,CAAC,IAAI,EAAE,yBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,mCAAY,GAAZ,UAAa,CAAS;QAClB,GAAG,CAAC,CAAU,UAAY,EAAZ,KAAA,IAAI,CAAC,OAAO,EAAZ,cAAY,EAAZ,IAAY;YAArB,IAAI,CAAC,SAAA;YACN,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;gBACd,MAAM,CAAC,CAAC,CAAC;SAChB;QAED,MAAM,CAAC,SAAS,CAAC;IACrB,CAAC;IACL,mBAAC;AAAD,CAAC,AAhBD,IAgBC;AAhBY,oCAAY"} \ No newline at end of file -- GitLab