DashboardPreferences.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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', './DashboardPreferencesAPI'], function (APIFactory, DashboardPreferencesAPI) {
  9. var DashboardPreferences = function () {
  10. function DashboardPreferences() {
  11. _classCallCheck(this, DashboardPreferences);
  12. this._api = APIFactory.createAPI(this, [DashboardPreferencesAPI]);
  13. this._preferences = {};
  14. }
  15. DashboardPreferences.prototype.initialize = function initialize() {
  16. try {
  17. var storageValue = window.localStorage.getItem('dashboardPreferences');
  18. if (storageValue !== null) {
  19. try {
  20. this._preferences = JSON.parse(storageValue);
  21. } catch (err) {
  22. this._preferences = {};
  23. }
  24. }
  25. return Promise.resolve();
  26. } catch (err) {
  27. return Promise.reject(err);
  28. }
  29. };
  30. DashboardPreferences.prototype.getAPI = function getAPI() {
  31. return this._api;
  32. };
  33. DashboardPreferences.prototype.getPreference = function getPreference(name) {
  34. return this._preferences[name];
  35. };
  36. DashboardPreferences.prototype.setPreference = function setPreference(name, value) {
  37. this._preferences[name] = value;
  38. };
  39. DashboardPreferences.prototype.savePreferences = function savePreferences() {
  40. var response = Promise.resolve();
  41. try {
  42. window.localStorage.setItem('dashboardPreferences', JSON.stringify(this._preferences));
  43. } catch (err) {
  44. response = Promise.reject(err);
  45. }
  46. return response;
  47. };
  48. return DashboardPreferences;
  49. }();
  50. return DashboardPreferences;
  51. });
  52. //# sourceMappingURL=DashboardPreferences.js.map