DatasetScopeMultiMeasure.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: BI Dashboard
  9. *| (C) Copyright IBM Corp. 2020
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) {
  16. var MULTI_MEASURE_SERIES = '_multiMeasuresSeries';
  17. var DatasetScopeMultiMeasure = function (_UpgradeBase) {
  18. _inherits(DatasetScopeMultiMeasure, _UpgradeBase);
  19. function DatasetScopeMultiMeasure() {
  20. _classCallCheck(this, DatasetScopeMultiMeasure);
  21. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  22. _this.VERSION = 1802;
  23. return _this;
  24. }
  25. /**
  26. * Perform upgrade
  27. *
  28. * @param {object} spec - spec to perform upgrade on
  29. *
  30. * @return {Promise} Promise to be resolved when upgrade performed
  31. */
  32. DatasetScopeMultiMeasure.prototype.up = function up(spec) {
  33. var _this2 = this;
  34. if (!spec) {
  35. return Promise.resolve(spec);
  36. }
  37. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  38. return Promise.resolve(spec);
  39. }
  40. _.each(spec.widgets, function (model) {
  41. if (WidgetUpgradeUtils.isLiveWidgetModel(model)) {
  42. _this2._removeSlotPointer(model);
  43. _this2._updateSlotmappingDataItem(model);
  44. _this2._updateDataViewDataItem(model);
  45. }
  46. });
  47. return Promise.resolve(spec);
  48. };
  49. // Downgrades are not available in CA
  50. DatasetScopeMultiMeasure.prototype.down = function down(spec) {
  51. return Promise.resolve(spec);
  52. };
  53. // New implementation can compute this anyway
  54. DatasetScopeMultiMeasure.prototype._removeSlotPointer = function _removeSlotPointer(model) {
  55. if (model.slotmapping && model.slotmapping.multiMeasureSlot) {
  56. delete model.slotmapping.multiMeasureSlot;
  57. }
  58. };
  59. // New implementation can have 1 multi-measure per dataset
  60. DatasetScopeMultiMeasure.prototype._updateSlotmappingDataItem = function _updateSlotmappingDataItem(model) {
  61. model.slotmapping && model.slotmapping.slots && model.slotmapping.slots.forEach(function (slot) {
  62. slot.dataItems && slot.dataItems.forEach(function (dataItem, index) {
  63. if (dataItem === MULTI_MEASURE_SERIES) {
  64. // all multimeasures prior to this upgrader belonged to the 'data' dataset
  65. slot.dataItems[index] = MULTI_MEASURE_SERIES + '_' + 'data';
  66. }
  67. });
  68. });
  69. };
  70. // New implementation can have 1 multi-measure per dataset
  71. DatasetScopeMultiMeasure.prototype._updateDataViewDataItem = function _updateDataViewDataItem(model) {
  72. if (model.data && !_.isEmpty(model.data.dataViews)) {
  73. // no multi-layer vis prior to this upgrader had multi-measure support
  74. model.data.dataViews.forEach(function (dataview) {
  75. dataview && dataview.dataItems && dataview.dataItems.forEach(function (dataItem) {
  76. if (dataItem.id === MULTI_MEASURE_SERIES) {
  77. // all multimeasures prior to this upgrader belonged to the 'data' dataset
  78. dataItem.id = MULTI_MEASURE_SERIES + '_data';
  79. }
  80. });
  81. });
  82. }
  83. };
  84. return DatasetScopeMultiMeasure;
  85. }(UpgradeBase);
  86. return new DatasetScopeMultiMeasure();
  87. });
  88. //# sourceMappingURL=DatasetScopeMultiMeasure.js.map