mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2387] added a stream for pagination size change (#3014)
* [ADF-2387] added a stream for pagination size change * [ADF-2387] added test for page size stream * [ADF-2387] start refactoring adding a general stream for user preference attributes * [ADF-2387] added documentation and test for user values stream
This commit is contained in:
@@ -22,6 +22,14 @@ import { Observable } from 'rxjs/Observable';
|
||||
import { AppConfigService } from '../app-config/app-config.service';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { StorageService } from './storage.service';
|
||||
import 'rxjs/add/operator/distinctUntilChanged';
|
||||
|
||||
export enum UserPreferenceValues {
|
||||
PaginationSize = 'PAGINATION_SIZE',
|
||||
DisableCSRF = 'DISABLE_CSRF',
|
||||
Locale = 'LOCALE',
|
||||
SupportedPageSizes = 'supportedPageSizes'
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UserPreferencesService {
|
||||
@@ -32,8 +40,20 @@ export class UserPreferencesService {
|
||||
locale: 'en'
|
||||
};
|
||||
|
||||
private localeSubject: BehaviorSubject<string> ;
|
||||
private userPreferenceStatus: any = {
|
||||
paginationSize: 25,
|
||||
supportedPageSizes: [5, 10, 15, 20],
|
||||
LOCALE: 'en'
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated we are grouping every value changed on the user preference in a single stream : userPreferenceValue$
|
||||
*/
|
||||
locale$: Observable<string>;
|
||||
private localeSubject: BehaviorSubject<string> ;
|
||||
|
||||
private onChangeSubject: BehaviorSubject<any>;
|
||||
onChange: Observable<any>;
|
||||
|
||||
constructor(
|
||||
public translate: TranslateService,
|
||||
@@ -41,11 +61,22 @@ export class UserPreferencesService {
|
||||
private storage: StorageService,
|
||||
private apiService: AlfrescoApiService
|
||||
) {
|
||||
const currentLocale = this.locale || this.getDefaultLocale();
|
||||
this.localeSubject = new BehaviorSubject(currentLocale);
|
||||
this.initUserPreferenceStatus();
|
||||
this.localeSubject = new BehaviorSubject(this.defaults.locale);
|
||||
this.locale$ = this.localeSubject.asObservable();
|
||||
this.defaults.paginationSize = this.appConfig.get('pagination.size', this.defaults.paginationSize);
|
||||
this.defaults.supportedPageSizes = this.appConfig.get('pagination.supportedPageSizes', this.defaults.supportedPageSizes);
|
||||
this.onChangeSubject = new BehaviorSubject(this.userPreferenceStatus);
|
||||
this.onChange = this.onChangeSubject.asObservable();
|
||||
}
|
||||
|
||||
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.userPreferenceStatus[UserPreferenceValues.DisableCSRF] = this.disableCSRF;
|
||||
}
|
||||
|
||||
select(property: string): Observable<any> {
|
||||
return this.onChange.map((userPreferenceStatus) => userPreferenceStatus[property]).distinctUntilChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,11 +100,12 @@ export class UserPreferencesService {
|
||||
*/
|
||||
set(property: string, value: any) {
|
||||
if (!property) { return; }
|
||||
|
||||
this.storage.setItem(
|
||||
this.getPropertyKey(property),
|
||||
value
|
||||
);
|
||||
this.userPreferenceStatus[property] = value;
|
||||
this.onChangeSubject.next(this.userPreferenceStatus);
|
||||
}
|
||||
|
||||
/** Gets the active storage prefix for preferences. */
|
||||
|
Reference in New Issue
Block a user