'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard * (C) Copyright IBM Corp. 2013, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * * VisModelManager * INTENT: VisModelManager object is a top-level manager for the LiveWidgetModel and its sub-managers. * It has an api for use by external callers and the renderer. * TODO: The functionality in this class should be investigated and moved into more focused sub-objects. * * The VisModelManager owns VisDataSlots and VisProperties that the renderer pieces render, * interactivity modifies and save persists. * * It also has utilities to ease access for Visualization items to data-oriented actions * (like querying/filtering). */ define(['underscore', '../../../../lib/@waca/core-client/js/core-client/ui/core/Events'], function (_, Events) { 'use strict'; var VisModelManagerLeftover = null; // class declaration VisModelManagerLeftover = Events.extend({ init: function init(options) { VisModelManagerLeftover.inherited('init', this, arguments); this.content = options.content; this.widgetModel = options.widgetModel; this.ownerWidget = options.ownerWidget; this.dashboardApi = options.dashboardApi; }, /** * * @returns customDataSelection is enable or not */ _isCustomDataSelectionEnabled: function _isCustomDataSelectionEnabled() { return this.dashboardApi.getAppConfig('enableCustomDataSelection') || this.supportsCustomDataSelection(); }, supportsCustomDataSelection: function supportsCustomDataSelection() { return this.content.getFeature('Visualization').getDefinition().getProperty('supportsCustomDataSelection'); }, /** * * @returns an array of object with the id of the custom data and the value of the decoration */ getCustomDataDecoration: function getCustomDataDecoration(decoration) { var decorations = []; if (this._isCustomDataSelectionEnabled()) { var customData = this.widgetModel.get('customData'); if (customData && customData[decoration]) { customData[decoration].forEach(function (item) { decorations.push({ id: item.id, value: item.value }); }); } } return decorations; }, /** * Sets a decoration value for a give array of custom data ids. * Any other exiting custom data that had that decoration will be cleared. * The decorations will be saved in the widget model and persisted. * @param {String} decorationName - decoration name * @param {Array} customDataDecorations - array of object that contain the id of the customData and the value of the decoration * @param {Object} options - model set options (optional) * */ setCustomDataDecoration: function setCustomDataDecoration(decorationName, customDataDecorations, options) { if (this._isCustomDataSelectionEnabled() && this._isCustomDataUpdateNeeded(customDataDecorations)) { // Save to the widget model var idArray = customDataDecorations.map(function (decoration) { return { id: decoration.id, value: decoration.value }; }); var payload = {}; payload[decorationName] = idArray; this.widgetModel.set({ 'customData': payload }, options); } }, /** * Get all custom data that have the given decoration set * @param {String} decorationname * @return {Array} array of custom data objects */ getDecoratedCustomData: function getDecoratedCustomData(decorationName) { var decorations = this.getCustomDataDecoration(decorationName); var ids = decorations.map(function (decoration) { return decoration.id; }); return this.getCustomData(ids); }, /** * Get the custom data Listen * @param {Array} ids - optional array of ids to match the custom data */ getCustomData: function getCustomData(ids) { var customData = this.ownerWidget.getCustomData() || []; // If we have an explicit list of ids, filter the custom data using that list if (ids) { customData = customData.filter(function (payload) { return ids.find(function (id) { return id === payload.id; }); }); } return customData; }, /** * Verifies if custom data in the model should be updated * @param {Map} Map containing custom data * @return {Boolean} True if model custom data needs to be updated, false otherwise */ _isCustomDataUpdateNeeded: function _isCustomDataUpdateNeeded(customDataDecorations) { var currCustomData = this.widgetModel.get('customData'); return currCustomData && currCustomData.selected && currCustomData.selected.length || customDataDecorations && customDataDecorations.length; } }); return VisModelManagerLeftover; }); //# sourceMappingURL=VisModelManagerLeftover.js.map