From 63a1bf8d1fa66c200f07fa34dadf790ba1143e90 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Wed, 16 Jun 2021 07:19:34 +0200 Subject: [PATCH] ui: fix language setting on the public interface * Fixes the current language on public interface. * Improves center the text above thumbnail on document brief view. * Moves the document availability at the end of the metadata of the document brief view. * Closes rero/rero-ils#1391. Co-Authored-by: Bertrand Zuchuat --- .../src/app/app-initializer.service.ts | 29 +++++++++++++------ .../src/app/app-initializer.service.spec.ts | 10 +++++-- .../src/app/app-initializer.service.ts | 29 +++++++++++++++++-- .../public-search/src/app/app.component.ts | 11 ++----- .../document-brief.component.html | 15 ++++++---- .../view/thumbnail/thumbnail.component.html | 4 +-- 6 files changed, 69 insertions(+), 29 deletions(-) diff --git a/projects/public-holdings-items/src/app/app-initializer.service.ts b/projects/public-holdings-items/src/app/app-initializer.service.ts index 42ac837fa..e0849c5b8 100644 --- a/projects/public-holdings-items/src/app/app-initializer.service.ts +++ b/projects/public-holdings-items/src/app/app-initializer.service.ts @@ -16,8 +16,9 @@ */ import { Injectable } from '@angular/core'; -import { TranslateService } from '@ngx-translate/core'; +import { TranslateService } from '@rero/ng-core'; import { AppSettingsService, UserService } from '@rero/shared'; +import { AppConfigService } from './app-config-service.service'; @Injectable({ providedIn: 'root' @@ -29,27 +30,37 @@ export class AppInitializerService { * @param _translateService - TranslateService * @param _userService - UserService * @param _appSettingsService - AppSettingsService + * @param _appConfigService - AppConfigService */ constructor( private _translateService: TranslateService, private _userService: UserService, - private _appSettingsService: AppSettingsService + private _appSettingsService: AppSettingsService, + private _appConfigService: AppConfigService ) { } /** Load */ load(): Promise { return new Promise((resolve) => { - this._initiliazeObservable(); + this._userService.loaded$.subscribe(() => { + this.initTranslateService(); + }); this._userService.load(); resolve(true); }); } - /** initialize observable */ - private _initiliazeObservable(): void { - // Set current language interface - this._userService.loaded$.subscribe(() => { - this._translateService.use(this._appSettingsService.currentLanguage); - }); + /** Initialize Translate Service */ + private initTranslateService(): void { + const language = this._appSettingsService.settings.language; + if (language) { + this._translateService.setLanguage(language); + } else { + const browserLang = this._translateService.getBrowserLang(); + this._translateService.setLanguage( + browserLang.match(this._appConfigService.languages.join('|')) ? + browserLang : this._appConfigService.defaultLanguage + ); + } } } diff --git a/projects/public-search/src/app/app-initializer.service.spec.ts b/projects/public-search/src/app/app-initializer.service.spec.ts index 6b40d8134..231e7dd03 100644 --- a/projects/public-search/src/app/app-initializer.service.spec.ts +++ b/projects/public-search/src/app/app-initializer.service.spec.ts @@ -17,13 +17,19 @@ import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; - +import { TranslateModule } from '@ngx-translate/core'; +import { BsLocaleService } from 'ngx-bootstrap/datepicker'; import { AppInitializerService } from './app-initializer.service'; + describe('AppInitializerService', () => { beforeEach(() => TestBed.configureTestingModule({ imports: [ - HttpClientTestingModule + HttpClientTestingModule, + TranslateModule.forRoot() + ], + providers: [ + BsLocaleService ] })); diff --git a/projects/public-search/src/app/app-initializer.service.ts b/projects/public-search/src/app/app-initializer.service.ts index 70c956efc..c7367d31e 100644 --- a/projects/public-search/src/app/app-initializer.service.ts +++ b/projects/public-search/src/app/app-initializer.service.ts @@ -16,7 +16,9 @@ */ import { Injectable } from '@angular/core'; -import { UserService } from '@rero/shared'; +import { TranslateService } from '@rero/ng-core'; +import { AppSettingsService, UserService } from '@rero/shared'; +import { AppConfigService } from './app-config.service'; import { RouteCollectionService } from './routes/route-collection.service'; @Injectable({ @@ -28,19 +30,42 @@ export class AppInitializerService { * Constructor * @param _routeCollectionService - RouteCollectionService * @param _userService - UserService + * @param _appSettingsService - AppSettingsService + * @param _translateService - TranslateService + * @param _appConfigService - AppConfigService */ constructor( private _routeCollectionService: RouteCollectionService, - private _userService: UserService + private _userService: UserService, + private _appSettingsService: AppSettingsService, + private _translateService: TranslateService, + private _appConfigService: AppConfigService ) { } /** load */ load(): Promise { return new Promise((resolve) => { + this._userService.loaded$.subscribe(() => { + this.initTranslateService(); + }); this._userService.load(); this._routeCollectionService.load(); resolve(true); }); } + + /** Initialize Translate Service */ + private initTranslateService(): void { + const language = this._appSettingsService.settings.language; + if (language) { + this._translateService.setLanguage(language); + } else { + const browserLang = this._translateService.getBrowserLang(); + this._translateService.setLanguage( + browserLang.match(this._appConfigService.languages.join('|')) ? + browserLang : this._appConfigService.defaultLanguage + ); + } + } } diff --git a/projects/public-search/src/app/app.component.ts b/projects/public-search/src/app/app.component.ts index 151e47989..4df3b0ed3 100644 --- a/projects/public-search/src/app/app.component.ts +++ b/projects/public-search/src/app/app.component.ts @@ -14,19 +14,12 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -import { Component, OnInit, Injector } from '@angular/core'; -import { TranslateService } from '@rero/ng-core'; +import { Component } from '@angular/core'; @Component({ selector: 'public-search-root', templateUrl: './app.component.html' }) -export class AppComponent implements OnInit { - lang: string = document.documentElement.lang; +export class AppComponent { - constructor(private injector: Injector) { } - - ngOnInit(): void { - this.injector.get(TranslateService).setLanguage(this.lang); - } } diff --git a/projects/public-search/src/app/document-brief/document-brief.component.html b/projects/public-search/src/app/document-brief/document-brief.component.html index 6b43ce421..07710525d 100644 --- a/projects/public-search/src/app/document-brief/document-brief.component.html +++ b/projects/public-search/src/app/document-brief/document-brief.component.html @@ -53,11 +53,7 @@

  • {{ publication.value }}
  • -
    -   - available - not available -
    +
    {{record.explanation|json}}
    + + + + +
    +   + available + not available +
    diff --git a/projects/shared/src/lib/view/thumbnail/thumbnail.component.html b/projects/shared/src/lib/view/thumbnail/thumbnail.component.html index 76a550735..e59bf7ae8 100644 --- a/projects/shared/src/lib/view/thumbnail/thumbnail.component.html +++ b/projects/shared/src/lib/view/thumbnail/thumbnail.component.html @@ -26,10 +26,10 @@ -
    {{ type.subtype }}
    +
    {{ type.subtype }}
    -
    {{ type.main_type }}
    +
    {{ type.main_type }}