123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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; }
- 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; }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class DashboardState
- * @hideconstructor
- * @classdesc This class provides APIs for dashboard avtivity state
- */
- 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) {
- var DashboardState = function (_CallbackInvoker) {
- _inherits(DashboardState, _CallbackInvoker);
- function DashboardState(_ref) {
- var features = _ref.features;
- _classCallCheck(this, DashboardState);
- var _this = _possibleConstructorReturn(this, _CallbackInvoker.call(this, { logger: features.Logger }));
- _this._dashboard = features.API;
- _this._api = APIFactory.createAPI(_this, [DashboardStateAPI]);
- _this._active = false;
- _this._uiState = {
- // active: false, // TODO: Implement me and remove the this._active
- dirty: false,
- authoring: false,
- eventGroups: false,
- fullScreen: false,
- selectionProperties: false,
- focus: false,
- sidePanel: {
- isOpen: false,
- current: null
- }
- };
- return _this;
- } // TODO: Remove this when we remove this._active
- DashboardState.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- return [{
- name: 'post:dashboard.initialize',
- action: this.postDashboardInitialize.bind(this)
- }];
- };
- DashboardState.prototype.postDashboardInitialize = function postDashboardInitialize() {
- var controller = this._dashboard.getFeature('InteractionController.internal');
- this._modeChangeHandler = controller.eventRouter.on('mode:change', this.authoringModeChanged.bind(this));
- this._uiState.authoring = this._dashboard.getMode() !== DashboardAPI.MODES.VIEW;
- return Promise.resolve();
- };
- DashboardState.prototype.getAPI = function getAPI() {
- return this._api;
- };
- DashboardState.prototype.destroy = function destroy() {
- this._uiState = null;
- this._api = null;
- this._active = null;
- if (this._modeChangeHandler) {
- this._modeChangeHandler.remove();
- this._modeChangeHandler = null;
- }
- };
- /**
- * @implements DashboardStateAPI#setDirty
- * @param {boolean} dirty
- */
- DashboardState.prototype.setDirty = function setDirty(dirty) {
- this._uiState.dirty = dirty;
- this._dashboard.setDirty(dirty);
- this._invokeUiChangeCallback();
- };
- /**
- * @implements DashboardStateAPI#onUiStateChange
- * @param {function} callback
- */
- DashboardState.prototype.onUiStateChange = function onUiStateChange(callback) {
- this.registerCallback(DashboardState.UI_CHANGE, callback);
- };
- /**
- * @implements DashboardStateAPI#offUiStateChange
- * @param {function} callback
- */
- DashboardState.prototype.offUiStateChange = function offUiStateChange(callback) {
- this.removeCallback(DashboardState.UI_CHANGE, callback);
- };
- DashboardState.prototype._invokeUiChangeCallback = function _invokeUiChangeCallback() {
- this.invokeCallbacks(DashboardState.UI_CHANGE, this._uiState);
- };
- /**
- * @implements DashboardStateAPI#getUiState
- * @returns {Object} the ui state object @see
- */
- DashboardState.prototype.getUiState = function getUiState() {
- return this._uiState;
- };
- /**
- * @implements DashboardStateAPI#updateStates
- */
- DashboardState.prototype.updateUiState = function updateUiState(_ref2) {
- var _this2 = this;
- var stateChange = _ref2.stateChange;
- try {
- Object.keys(stateChange).forEach(function (stateName) {
- _this2._uiState[stateName] = stateChange[stateName];
- });
- this._invokeUiChangeCallback();
- } catch (error) {
- throw error;
- }
- };
- /**
- * @implements DashboardStateAPI#setAuthoring
- * TODO: the selectionProperties should not be set in the setAuthoring. This
- * needs to be removed.
- */
- DashboardState.prototype.setAuthoring = function setAuthoring(flag) {
- this._uiState.authoring = !!flag;
- if (this._uiState.authoring === true) {
- this._dashboard.setMode(DashboardAPI.MODES.EDIT);
- } else {
- this._dashboard.setMode(DashboardAPI.MODES.VIEW);
- this._uiState.eventGroups = false;
- this._uiState.selectionProperties = false;
- }
- };
- DashboardState.prototype.authoringModeChanged = function authoringModeChanged(event) {
- this._uiState.authoring = !!event.authoring;
- this._invokeUiChangeCallback();
- };
- /**
- * @implements DashboardStateAPI#setSelectionProperties
- */
- DashboardState.prototype.setSelectionProperties = function setSelectionProperties(flag) {
- this._uiState.selectionProperties = !!flag;
- this._invokeUiChangeCallback();
- };
- DashboardState.prototype.setSidePanelOpen = function setSidePanelOpen(state) {
- this._uiState.sidePanel.isOpen = !!state;
- this._invokeUiChangeCallback();
- };
- DashboardState.prototype.setSidePanelCurrentView = function setSidePanelCurrentView(view) {
- this._uiState.sidePanel.current = view;
- this._invokeUiChangeCallback();
- };
- /**
- * @implements DashboardStateAPI#setEventGroups
- * TODO: the selectionProperties should not be set in the setEventGroups. This
- * needs to be removed.
- */
- DashboardState.prototype.setEventGroups = function setEventGroups(flag) {
- var _this3 = this;
- if (this._uiState.authoring === true) {
- this._uiState.eventGroups = !!flag;
- var newMode = void 0;
- if (this._uiState.eventGroups === true) {
- newMode = DashboardAPI.MODES.EDIT_GROUP;
- this._uiState.selectionProperties = false;
- } else {
- newMode = DashboardAPI.MODES.EDIT;
- }
- return this._dashboard.setMode(newMode).then(function () {
- _this3._invokeUiChangeCallback();
- });
- } else {
- this._logger.info('The dashboard is not in the correct mode to perform the EventGroups action');
- }
- };
- DashboardState.prototype.setFullScreen = function setFullScreen(flag) {
- this._uiState.fullScreen = !!flag;
- this._invokeUiChangeCallback();
- };
- /* TODO: The following should be removed/updated to use uiState object */
- /**
- * @implements DashboardStateAPI#isActive
- */
- DashboardState.prototype.isActive = function isActive() {
- return this._active;
- };
- /**
- * @implements DashboardStateAPI#setActive
- */
- DashboardState.prototype.setActive = function setActive(isActive) {
- this._active = isActive;
- this.invokeCallbacks(DashboardState.ON_DASHBOARD_STATE_CHANGE, {
- name: 'change:' + (this._active ? 'active' : 'deactive'),
- info: {
- actionName: 'setActive',
- value: this._active
- }
- });
- };
- /**
- * @implements DashboardStateAPI#onActive
- */
- DashboardState.prototype.onChangeActive = function onChangeActive(callBack) {
- this.registerCallback(DashboardState.ON_DASHBOARD_STATE_CHANGE, callBack);
- };
- return DashboardState;
- }(CallbackInvoker);
- DashboardState.ON_DASHBOARD_STATE_CHANGE = 'dashboardStateChange';
- DashboardState.UI_CHANGE = 'dashboardStateUiChange';
- return DashboardState;
- });
- //# sourceMappingURL=DashboardState.js.map
|