123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- '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 Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (StringResources, APIFactory, ContentActionsProviderAPI) {
- var LassoSelectAction = function () {
- function LassoSelectAction(_ref) {
- var features = _ref.features;
- _classCallCheck(this, LassoSelectAction);
- if (features) {
- this.dashboard = features.API;
- this.icons = features.Icons;
- this._actions = [{
- id: 'lw-lasso-select',
- name: 'lasso',
- icon: 'visualizations-marquee_16',
- label: StringResources.get('toolbarActionLassoSelect')
- }];
- features.ContentActions.registerProvider('lasso', this.getAPI());
- }
- }
- LassoSelectAction.prototype.initialize = function initialize() {
- var _this = this;
- return this.dashboard.getCollectionExtension('com.ibm.bi.dashboard.live-lassoAction').then(function (actions) {
- actions.forEach(function (action) {
- var id = action.id,
- name = action.name,
- icon = action.icon,
- label = action.label;
- _this._actions.push({ id: id, name: name, icon: icon, label: label });
- });
- });
- };
- LassoSelectAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
- }
- return this._api;
- };
- LassoSelectAction.prototype.destroy = function destroy() {
- this.dashboard = null;
- };
- LassoSelectAction.prototype.getContentActionList = function getContentActionList(idList) {
- var _this2 = this;
- if (this._supportAction(idList) && this.content) {
- var visualizationGesture = this.content.getFeature('VisualizationGesture');
- return this._actions.map(function (action) {
- return {
- id: action.id,
- name: action.name,
- label: action.label,
- icon: _this2.icons.getIcon(action.icon) && _this2.icons.getIcon(action.icon).id,
- type: 'Button',
- selected: visualizationGesture ? visualizationGesture.getLassoSelectState() && visualizationGesture.getLassoViewId() === action.id : false,
- order: 50,
- actions: {
- apply: _this2._toggleLassoSelect.bind(_this2, action.id)
- }
- };
- });
- }
- return [];
- };
- LassoSelectAction.prototype._supportAction = function _supportAction(idList) {
- if (!this._isInteractionEnabled('lassoSelect')) {
- return false;
- }
- if (idList.length !== 1) {
- return false;
- }
- if (this.dashboard.getMode() === this.dashboard.MODES.EDIT_GROUP) {
- return false;
- }
- this.content = this.dashboard.getCanvas().getContent(idList[0]);
- if (!this.content) {
- return false;
- }
- var visualization = this.content.getFeature('Visualization');
- if (!visualization || visualization.getDefinition().getState().getError() || !visualization.getSlots().isMappingComplete()) {
- return false;
- }
- var state = this.content.getFeature('state');
- var hasError = Boolean(state && !!state.getError());
- if (hasError) {
- return false;
- }
- return this.content.getType() === 'widget.live' && this._isSupportedVisualizationType(visualization.getType()) && !visualization.getDefinition().getProperty('isSchematic') && !visualization.getDefinition().getProperty('isCustomVis');
- };
- LassoSelectAction.prototype._isSupportedVisualizationType = function _isSupportedVisualizationType(type) {
- var visDefsNoLassoSelect = ['Singleton', 'DataPlayer', 'Crosstab', 'List', 'Hierarchy', 'KPI', 'Pie', 'Wordle', 'Area', 'Dial', 'Bullet', 'DecisionTree', 'Sunburst', 'Spiral', 'DriverAnalysis', 'visualizationPreview', 'snippetList'];
- return !(visDefsNoLassoSelect.indexOf(type) !== -1);
- };
- /**
- * Check whether a particular interaction is enabled.
- * Perspective drives this config.
- *
- * @param {string} name - interaction name
- *
- * @return {boolean} TRUE if interaction is enabled and FALSE if not
- */
- LassoSelectAction.prototype._isInteractionEnabled = function _isInteractionEnabled(name) {
- var config = this._getInteractionConfig();
- if (config.hasOwnProperty(name) && [false, 'false'].indexOf(config[name]) !== -1) {
- return false;
- }
- return true;
- };
- LassoSelectAction.prototype._getInteractionConfig = function _getInteractionConfig() {
- return this.dashboard.getAppConfig('interactions') || {};
- };
- /**
- * Action invoked to toggle laaso selection on a viz
- */
- LassoSelectAction.prototype._toggleLassoSelect = function _toggleLassoSelect(viewId, event) {
- var visualizationGesture = this.content.getFeature('VisualizationGesture');
- if (visualizationGesture) {
- var lassoState = visualizationGesture.getLassoSelectState();
- visualizationGesture.setLassoSelectState(!lassoState, viewId);
- var toolbar = this.content.getFeature('Toolbar.internal');
- if (toolbar) {
- toolbar.refresh();
- } else {
- //Ideally, toolbar should exist for content, but explore doesn't use this feature and have their toolbar ¯\_(ツ)_/¯
- //Manually select the button
- //Future realses will have a better impelemtation.
- var $toolBarItem = event && event.currentTarget;
- if ($toolBarItem) {
- if (lassoState) {
- $toolBarItem.classList.remove('selected');
- } else {
- $toolBarItem.classList.add('selected');
- }
- }
- }
- }
- };
- return LassoSelectAction;
- }();
- return LassoSelectAction;
- });
- //# sourceMappingURL=LassoSelectAction.js.map
|