'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(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', '../../../visualizations/vipr/properties/VIPRProperties', '../../../util/TransactionUtil'], function (_, APIFactory, PropertiesProviderAPI, VIPRProperties, TransactionUtil) { var ViprPropertyProvider = function () { function ViprPropertyProvider(options) { _classCallCheck(this, ViprPropertyProvider); this.content = options.content; this.dashboard = options.dashboardAPI; this.features = options.features; var Properties = options.features.Properties; Properties.registerProvider(this.getAPI()); this.model = this.content.getFeature('Models.internal').getWidgetModel(); this.content.on('change:visualization:type', this.onVisualizationChange, this); this.content.on('change:visualization:slots', this.onVisualizationChange, this); this.content.on('change:property', this.onVisualizationChange, this); this.VisDefinitions = this.dashboard.getFeature('VisDefinitions'); this.VisDefinitions.on('refresh:definition', this.onVisualizationChange, this); this.state = this.content.getFeature('state'); this.visualization = options.features.Visualization; // TODO - livewidget_cleanup - figure a a cleaner way to clean the property list cache // When the slots or type change, during rendering, we will try to access the property , so if we reset it bebfore rendering, // then we will attempt to generate the property list during rendering and using the old slots mappings and we might get the wrong properties (those props that depend on slots like legend) this.content.on('change:state:status', this.onRenderStateChange, this); this._isChanged = true; } ViprPropertyProvider.prototype.getAPI = function getAPI() { if (!this._api) { this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]); } return this._api; }; ViprPropertyProvider.prototype.destroy = function destroy() { this.content.off('change:state:status', this.onRenderStateChange, this); this.content.off('change:type', this.onVisualizationChange, this); this.content.off('change:property', this.onVisualizationChange, this); this.VisDefinitions.off('refresh:definition', this.onVisualizationChange, this); this.content = null; }; ViprPropertyProvider.prototype.onRenderStateChange = function onRenderStateChange(event) { if (this._isChanged && event.info.value === 'rendered') { this._isChanged = false; this._propertyList = null; this._propertyLayoutList = null; } }; ViprPropertyProvider.prototype.onVisualizationChange = function onVisualizationChange() { this._isChanged = true; }; ViprPropertyProvider.prototype._getLivewidgetInternal = function _getLivewidgetInternal() { if (!this.livewidgetInternal) { this.livewidgetInternal = this.content.getFeature('livewidget.internal'); } return this.livewidgetInternal; }; ViprPropertyProvider.prototype._getView = function _getView() { var lwInternal = this._getLivewidgetInternal(); return lwInternal && lwInternal.getVisView(); }; ViprPropertyProvider.prototype._isVIPR = function _isVIPR() { var renderer = this.visualization.getDefinition().getProperty('renderer'); return renderer && renderer.indexOf('VIPRView') !== -1; }; /** * @param {*} property * @param {*} widget */ ViprPropertyProvider.prototype.modifyPropertyWithSetterAndGetter = function modifyPropertyWithSetterAndGetter(property) { var _this = this; // [livewidget-cleanup] todo: removed the dependenty from widget var propertySupport = this.content.getFeature('Visualization.legacy').getLegacyManagers().visPropertySupport; _.extend(property, { getPropertyValue: function getPropertyValue() { return propertySupport.getPropertyValue(property.id); }, setPropertyValue: function setPropertyValue(value, transactionToken) { _this.updateProperty({ id: property.id, value: value }, transactionToken); }, supportsUndoRedo: true }); }; /** * @returns true if the property is not a 'general' property (i.e. is a * visualization property that can be overriden by a user) */ ViprPropertyProvider.prototype.isAnOverridableVisProperty = function isAnOverridableVisProperty(property) { var commonProps = { 'fillColor': true, 'borderColor': true, 'transparency': true, 'showTitle': true, 'saveTitle': true, 'queryRefresh': true }; return !commonProps[property]; }; ViprPropertyProvider.prototype.updateProperty = function updateProperty(property, transactionToken) { if (this.isAnOverridableVisProperty(property.id)) { var boardModel = this.dashboard.getFeature('internal').getBoardModel(); var options = TransactionUtil.transactionTokenToOptions(transactionToken); var extendedOptions = _.extend({}, options, boardModel.getLanguageModelOptions(true)); var widgetModel = this.content.getFeature('Models.internal').getWidgetModel(); if (property.id.indexOf('colorPalette') > -1) { if (this.features.LiveWidgetSegment) { this.features.LiveWidgetSegment.track({ category: 'colorPalette', visualization: this.content.getFeature('Visualization'), content: this.content, info: { propertyId: property.id, previousValue: this.content.getPropertyValue(property.id), newValue: property.value } }); } } // Update the properties on the vismodel widgetModel.properties.set(property, _.extend({ merge: true, remove: false, silent: true }, extendedOptions)); } }; ViprPropertyProvider.prototype.getPropertyList = function getPropertyList() { var _this2 = this; if (!this._propertyList && this._isVIPR()) { var rawPropertyList = void 0; var visView = this._getView(); if (visView && this.state.getStatus() === this.state.STATUS.RENDERED) { rawPropertyList = visView.getPropertyList(); } else { var slots = this.visualization.getSlots().getSlotList(); var properties = this.visualization.getDefinition().getProperty('vizDefProperties'); rawPropertyList = VIPRProperties.getInstance().getPropertyList(properties, slots, this.content); } if (rawPropertyList) { var propertyList = _.map(rawPropertyList, function (property) { var newProp = _.extend({}, property); _this2.modifyPropertyWithSetterAndGetter(newProp); // If the property is tagged as multilingual and we're in translation mode and we're missing the translation for the current locale if (newProp.editor && newProp.editor.uiControl && newProp.editor.uiControl.multilingual) { var translationService = _this2.dashboard.getFeature('TranslationService'); if (translationService) { var _ref = _this2.model.getMultilingualAttribute(newProp.id) || {}, multilingualProperty = _ref.multilingualProperty; translationService.processMultilingualProperty(newProp, multilingualProperty); } } return newProp; }); this._propertyList = propertyList; } } return this._propertyList; }; ViprPropertyProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() { if (!this._propertyLayoutList && this._isVIPR()) { this._propertyLayoutList = []; var visView = this._getView(); if (visView && this.state.getStatus() === this.state.STATUS.RENDERED) { this._propertyLayoutList = visView.getPropertyLayoutList(); } else { var slots = this.visualization.getSlots().getSlotList(); var properties = this.visualization.getDefinition().getProperty('vizDefProperties'); this._propertyLayoutList = VIPRProperties.getInstance().getPropertyLayoutList(properties, slots, this.content, this.dashboard); } } return this._propertyLayoutList; }; return ViprPropertyProvider; }(); return ViprPropertyProvider; }); //# sourceMappingURL=ViprPropertyProvider.js.map