NewGenSpec.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. 2019
  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 MissingOriginalCustomGroupItemId = function (_UpgradeBase) {
  17. _inherits(MissingOriginalCustomGroupItemId, _UpgradeBase);
  18. function MissingOriginalCustomGroupItemId() {
  19. _classCallCheck(this, MissingOriginalCustomGroupItemId);
  20. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  21. _this.VERSION = 1800;
  22. return _this;
  23. }
  24. /**
  25. * Perform upgrade to add "originalCustomGroupItemId" to the dataItem when it represents a custom group
  26. * @param {object} spec - spec to perform upgrade on
  27. * @return {Promise} Promise to be resolved when upgrade performed
  28. */
  29. MissingOriginalCustomGroupItemId.prototype.up = function up(spec) {
  30. if (!spec) {
  31. return Promise.resolve(spec);
  32. }
  33. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  34. return Promise.resolve(spec);
  35. }
  36. return this._upgradeWidgets(spec);
  37. };
  38. MissingOriginalCustomGroupItemId.prototype.down = function down(spec) {
  39. // Downgrades are not available in CA
  40. return Promise.resolve(spec);
  41. };
  42. MissingOriginalCustomGroupItemId.prototype._upgradeWidgets = function _upgradeWidgets(spec) {
  43. var _this2 = this;
  44. try {
  45. _.each(spec.widgets, function (model) {
  46. _this2._upgradeWidgetProperties(model, spec);
  47. });
  48. return Promise.resolve(spec);
  49. } catch (error) {
  50. throw error;
  51. }
  52. };
  53. MissingOriginalCustomGroupItemId.prototype._getContentSpec = function _getContentSpec(model, spec) {
  54. var layout = WidgetUpgradeUtils.findLayout([spec.layout], model.id);
  55. var content = null;
  56. if (layout) {
  57. if (!layout.content) {
  58. layout.content = {};
  59. }
  60. content = layout.content;
  61. }
  62. return content;
  63. };
  64. MissingOriginalCustomGroupItemId.prototype._getContentProps = function _getContentProps(model, spec) {
  65. var content = this._getContentSpec(model, spec);
  66. var props = void 0;
  67. if (content) {
  68. if (!content.properties) {
  69. content.properties = {};
  70. }
  71. props = content.properties;
  72. }
  73. return props;
  74. };
  75. MissingOriginalCustomGroupItemId.prototype._upgradeVisGridProps = function _upgradeVisGridProps(model, props) {
  76. if (model && model.data && model.data.dataViews && model.data.dataViews.length > 0) {
  77. var gridSettings = model.data.dataViews[0].grid;
  78. if (gridSettings) {
  79. props['datagrid.viewOption'] = gridSettings['viewOption'];
  80. }
  81. delete model.data.dataViews[0].grid;
  82. }
  83. };
  84. MissingOriginalCustomGroupItemId.prototype._upgradeInfoGraphicProps = function _upgradeInfoGraphicProps(model, props) {
  85. if (model && model.slotmapping && model.slotmapping.slots && model.slotmapping.slots.length > 0) {
  86. var dataItemSettings = model.slotmapping.slots[0].dataItemSettings;
  87. if (dataItemSettings && dataItemSettings.length > 0) {
  88. var graphic = dataItemSettings[0].graphic;
  89. if (graphic) {
  90. props['value.graphic.content'] = graphic.content;
  91. props['value.graphic.currentScaleOption'] = graphic.currentScaleOption;
  92. props['value.graphic.fillColor'] = graphic.fillColor;
  93. props['value.graphic.borderColor'] = graphic.borderColor;
  94. }
  95. }
  96. delete model.slotmapping.slots[0].dataItemSettings;
  97. }
  98. };
  99. MissingOriginalCustomGroupItemId.prototype._upgradeWidgetProperties = function _upgradeWidgetProperties(model, spec) {
  100. var props = this._getContentProps(model, spec);
  101. if (props) {
  102. // Upgrade grid view options to a prop
  103. this._upgradeVisGridProps(model, props);
  104. // Upgrade infographic shape props
  105. this._upgradeInfoGraphicProps(model, props);
  106. }
  107. };
  108. return MissingOriginalCustomGroupItemId;
  109. }(UpgradeBase);
  110. return new MissingOriginalCustomGroupItemId();
  111. });
  112. //# sourceMappingURL=NewGenSpec.js.map