mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ADF-3918] Fix translation issue (#4169)
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
||||
SearchApi,
|
||||
Node
|
||||
} from '@alfresco/js-api';
|
||||
import { AlfrescoApiCompatibility } from '@alfresco/js-api';
|
||||
import { AlfrescoApiCompatibility, AlfrescoApiConfig } from '@alfresco/js-api';
|
||||
import { AppConfigService, AppConfigValues } from '../app-config/app-config.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { Subject } from 'rxjs';
|
||||
@@ -42,6 +42,8 @@ export class AlfrescoApiService {
|
||||
|
||||
protected alfrescoApi: AlfrescoApiCompatibility;
|
||||
|
||||
lastConfig: AlfrescoApiConfig;
|
||||
|
||||
getInstance(): AlfrescoApiCompatibility {
|
||||
return this.alfrescoApi;
|
||||
}
|
||||
@@ -126,11 +128,16 @@ export class AlfrescoApiService {
|
||||
oauth2: oauth
|
||||
};
|
||||
|
||||
if (this.alfrescoApi) {
|
||||
if (this.alfrescoApi && this.isDifferentConfig(this.lastConfig, config)) {
|
||||
this.lastConfig = config;
|
||||
this.alfrescoApi.configureJsApi(config);
|
||||
} else {
|
||||
this.lastConfig = config;
|
||||
this.alfrescoApi = new AlfrescoApiCompatibility(config);
|
||||
}
|
||||
}
|
||||
|
||||
isDifferentConfig(lastConfig: AlfrescoApiConfig, newConfig: AlfrescoApiConfig) {
|
||||
return JSON.stringify(lastConfig) !== JSON.stringify(newConfig);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,11 @@ export class TranslationService {
|
||||
}
|
||||
|
||||
userPreferencesService.select(UserPreferenceValues.Locale).subscribe((locale) => {
|
||||
this.userLang = locale;
|
||||
this.use(this.userLang); });
|
||||
if (locale) {
|
||||
this.userLang = locale;
|
||||
this.use(this.userLang);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,22 +19,25 @@ import { TestBed } from '@angular/core/testing';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import { UserPreferencesService } from './user-preferences.service';
|
||||
import { UserPreferencesService, UserPreferenceValues } from './user-preferences.service';
|
||||
import { setupTestBed } from '../testing/setupTestBed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { AppConfigServiceMock } from '../mock/app-config.service.mock';
|
||||
|
||||
describe('UserPreferencesService', () => {
|
||||
|
||||
const defaultPaginationSize: number = 25;
|
||||
const supportedPaginationSize = [5, 10, 15, 20];
|
||||
let preferences: UserPreferencesService;
|
||||
let storage: StorageService;
|
||||
let appConfig: AppConfigService;
|
||||
let appConfig: AppConfigServiceMock;
|
||||
let translate: TranslateService;
|
||||
let changeDisposable: any;
|
||||
|
||||
setupTestBed({
|
||||
imports: [CoreTestingModule]
|
||||
imports: [CoreTestingModule],
|
||||
providers: [
|
||||
{ provide: AppConfigService, useClass: AppConfigServiceMock }
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -56,13 +59,17 @@ describe('UserPreferencesService', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('should get default pagination from app config', () => {
|
||||
it('should get default pagination from app config', (done) => {
|
||||
appConfig.config.pagination.size = 0;
|
||||
expect(preferences.defaults.paginationSize).toBe(defaultPaginationSize);
|
||||
appConfig.load().then(() => {
|
||||
expect(preferences.paginationSize).toBe(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return supported page sizes defined in the app config', () => {
|
||||
const supportedPages = preferences.getDefaultPageSizes();
|
||||
const supportedPages = preferences.supportedPageSizes;
|
||||
appConfig.load();
|
||||
expect(supportedPages).toEqual(supportedPaginationSize);
|
||||
});
|
||||
|
||||
@@ -105,16 +112,6 @@ describe('UserPreferencesService', () => {
|
||||
expect(storage.getItem(propertyKey)).toBe('valueA');
|
||||
});
|
||||
|
||||
it('should store custom pagination settings for default prefix', () => {
|
||||
preferences.paginationSize = 5;
|
||||
expect(preferences.paginationSize).toBe(5);
|
||||
});
|
||||
|
||||
it('should return default paginationSize value', () => {
|
||||
preferences.set('PAGINATION_SIZE', 0);
|
||||
expect(preferences.paginationSize).toBe(defaultPaginationSize);
|
||||
});
|
||||
|
||||
it('should return as default locale the app.config locate as first', () => {
|
||||
appConfig.config.locale = 'fake-locate-config';
|
||||
spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locate-browser');
|
||||
@@ -141,7 +138,7 @@ describe('UserPreferencesService', () => {
|
||||
it('should stream the page size value when is set', (done) => {
|
||||
preferences.paginationSize = 5;
|
||||
changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => {
|
||||
expect(userPreferenceStatus.PAGINATION_SIZE).toBe(5);
|
||||
expect(userPreferenceStatus[UserPreferenceValues.PaginationSize]).toBe(5);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,8 +23,8 @@ import { StorageService } from './storage.service';
|
||||
import { distinctUntilChanged, map } from 'rxjs/operators';
|
||||
|
||||
export enum UserPreferenceValues {
|
||||
PaginationSize = 'PAGINATION_SIZE',
|
||||
Locale = 'LOCALE',
|
||||
PaginationSize = 'paginationSize',
|
||||
Locale = 'locale',
|
||||
SupportedPageSizes = 'supportedPageSizes'
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ export class UserPreferencesService {
|
||||
}
|
||||
|
||||
private initUserPreferenceStatus() {
|
||||
this.userPreferenceStatus[UserPreferenceValues.Locale] = this.locale || this.getDefaultLocale();
|
||||
this.userPreferenceStatus[UserPreferenceValues.PaginationSize] = this.appConfig.get('pagination.size', this.defaults.paginationSize);
|
||||
this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes] = this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
|
||||
this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale()));
|
||||
this.set(UserPreferenceValues.PaginationSize, this.paginationSize);
|
||||
this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(this.supportedPageSizes));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,8 +145,18 @@ export class UserPreferencesService {
|
||||
* Gets an array containing the available page sizes.
|
||||
* @returns Array of page size values
|
||||
*/
|
||||
getDefaultPageSizes(): number[] {
|
||||
return this.userPreferenceStatus[UserPreferenceValues.SupportedPageSizes];
|
||||
get supportedPageSizes(): number[] {
|
||||
let supportedPageSizes = this.get(UserPreferenceValues.SupportedPageSizes);
|
||||
|
||||
if (supportedPageSizes) {
|
||||
return JSON.parse(supportedPageSizes);
|
||||
} else {
|
||||
return this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
|
||||
}
|
||||
}
|
||||
|
||||
set supportedPageSizes(value: number[]) {
|
||||
this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(value));
|
||||
}
|
||||
|
||||
/** Pagination size. */
|
||||
@@ -155,12 +165,18 @@ export class UserPreferencesService {
|
||||
}
|
||||
|
||||
get paginationSize(): number {
|
||||
return Number(this.get(UserPreferenceValues.PaginationSize, this.userPreferenceStatus[UserPreferenceValues.PaginationSize])) || this.defaults.paginationSize;
|
||||
let paginationSize = this.get(UserPreferenceValues.PaginationSize);
|
||||
|
||||
if (paginationSize) {
|
||||
return Number(paginationSize);
|
||||
} else {
|
||||
return Number(this.appConfig.get('pagination.size', this.defaults.paginationSize));
|
||||
}
|
||||
}
|
||||
|
||||
/** Current locale setting. */
|
||||
get locale(): string {
|
||||
return this.get(UserPreferenceValues.Locale, this.userPreferenceStatus[UserPreferenceValues.Locale]);
|
||||
return this.get(UserPreferenceValues.Locale);
|
||||
}
|
||||
|
||||
set locale(value: string) {
|
||||
@@ -172,7 +188,7 @@ export class UserPreferencesService {
|
||||
* @returns Default locale language code
|
||||
*/
|
||||
public getDefaultLocale(): string {
|
||||
return this.appConfig.get<string>('locale') || this.translate.getBrowserCultureLang() || 'en';
|
||||
return this.appConfig.get<string>(UserPreferenceValues.Locale) || this.translate.getBrowserCultureLang() || 'en';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user