Stores preferences for the app and for individual components.
string
, defaultValue?: string
): string
string
- Name of the propertystring
- (Optional) Default to return if the property is not foundstring
- Preference propertystring
string
- Default locale language codestring
): string
string
- The property namestring
- Property keystring
string
- Storage prefixstring
): boolean
string
- Name of the propertyboolean
- True if the item is present, false otherwisestring
): Observable
<any>
string
- The property to watchObservable
<any>
- Notification callbackstring
, value: any
)string
- Name of the propertyany
- New value for the propertystring
)string
- Name of the prefixstring
, value: any
)string
- Name of the propertyany
- New value for the propertyThe preferences are bound to a particular prefix
so the application can switch between different profiles on demand.
For example, upon login you can set the prefix
to the current username:
import { UserPreferencesService, AuthenticationService } from '@alfresco/adf-core';
@Component({...})
class AppComponent {
constructor(private userPreferences: UserPreferencesService,
private authService: AuthenticationService) {
}
onLoggedIn() {
this.userPreferences.setStoragePrefix(
this.authService.getEcmUsername()
);
}
}
As soon as you assign the storage prefix, all settings that you get or set via the UserPreferencesService
will be saved to a dedicated profile.
You can import the service into your controller and use its APIs as shown below:
@Component({...})
class AppComponent {
constructor(userPreferences: UserPreferencesService) {
userPreferences.set('myProperty1', 'value1');
userPreferences.set('myProperty2', 'value2');
console.log(
userPreferences.get('myProperty1')
);
}
}
The service also provides quick access to a set of the "known" properties used across ADF components:
Name | Type | Description |
---|---|---|
authType | string | Authorization type (can be "ECM", "BPM" or "ALL"). |
disableCSRF | boolean | Prevents the CSRF Token from being submitted if true. Only valid for Process Services. |
paginationSize | number | Pagination size. |
locale | string | Current locale setting. |
Whenever a property is set with the user preferences service, an onChange
event is sent with the
whole set of user properties. This is useful when a component needs to react to a property change:
userPreferences.paginationSize = 10;
userPreferences.onChange().subscribe((userStatusValues) => {
console.log(userStatusValues.PAGINATION_SIZE); //this will be 10
});
You can also use the select
method to get notification when a particular property is changed.
A set of basic properties is added into the enumeration UserPreferenceValues
which gives you the key value to access the standard user preference service properties : PaginationSize, DisableCSRF, Locale, SupportedPageSizes and ExpandedSideNavStatus.
userPreferences.disableCSRF = true;
userPreferences.select(UserPreferenceValues.DisableCSRF).subscribe((CSRFflag) => {
console.log(CSRFflag); //this will be true;
});
© 2023 Alfresco Software, Inc. All Rights Reserved.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.