VIDALegendFontSizeMappingUpgrade.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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, 2021
  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 VIDA Legend property - Change the Font Size. Currently we have four values for Font size. We will now have only 3 values. This script will check for the current user defined value (if any), and map it to the right value.
  18. **/
  19. var VIDALegendFontSizeMappingUpgrade = function (_UpgradeBase) {
  20. _inherits(VIDALegendFontSizeMappingUpgrade, _UpgradeBase);
  21. function VIDALegendFontSizeMappingUpgrade() {
  22. _classCallCheck(this, VIDALegendFontSizeMappingUpgrade);
  23. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  24. _this.VERSION = 1400;
  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. VIDALegendFontSizeMappingUpgrade.prototype.up = function up(spec) {
  35. var _this2 = this;
  36. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  37. return Promise.resolve(spec);
  38. }
  39. _.each(spec.widgets, function (model) {
  40. if (model && WidgetUpgradeUtils.isLiveWidgetModel(model) && model.properties) {
  41. _this2._legendFontSizeMappingUpgrade(model);
  42. }
  43. });
  44. return Promise.resolve(spec);
  45. };
  46. // Downgrades are not available in CA
  47. VIDALegendFontSizeMappingUpgrade.prototype.down = function down(spec) {
  48. return Promise.resolve(spec);
  49. };
  50. /**
  51. * If font size property is defined, then check the defined size and map it to the right value. Here is the mapping:
  52. * 12px -> 11px
  53. * 14px -> 14px
  54. * 16px, 24px -> 16px
  55. * If no font size is defined (default is 11px), then don't do anything
  56. * @param {object} model
  57. */
  58. VIDALegendFontSizeMappingUpgrade.prototype._legendFontSizeMappingUpgrade = function _legendFontSizeMappingUpgrade(model) {
  59. var fontSizePropName = 'widget.legend.font';
  60. var fontSizePropOfWidget = WidgetUpgradeUtils.findProperty(fontSizePropName, model.properties);
  61. if (fontSizePropOfWidget && fontSizePropOfWidget.value !== null) {
  62. var fontSize = fontSizePropOfWidget.value.trim();
  63. var fontMap = {
  64. '12px': '11px',
  65. '24px': '16px'
  66. };
  67. var mappedValue = fontMap[fontSize];
  68. //except for 14px and 16px, remap the Legend font size
  69. if (mappedValue) {
  70. //filter out the font size prop from the model properties so that the new prop can be pushed
  71. model.properties = _.filter(model.properties, function (prop) {
  72. return fontSizePropName !== prop.id;
  73. });
  74. model.properties.push({
  75. id: fontSizePropName,
  76. value: mappedValue
  77. });
  78. }
  79. }
  80. };
  81. return VIDALegendFontSizeMappingUpgrade;
  82. }(UpgradeBase);
  83. return new VIDALegendFontSizeMappingUpgrade();
  84. });
  85. //# sourceMappingURL=VIDALegendFontSizeMappingUpgrade.js.map