From d0d3582de6e59a106b79721c22a98293b8ae2a7a Mon Sep 17 00:00:00 2001 From: "francois.grand" <francois.grand@irstea.fr> Date: Fri, 3 Nov 2017 16:43:08 +0100 Subject: [PATCH] =?UTF-8?q?classe=20ErrorMessage=20renomm=C3=A9e=20en=20Me?= =?UTF-8?q?ssage,=20ErrorCode=20en=20MessageCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/calculators/generic/ngparam.ts | 2 +- .../param-input/param-input.component.ts | 6 ++--- .../remous-results.component.ts | 6 ++--- .../internationalisation.service.ts | 26 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/app/calculators/generic/ngparam.ts b/src/app/calculators/generic/ngparam.ts index f477e9ec5..8d7f12bdb 100644 --- a/src/app/calculators/generic/ngparam.ts +++ b/src/app/calculators/generic/ngparam.ts @@ -1,4 +1,4 @@ -import { ComputeNodeType, ParamDefinition, ParamDomainValue, ErrorMessage } from 'jalhyd'; +import { ComputeNodeType, ParamDefinition, ParamDomainValue } from 'jalhyd'; import { InputField, Dependency, DependencyConditionType, ValueDependencyCondition } from './formulaire'; import { StringMap } from '../../stringmap'; diff --git a/src/app/components/param-input/param-input.component.ts b/src/app/components/param-input/param-input.component.ts index acf2d03f0..47c7e7695 100644 --- a/src/app/components/param-input/param-input.component.ts +++ b/src/app/components/param-input/param-input.component.ts @@ -3,7 +3,7 @@ import { Component, Input, forwardRef, OnInit, DoCheck, ChangeDetectorRef } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl } from '@angular/forms'; -import { ComputeNodeType, ParamDefinition, NumericalString, ErrorMessage } from 'jalhyd'; +import { ComputeNodeType, ParamDefinition, NumericalString, Message } from 'jalhyd'; import { ParamService } from '../../services/param/param.service'; import { InternationalisationService, LanguageCode } from '../../services/internationalisation/internationalisation.service'; @@ -152,8 +152,8 @@ export class ParamInputComponent implements ControlValueAccessor, OnInit, DoChec this._paramDef.checkValue(v.numericalValue); } catch (e) { - if (e instanceof ErrorMessage) - this._message = this.intlService.localizeErrorMessage(e); + if (e instanceof Message) + this._message = this.intlService.localizeMessage(e); else this._message = "invalid value"; } diff --git a/src/app/components/remous-results/remous-results.component.ts b/src/app/components/remous-results/remous-results.component.ts index f26d1c4b8..89358f567 100644 --- a/src/app/components/remous-results/remous-results.component.ts +++ b/src/app/components/remous-results/remous-results.component.ts @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; -import { ErrorMessage } from 'jalhyd'; +import { Message } from 'jalhyd'; import { InternationalisationService } from '../../services/internationalisation/internationalisation.service'; @@ -174,8 +174,8 @@ export class RemousResultsComponent { this._results.push({ "abs": x, "flu": f, "tor": t }); } - public addLogEntry(m: ErrorMessage, nDigits: number) { - this._logEntries.push(this.intlService.localizeErrorMessage(m, nDigits)); + public addLogEntry(m: Message, nDigits: number) { + this._logEntries.push(this.intlService.localizeMessage(m, nDigits)); } public setPenteFond(v: number) { diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index d76b6c925..c1a2ffc6b 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { Response } from '@angular/http'; -import { ErrorMessage, ErrorCode } from "jalhyd"; +import { Message, MessageCode } from "jalhyd"; import { HttpService } from "../http/http.service"; import { Observable } from "../observer"; @@ -47,7 +47,7 @@ export class Language { export class InternationalisationService extends Observable { private _currLang: Language; private _sLang: string; - private _errorMessages: StringMap; + private _Messages: StringMap; private _languages: Language[]; @@ -71,7 +71,7 @@ export class InternationalisationService extends Observable { if (l.code == lc) return l; } - throw new ErrorMessage(ErrorCode.ERROR_LANG_UNSUPPORTED); + throw new Message(MessageCode.ERROR_LANG_UNSUPPORTED); } private getLanguageFromTag(tag: string) { @@ -79,7 +79,7 @@ export class InternationalisationService extends Observable { if (l.tag === tag) return l; } - let e = new ErrorMessage(ErrorCode.ERROR_LANG_UNSUPPORTED); + let e = new Message(MessageCode.ERROR_LANG_UNSUPPORTED); e.extraVar["locale"] = tag; throw e; } @@ -96,17 +96,17 @@ export class InternationalisationService extends Observable { this._currLang = this.getLanguageFromCode(lng); } - let prom = this.httpGetErrorMessages(); + let prom = this.httpGetMessages(); prom.then((res) => { this.notifyObservers(undefined); }) } - private httpGetErrorMessages(): Promise<Response> { + private httpGetMessages(): Promise<Response> { let is: InternationalisationService = this; let processData = function (s: string) { // fermeture nécessaire pour capturer la valeur de this (undefined sinon) - is._errorMessages = JSON.parse(s); + is._Messages = JSON.parse(s); } let l; @@ -123,9 +123,9 @@ export class InternationalisationService extends Observable { return this.httpService.httpGetRequest(undefined, undefined, undefined, "locale/" + f, processData); } - private getErrorMessageFromCode(c: ErrorCode): string { - let sCode: string = ErrorCode[c]; - return this._errorMessages[ErrorCode[c]]; + private getMessageFromCode(c: MessageCode): string { + let sCode: string = MessageCode[c]; + return this._Messages[MessageCode[c]]; } private replaceAll(str: string, find: string, replace: string) { @@ -137,9 +137,9 @@ export class InternationalisationService extends Observable { * @param r message * @param nDigits nombre de chiffres à utiliser pour l'arrondi dans le cas de données numériques */ - public localizeErrorMessage(r: ErrorMessage, nDigits: number = 3): string { - let sCode: string = ErrorCode[r.code]; - let m: string = this.getErrorMessageFromCode(r.code); + public localizeMessage(r: Message, nDigits: number = 3): string { + let sCode: string = MessageCode[r.code]; + let m: string = this.getMessageFromCode(r.code); for (let k in r.extraVar) { let v: any = r.extraVar[k]; -- GitLab