'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: BI Dashboard *| (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', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils', '../../../features/dashboard/colors/api/impl/Colors'], function (_, UpgradeBase, WidgetUpgradeUtils, Colors) { /** * Upgrade summary widgets to the new version based on the KPI widget **/ var SummaryKPIUpgrade = function (_UpgradeBase) { _inherits(SummaryKPIUpgrade, _UpgradeBase); function SummaryKPIUpgrade() { _classCallCheck(this, SummaryKPIUpgrade); var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this)); _this.VERSION = 1401; return _this; } /** * Perform upgrade * * @param {object} spec - spec to perform upgrade on * * @return {Promise} Promise to be resolved when upgrade performed */ SummaryKPIUpgrade.prototype.up = function up(spec) { var _this2 = this; var dashboard = this.data.dashboardApi; var dashboardThemeFeature = dashboard.getFeature('DashboardTheme'); var paletteFeature = dashboard.getFeature('Palette'); this._colorsService = new Colors({ features: { API: this.data.dashboardApi, DashboardTheme: dashboardThemeFeature, Palette: paletteFeature } }); if (!WidgetUpgradeUtils.specHasWidgets(spec)) { return Promise.resolve(spec); } var themeName = spec.theme || 'defaultTheme'; return this._colorsService.initializeColorsFeatureForUpgrade(themeName).then(function () { var widgetPromises = []; _.each(spec.widgets, function (model) { if (model && WidgetUpgradeUtils.isLiveWidgetModel(model) && model.visId === 'summary') { widgetPromises.push(_this2._summaryWidgetUpgrade(model, spec)); } }); return Promise.all(widgetPromises).then(function () { return spec; }); }); }; // Downgrades are not available in CA SummaryKPIUpgrade.prototype.down = function down(spec) { return Promise.resolve(spec); }; SummaryKPIUpgrade.prototype._summaryWidgetUpgrade = function _summaryWidgetUpgrade(model, spec) { var _this3 = this; //Upgrade the slot mapping. The slot has changed from values to actual. if (!_.isEmpty(model.slotmapping)) { model.slotmapping.slots[0].name = 'actual'; } model.enableSlotDefinitionFormat = false; var propertyMap = {}; if (model.properties) { model.properties = model.properties.filter(function (property) { propertyMap[property.id] = property.value; return property.id !== 'summaryValueColor' && property.id !== 'summaryLabelColor'; }); } var paletteId = propertyMap.colorPalette || this._colorsService.getDefaultPaletteName('ColorPalette'); var colorIndex = propertyMap.valueColor || 0; return this._colorsService.getHexColorFromPalette({ paletteId: paletteId, colorIndex: colorIndex, defaultIfNotFound: true, addMissingBaseColors: false }).then(function (paletteHexColor) { if (!model.properties) { model.properties = []; } var color = paletteHexColor.toUpperCase(); _this3._addCustomColor(spec, color); model.properties.push({ id: 'elementColor', value: 'customColor' + color.substring(1) }); }); }; SummaryKPIUpgrade.prototype._addCustomColor = function _addCustomColor(spec, color) { if (!spec.properties) { spec.properties = {}; } if (!spec.properties.customColors) { spec.properties['customColors'] = { 'colors': [color] }; } else { var colorList = spec.properties.customColors.colors; if (colorList.indexOf(color) === -1) { colorList.push(color); } } }; return SummaryKPIUpgrade; }(UpgradeBase); return new SummaryKPIUpgrade(); }); //# sourceMappingURL=SummaryKPIUpgrade.js.map