From 94f7648bac2c5f9ee9f0eaf49c2c90e1365687e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= <francois.grand@irstea.fr> Date: Mon, 9 Jul 2018 16:16:21 +0200 Subject: [PATCH] =?UTF-8?q?HttpService.httpGetRequest()=20:=20modif=20pour?= =?UTF-8?q?=20ex=C3=A9cuter=20correctement=20la=20fonction=20de=20traiteme?= =?UTF-8?q?nt=20(processDataCallback)=20dans=20la=20cha=C3=AEne=20des=20Pr?= =?UTF-8?q?omise=20-=20InternationalisationService.setLocale()=20:=20modif?= =?UTF-8?q?=20pour=20ne=20pas=20recharger=20inutilement=20les=20donn=C3=A9?= =?UTF-8?q?es=20d'internationalisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/services/http/http.service.ts | 19 +++++++++---------- .../internationalisation.service.ts | 13 +++++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/app/services/http/http.service.ts b/src/app/services/http/http.service.ts index d99733819..6aea6fb80 100644 --- a/src/app/services/http/http.service.ts +++ b/src/app/services/http/http.service.ts @@ -27,17 +27,16 @@ export class HttpService { public httpGetRequest(protocol: string, host: string, port: number, path: string, processDataCallback: (s: string) => void, errorCallback?: (err: any) => void, - headers?: StringMap): Promise<Response> { - let resp: Observable<Response> = this.httpGetRequestResponse(protocol, host, port, path, headers); + headers?: StringMap): Promise<any> { - resp.map(res => res.text()) - .subscribe( - data => processDataCallback(data), - err => { if (errorCallback) errorCallback(err) }, - // () => console.log('Random Quote Complete') - ); - - return resp.toPromise(); + const prom = this.httpGetRequest2(protocol, host, port, path); + prom.then(data => { + processDataCallback(data); + }).catch(err => { + if (errorCallback) + errorCallback(err) + }); + return prom; } /** diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index dcdc33e13..09194cdd5 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -99,10 +99,15 @@ export class InternationalisationService extends Observable { this._currLang = this.getLanguageFromCode(lng); } - let prom = this.httpGetMessages(); - prom.then((res) => { - this.notifyObservers(undefined); - }) + if (this._currLang.code !== oldLang) { + this._Messages = undefined; + const prom = this.httpGetMessages(); + + const is: InternationalisationService = this; + prom.then((res) => { + is.notifyObservers(undefined); + }) + } } private httpGetMessages(): Promise<Response> { -- GitLab