Skip to content
Snippets Groups Projects
Commit b83574b8 authored by francois.grand's avatar francois.grand
Browse files

composant param-input : ajout des messages d'erreur sous la zone de saisie

parent 4069e966
No related branches found
No related tags found
No related merge requests found
......@@ -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]
})
......
<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
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
//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
{"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
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