UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

76 lines (75 loc) 2.48 kB
export const PreferenceGroups = ['system', 'map', 'visual']; /** Contains info/config about preference items the user can change in the UserPreferenceComponent. */ export class UserPreference { constructor(configPath, statePath, group, uiElement, configToStateMapper) { Object.defineProperty(this, "currentValue", { enumerable: true, configurable: true, writable: true, value: undefined }); Object.defineProperty(this, "visible", { enumerable: true, configurable: true, writable: true, value: true }); Object.defineProperty(this, "configPath", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "statePath", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "group", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "uiElement", { enumerable: true, configurable: true, writable: true, value: void 0 }); // The setting value in the config can have a different type as in the state, e.g. string vs object. In these cases, // a mapping function is needed to get from the config value to the value in the state. Object.defineProperty(this, "_configToStateMapper", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "_options", { enumerable: true, configurable: true, writable: true, value: [] }); this.configPath = configPath; this.statePath = statePath; this.group = group; this.uiElement = uiElement; this._configToStateMapper = configToStateMapper || ((valueInConfig) => valueInConfig); } get options() { return this._options; } set options(options) { this._options = options; if (this._options.length === 0) { this.visible = false; } } getCurrentValueForState() { return this._configToStateMapper(this.currentValue); } }