[ADF-3918] Fix translation issue (#4169)

This commit is contained in:
Eugenio Romano
2019-01-20 23:40:07 +00:00
committed by GitHub
parent 9a70852985
commit 348bee9c6f
22 changed files with 253 additions and 201 deletions

View File

@@ -34,7 +34,9 @@ describe('AppConfigService', () => {
},
files: {
'excluded': ['excluded']
}
},
logLevel: 'silent',
alfrescoRepositoryName: 'alfresco-1'
};
beforeEach(() => {
@@ -127,6 +129,7 @@ describe('AppConfigService', () => {
it('should load external settings', () => {
appConfigService.load().then((config) => {
expect(config).toEqual(mockResponse);
});
});

View File

@@ -38,6 +38,13 @@ export enum AppConfigValues {
LOGIN_ROUTE = 'loginRoute',
DISABLECSRF = 'disableCSRF'
}
export enum Status {
INIT = 'init',
LOADING = 'loading',
LOADED = 'loaded'
}
/* spellchecker: enable */
@Injectable({
@@ -55,7 +62,8 @@ export class AppConfigService {
alfrescoRepositoryName: 'alfresco-1'
};
private onLoadSubject: Subject<any>;
status: Status = Status.INIT;
protected onLoadSubject: Subject<any>;
onLoad: Observable<any>;
constructor(private http: HttpClient) {
@@ -128,19 +136,29 @@ export class AppConfigService {
* @returns Notification when loading is complete
*/
load(): Promise<any> {
return new Promise((resolve) => {
return new Promise(async (resolve) => {
const configUrl = `app.config.json?v=${Date.now()}`;
this.http.get(configUrl).subscribe(
(data: any) => {
this.config = Object.assign({}, this.config, data || {});
this.onLoadSubject.next(this.config);
if (this.status === Status.INIT) {
this.status = Status.LOADING;
await this.http.get(configUrl).subscribe(
(data: any) => {
this.status = Status.LOADED;
this.config = Object.assign({}, this.config, data || {});
this.onLoadSubject.next(this.config);
resolve(this.config);
},
() => {
resolve(this.config);
}
);
} else if (this.status === Status.LOADED) {
resolve(this.config);
} else if (this.status === Status.LOADING) {
this.onLoad.subscribe(() => {
resolve(this.config);
},
() => {
resolve(this.config);
}
);
});
}
});
}

View File

@@ -54,8 +54,7 @@ export abstract class DataTableSchema {
}
public mergeJsonAndHtmlSchema(): any {
let customSchemaColumns = [];
customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml(this.columnList));
let customSchemaColumns = this.getSchemaFromConfig(this.presetColumn).concat(this.getSchemaFromHtml(this.columnList));
if (customSchemaColumns.length === 0) {
customSchemaColumns = this.getDefaultLayoutPreset();
}

View File

@@ -36,6 +36,7 @@ export class AppConfigServiceMock extends AppConfigService {
load(): Promise<any> {
return new Promise((resolve) => {
this.onLoadSubject.next(this.config);
resolve(this.config);
});
}

View File

@@ -1,5 +1,4 @@
<div *ngIf="pagination?.hasMoreItems || isLoading" class="adf-infinite-pagination">
isLoading : {{isLoading}}
<button mat-button
*ngIf="!isLoading"
class="adf-infinite-pagination-load-more"

View File

@@ -27,7 +27,7 @@ import { PaginatedComponent } from './paginated-component.interface';
import { Subscription } from 'rxjs';
import { PaginationComponentInterface } from './pagination-component.interface';
import { PaginationModel } from '../models/pagination.model';
import { UserPreferencesService } from '../services/user-preferences.service';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
@Component({
selector: 'adf-infinite-pagination',
@@ -73,11 +73,14 @@ export class InfinitePaginationComponent implements OnInit, OnDestroy, Paginatio
this.paginationSubscription = this.target.pagination.subscribe((pagination) => {
this.isLoading = false;
this.pagination = pagination;
this.pageSize = this.pageSize || this.userPreferencesService.paginationSize;
this.cdr.detectChanges();
});
}
this.userPreferencesService.select(UserPreferenceValues.PaginationSize).subscribe((pagSize) => {
this.pageSize = this.pageSize || pagSize;
});
if (!this.pagination) {
this.pagination = InfinitePaginationComponent.DEFAULT_PAGINATION;
}

View File

@@ -95,7 +95,7 @@ export class PaginationComponent implements OnInit, OnDestroy, PaginationCompone
}
if (!this.supportedPageSizes) {
this.supportedPageSizes = this.userPreferencesService.getDefaultPageSizes();
this.supportedPageSizes = this.userPreferencesService.supportedPageSizes;
}
if (this.target) {

View File

@@ -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);
}
}

View File

@@ -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);
}
});
}
/**

View File

@@ -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();
});
});

View File

@@ -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';
}
}