LayoutTemplateIndicatorUpgrade.js 3.0 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. 2018
  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(['../../../lib/@waca/upgrades/UpgradeBase'], function (UpgradeBase) {
  16. /* adds template indicator to the tab/scene if it has no template or indicator*/
  17. var LayoutTemplateIndicatorUpgrade = function (_UpgradeBase) {
  18. _inherits(LayoutTemplateIndicatorUpgrade, _UpgradeBase);
  19. function LayoutTemplateIndicatorUpgrade() {
  20. _classCallCheck(this, LayoutTemplateIndicatorUpgrade);
  21. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  22. _this.VERSION = 1023;
  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. LayoutTemplateIndicatorUpgrade.prototype.up = function up(spec) {
  33. var _this2 = this;
  34. if (!spec || !spec.layout) {
  35. return Promise.resolve(spec);
  36. }
  37. (spec.layout.items || []).forEach(function (pageContainers) {
  38. (pageContainers.items || []).forEach(function (page) {
  39. _this2._upgradePage(page);
  40. });
  41. });
  42. return Promise.resolve(spec);
  43. };
  44. LayoutTemplateIndicatorUpgrade.prototype._upgradePage = function _upgradePage(page) {
  45. if (!page || page.type !== 'genericPage') {
  46. return;
  47. }
  48. page.items = page.items || [];
  49. var hasIndicatorOrTemplate = !!page.items.find(function (item) {
  50. return item.type === 'templateDropZone' || item.type === 'templateIndicator';
  51. });
  52. if (!hasIndicatorOrTemplate) {
  53. page.items.unshift({
  54. 'style': {
  55. 'top': '0%',
  56. 'left': '0%',
  57. 'right': '0%',
  58. 'bottom': '0%'
  59. },
  60. 'type': 'templateIndicator'
  61. });
  62. }
  63. };
  64. return LayoutTemplateIndicatorUpgrade;
  65. }(UpgradeBase);
  66. return new LayoutTemplateIndicatorUpgrade();
  67. });
  68. //# sourceMappingURL=LayoutTemplateIndicatorUpgrade.js.map