123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- '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: BI Cloud (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../../../../widgets/livewidget/nls/StringResources', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../api/DataPointActionsProviderAPI', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../util/ContentUtil'], function (_, stringResources, APIFactory, DataPointActionsProviderAPI, ContentActionsProviderAPI, ContentUtil) {
- var PROPERTYNAME = 'hiddenRowsAndColumns';
- var LOCALVIS = ['crosstab'];
- var HideRowColumnAction = function () {
- function HideRowColumnAction(_ref) {
- var dashboardAPI = _ref.dashboardAPI,
- content = _ref.content,
- features = _ref.features;
- _classCallCheck(this, HideRowColumnAction);
- this.dashboard = dashboardAPI || features && features.API;
- this.icons = features['Icons'] || features['Dashboard.Icons'];
- if (content) {
- // dataPointAction will pass in the content api
- this.content = content;
- if (features) {
- features.DataPointActions.registerProvider('HideRowColumnAction', this.getAPI());
- }
- } else {
- features && features.ContentActions.registerProvider('HideRowColumnAction', this.getAPI());
- }
- }
- HideRowColumnAction.prototype.getDataPointActionList = function getDataPointActionList(selections, options) {
- if (this._isLocalVis() && this._supportDataPointAction() && options.isAreaSelected) {
- this.selectedArea = ContentUtil.getContextFromSelection(this.content, this.dashboard);
- // if the selection is not valid, disable the action
- if (!this.selectedArea.length) {
- return [];
- }
- this.isAreaSelected = true;
- var iconHide = this.icons.getIcon('iconHide');
- return this._getContribution('Datapoint', stringResources.get('hideRowColumn'), iconHide, false);
- }
- return [];
- };
- HideRowColumnAction.prototype._supportDataPointAction = function _supportDataPointAction() {
- if (this.content.getFeature('state').getError() || this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
- return false;
- }
- return true;
- };
- /**
- * widgetAction interface
- * @param {*} idList
- */
- HideRowColumnAction.prototype.getContentActionList = function getContentActionList(idList) {
- var contentId = idList[0];
- this.content = this.dashboard.getCanvas().getContent(contentId);
- if (this._isLocalVis() && this._supportContentAction(idList)) {
- var iconView = this.icons.getIcon('iconView');
- return this._getContribution('Content', stringResources.get('showAllRowColumn'), iconView, this._isHidden());
- }
- return [];
- };
- HideRowColumnAction.prototype._getContribution = function _getContribution(actionOrigin, actionName, icon, isDisabled) {
- return [{
- name: 'hideRowColumnAction' + actionOrigin,
- label: actionName,
- icon: icon.id,
- type: 'Button',
- closeOnActionApplied: true,
- disabled: isDisabled,
- actions: {
- apply: this.onStateChange.bind(this)
- }
- }];
- };
- HideRowColumnAction.prototype._supportContentAction = function _supportContentAction(idList) {
- if (idList && idList.length > 1 || this.content.getFeature('state').getError() || this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
- return false;
- }
- return true;
- };
- HideRowColumnAction.prototype._isLocalVis = function _isLocalVis() {
- var visFeature = this.content.getFeature('Visualization');
- var visId = visFeature && visFeature.getDefinition().getId();
- return !!visId && _.contains(LOCALVIS, visId);
- };
- HideRowColumnAction.prototype.onStateChange = function onStateChange() {
- var propertyList = [];
- propertyList = this._buildPropertyList(propertyList);
- var transactionToken = this.dashboard.getFeature('Transaction').startTransaction();
- this.setProperties(propertyList, transactionToken);
- this._removeFilters(transactionToken);
- this.dashboard.getFeature('Transaction').endTransaction(transactionToken);
- };
- HideRowColumnAction.prototype._isHidden = function _isHidden() {
- return _.isEmpty(this.content.getPropertyValue(PROPERTYNAME) || []);
- };
- HideRowColumnAction.prototype._buildPropertyList = function _buildPropertyList(propertyList) {
- var newPropertyVal = [];
- if (this.isAreaSelected) {
- var currentPropertyValue = this.content.getPropertyValue(PROPERTYNAME) || [];
- newPropertyVal = _.union(this.selectedArea, currentPropertyValue);
- }
- propertyList.push({ 'id': PROPERTYNAME, 'value': newPropertyVal });
- return propertyList;
- };
- /**
- * This method sets the vis properties to the value given
- * @param propertyList - the propertyList that trigerred the state change
- */
- HideRowColumnAction.prototype.setProperties = function setProperties(propertyList, transactionToken) {
- var _this = this;
- propertyList.forEach(function (prop) {
- _this.content.setPropertyValue(prop.id, prop.value, transactionToken);
- });
- };
- HideRowColumnAction.prototype._removeFilters = function _removeFilters(transactionToken) {
- this.dashboard.getFeature('GlobalFilters').removeFilters(ContentUtil.getSelectors(this.content, this.dashboard), transactionToken);
- };
- HideRowColumnAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- return APIFactory.createAPI(this, [DataPointActionsProviderAPI, ContentActionsProviderAPI]);
- }
- return this._api;
- };
- return HideRowColumnAction;
- }();
- return HideRowColumnAction;
- });
- //# sourceMappingURL=HideRowColumnAction.js.map
|