CompositeChartUpgrade.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) {
  16. /**
  17. * Upgrade 'lineColor' prop for composite chart, renaming it to 'compositeLineColor'.
  18. **/
  19. var CompositeChartUpgrade = function (_UpgradeBase) {
  20. _inherits(CompositeChartUpgrade, _UpgradeBase);
  21. function CompositeChartUpgrade() {
  22. _classCallCheck(this, CompositeChartUpgrade);
  23. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  24. _this.VERSION = 1016;
  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. CompositeChartUpgrade.prototype.up = function up(spec) {
  35. if (!spec) {
  36. return Promise.resolve(spec);
  37. }
  38. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  39. return Promise.resolve(spec);
  40. }
  41. this._lineColorPropUpgrade(spec);
  42. return Promise.resolve(spec);
  43. };
  44. // Downgrades are not available in CA
  45. CompositeChartUpgrade.prototype.down = function down(spec) {
  46. return Promise.resolve(spec);
  47. };
  48. CompositeChartUpgrade.prototype._lineColorPropUpgrade = function _lineColorPropUpgrade(spec) {
  49. var lineColorPropId = 'lineColor';
  50. var compositeLineColorPropId = 'compositeLineColor';
  51. var upgradeVisId = ['com.ibm.vis.rave2bundlecomposite'];
  52. _.each(spec.widgets, function (model) {
  53. // we do not want to ruin the prossible lineColor prop in other models, so add a visid check here
  54. if (model && model.properties && model.visId && _.contains(upgradeVisId, model.visId)) {
  55. var deprecatedLineColorProp = WidgetUpgradeUtils.findProperty(lineColorPropId, model.properties);
  56. model.properties = _.filter(model.properties, function (prop) {
  57. return lineColorPropId !== prop.id;
  58. });
  59. if (deprecatedLineColorProp) {
  60. model.properties.push({
  61. id: compositeLineColorPropId,
  62. value: deprecatedLineColorProp.value
  63. });
  64. }
  65. }
  66. });
  67. };
  68. return CompositeChartUpgrade;
  69. }(UpgradeBase);
  70. return new CompositeChartUpgrade();
  71. });
  72. //# sourceMappingURL=CompositeChartUpgrade.js.map