Skip to content

user preferences

“Preferences” is a custom metadata column which can be added to any model. ‘User preferences’ is currently in use some, but other objects (a company, or a hospital site, for example) might also have ‘preferences’ of some type that would be useful to save/load/manage.

hasPrefs trait

A HasPrefs trait exists and is used on User model currently.

defaults for user

The trait has a ‘boot’ method which will call a ‘setDefaults’ method.
The setDefaults will check if the model is a User model. If so, it will check the type, and associate a set of default preferences defined in config/preferences for various user types.

methods

setDefaults(model) - set default values for the model getPref(key) - get single value setPref(key, val) - set single value setAllPrefs(array) - set all values saveAllPrefs(array) - set and save all values getAllPrefs() - get all preferences as array