CADashboardPreferences.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../js/features/dashboard/dashboardPreferences/DashboardPreferencesAPI'], function (APIFactory, DashboardPreferencesAPI) {
  9. var CADashboardPreferences = function () {
  10. function CADashboardPreferences() {
  11. _classCallCheck(this, CADashboardPreferences);
  12. this._preferences = {};
  13. this._dirtyPreferences = {};
  14. }
  15. CADashboardPreferences.prototype.initialize = function initialize(glassContext) {
  16. this._glassContext = glassContext;
  17. this._api = APIFactory.createAPI(this, [DashboardPreferencesAPI]);
  18. this._userProfile = glassContext.getCoreSvc('.UserProfile');
  19. this._logger = glassContext.getCoreSvc('.Logger');
  20. this._preferences = this._userProfile.preferences;
  21. };
  22. CADashboardPreferences.prototype.getAPI = function getAPI() {
  23. return this._api;
  24. };
  25. CADashboardPreferences.prototype.getPreference = function getPreference(name) {
  26. return this._preferences[name];
  27. };
  28. CADashboardPreferences.prototype._isValidValue = function _isValidValue(value) {
  29. return value === null || typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number';
  30. };
  31. CADashboardPreferences.prototype.setPreference = function setPreference(name, value) {
  32. if (this._isValidValue(value)) {
  33. this._preferences[name] = value;
  34. this._dirtyPreferences[name] = value;
  35. } else {
  36. throw new Error('Invalid value type', value);
  37. }
  38. };
  39. CADashboardPreferences.prototype.savePreferences = function savePreferences() {
  40. var _this = this;
  41. var response = void 0;
  42. if (Object.keys(this._dirtyPreferences).length === 0) {
  43. this._logger.info('No preferences to save to CM');
  44. response = Promise.resolve();
  45. } else {
  46. response = this._userProfile.savePreferences(this._dirtyPreferences).then(function () {
  47. _this._dirtyPreferences = {};
  48. });
  49. }
  50. return response;
  51. };
  52. return CADashboardPreferences;
  53. }();
  54. return CADashboardPreferences;
  55. });
  56. //# sourceMappingURL=CADashboardPreferences.js.map