ActiveUI has built-in support for user and role based settings. Depending on the current user and their roles, settings allow to:
A setting is a key-value pair where the key is unique among all the settings and the value can be any native JavaScript type.
ActiveUI uses the Content Server to store and read, in real-time, the settings of the current user.
Everything happens under the settings
folder just under the ActiveUI Content Server root folder.
The fact that settings are stored on the Content Server means that an asynchronous remote request has to be made to fetch their values.
It introduces a small time interval between the application start up and the first response of the Content Server during which reading a setting will always return its default value.
If a user changes their theme setting in order not to use the default one, it can lead to a “glitch” effect. In fact, the application will first be rendered with the default theme but as soon as the user favorite theme is retrieved from the Content Server, the application will re-render everything with the new palette. To avoid this issue you can:
onSync
method of the SettingsManager before rendering anythingLet’s say that our project has:
Then settingExample could be declared in all of these files:
As you can see, there is a concept of preferences and permissions. The idea is that the value of settingExample can be declared both in a permissions and a preferences file. However, the value written in the permissions file will override the one set in preferences. In fact there is a very specific order in which settings files are merged.
For USER_A, the settings files will be merged on top of each others in this order:
The permissions files are merged last and thus override the preferences ones. The ROLE_USER files are merged before the ROLE_MANAGEMENT so that the values written in the ROLE_MANAGEMENT files take precedence over the one in ROLE_USER accordingly to the order in which these roles were granted to the user.
The other thing to notice is the reader and owner roles of the settings files. The only file that USER_A can edit is the users/USER_A/preferences one. It means that if a setting value is specified in a file merged after users/USER_A/preferences, then this value will be enforced to USER_A.
Settings files are written in JSON and have the following structure:
{
"allow": [
/* array of patterns matching settings keys which value should be set to true */
],
"deny": [
/* array of patterns matching settings keys which value should be set to false */
],
"map": {
"settingKey1": "value",
"settingKey2": ["value"],
"...": "..."
}
}
The allow and deny arrays are optionals. They contain regex patterns matching setting keys. If a setting key is matched by an element in the allow array and also in the deny one, it will be set to false. The map object allows to set the value of settings by using their key. If there is a conflict between allow/deny and map, it’s map, which is more explicit, that has the last word.
Let’s say the default settings are:
component1.clickButton1
: truecomponent1.clickButton2
: falsecomponent2.clickButton1
: falsecomponent2.clickButton2
: truecomponent2.clickButton3
: trueand the setting file is:
{
"allow": ["component1..+"],
"deny": ["component1.clickButton2", "component2..+"],
"map": {
"component2.clickButton2": true
}
}
then after applying the allow pattern we get:
component1.clickButton1
: truecomponent1.clickButton2
: truecomponent2.clickButton1
: falsecomponent2.clickButton2
: truecomponent2.clickButton3
: trueafter deny:
component1.clickButton1
: truecomponent1.clickButton2
: falsecomponent2.clickButton1
: falsecomponent2.clickButton2
: falsecomponent2.clickButton3
: falseand finally, after map:
component1.clickButton1
: truecomponent1.clickButton2
: falsecomponent2.clickButton1
: falsecomponent2.clickButton2
: truecomponent2.clickButton3
: falseThe SettingsManager can be retrieved through the ActiveUIAPI.
The list of default settings is available here.