DashboardState.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. /**
  11. * @class DashboardState
  12. * @hideconstructor
  13. * @classdesc This class provides APIs for dashboard avtivity state
  14. */
  15. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/impl/CallbackInvoker', '../../../api/DashboardAPI', './DashboardStateAPI'], function (_, APIFactory, CallbackInvoker, DashboardAPI, DashboardStateAPI) {
  16. var DashboardState = function (_CallbackInvoker) {
  17. _inherits(DashboardState, _CallbackInvoker);
  18. function DashboardState(_ref) {
  19. var features = _ref.features;
  20. _classCallCheck(this, DashboardState);
  21. var _this = _possibleConstructorReturn(this, _CallbackInvoker.call(this, { logger: features.Logger }));
  22. _this._dashboard = features.API;
  23. _this._api = APIFactory.createAPI(_this, [DashboardStateAPI]);
  24. _this._active = false;
  25. _this._uiState = {
  26. // active: false, // TODO: Implement me and remove the this._active
  27. dirty: false,
  28. authoring: false,
  29. eventGroups: false,
  30. fullScreen: false,
  31. selectionProperties: false,
  32. focus: false,
  33. sidePanel: {
  34. isOpen: false,
  35. current: null
  36. }
  37. };
  38. return _this;
  39. } // TODO: Remove this when we remove this._active
  40. DashboardState.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
  41. return [{
  42. name: 'post:dashboard.initialize',
  43. action: this.postDashboardInitialize.bind(this)
  44. }];
  45. };
  46. DashboardState.prototype.postDashboardInitialize = function postDashboardInitialize() {
  47. var controller = this._dashboard.getFeature('InteractionController.internal');
  48. this._modeChangeHandler = controller.eventRouter.on('mode:change', this.authoringModeChanged.bind(this));
  49. this._uiState.authoring = this._dashboard.getMode() !== DashboardAPI.MODES.VIEW;
  50. return Promise.resolve();
  51. };
  52. DashboardState.prototype.getAPI = function getAPI() {
  53. return this._api;
  54. };
  55. DashboardState.prototype.destroy = function destroy() {
  56. this._uiState = null;
  57. this._api = null;
  58. this._active = null;
  59. if (this._modeChangeHandler) {
  60. this._modeChangeHandler.remove();
  61. this._modeChangeHandler = null;
  62. }
  63. };
  64. /**
  65. * @implements DashboardStateAPI#setDirty
  66. * @param {boolean} dirty
  67. */
  68. DashboardState.prototype.setDirty = function setDirty(dirty) {
  69. this._uiState.dirty = dirty;
  70. this._dashboard.setDirty(dirty);
  71. this._invokeUiChangeCallback();
  72. };
  73. /**
  74. * @implements DashboardStateAPI#onUiStateChange
  75. * @param {function} callback
  76. */
  77. DashboardState.prototype.onUiStateChange = function onUiStateChange(callback) {
  78. this.registerCallback(DashboardState.UI_CHANGE, callback);
  79. };
  80. /**
  81. * @implements DashboardStateAPI#offUiStateChange
  82. * @param {function} callback
  83. */
  84. DashboardState.prototype.offUiStateChange = function offUiStateChange(callback) {
  85. this.removeCallback(DashboardState.UI_CHANGE, callback);
  86. };
  87. DashboardState.prototype._invokeUiChangeCallback = function _invokeUiChangeCallback() {
  88. this.invokeCallbacks(DashboardState.UI_CHANGE, this._uiState);
  89. };
  90. /**
  91. * @implements DashboardStateAPI#getUiState
  92. * @returns {Object} the ui state object @see
  93. */
  94. DashboardState.prototype.getUiState = function getUiState() {
  95. return this._uiState;
  96. };
  97. /**
  98. * @implements DashboardStateAPI#updateStates
  99. */
  100. DashboardState.prototype.updateUiState = function updateUiState(_ref2) {
  101. var _this2 = this;
  102. var stateChange = _ref2.stateChange;
  103. try {
  104. Object.keys(stateChange).forEach(function (stateName) {
  105. _this2._uiState[stateName] = stateChange[stateName];
  106. });
  107. this._invokeUiChangeCallback();
  108. } catch (error) {
  109. throw error;
  110. }
  111. };
  112. /**
  113. * @implements DashboardStateAPI#setAuthoring
  114. * TODO: the selectionProperties should not be set in the setAuthoring. This
  115. * needs to be removed.
  116. */
  117. DashboardState.prototype.setAuthoring = function setAuthoring(flag) {
  118. this._uiState.authoring = !!flag;
  119. if (this._uiState.authoring === true) {
  120. this._dashboard.setMode(DashboardAPI.MODES.EDIT);
  121. } else {
  122. this._dashboard.setMode(DashboardAPI.MODES.VIEW);
  123. this._uiState.eventGroups = false;
  124. this._uiState.selectionProperties = false;
  125. }
  126. };
  127. DashboardState.prototype.authoringModeChanged = function authoringModeChanged(event) {
  128. this._uiState.authoring = !!event.authoring;
  129. this._invokeUiChangeCallback();
  130. };
  131. /**
  132. * @implements DashboardStateAPI#setSelectionProperties
  133. */
  134. DashboardState.prototype.setSelectionProperties = function setSelectionProperties(flag) {
  135. this._uiState.selectionProperties = !!flag;
  136. this._invokeUiChangeCallback();
  137. };
  138. DashboardState.prototype.setSidePanelOpen = function setSidePanelOpen(state) {
  139. this._uiState.sidePanel.isOpen = !!state;
  140. this._invokeUiChangeCallback();
  141. };
  142. DashboardState.prototype.setSidePanelCurrentView = function setSidePanelCurrentView(view) {
  143. this._uiState.sidePanel.current = view;
  144. this._invokeUiChangeCallback();
  145. };
  146. /**
  147. * @implements DashboardStateAPI#setEventGroups
  148. * TODO: the selectionProperties should not be set in the setEventGroups. This
  149. * needs to be removed.
  150. */
  151. DashboardState.prototype.setEventGroups = function setEventGroups(flag) {
  152. var _this3 = this;
  153. if (this._uiState.authoring === true) {
  154. this._uiState.eventGroups = !!flag;
  155. var newMode = void 0;
  156. if (this._uiState.eventGroups === true) {
  157. newMode = DashboardAPI.MODES.EDIT_GROUP;
  158. this._uiState.selectionProperties = false;
  159. } else {
  160. newMode = DashboardAPI.MODES.EDIT;
  161. }
  162. return this._dashboard.setMode(newMode).then(function () {
  163. _this3._invokeUiChangeCallback();
  164. });
  165. } else {
  166. this._logger.info('The dashboard is not in the correct mode to perform the EventGroups action');
  167. }
  168. };
  169. DashboardState.prototype.setFullScreen = function setFullScreen(flag) {
  170. this._uiState.fullScreen = !!flag;
  171. this._invokeUiChangeCallback();
  172. };
  173. /* TODO: The following should be removed/updated to use uiState object */
  174. /**
  175. * @implements DashboardStateAPI#isActive
  176. */
  177. DashboardState.prototype.isActive = function isActive() {
  178. return this._active;
  179. };
  180. /**
  181. * @implements DashboardStateAPI#setActive
  182. */
  183. DashboardState.prototype.setActive = function setActive(isActive) {
  184. this._active = isActive;
  185. this.invokeCallbacks(DashboardState.ON_DASHBOARD_STATE_CHANGE, {
  186. name: 'change:' + (this._active ? 'active' : 'deactive'),
  187. info: {
  188. actionName: 'setActive',
  189. value: this._active
  190. }
  191. });
  192. };
  193. /**
  194. * @implements DashboardStateAPI#onActive
  195. */
  196. DashboardState.prototype.onChangeActive = function onChangeActive(callBack) {
  197. this.registerCallback(DashboardState.ON_DASHBOARD_STATE_CHANGE, callBack);
  198. };
  199. return DashboardState;
  200. }(CallbackInvoker);
  201. DashboardState.ON_DASHBOARD_STATE_CHANGE = 'dashboardStateChange';
  202. DashboardState.UI_CHANGE = 'dashboardStateUiChange';
  203. return DashboardState;
  204. });
  205. //# sourceMappingURL=DashboardState.js.map