R9toR10.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2018
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, Class, UpgradeBase, WidgetUpgradeUtils) {
  13. 'use strict';
  14. var Upgrade = Class.extend([UpgradeBase], {
  15. init: function init() {
  16. this.VERSION = 1008;
  17. },
  18. /**
  19. * Perform upgrade
  20. *
  21. * @param {object} spec - spec to perform upgrade on
  22. *
  23. * @return {Promise} Promise to be resolved when upgrade performed
  24. */
  25. up: function up(spec) {
  26. if (spec.widgets) {
  27. this._upgradeWidgets(spec);
  28. }
  29. return Promise.resolve(spec);
  30. },
  31. _supportsAxisLabelVerticalProperty: function _supportsAxisLabelVerticalProperty(widget) {
  32. var supportedVisIds = ['com.ibm.vis.rave2line', 'com.ibm.vis.rave2point'];
  33. return supportedVisIds.indexOf(widget.visId) > -1;
  34. },
  35. _upgradeWidgets: function _upgradeWidgets(spec) {
  36. var _this = this;
  37. try {
  38. _.each(spec.widgets, function (widget) {
  39. // itemAxis.labels.vertical property is only available for line and point visualization
  40. // check the visId before upgrading the property
  41. if (_this._supportsAxisLabelVerticalProperty(widget)) {
  42. _this._upgradeItemAxisLabelVerticalProperty(widget);
  43. }
  44. });
  45. } catch (error) {
  46. throw error;
  47. }
  48. },
  49. _upgradeItemAxisLabelVerticalProperty: function _upgradeItemAxisLabelVerticalProperty(model) {
  50. /*
  51. Pre R8, the property name for label orientation is 'itemAxis.labels.vertical' and it is a boolean property with default value to false.
  52. The property has been upgrader starting from R9 using the name as 'itemAxis.labels.layoutMode' which is an enum type property.
  53. The scenarios that need to be considered are:
  54. 1) Upgrade from pre R8, which should be set the new prop value as 'horizontal' for default true value,set new prop as 'rotate90' for vertical value to true
  55. 2) Upgrade from R9, R10 or R11, which need to check if the new property exists, if so using the new property values and clean the old one
  56. 3) Upgrade from R12 or R13 with default value 'automatic', the spec version for R12 is 1008, which is already higher then this upgrader, so this scenario is safe, since from here the prop has the same behavior as endor
  57. */
  58. var deprecatedPropName = 'itemAxis.labels.vertical';
  59. var newPropName = 'itemAxis.labels.layoutMode';
  60. var oldProp = WidgetUpgradeUtils.findProperty(deprecatedPropName, model.properties);
  61. var newProp = WidgetUpgradeUtils.findProperty(newPropName, model.properties);
  62. // remove the old property as its no longer being used
  63. model.properties = _.filter(model.properties, function (prop) {
  64. return prop.id !== deprecatedPropName;
  65. });
  66. // if new prop exists just return
  67. if (newProp) {
  68. return;
  69. }
  70. // if the oldProp does not exist or set value false, set the new prop as 'horizontal', otherwise set as 'rotate90'
  71. var propValue = oldProp && oldProp.value ? 'rotate90' : 'horizontal';
  72. model.properties.push({
  73. id: newPropName,
  74. value: propValue
  75. });
  76. },
  77. down: function down(spec) {
  78. return Promise.resolve(spec);
  79. }
  80. });
  81. return new Upgrade();
  82. });
  83. //# sourceMappingURL=R9toR10.js.map