LayoutPositioningUpgrade.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. var ABSOLUTE_TYPE = 'absolute';
  17. var SCALINGABSOLUTE_TYPE = 'scalingAbsolute';
  18. var GENERICPAGE_TYPE = 'genericPage';
  19. var ABSOLUTE_LAYOUTPOSITIONING = 'absolute';
  20. var RELATIVE_LAYOUTPOSITIONING = 'relative';
  21. /**
  22. * Upgrades absolute and scalingAbsolute layouts to new genericPage type.
  23. * The new genericPage layout has a layoutPositioning property (absolute or relative)
  24. * Freeform templates are converted to Template1.
  25. **/
  26. var LayoutPositioningUpgrade = function (_UpgradeBase) {
  27. _inherits(LayoutPositioningUpgrade, _UpgradeBase);
  28. function LayoutPositioningUpgrade() {
  29. _classCallCheck(this, LayoutPositioningUpgrade);
  30. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  31. _this.VERSION = 1012;
  32. return _this;
  33. }
  34. /**
  35. * Perform upgrade
  36. *
  37. * @param {object} spec - spec to perform upgrade on
  38. *
  39. * @return {Promise} Promise to be resolved when upgrade performed
  40. */
  41. LayoutPositioningUpgrade.prototype.up = function up(spec) {
  42. var _this2 = this;
  43. return Promise.resolve().then(function () {
  44. _this2._init();
  45. if (spec && spec.layout) {
  46. _this2._upgradeLayout(spec.layout);
  47. _this2._setTopLayoutPositioning(spec.layout);
  48. }
  49. return spec;
  50. });
  51. };
  52. // Downgrades are not available in CA
  53. LayoutPositioningUpgrade.prototype.down = function down(spec) {
  54. return Promise.resolve(spec);
  55. };
  56. LayoutPositioningUpgrade.prototype._init = function _init() {
  57. this._hasRelativeLayouts = false;
  58. this._hasAbsoluteLayouts = false;
  59. };
  60. LayoutPositioningUpgrade.prototype._upgradeLayout = function _upgradeLayout(layout, parent) {
  61. if (layout.items) {
  62. // Recursively upgrade child layouts
  63. for (var _iterator = layout.items, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  64. var _ref;
  65. if (_isArray) {
  66. if (_i >= _iterator.length) break;
  67. _ref = _iterator[_i++];
  68. } else {
  69. _i = _iterator.next();
  70. if (_i.done) break;
  71. _ref = _i.value;
  72. }
  73. var item = _ref;
  74. this._upgradeLayout(item, layout);
  75. }
  76. }
  77. this._upgradeLayoutPositioning(layout, parent);
  78. };
  79. LayoutPositioningUpgrade.prototype._upgradeLayoutPositioning = function _upgradeLayoutPositioning(layout, parent) {
  80. if (layout.type === ABSOLUTE_TYPE) {
  81. layout.layoutPositioning = ABSOLUTE_LAYOUTPOSITIONING;
  82. layout.type = GENERICPAGE_TYPE;
  83. this._hasAbsoluteLayouts = true;
  84. this._upgradeAbsoluteTemplate(layout, parent);
  85. } else if (layout.type === SCALINGABSOLUTE_TYPE) {
  86. layout.layoutPositioning = RELATIVE_LAYOUTPOSITIONING;
  87. layout.type = GENERICPAGE_TYPE;
  88. this._hasRelativeLayouts = true;
  89. }
  90. };
  91. // Convert the freeform template (NoTemplate) to one of the non-freeform templates - Template1
  92. LayoutPositioningUpgrade.prototype._upgradeAbsoluteTemplate = function _upgradeAbsoluteTemplate(layout, parent) {
  93. parent.templateName = 'Template1';
  94. layout.css = 'templateBox aspectRatio_default';
  95. layout.items.unshift({
  96. 'type': 'templateIndicator',
  97. 'style': {
  98. 'top': '0%',
  99. 'left': '0%',
  100. 'right': '0%',
  101. 'bottom': '0%'
  102. }
  103. });
  104. };
  105. LayoutPositioningUpgrade.prototype._setTopLayoutPositioning = function _setTopLayoutPositioning(layout) {
  106. if (this._hasAbsoluteLayouts && !this._hasRelativeLayouts) {
  107. layout.layoutPositioning = ABSOLUTE_LAYOUTPOSITIONING;
  108. } else if (this._hasRelativeLayouts && !this._hasAbsoluteLayouts) {
  109. layout.layoutPositioning = RELATIVE_LAYOUTPOSITIONING;
  110. }
  111. // Undefined otherwise
  112. };
  113. return LayoutPositioningUpgrade;
  114. }(UpgradeBase);
  115. return new LayoutPositioningUpgrade();
  116. });
  117. //# sourceMappingURL=LayoutPositioningUpgrade.js.map