not store locale if not present in app.config.json or changed by the language picker (#4431)

This commit is contained in:
Eugenio Romano
2019-03-13 16:50:34 +00:00
committed by GitHub
parent 5193a42983
commit 2b5b915d55
2 changed files with 30 additions and 1 deletions

View File

@@ -135,6 +135,14 @@ describe('UserPreferencesService', () => {
expect(preferences.locale).toBe('fake-store-locate');
});
it('should not store in the storage the locale if the app.config.json does not have a value', () => {
preferences.locale = 'fake-store-locate';
spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locate-browser');
expect(preferences.locale).toBe('fake-store-locate');
expect(storage.getItem(UserPreferenceValues.Locale)).toBe(null);
});
it('should stream the page size value when is set', (done) => {
preferences.paginationSize = 5;
changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => {

View File

@@ -52,11 +52,19 @@ export class UserPreferencesService {
}
private initUserPreferenceStatus() {
this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale()));
this.initUserLanguage();
this.set(UserPreferenceValues.PaginationSize, this.paginationSize);
this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(this.supportedPageSizes));
}
private initUserLanguage() {
if (this.locale || this.appConfig.get<string>(UserPreferenceValues.Locale)) {
this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale()));
} else {
this.setWithoutStore(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale()));
}
}
/**
* Sets up a callback to notify when a property has changed.
* @param property The property to watch
@@ -102,6 +110,19 @@ export class UserPreferencesService {
this.onChangeSubject.next(this.userPreferenceStatus);
}
/**
* Sets a preference property.
* @param property Name of the property
* @param value New value for the property
*/
setWithoutStore(property: string, value: any) {
if (!property) {
return;
}
this.userPreferenceStatus[property] = value;
this.onChangeSubject.next(this.userPreferenceStatus);
}
/**
* Check if an item is present in the storage
* @param property Name of the property