RankSlotUpgrade.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 RankSlotUpgrade = function (_UpgradeBase) {
  17. _inherits(RankSlotUpgrade, _UpgradeBase);
  18. function RankSlotUpgrade() {
  19. _classCallCheck(this, RankSlotUpgrade);
  20. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  21. _this.VERSION = 1027;
  22. return _this;
  23. }
  24. /**
  25. * Perform upgrade to remove rank slots. Hidden rank slots were being persisted in the spec
  26. * before the rank refactoring. Now we don't create and use rank slots.
  27. * @param {object} spec - spec to perform upgrade on
  28. * @return {Promise} Promise to be resolved when upgrade performed
  29. */
  30. RankSlotUpgrade.prototype.up = function up(spec) {
  31. if (!spec) {
  32. return Promise.resolve(spec);
  33. }
  34. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  35. return Promise.resolve(spec);
  36. }
  37. return this._upgradeWidgets(spec);
  38. };
  39. RankSlotUpgrade.prototype.down = function down(spec) {
  40. // Downgrades are not available in CA
  41. return Promise.resolve(spec);
  42. };
  43. RankSlotUpgrade.prototype._upgradeWidgets = function _upgradeWidgets(spec) {
  44. var _this2 = this;
  45. try {
  46. _.each(spec.widgets, function (model) {
  47. _this2._upgradeWidget(model);
  48. });
  49. return Promise.resolve(spec);
  50. } catch (error) {
  51. throw error;
  52. }
  53. };
  54. RankSlotUpgrade.prototype._upgradeWidget = function _upgradeWidget(model) {
  55. if (model.slotmapping && model.slotmapping.slots && model.slotmapping.slots.length) {
  56. model.slotmapping.slots = _.filter(model.slotmapping.slots, function (slot) {
  57. return slot.name !== 'rank';
  58. });
  59. }
  60. };
  61. return RankSlotUpgrade;
  62. }(UpgradeBase);
  63. return new RankSlotUpgrade();
  64. });
  65. //# sourceMappingURL=RankSlotUpgrade.js.map