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

début de prise en charge du changement dynamique de la langue de l'interface...

début de prise en charge du changement dynamique de la langue de l'interface (les textes gérés par angular i18n mis à part)
parent d7b4e180
No related branches found
No related tags found
No related merge requests found
Showing
with 159 additions and 630 deletions
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/build
/tmp
/out-tsc
/src/main.js*
/src/app/*.js*
/src/main.js
/src/app/**/*.js
/src/app/**/*.js.map
# dependencies
/node_modules
......
import { Component } from '@angular/core';
import { Component, ChangeDetectorRef, ApplicationRef, AfterViewChecked } from '@angular/core';
import { ParamService } from './services/param/param.service';
import { HttpService } from './services/http/http.service';
import { InternationalisationService } from './services/internationalisation/internationalisation.service';
import { InternationalisationService, Language, LanguageCode } from './services/internationalisation/internationalisation.service';
@Component({
selector: 'nghyd-app',
template: `
<select [(ngModel)]=_currentLanguage (change)=onSelectLang($event)>
<option *ngFor="let l of intlService.languages" [value]=l.code>{{l.label}}</option>
</select>
<cond-distri></cond-distri>
<!--
<select name="Language" (change)=selectLang($event)>
<option *ngFor="let l of intlService.languages" [value]=l.code>{{l.label}}</option>
</select>
<h1>{{title}}</h1>
<param-input symbol="Q"></param-input>
<param-input symbol="Q"></param-input>
......@@ -18,14 +26,37 @@ import { InternationalisationService } from './services/internationalisation/int
providers: [ParamService, InternationalisationService, HttpService]
})
export class AppComponent {
constructor(private intlService: InternationalisationService) { }
private _currentLanguage: LanguageCode;
constructor(private intlService: InternationalisationService, private appRef: ApplicationRef) { }
private initLocale() {
let docLocale: string = document['locale'] as string;
this.intlService.setLocale(docLocale);
this._currentLanguage = this.intlService.currentLanguage.code;
}
ngOnInit() {
this.initLocale();
}
private onSelectLang(evt: any) {
let v = evt.target.value;
let lc = LanguageCode[v];
this.intlService.setLocale(lc);
this._currentLanguage = this.intlService.currentLanguage.code;
let tag = this.intlService.currentLanguage.tag;
document['locale'] = tag;
// location.reload(true);
// this.cdRef.markForCheck();
// this.cdRef.detectChanges();
this.appRef.tick();
}
ngAfterViewChecked() {
this.intlService.acknowledgeLocaleChanged();
}
}
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var param_service_1 = require("../../services/param/param.service");
var http_service_1 = require("../../services/http/http.service");
var internationalisation_service_1 = require("../../services/internationalisation/internationalisation.service");
var field_set_component_1 = require("../../components/field-set/field-set.component");
var CondDistriComponent = (function () {
function CondDistriComponent(paramService, httpService, intlService) {
this.paramService = paramService;
this.httpService = httpService;
this.intlService = intlService;
this._title = "Conduite distributrice";
this._localisation = {};
this._config = {};
this._fieldSets = [];
}
CondDistriComponent.prototype.loadLocalisation = function () {
var ths = this;
var processData = function (s) {
// fermeture nécessaire pour capturer la valeur de this (undefined sinon)
ths._localisation = JSON.parse(s);
ths.paramService.updateLocalisation(ths._localisation);
};
var f = "app/calculators/cond_distri/cond_distri." + this.intlService.languageCode + ".json";
this.httpService.httpGetRequest(undefined, undefined, undefined, f, processData);
};
CondDistriComponent.prototype.logObject = function (obj) {
console.log(JSON.stringify(obj));
};
CondDistriComponent.prototype.parseConfig = function () {
this._fieldSets = [];
for (var conf_index in this._config) {
//this.logObject(this._fieldSets);
var conf = this._config[conf_index];
//console.log(conf);
var conf_id = conf["id"];
if (conf_id.startsWith("fs_")) {
var fieldSet = new field_set_component_1.FieldSet();
fieldSet.title = this._localisation[conf_id];
var fields = conf["fields"];
for (var field_index in fields) {
var field = fields[field_index];
// console.log(field);
if (field["type"] === "input") {
var input_id = field["id"];
// console.log(input_id);
var param = this.paramService.getParameter(input_id);
if (param != undefined) {
//this.logObject(param);
fieldSet.params.push(param);
}
}
}
if (fieldSet.params.length > 0) {
// this.logObject(fieldSet);
this._fieldSets.push(fieldSet);
}
}
}
};
CondDistriComponent.prototype.loadConfig = function () {
var ths = this;
var processData = function (s) {
// fermeture nécessaire pour capturer la valeur de this (undefined sinon)
ths._config = JSON.parse(s);
ths.parseConfig();
};
var f = "app/calculators/cond_distri/cond_distri.config.json";
this.httpService.httpGetRequest(undefined, undefined, undefined, f, processData);
};
CondDistriComponent.prototype.ngOnInit = function () {
this.loadLocalisation();
this.loadConfig();
};
return CondDistriComponent;
}());
CondDistriComponent = __decorate([
core_1.Component({
selector: 'cond-distri',
template: "\n <h1>{{_title}}</h1>\n <field-set *ngFor=\"let fs of _fieldSets\" [fieldSet]=fs></field-set>\n <!--\n <field-set *ngFor=\"let fs of _fieldSets\" title=\"fs.title\" fields=\"fs.paramList\"></field-set>\n <field-set title=\"titre de field set\" fields=\"Q,D\"></field-set>\n <param-input symbol=\"Q\"></param-input>\n <param-input symbol=\"Q\"></param-input>\n <param-input symbol=\"Ks\"></param-input>\n <field-set title=\"aaaa\"></field-set>\n -->\n "
}),
__metadata("design:paramtypes", [param_service_1.ParamService, http_service_1.HttpService, internationalisation_service_1.InternationalisationService])
], CondDistriComponent);
exports.CondDistriComponent = CondDistriComponent;
//# sourceMappingURL=conddistri.component.js.map
\ No newline at end of file
{"version":3,"file":"conddistri.component.js","sourceRoot":"","sources":["conddistri.component.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAkD;AAElD,oEAAkE;AAClE,iEAA+D;AAC/D,iHAA+G;AAC/G,sFAA0E;AAiB1E,IAAa,mBAAmB;IAO5B,6BAAoB,YAA0B,EAAU,WAAwB,EAAU,WAAwC;QAA9G,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,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;IACrF,CAAC;IAED,sCAAQ,GAAR;QACI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,EAAE,CAAC;IACtB,CAAC;IACL,0BAAC;AAAD,CAAC,AA9ED,IA8EC;AA9EY,mBAAmB;IAf/B,gBAAS,CAAC;QACP,QAAQ,EAAE,aAAa;QACvB,QAAQ,EAAE,idAWX;KACF,CAAC;qCAQoC,4BAAY,EAAuB,0BAAW,EAAuB,0DAA2B;GAPzH,mBAAmB,CA8E/B;AA9EY,kDAAmB"}
\ No newline at end of file
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, DoCheck } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/toPromise';
import { ParamService } from '../../services/param/param.service';
import { HttpService } from '../../services/http/http.service';
......@@ -8,21 +11,19 @@ import { FieldSet } from '../../components/field-set/field-set.component';
@Component({
selector: 'cond-distri',
template: `
<h1>{{_title}}</h1>
<h1 i18n="@@titre_cond_distri">Conduite distributrice</h1>
<field-set *ngFor="let fs of _fieldSets" [fieldSet]=fs></field-set>
<!--
<h1>{{_title}}</h1>
<field-set *ngFor="let fs of _fieldSets" title="fs.title" fields="fs.paramList"></field-set>
<field-set title="titre de field set" fields="Q,D"></field-set>
<param-input symbol="Q"></param-input>
<param-input symbol="Q"></param-input>
<param-input symbol="Ks"></param-input>
<field-set title="aaaa"></field-set>
-->
`
})
export class CondDistriComponent implements OnInit {
private _title = "Conduite distributrice";
export class CondDistriComponent implements OnInit, DoCheck {
private _localisation = {};
private _config = {};
private _fieldSets: FieldSet[] = [];
......@@ -30,7 +31,18 @@ export class CondDistriComponent implements OnInit {
constructor(private paramService: ParamService, private httpService: HttpService, private intlService: InternationalisationService) {
}
private loadLocalisation() {
// private loadLocalisation() {
// let ths = this;
// let processData = function (s: string) {
// // fermeture nécessaire pour capturer la valeur de this (undefined sinon)
// ths._localisation = JSON.parse(s);
// ths.paramService.updateLocalisation(ths._localisation);
// }
// let f: string = "app/calculators/cond_distri/cond_distri." + this.intlService.languageCode + ".json"
// this.httpService.httpGetRequest(undefined, undefined, undefined, f, processData);
// }
private loadLocalisation(): Promise<string> {
let ths = this;
let processData = function (s: string) {
// fermeture nécessaire pour capturer la valeur de this (undefined sinon)
......@@ -38,9 +50,15 @@ export class CondDistriComponent implements OnInit {
ths.paramService.updateLocalisation(ths._localisation);
}
let f: string = "app/calculators/cond_distri/cond_distri." + this.intlService.currentLanguage.tag + ".json"
let resp: Observable<Response> = this.httpService.httpGetRequestResponse(undefined, undefined, undefined, f);
let f: string = "app/calculators/cond_distri/cond_distri." + this.intlService.languageCode + ".json"
this.httpService.httpGetRequest(undefined, undefined, undefined, f, processData);
let prom = resp.map(res => res.text()).toPromise();
prom.then((res) => {
processData(res);
})
return prom;
}
private logObject(obj: {}) {
......@@ -51,31 +69,25 @@ export class CondDistriComponent implements OnInit {
this._fieldSets = [];
for (let conf_index in this._config) {
//this.logObject(this._fieldSets);
let conf = this._config[conf_index];
//console.log(conf);
let conf_id: string = conf["id"];
if (conf_id.startsWith("fs_")) {
let fieldSet: FieldSet = new FieldSet();
fieldSet.title = this._localisation[conf_id];
let fieldSet: FieldSet = new FieldSet(conf_id);
let fields = conf["fields"];
for (let field_index in fields) {
let field = fields[field_index];
// console.log(field);
if (field["type"] === "input") {
let input_id = field["id"];
// console.log(input_id);
let param = this.paramService.getParameter(input_id);
if (param != undefined) {
//this.logObject(param);
param.unit = field["unit"];
fieldSet.params.push(param);
}
}
}
if (fieldSet.params.length > 0) {
// this.logObject(fieldSet);
this._fieldSets.push(fieldSet);
}
}
......@@ -97,5 +109,35 @@ export class CondDistriComponent implements OnInit {
ngOnInit() {
this.loadLocalisation();
this.loadConfig();
this.updateLanguage();
}
private getFieldSet(id: string) {
for (let fs of this._fieldSets) {
if (fs._id == id)
return fs;
}
return undefined;
}
private updateLanguage() {
for (let conf_index in this._config) {
let conf = this._config[conf_index];
let conf_id: string = conf["id"];
if (conf_id.startsWith("fs_")) {
let fieldSet: FieldSet = this.getFieldSet(conf_id);
fieldSet.title = this._localisation[conf_id];
}
}
}
ngDoCheck() {
if (this.intlService.localeChanged) {
const promise = this.loadLocalisation()
.then(() => {
this.updateLanguage();
});
}
}
}
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var ngparam_1 = require("../../services/ngparam");
var FieldSet = (function () {
function FieldSet() {
this.params = [];
}
FieldSet.prototype.addParameter = function (prm) {
this.params.push(new ngparam_1.NgParameter(prm));
};
return FieldSet;
}());
exports.FieldSet = FieldSet;
var FieldSetComponent = (function () {
function FieldSetComponent() {
}
Object.defineProperty(FieldSetComponent.prototype, "fieldSet", {
set: function (fs) {
this._fieldSet = fs;
},
enumerable: true,
configurable: true
});
return FieldSetComponent;
}());
__decorate([
core_1.Input(),
__metadata("design:type", FieldSet),
__metadata("design:paramtypes", [FieldSet])
], FieldSetComponent.prototype, "fieldSet", null);
FieldSetComponent = __decorate([
core_1.Component({
selector: "field-set",
templateUrl: "./field-set.html",
styles: [".field_set_title {\
font-weight: bold;\
margin: 0.3em 0 0.2em;\
padding: 0.3em;\
background-color: #eeeeee;\
}"]
}),
__metadata("design:paramtypes", [])
], FieldSetComponent);
exports.FieldSetComponent = FieldSetComponent;
//# sourceMappingURL=field-set.component.js.map
\ No newline at end of file
{"version":3,"file":"field-set.component.js","sourceRoot":"","sources":["field-set.component.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAiD;AAIjD,kDAAqD;AAErD;IAII;QACI,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAEM,+BAAY,GAAnB,UAAoB,GAAoB;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,qBAAW,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IACL,eAAC;AAAD,CAAC,AAXD,IAWC;AAXY,4BAAQ;AAuBrB,IAAa,iBAAiB;IAW1B;IACA,CAAC;IALD,sBAAY,uCAAQ;aAApB,UAAqB,EAAY;YAC7B,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACxB,CAAC;;;OAAA;IAIL,wBAAC;AAAD,CAAC,AAbD,IAaC;AANG;IADC,YAAK,EAAE;8BACiB,QAAQ;qCAAR,QAAQ;iDAEhC;AATQ,iBAAiB;IAV7B,gBAAS,CAAC;QACP,QAAQ,EAAE,WAAW;QACrB,WAAW,EAAE,kBAAkB;QAC/B,MAAM,EAAE,CAAC;;;;;UAKH,CAAC;KACV,CAAC;;GACW,iBAAiB,CAa7B;AAbY,8CAAiB"}
\ No newline at end of file
......@@ -5,11 +5,17 @@ import { ParamDefinition } from 'jalhyd';
import { NgParameter } from '../../services/ngparam';
export class FieldSet {
_id: string;
title: string;
params: NgParameter[];
constructor() {
constructor(id: string) {
this.params = [];
this._id = id;
}
get id() {
return this._id;
}
public addParameter(prm: ParamDefinition) {
......
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var param_service_1 = require("../../services/param/param.service");
var ParamFieldLineComponent = (function () {
function ParamFieldLineComponent(paramService) {
this.paramService = paramService;
}
Object.defineProperty(ParamFieldLineComponent.prototype, "symbol", {
/**
* Parameter symbol string
*/
get: function () {
return this._param.symbol;
},
/**
* Parameter symbol (Q, Ks, B, ...) input attribute
*/
set: function (s) {
this._param = this.paramService.getParameter(s);
this._label = this._param.label;
},
enumerable: true,
configurable: true
});
return ParamFieldLineComponent;
}());
__decorate([
core_1.Input(),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], ParamFieldLineComponent.prototype, "symbol", null);
ParamFieldLineComponent = __decorate([
core_1.Component({
selector: "param-field-line",
templateUrl: "./param-field-line.html"
}),
__metadata("design:paramtypes", [param_service_1.ParamService])
], ParamFieldLineComponent);
exports.ParamFieldLineComponent = ParamFieldLineComponent;
//# sourceMappingURL=param-field-line.component.js.map
\ No newline at end of file
{"version":3,"file":"param-field-line.component.js","sourceRoot":"","sources":["param-field-line.component.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAyD;AAEzD,oEAAkE;AAOlE,IAAa,uBAAuB;IAwBhC,iCAAoB,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAC9C,CAAC;IAbD,sBAAY,2CAAM;QAKlB;;WAEG;aACH;YACI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAC9B,CAAC;QAdD;;WAEG;aAEH,UAAmB,CAAS;YACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QACpC,CAAC;;;OAAA;IAWL,8BAAC;AAAD,CAAC,AA1BD,IA0BC;AAdG;IADC,YAAK,EAAE;;;qDAIP;AAfQ,uBAAuB;IAJnC,gBAAS,CAAC;QACP,QAAQ,EAAE,kBAAkB;QAC5B,WAAW,EAAE,yBAAyB;KACzC,CAAC;qCAyBoC,4BAAY;GAxBrC,uBAAuB,CA0BnC;AA1BY,0DAAuB"}
\ No newline at end of file
import { Component, Input, OnInit } from '@angular/core';
import { Component, Input, DoCheck } from '@angular/core';
import { ParamService } from '../../services/param/param.service';
import { NgParameter } from '../../services/ngparam';
......@@ -7,21 +7,35 @@ import { NgParameter } from '../../services/ngparam';
selector: "param-field-line",
templateUrl: "./param-field-line.html"
})
export class ParamFieldLineComponent {
export class ParamFieldLineComponent implements DoCheck {
private _param: NgParameter;
constructor(private paramService: ParamService) {
}
/**
* associated (localised) label
*/
private _label: string;
/**
* associated unit
*/
get _unit(): string {
return this._param.unit;
}
private updateLanguage() {
this._label = this._param.label;
}
/**
* Parameter symbol (Q, Ks, B, ...) input attribute
*/
@Input()
private set symbol(s: string) {
this._param = this.paramService.getParameter(s);
this._label = this._param.label;
this.updateLanguage();
}
/**
......@@ -31,6 +45,7 @@ export class ParamFieldLineComponent {
return this._param.symbol;
}
constructor(private paramService: ParamService) {
public ngDoCheck() {
this.updateLanguage();
}
}
<tr id="tr_FT_rLargeurFond">
<td align="right">{{_label}}</td>
<td align="right">{{_label}} ({{_unit}})</td>
<td>
<!--
......
// cf. https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var forms_1 = require("@angular/forms");
var jalhyd_1 = require("jalhyd");
var param_service_1 = require("../../services/param/param.service");
var internationalisation_service_1 = require("../../services/internationalisation/internationalisation.service");
var ParamInputComponent = ParamInputComponent_1 = (function () {
function ParamInputComponent(paramService, changeDetector, intlService) {
this.paramService = paramService;
this.changeDetector = changeDetector;
this.intlService = intlService;
/**
* flag d'affichage du titre
*/
this.displayTitle = false;
// ControlValueAccessor interface
this.propagateChange = function (_) { };
this._id = ParamInputComponent_1._idGen++;
if (ParamInputComponent_1._startTime == undefined)
ParamInputComponent_1._startTime = new Date().getTime();
this._uiValue = new jalhyd_1.NumericalString();
}
ParamInputComponent.prototype.hasError = function () {
var res = (this._message != undefined);
if (res)
this.log("hasError : true " + this._message);
else
this.log("hasError : false");
return res;
};
ParamInputComponent.prototype.getSfromUI = function () {
return this._fromUI ? " fromUI " : " fromMODEL";
};
ParamInputComponent.prototype.getSParam = function () {
return " " + this._paramDef.symbol + "=" + this._paramDef.toString();
};
ParamInputComponent.prototype.getSUIvalue = function (v) {
if (v === void 0) { v = undefined; }
if (v == undefined)
return " uiValue=" + this._uiValue.toString() + "";
return " uiValue=" + v.toString() + "";
};
ParamInputComponent.prototype.ngOnInit = function () {
// retrieve parameter from symbol
this._paramDef = this.paramService.getParameter(this._paramSymbol);
};
// private getValue() {
// if (this._paramDef.isDefined)
// return this._paramDef.v;
// return "";
// // return this._uiValue.value;
// }
/**
* fonction appelée lorsque l'utilisateur fait une saisie
* @param event valeur du contrôle
*/
ParamInputComponent.prototype.setValue = function (event) {
this._fromUI = true;
this._uiValue.value = event;
this.log(this._uiValue.toString());
return this.validateUIValue();
};
/**
* fonction appelée lors d'un rafraîchissement de l'UI
*/
ParamInputComponent.prototype.ngDoCheck = function () {
this.log("ngDoCheck start : " + this.getSParam() + this.getSUIvalue() + this.getSfromUI());
if (this._fromUI)
this.updateMessage(this._uiValue);
else {
if (this._paramDef.isDefined) {
this.updateMessage(new jalhyd_1.NumericalString(this._paramDef.v));
this._uiValue.value = String(this._paramDef.v);
}
else
this.updateMessage(this._uiValue);
}
this.log("ngDoCheck end : " + this.getSParam() + this.getSUIvalue());
this._fromUI = false;
};
ParamInputComponent.prototype.updateMessage = function (v) {
this.log("updateMessage start :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
if (v.isNumerical) {
this._message = undefined;
try {
this._paramDef.checkValue(v.numericalValue);
}
catch (e) {
if (e instanceof jalhyd_1.ErrorMessage)
this._message = this.intlService.localizeErrorMessage(e);
else
this._message = "invalid value";
}
}
else {
switch (this.intlService.lang) {
case internationalisation_service_1.Language.FRENCH:
this._message = "Veuillez entrer une valeur numérique";
break;
default:
this._message = "Please enter a numerical value";
}
}
this.log("updateMessage end :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
};
ParamInputComponent.prototype.validateUIValue = function () {
this.log("");
this.log("validateValue start : val '" + this._uiValue.toString() + "'" + this.getSParam() + this.getSfromUI());
var ok = this._uiValue.isNumerical;
if (ok) {
try {
if (!this._paramDef.isDefined || this._paramDef.v != this._uiValue.numericalValue) {
this._paramDef.v = this._uiValue.numericalValue;
this.changeDetector.detectChanges(); // provoque une détection des changements dans les contrôles
}
}
catch (e) {
ok = false;
}
}
if (!ok) {
this.log("validateValue end : " + this.getSParam());
var err = {
rangeError: {
// given: val,
given: this._uiValue.toString(),
max: 4,
min: 0
}
};
return err;
}
this.log("validateValue end : " + this.getSParam());
return null;
};
ParamInputComponent.prototype.log = function (m) {
// let t: number = new Date().getTime() - ParamInputComponent._startTime;
// console.log("ParamInputComponent(" + this._id + ") " + t + " : " + m);
};
/*
//From ControlValueAccessor interface
writeValue(value: any) {
if (value !== this.innerValue) {
this.innerValue = value;
}
}
*/
ParamInputComponent.prototype.writeValue = function (value) {
this.log("writeValue " + value);
};
ParamInputComponent.prototype.registerOnChange = function (fn) {
this.propagateChange = fn;
};
ParamInputComponent.prototype.registerOnTouched = function () { };
return ParamInputComponent;
}());
ParamInputComponent._idGen = 0; // A VIRER
__decorate([
core_1.Input('symbol'),
__metadata("design:type", String)
], ParamInputComponent.prototype, "_paramSymbol", void 0);
ParamInputComponent = ParamInputComponent_1 = __decorate([
core_1.Component({
selector: 'param-input[symbol]',
/* OK
<input placeholder="{{_paramDef.symbol}}" [ngModel]="_paramDef.v" (ngModelChange)="setValue($event)"/>
<p *ngIf="_message">{{_message}}</p>
*/
templateUrl: "./param-input.component.html",
providers: [
{
provide: forms_1.NG_VALUE_ACCESSOR,
useExisting: core_1.forwardRef(function () { return ParamInputComponent_1; }),
multi: true
},
{
provide: forms_1.NG_VALIDATORS,
useExisting: core_1.forwardRef(function () { return ParamInputComponent_1; }),
multi: true
}
]
}),
__metadata("design:paramtypes", [param_service_1.ParamService, core_1.ChangeDetectorRef, internationalisation_service_1.InternationalisationService])
], ParamInputComponent);
exports.ParamInputComponent = ParamInputComponent;
var ParamInputComponent_1;
//# sourceMappingURL=param-input.component.js.map
\ No newline at end of file
{"version":3,"file":"param-input.component.js","sourceRoot":"","sources":["param-input.component.ts"],"names":[],"mappings":"AAAA,2FAA2F;;;;;;;;;;;;AAE3F,sCAAiG;AACjG,wCAAqG;AAErG,iCAAwE;AAExE,oEAAkE;AAClE,iHAAyH;AAuBzH,IAAa,mBAAmB;IAmC5B,6BAAoB,YAA0B,EAAU,cAAiC,EAAU,WAAwC;QAAvH,iBAAY,GAAZ,YAAY,CAAc;QAAU,mBAAc,GAAd,cAAc,CAAmB;QAAU,gBAAW,GAAX,WAAW,CAA6B;QAjB3I;;WAEG;QACI,iBAAY,GAAY,KAAK,CAAC;QAkKrC,iCAAiC;QAEjC,oBAAe,GAAG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AAG,GAAX,UAAY,CAAS;QACjB,yEAAyE;QACzE,2EAA2E;IAC/E,CAAC;IAMD;;;;;;;MAOE;IACF,wCAAU,GAAV,UAAW,KAAU;QACjB,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,8CAAgB,GAAhB,UAAiB,EAAO;QACpB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;IAC9B,CAAC;IAED,+CAAiB,GAAjB,cAAsB,CAAC;IAC3B,0BAAC;AAAD,CAAC,AA5MD,IA4MC;AA9LkB,0BAAM,GAAW,CAAC,CAAC,CAAC,UAAU;AAT7C;IADC,YAAK,CAAC,QAAQ,CAAC;;yDACa;AALpB,mBAAmB;IApB/B,gBAAS,CAAC;QACP,QAAQ,EAAE,qBAAqB;QAC/B;;;UAGE;QACF,WAAW,EAAE,8BAA8B;QAC3C,SAAS,EAAE;YACP;gBACI,OAAO,EAAE,yBAAiB;gBAC1B,WAAW,EAAE,iBAAU,CAAC,cAAM,OAAA,qBAAmB,EAAnB,CAAmB,CAAC;gBAClD,KAAK,EAAE,IAAI;aACd;YACD;gBACI,OAAO,EAAE,qBAAa;gBACtB,WAAW,EAAE,iBAAU,CAAC,cAAM,OAAA,qBAAmB,EAAnB,CAAmB,CAAC;gBAClD,KAAK,EAAE,IAAI;aACd;SACJ;KACJ,CAAC;qCAoCoC,4BAAY,EAA0B,wBAAiB,EAAuB,0DAA2B;GAnClI,mBAAmB,CA4M/B;AA5MY,kDAAmB"}
\ No newline at end of file
......@@ -6,7 +6,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl } f
import { ParamDefinition, NumericalString, ErrorMessage } from 'jalhyd';
import { ParamService } from '../../services/param/param.service';
import { InternationalisationService, Language } from '../../services/internationalisation/internationalisation.service';
import { InternationalisationService, LanguageCode } from '../../services/internationalisation/internationalisation.service';
import { NgParameter } from '../../services/ngparam';
@Component({
......@@ -74,10 +74,10 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
hasError(): boolean {
let res = (this._message != undefined);
if (res)
this.log("hasError : true " + this._message);
else
this.log("hasError : false");
// if (res)
// this.log("hasError : true " + this._message);
// else
// this.log("hasError : false");
return res;
}
......@@ -116,7 +116,7 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
private setValue(event: any) {
this._fromUI = true;
this._uiValue.value = event;
this.log(this._uiValue.toString());
// this.log(this._uiValue.toString());
return this.validateUIValue();
}
......@@ -124,7 +124,7 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
* fonction appelée lors d'un rafraîchissement de l'UI
*/
ngDoCheck(): void {
this.log("ngDoCheck start : " + this.getSParam() + this.getSUIvalue() + this.getSfromUI());
// this.log("ngDoCheck start : " + this.getSParam() + this.getSUIvalue() + this.getSfromUI());
if (this._fromUI)
this.updateMessage(this._uiValue);
......@@ -137,13 +137,13 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
this.updateMessage(this._uiValue);
}
this.log("ngDoCheck end : " + this.getSParam() + this.getSUIvalue());
// this.log("ngDoCheck end : " + this.getSParam() + this.getSUIvalue());
this._fromUI = false;
}
private updateMessage(v: NumericalString) {
this.log("updateMessage start :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
// this.log("updateMessage start :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
if (v.isNumerical) {
this._message = undefined;
......@@ -159,8 +159,8 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
}
}
else {
switch (this.intlService.lang) {
case Language.FRENCH:
switch (this.intlService.currentLanguage.code) {
case LanguageCode.FRENCH:
this._message = "Veuillez entrer une valeur numérique";
break;
......@@ -169,12 +169,12 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
}
}
this.log("updateMessage end :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
// this.log("updateMessage end :" + this.getSParam() + this.getSfromUI() + this.getSUIvalue(v) + " message=" + this._message);
}
private validateUIValue() {
this.log("");
this.log("validateValue start : val '" + this._uiValue.toString() + "'" + this.getSParam() + this.getSfromUI());
// this.log("");
// this.log("validateValue start : val '" + this._uiValue.toString() + "'" + this.getSParam() + this.getSfromUI());
let ok: boolean = this._uiValue.isNumerical;
if (ok) {
......@@ -190,7 +190,7 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
}
if (!ok) {
this.log("validateValue end : " + this.getSParam());
// this.log("validateValue end : " + this.getSParam());
let err = {
rangeError: {
......@@ -203,13 +203,13 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec
return err;
}
this.log("validateValue end : " + this.getSParam());
// this.log("validateValue end : " + this.getSParam());
return null;
}
private log(m: string) {
// let t: number = new Date().getTime() - ParamInputComponent._startTime;
// console.log("ParamInputComponent(" + this._id + ") " + t + " : " + m);
let t: number = new Date().getTime() - ParamInputComponent._startTime;
console.log("ParamInputComponent(" + this._id + ") " + t + " : " + m);
}
// ControlValueAccessor interface
......
......@@ -4,13 +4,14 @@ import { CompilerConfig } from '@angular/compiler';
export function getTranslationProviders(): Promise<Object[]> {
// Get the locale id from the global
// const locale = localStorage.getItem('localeId');
const locale = document['locale'] as string;
// return no providers if fail to get translation file for locale
const noProviders: Object[] = [];
// No locale or French: no translation providers
if (!locale || locale === 'fr-FR') {
if (!locale || locale === 'fr-FR' || locale === 'fr') {
return Promise.resolve(noProviders);
}
......
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var http_1 = require("@angular/http");
var HttpService = (function () {
function HttpService(http) {
this.http = http;
}
HttpService.prototype.concat = function (s1, s2) {
if (s1 == undefined)
return s2;
if (s2 == undefined)
return s1;
return s1 + s2;
};
HttpService.prototype.httpGetRequest = function (protocol, host, port, path, processDataCallback) {
var url;
if (protocol != undefined)
url = protocol + "://" + host;
else if (host != undefined)
url = host;
if (port != undefined)
url = this.concat(url, ":" + String(port));
var p = path === "/" ? "" : path;
url = this.concat(url, "/" + p);
//console.log(url);
var enc = encodeURI(url);
var opts = new http_1.RequestOptions();
this.http.get(enc, opts)
.map(function (res) { return res.text(); })
.subscribe(function (data) { return processDataCallback(data); });
};
return HttpService;
}());
HttpService = __decorate([
core_1.Injectable(),
__metadata("design:paramtypes", [http_1.Http])
], HttpService);
exports.HttpService = HttpService;
//# sourceMappingURL=http.service.js.map
\ No newline at end of file
{"version":3,"file":"http.service.js","sourceRoot":"","sources":["http.service.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAA2C;AAC3C,sCAAkF;AAGlF,IAAa,WAAW;IACpB,qBAAoB,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAI,CAAC;IAE3B,4BAAM,GAAd,UAAe,EAAU,EAAE,EAAU;QACjC,EAAE,CAAC,CAAC,EAAE,IAAI,SAAS,CAAC;YAChB,MAAM,CAAC,EAAE,CAAC;QAEd,EAAE,CAAC,CAAC,EAAE,IAAI,SAAS,CAAC;YAChB,MAAM,CAAC,EAAE,CAAC;QAEd,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,CAAC;IAEM,oCAAc,GAArB,UAAsB,QAAgB,EAAE,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,mBAAwC;QACtH,IAAI,GAAW,CAAC;QAChB,EAAE,CAAC,CAAC,QAAQ,IAAI,SAAS,CAAC;YACtB,GAAG,GAAG,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAC;QAClC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;YACvB,GAAG,GAAG,IAAI,CAAC;QAEf,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;YAClB,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAE/C,IAAI,CAAC,GAAG,IAAI,KAAK,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;QACjC,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;QAEhC,mBAAmB;QACnB,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAEzB,IAAI,IAAI,GAAG,IAAI,qBAAc,EAAE,CAAC;QAEhC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC;aACnB,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,IAAI,EAAE,EAAV,CAAU,CAAC;aACtB,SAAS,CACV,UAAA,IAAI,IAAI,OAAA,mBAAmB,CAAC,IAAI,CAAC,EAAzB,CAAyB,CAGpC,CAAC;IACN,CAAC;IACL,kBAAC;AAAD,CAAC,AAvCD,IAuCC;AAvCY,WAAW;IADvB,iBAAU,EAAE;qCAEiB,WAAI;GADrB,WAAW,CAuCvB;AAvCY,kCAAW"}
\ No newline at end of file
import { Injectable } from '@angular/core';
import { Http, RequestOptions, RequestOptionsArgs, Headers } from '@angular/http';
import { Http, RequestOptions, RequestOptionsArgs, Headers, Response } from '@angular/http';
import { Observable } from "rxjs/Observable";
@Injectable()
export class HttpService {
......@@ -16,6 +18,17 @@ export class HttpService {
}
public httpGetRequest(protocol: string, host: string, port: number, path: string, processDataCallback: (s: string) => void) {
let resp: Observable<Response> = this.httpGetRequestResponse(protocol, host, port, path);
resp.map(res => res.text())
.subscribe(
data => processDataCallback(data),
// err => this.logError(err),
// () => console.log('Random Quote Complete')
);
}
public httpGetRequestResponse(protocol: string, host: string, port: number, path: string): Observable<Response> {
let url: string;
if (protocol != undefined)
url = protocol + "://" + host;
......@@ -28,17 +41,11 @@ export class HttpService {
let p = path === "/" ? "" : path;
url = this.concat(url, "/" + p);
//console.log(url);
let enc = encodeURI(url);
let opts = new RequestOptions();
this.http.get(enc, opts)
.map(res => res.text())
.subscribe(
data => processDataCallback(data),
// err => this.logError(err),
// () => console.log('Random Quote Complete')
);
let res: Observable<Response> = this.http.get(enc, opts);
return res;
}
}
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var jalhyd_1 = require("jalhyd");
var http_service_1 = require("../http/http.service");
/*
language tag : fr-FR
primary subcode : fr
optional subcode : FR
*/
var Language;
(function (Language) {
Language[Language["FRENCH"] = 0] = "FRENCH";
Language[Language["ENGLISH"] = 1] = "ENGLISH";
})(Language = exports.Language || (exports.Language = {}));
var InternationalisationService = (function () {
function InternationalisationService(httpService) {
this.httpService = httpService;
}
Object.defineProperty(InternationalisationService.prototype, "lang", {
get: function () {
return this._lang;
},
enumerable: true,
configurable: true
});
// public set lang(l: Language) {
// this._lang = l;
// this._sLang = Language[l];
// }
InternationalisationService.prototype.setLocale = function (tag) {
var l = tag.substr(0, 2).toLowerCase();
if (l === "en")
this._lang = Language.ENGLISH;
else if (l === "fr")
this._lang = Language.FRENCH;
else {
var e = new jalhyd_1.ErrorMessage(jalhyd_1.ErrorCode.ERROR_LANG_UNSUPPORTED);
e.extraVar["locale"] = tag;
throw e;
}
// this.loadErrorMessages();
this.httpGetErrorMessages();
};
Object.defineProperty(InternationalisationService.prototype, "languageCode", {
get: function () {
switch (this._lang) {
case Language.ENGLISH:
return "en";
case Language.FRENCH:
return "fr";
default:
throw new jalhyd_1.ErrorMessage(jalhyd_1.ErrorCode.ERROR_LANG_UNSUPPORTED);
}
},
enumerable: true,
configurable: true
});
// private loadErrorMessages() {
// let l;
// switch (this.lang) {
// case Language.FRENCH:
// l = "fr";
// break;
// default:
// l = "en";
// }
// let s: string = fs.readFileSync("src/error_messages." + l + ".json", "utf8");
// this._errorMessages = JSON.parse(s);
// }
InternationalisationService.prototype.httpGetErrorMessages = function () {
var is = this;
var processData = function (s) {
// fermeture nécessaire pour capturer la valeur de this (undefined sinon)
is._errorMessages = JSON.parse(s);
};
var l;
switch (this.lang) {
case Language.FRENCH:
l = "fr";
break;
default:
l = "en";
}
var f = "error_messages." + l + ".json";
this.httpService.httpGetRequest(undefined, undefined, undefined, "locale/" + f, processData);
};
InternationalisationService.prototype.getErrorMessageFromCode = function (c) {
var sCode = jalhyd_1.ErrorCode[c];
return this._errorMessages[jalhyd_1.ErrorCode[c]];
};
InternationalisationService.prototype.replaceAll = function (str, find, replace) {
return str.replace(new RegExp(find, 'g'), replace);
};
InternationalisationService.prototype.localizeErrorMessage = function (r) {
var sCode = jalhyd_1.ErrorCode[r.code];
var m = this.getErrorMessageFromCode(r.code);
for (var k in r.extraVar) {
m = this.replaceAll(m, "%" + k + "%", r.extraVar[k]);
}
return m;
};
return InternationalisationService;
}());
InternationalisationService = __decorate([
core_1.Injectable(),
__metadata("design:paramtypes", [http_service_1.HttpService])
], InternationalisationService);
exports.InternationalisationService = InternationalisationService;
//# sourceMappingURL=internationalisation.service.js.map
\ 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