9.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2016, 2017
  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(['jquery', 'underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase'], function ($, _, Class, UpgradeBase) {
  13. var Upgrade = Class.extend([UpgradeBase], {
  14. init: function init() {
  15. this.VERSION = 9;
  16. },
  17. /**
  18. * Perform upgrade
  19. *
  20. * @param {object} spec - spec to perform upgrade on
  21. *
  22. * @return {Promise} Promise to be resolved when upgrade performed
  23. */
  24. up: function up(spec) {
  25. if (!spec) {
  26. return Promise.resolve(spec);
  27. }
  28. this.moveTransparencyToLayoutModel(spec);
  29. this.fixTextAutosize(spec);
  30. return Promise.resolve(spec);
  31. },
  32. moveTransparencyToLayoutModel: function moveTransparencyToLayoutModel(boardSpec) {
  33. if (boardSpec && boardSpec.widgets) {
  34. var widgetIds = _.keys(boardSpec.widgets);
  35. _.each(widgetIds, function (widgetId) {
  36. var layoutSpec = this._findLayoutSpecById(boardSpec.layout, widgetId);
  37. var widget = boardSpec.widgets[widgetId];
  38. if (layoutSpec && typeof widget.transparency !== 'undefined') {
  39. if (!layoutSpec.style) {
  40. layoutSpec.style = {};
  41. }
  42. if (typeof layoutSpec.style.opacity === 'undefined') {
  43. layoutSpec.style.opacity = widget.transparency;
  44. }
  45. delete widget.transparency;
  46. }
  47. // transparency now stored on a different node, remove it from existing dashboards/stories on load.
  48. if (widget && widget.content) {
  49. widget.content = this._removeOpacity(widget.content);
  50. }
  51. }.bind(this));
  52. }
  53. },
  54. _findLayoutSpecById: function _findLayoutSpecById(layoutSpec, id) {
  55. var spec;
  56. if (layoutSpec.id === id) {
  57. spec = layoutSpec;
  58. }
  59. if (!spec && layoutSpec.items) {
  60. for (var i = 0; !spec && i < layoutSpec.items.length; i++) {
  61. spec = this._findLayoutSpecById(layoutSpec.items[i], id);
  62. }
  63. }
  64. return spec;
  65. },
  66. _removeOpacity: function _removeOpacity(content) {
  67. var contentWithoutOpacity = content.replace(RegExp('[ ]*opacity:[ ]*[0-9.]+[ ]*;?[ ]*'), '');
  68. // remove empty style attributes
  69. contentWithoutOpacity = contentWithoutOpacity.replace(RegExp('[ ]?style=""'), '');
  70. return contentWithoutOpacity;
  71. },
  72. fixTextAutosize: function fixTextAutosize(boardSpec) {
  73. if (boardSpec && boardSpec.widgets) {
  74. _.each(boardSpec.widgets, function (widget) {
  75. // remove any font-size styles if isResponsive is true
  76. if (widget && widget.content && widget.type === 'text' && widget.isResponsive) {
  77. var $content = $(widget.content);
  78. $content.find('[style*="font-size"]').css('font-size', '');
  79. widget.content = $content[0].outerHTML;
  80. }
  81. });
  82. }
  83. },
  84. down: function down(spec) {
  85. // no downgrade at this time; return as is
  86. return Promise.resolve(spec);
  87. }
  88. });
  89. return new Upgrade();
  90. });
  91. //# sourceMappingURL=9.js.map