'use strict'; /** *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Dashboard *| (C) Copyright IBM Corp. 2018, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', 'dashboard-analytics/widgets/livewidget/nls/StringResources', 'dashboard-analytics/visualizations/properties/PropertiesCreator', 'dashboard-analytics/visualizations/vipr/properties/ColorPropertiesCreator', 'dashboard-analytics/visualizations/vipr/VIPRUtils', '../VIPRConfig'], function (_, StringResources, PropertiesCreator, ColorPropertiesCreator, VIPRUtils, VIPRConfig) { 'use strict'; /* * This purpose of this singleton is to create generic vida property descriptions * from the Vis bundles that can be stored in our model. */ var PropertiesCreatorFromVisDef = function () { /** * Instance stores a reference to the Singleton * @type {object} */ var instance = null; function init() { return { /** * We only need generic descriptions for properties in the model cache. * @param {String} propId - id of the property of interest * @param {Object} simple object with id and name defined */ _createGenericProperty: function _createGenericProperty(propId) { return { 'id': propId, 'name': propId }; }, /** * @returns a list of vipr properties as an array in a format useable by * the properties model. */ getPropertiesFromDefintion: function getPropertiesFromDefintion(visId) { var PropCreatorInstance = PropertiesCreator.getInstance(); var ColorPropertiesCreatorInstance = ColorPropertiesCreator.getInstance(); var items = []; // We need to use known property IDs so they match what we have supported // previously or have added. Vida handles property upgrade on the fly. var configuration = VIPRConfig.getConfig(visId) || {}; if (configuration && configuration.config && configuration.config.include) { configuration.config.include.forEach(function (propertyId) { var propDesc = instance._createGenericProperty(propertyId); var property = VIPRUtils.overrideProperty(visId, propDesc, propertyId); items.push(property); }); } items.push(PropCreatorInstance.getMaintainAxisScaleProperty()); // If there are single palettes create the individual props from config. var singlePaletteProps = VIPRUtils.getSinglePaletteProperties(visId); if (singlePaletteProps) { Object.values(singlePaletteProps).forEach(function (palettePropDesc) { items.push(ColorPropertiesCreatorInstance.getSinglePaletteColorProperty(palettePropDesc)); }); } else { // Otherwise create the default one. items.push(ColorPropertiesCreatorInstance.getDefaultPaletteIndexProperty()); } var colorPaletteProperties = ColorPropertiesCreatorInstance.getColorPalettePropertiesFromVisId(visId); if (colorPaletteProperties && colorPaletteProperties.length) { items = items.concat(colorPaletteProperties); } if (configuration.propertyList) { items = items.concat(configuration.propertyList); } return items; }, getVizDefPropertiesFromDefinition: function getVizDefPropertiesFromDefinition(viprDefinition) { var items = []; var configuration = VIPRConfig.getConfig(viprDefinition.id) || {}; if (configuration && configuration.config && configuration.config.include) { configuration.config.include.forEach(function (propertyId) { var propDesc = instance._createGenericProperty(propertyId); var vizDefPropDesc = viprDefinition.vizDef.getProperty(propertyId) || {}; propDesc.active = true; propDesc = _.extend(vizDefPropDesc, propDesc); var property = VIPRUtils.overrideProperty(viprDefinition.id, propDesc, propertyId); items.push(property); }); } // augment this array to match viprwidget.properties object functionality items.get = function (id) { return items.find(function (item) { return item.id === id; }); }; return items; } }; } return { // Get the Singleton instance if one exists // or create one if it doesn't getInstance: function getInstance() { if (!instance) { instance = init(); } return instance; } }; }(); return PropertiesCreatorFromVisDef; }); //# sourceMappingURL=PropertiesCreatorFromVisDefinition.js.map