123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2016, 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase', 'underscore'], function (Class, UpgradeBase, _) {
- var Upgrade = Class.extend([UpgradeBase], {
- init: function init() {
- this.VERSION = 6;
- },
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- up: function up(spec) {
- if (!spec) {
- return Promise.resolve(spec);
- }
- // Upgrade dataset shaping
- this._upgradeDatasetShaping(spec);
- // Upgrade widget spec;
- _.each(spec.widgets, this._upgradeWidgetSpec.bind(this));
- return Promise.resolve(spec);
- },
- _upgradeDatasetShaping: function _upgradeDatasetShaping(oBoardSpec) {
- var datasetShaping = oBoardSpec.datasetShaping;
- var widgets = oBoardSpec.widgets;
- //Update model mappings attributes
- if (!datasetShaping || !widgets) {
- return false; //Upgrade is not needed
- }
- var bUpgraded = false;
- var aDatasets = [];
- //Local cache all distinct data sets with type info
- var sID = null;
- _.each(widgets, function (widget) {
- if (widget.dataSet) {
- sID = widget.dataSet.id;
- if (sID && aDatasets.indexOf(sID) === -1) {
- aDatasets.push({
- id: sID,
- type: widget.dataSet.type
- });
- }
- }
- });
- //Upgrade data sets shaping
- var oDataset = null;
- _.each(datasetShaping, function (shaping) {
- if (shaping) {
- oDataset = _.find(aDatasets, function (dataset) {
- return dataset.id === shaping.id;
- });
- if (oDataset) {
- var options = { 'isUploadedFile': oDataset.type === 'uploadedFile' };
- _.each(shaping.filters, function (filter) {
- filter.columnId = this._getShortenedColID(filter.columnId, options);
- bUpgraded = true;
- }.bind(this));
- }
- }
- }.bind(this));
- return bUpgraded;
- },
- _upgradeWidgetSpec: function _upgradeWidgetSpec(widgetModel) {
- if (!widgetModel || !widgetModel.dataSet) {
- return false; //Upgrade is not needed
- }
- var options = {
- isUploadedFile: widgetModel.dataSet.type === 'uploadedFile'
- };
- _.each(widgetModel.mapping, function (mapping) {
- if (mapping.id) {
- mapping.id = this._getShortenedColID(mapping.id, options);
- }
- if (mapping.columnId) {
- mapping.columnId = this._getShortenedColID(mapping.columnId, options);
- }
- }.bind(this));
- //Update model filters attributes
- _.each(widgetModel.filters, function (filter) {
- this._upgradeFilters(filter, options);
- }.bind(this));
- //Update model local filters attributes
- _.each(widgetModel.localFilters, function (filter) {
- this._upgradeFilters(filter, options);
- }.bind(this));
- return widgetModel;
- },
- _upgradeFilters: function _upgradeFilters(filter, options) {
- if (!filter) {
- return;
- }
- if (filter.columnId) {
- filter.columnId = this._getShortenedColID(filter.columnId, options);
- } else if (filter.values) {
- _.each(filter.values, function (value) {
- this._upgradeFilters(value, options);
- }.bind(this));
- }
- },
- down: function down(spec) {
- // no downgrade at this time; return as is
- return Promise.resolve(spec);
- },
- /**
- * @private
- * Migrate the older release long format column ID to a shortened version in the new release
- **/
- _getShortenedColID: function _getShortenedColID(sOrigID, options) {
- if (sOrigID && sOrigID.length > 0) {
- var aSections = sOrigID.split('.');
- var nLen = aSections.length;
- if (options && options.isUploadedFile === true) {
- return 'Sheet1.' + aSections[nLen - 1];
- } else if (nLen >= 2) {
- var aResult = [];
- aResult.push(aSections[nLen - 2]);
- aResult.push(aSections[nLen - 1]);
- return aResult.join('.'); //Shortened version
- }
- }
- return sOrigID;
- }
- });
- return new Upgrade();
- });
- //# sourceMappingURL=6.js.map
|