'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, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * @class DashboardServiceability * @hideconstructor * @classdesc API class that is used to manage DashboardServiceability * (including the corrsponding view) across API calls */ define(['jquery', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/core-client/js/core-client/ui/KeyCodes', './api/DashboardServiceabilityAPI'], function ($, APIFactory, KeyCodes, DashboardServiceabilityAPI) { var DashboardServiceability = function () { function DashboardServiceability(options) { var _this = this; _classCallCheck(this, DashboardServiceability); this._dashboardApi = options.features['API']; this._selectedContent = null; this._selectedContentIds = []; this._keysPressed = []; this._slideout = null; this._openPromise = null; this._closePromise = null; this._dashboardState = null; this._callback = function (event) { this._keyUpDownCallback(event); }.bind(this); this._dashboardState = options.features['DashboardState']; this._isInfoVisible = false; this._dashboardApi.getCanvasWhenReady().then(function (canvas) { _this.canvas = canvas; canvas.on('change:selections:select', _this.onContentSelection, _this); canvas.on('change:selections:deselect', _this.onContentDeselection, _this); }); } DashboardServiceability.prototype.getAPI = function getAPI() { return this._api; }; DashboardServiceability.prototype.initialize = function initialize() { this._api = APIFactory.createAPI(this, [DashboardServiceabilityAPI]); this._dashboardState.onChangeActive(this.dashboardStateCallback.bind(this)); return new Promise.resolve(); }; DashboardServiceability.prototype.showS12yView = function showS12yView(widgetInfo) { return this._dashboardApi.showSlideOut({ 'width': 400, 'position': 'right', 'content': { 'module': 'dashboard-core/js/features/dashboard/dashboardServiceability/view/ServiceabilityView', id: 's12ySlideoutContainer', widgetInfo: widgetInfo, dashboardApi: this._dashboardApi }, resizable: { min: 400 } }); }; DashboardServiceability.prototype.openPanel = function openPanel() { this._closePromise = null; this._openPromise = Promise.resolve(false); if (this._selectedContent) { var widgetIsReady = this._selectedContent.getFeature('Serviceability') === undefined ? false : true; if (widgetIsReady) { this._slideout = this.showS12yView(this._selectedContent.getFeature('Serviceability').getContentInfo()); if (this._slideout) { this._openPromise = this._monitorOpeningSlideout(); } } } return this._openPromise; }; DashboardServiceability.prototype._monitorOpeningSlideout = function _monitorOpeningSlideout() { var _this2 = this; return new Promise(function (resolve) { if (_this2._slideout) { _this2._slideout.on('done:show', function () { resolve(true); }); _this2._slideout.on('hide', function () { _this2._slideout = null; }); } }); }; DashboardServiceability.prototype.closePanel = function closePanel() { this._openPromise = null; this._closePromise = Promise.resolve(); if (this._slideout) { this._slideout.hide(); this._closePromise = this._monitorClosingSlideout(); } return this._closePromise; }; DashboardServiceability.prototype.showInfo = function showInfo() { this._isInfoVisible = true; this._dashboardApi.getCanvas().findContent().forEach(function (content) { var serviceabilityFeature = content.getFeature('Serviceability'); if (serviceabilityFeature) { serviceabilityFeature.showInfo(); } }); }; DashboardServiceability.prototype.hideInfo = function hideInfo() { this._isInfoVisible = false; this._dashboardApi.getCanvas().findContent().forEach(function (content) { var serviceabilityFeature = content.getFeature('Serviceability'); if (serviceabilityFeature) { serviceabilityFeature.hideInfo(); } }); }; /** * @implements DashboardServiceabilityAPI.isRenderTimeOn */ DashboardServiceability.prototype.isInfoVisible = function isInfoVisible() { return this._isInfoVisible; }; DashboardServiceability.prototype._monitorClosingSlideout = function _monitorClosingSlideout() { var _this3 = this; return new Promise(function (resolve) { if (_this3._slideout) { _this3._slideout.on('hide', function () { _this3._slideout = null; resolve(); }); } else { resolve(); } }); }; DashboardServiceability.prototype.getPanelState = function getPanelState() { var _this4 = this; var promise = this._openPromise || this._closePromise || Promise.resolve(); return promise.then(function () { return { isOpen: _this4._slideout !== null }; }); }; DashboardServiceability.prototype.onContentSelection = function onContentSelection(event) { var _this5 = this; event.info.value.forEach(function (id) { var content = _this5._dashboardApi.getCanvas().getContent(id); if (content && content.getFeature('Serviceability')) { _this5._selectedContentIds.push(id); } }); this._updateSelectedWidget(); }; /** * @description One of the tasks this method needs to do is hiding info on * contents when selecting another tab. Listening to `change:selections:deselect` * event is necessary because re-selecting the same tab will also trigger an * `change:selections:select` event hence we cannot tell if we're selecting a different * tab or not. Another taks of this method is to remove some contents from the * internal _selectedContent variable. * @param {Object} event */ DashboardServiceability.prototype.onContentDeselection = function onContentDeselection(event) { var _this6 = this; this._selectedContentIds = this._selectedContentIds.filter(function (id) { return event.info.value.indexOf(id) === -1; }); this._updateSelectedWidget(); event.info.value.forEach(function (id) { var content = _this6._dashboardApi.getCanvas().getContent(id); if (content && content.getType() === 'page') { _this6.hideInfo(); } }); }; DashboardServiceability.prototype.setSelectedWidget = function setSelectedWidget(widget) { this._selectedContent = widget; }; DashboardServiceability.prototype._updateSelectedWidget = function _updateSelectedWidget() { this._selectedContent = null; if (this._selectedContentIds.length == 1) { var id = this._selectedContentIds[0]; this.setSelectedWidget(this._dashboardApi.getCanvas().getContent(id)); } }; DashboardServiceability.prototype.destroy = function destroy() { if (this.canvas) { this.canvas.off('change:selections:select', this.onContentSelection, this); this.canvas.off('change:selections:deselect', this.onContentDeselection, this); this.canvas = null; } $('body').off('keydown.serviceability', this._callback); $('body').off('keyup.serviceability', this._callback); this._api = null; this._slideout = null; this._selectedContentIds = null; this._dashboardApi = null; this._keysPressed = null; this._dashboardState = null; }; DashboardServiceability.prototype.dashboardStateCallback = function dashboardStateCallback(payload) { if (payload.info.value === true) { $('body').on('keydown.serviceability', this._callback); $('body').on('keyup.serviceability', this._callback); } else { $('body').off('keydown.serviceability', this._callback); $('body').off('keyup.serviceability', this._callback); } }; DashboardServiceability.prototype._keyUpDownCallback = function _keyUpDownCallback(e) { if (e.type === 'keydown' && !(this._keysPressed.indexOf(e.keyCode) >= 0)) { if (this._keysPressed.length === 2) { this._keysPressed.shift(); } this._keysPressed.push(e.keyCode); } if (e.type === 'keyup' && this._keysPressed.indexOf(e.keyCode) >= 0) { var index = this._keysPressed.indexOf(e.keyCode); this._keysPressed.splice(index, 1); } if (this._keysReady()) { this.openPanel(); this._keysPressed = []; } }; DashboardServiceability.prototype._keysReady = function _keysReady() { return this._keysPressed.length === 2 && this._keysPressed[0] === KeyCodes.CTRL && this._keysPressed[1] === KeyCodes.PERIOD; }; return DashboardServiceability; }(); return DashboardServiceability; }); //# sourceMappingURL=DashboardServiceability.js.map