123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../js/features/dashboard/dashboardPreferences/DashboardPreferencesAPI'], function (APIFactory, DashboardPreferencesAPI) {
- var CADashboardPreferences = function () {
- function CADashboardPreferences() {
- _classCallCheck(this, CADashboardPreferences);
- this._preferences = {};
- this._dirtyPreferences = {};
- }
- CADashboardPreferences.prototype.initialize = function initialize(glassContext) {
- this._glassContext = glassContext;
- this._api = APIFactory.createAPI(this, [DashboardPreferencesAPI]);
- this._userProfile = glassContext.getCoreSvc('.UserProfile');
- this._logger = glassContext.getCoreSvc('.Logger');
- this._preferences = this._userProfile.preferences;
- };
- CADashboardPreferences.prototype.getAPI = function getAPI() {
- return this._api;
- };
- CADashboardPreferences.prototype.getPreference = function getPreference(name) {
- return this._preferences[name];
- };
- CADashboardPreferences.prototype._isValidValue = function _isValidValue(value) {
- return value === null || typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number';
- };
- CADashboardPreferences.prototype.setPreference = function setPreference(name, value) {
- if (this._isValidValue(value)) {
- this._preferences[name] = value;
- this._dirtyPreferences[name] = value;
- } else {
- throw new Error('Invalid value type', value);
- }
- };
- CADashboardPreferences.prototype.savePreferences = function savePreferences() {
- var _this = this;
- var response = void 0;
- if (Object.keys(this._dirtyPreferences).length === 0) {
- this._logger.info('No preferences to save to CM');
- response = Promise.resolve();
- } else {
- response = this._userProfile.savePreferences(this._dirtyPreferences).then(function () {
- _this._dirtyPreferences = {};
- });
- }
- return response;
- };
- return CADashboardPreferences;
- }();
- return CADashboardPreferences;
- });
- //# sourceMappingURL=CADashboardPreferences.js.map
|