123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- '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. 2018, 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'], function (_, UpgradeBase) {
- /**
- * Upgrade data item ids in dashboard spec for better performance to avoid querying same data items with different ids.
- **/
- var DataItemUpgrade = function (_UpgradeBase) {
- _inherits(DataItemUpgrade, _UpgradeBase);
- function DataItemUpgrade() {
- _classCallCheck(this, DataItemUpgrade);
- var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
- _this.VERSION = 1015;
- return _this;
- }
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- DataItemUpgrade.prototype.up = function up(spec) {
- var _this2 = this;
- if (!spec || !spec.widgets || _.isEmpty(spec.widgets)) {
- return Promise.resolve(spec);
- }
- for (var key in spec.widgets) {
- var widget = spec.widgets[key];
- widget = this._mergeIncorrectDataItems(widget);
- var dataViews = widget.data && widget.data.dataViews;
- if (dataViews) {
- dataViews.forEach(function (dataView) {
- dataView.dataItems.forEach(function (dataItem, curIndex) {
- dataView.dataItems[curIndex] = _this2._upgradeDataItemFormat(dataItem);
- });
- });
- spec.widgets[key].data.dataViews = dataViews;
- }
- }
- return Promise.resolve(spec);
- };
- // Downgrades are not available in CA
- DataItemUpgrade.prototype.down = function down(spec) {
- return Promise.resolve(spec);
- };
- DataItemUpgrade.prototype._mergeIncorrectDataItems = function _mergeIncorrectDataItems(widget) {
- // RTC Defect #262782
- // we encounter this issue when upgrading r13-endor in a widget with a multi-measure group created by moving a dataitem from a different slot
- // we have 2 data items inside the dataview where the modelref of dataitem 2 matches the id of dataitem 1
- // the correct version features just 1 data item with a modelref = pagecontext.sources.id
- if (!widget || !widget.data || !widget.data.dataViews || !widget.slotmapping) return widget;
- var dataViews = widget.data.dataViews;
- // for map widgets we have multiple valid data views and layers, we ignore this case
- if (dataViews.length < 2 || widget.slotmapping.layers) return dataViews;
- var base = void 0;
- var slotMappingDataItems = [];
- widget.slotmapping.slots.forEach(function (slot) {
- return slotMappingDataItems = slotMappingDataItems.concat(slot.dataItems);
- });
- // merge 2 dataviews data items
- var _merge = function _merge(base, dataView) {
- dataView.dataItems.forEach(function (dataItem) {
- if (slotMappingDataItems.indexOf(dataItem.id) !== -1) {
- base.dataItems.push(dataItem);
- }
- });
- return base;
- };
- dataViews.forEach(function (dataView, curIndex) {
- if (!base) {
- base = dataView;
- }
- if (base && base.id === dataView.modelRef) {
- base = _merge(base, dataView);
- dataViews.splice(curIndex); // delete old data view
- }
- });
- dataViews[0] = base;
- widget.data.dataViews = dataViews;
- return widget;
- };
- DataItemUpgrade.prototype._upgradeDataItemFormat = function _upgradeDataItemFormat(dataItem) {
- if (dataItem && dataItem.format && dataItem.format.formatSpec && dataItem.format.formatSpec.type) {
- var formatSpec = dataItem.format.formatSpec,
- type = formatSpec.type;
- if (type === 'datetime' || type === 'date') {
- if (type === 'datetime') {
- formatSpec = this._upgradeDateTimeFormat(formatSpec);
- }
- formatSpec = this._syncDateStyle(formatSpec);
- } else if (type === 'number') {
- formatSpec = this._upgradeNumberFormat(formatSpec);
- }
- dataItem.format.formatSpec = formatSpec;
- }
- return dataItem;
- };
- DataItemUpgrade.prototype._syncDateStyle = function _syncDateStyle(formatSpec) {
- if (formatSpec.formatLength && formatSpec.selectedFormat) {
- formatSpec.dateStyle = formatSpec.selectedFormat;
- }
- return formatSpec;
- };
- DataItemUpgrade.prototype._upgradeDateTimeFormat = function _upgradeDateTimeFormat(formatSpec) {
- if (formatSpec.formatLength && formatSpec.selectedFormat) {
- if (formatSpec.formatLength === 'medium' && formatSpec.selectedFormat === 'medium') {
- formatSpec.formatLength = 'long';
- formatSpec.selectedFormat = 'long';
- }
- formatSpec.dateStyle = formatSpec.selectedFormat;
- }
- return formatSpec;
- };
- DataItemUpgrade.prototype._upgradeNumberFormat = function _upgradeNumberFormat(formatSpec) {
- // sometimes maximumFractionDigits is the number 0 which will return false so we explicitly check against null and undefined
- if (formatSpec.maximumFractionDigits !== null && formatSpec.maximumFractionDigits !== undefined && _.isNumber(formatSpec.maximumFractionDigits)) {
- formatSpec.maximumFractionDigits = formatSpec.maximumFractionDigits.toString();
- }
- if (formatSpec.minimumFractionDigits !== null && formatSpec.minimumFractionDigits !== undefined && _.isNumber(formatSpec.minimumFractionDigits)) {
- formatSpec.minimumFractionDigits = formatSpec.minimumFractionDigits.toString();
- } else {
- formatSpec.minimumFractionDigits = formatSpec.maximumFractionDigits;
- }
- return formatSpec;
- };
- return DataItemUpgrade;
- }(UpgradeBase);
- return new DataItemUpgrade();
- });
- //# sourceMappingURL=DataItemUpgrade.js.map
|