VIDAPaddingPropUpgrade.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /**
  17. * Upgrade VIDA property. Remove title.visible from the old spec and introduce 'itemAxis.title.visible' and 'valueAxis.title.visible' instead.
  18. **/
  19. var VIDAPaddingPropUpgrade = function (_UpgradeBase) {
  20. _inherits(VIDAPaddingPropUpgrade, _UpgradeBase);
  21. function VIDAPaddingPropUpgrade() {
  22. _classCallCheck(this, VIDAPaddingPropUpgrade);
  23. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  24. _this.VERSION = 1300;
  25. return _this;
  26. }
  27. /**
  28. * Perform upgrade
  29. *
  30. * @param {object} spec - spec to perform upgrade on
  31. *
  32. * @return {Promise} Promise to be resolved when upgrade performed
  33. */
  34. VIDAPaddingPropUpgrade.prototype.up = function up(spec) {
  35. var _this2 = this;
  36. if (!spec) {
  37. return Promise.resolve(spec);
  38. }
  39. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  40. return Promise.resolve(spec);
  41. }
  42. _.each(spec.widgets, function (model) {
  43. if (model && _this2._isLive(model)) {
  44. if (!model.properties) {
  45. model.properties = [];
  46. }
  47. _this2._noPaddingPropertyUpgrade(model);
  48. }
  49. });
  50. return Promise.resolve(spec);
  51. };
  52. // Downgrades are not available in CA
  53. VIDAPaddingPropUpgrade.prototype.down = function down(spec) {
  54. return Promise.resolve(spec);
  55. };
  56. VIDAPaddingPropUpgrade.prototype._isLive = function _isLive(model) {
  57. return model && model.type && model.type === 'live';
  58. };
  59. VIDAPaddingPropUpgrade.prototype._noPaddingPropertyUpgrade = function _noPaddingPropertyUpgrade(model) {
  60. var deprecatedPropId = ['bar.noPadding'];
  61. var deprecatedProp = WidgetUpgradeUtils.findProperty(deprecatedPropId[0], model.properties);
  62. var newPropId = ['bar.padding'];
  63. var newProp = WidgetUpgradeUtils.findProperty(newPropId[0], model.properties);
  64. // clean up the spec poperties by filter out the deprecated props
  65. model.properties = _.filter(model.properties, function (prop) {
  66. return deprecatedPropId[0] !== prop.id;
  67. });
  68. // add new property if not already present
  69. if (!newProp) {
  70. model.properties.push({
  71. id: newPropId[0],
  72. value: deprecatedProp ? !deprecatedProp.value : true
  73. });
  74. }
  75. };
  76. return VIDAPaddingPropUpgrade;
  77. }(UpgradeBase);
  78. return new VIDAPaddingPropUpgrade();
  79. });
  80. //# sourceMappingURL=VIDAPaddingPropUpgrade.js.map