123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2016, 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['jquery', 'underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase'], function ($, _, Class, UpgradeBase) {
- var Upgrade = Class.extend([UpgradeBase], {
- init: function init() {
- this.VERSION = 9;
- },
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- up: function up(spec) {
- if (!spec) {
- return Promise.resolve(spec);
- }
- this.moveTransparencyToLayoutModel(spec);
- this.fixTextAutosize(spec);
- return Promise.resolve(spec);
- },
- moveTransparencyToLayoutModel: function moveTransparencyToLayoutModel(boardSpec) {
- if (boardSpec && boardSpec.widgets) {
- var widgetIds = _.keys(boardSpec.widgets);
- _.each(widgetIds, function (widgetId) {
- var layoutSpec = this._findLayoutSpecById(boardSpec.layout, widgetId);
- var widget = boardSpec.widgets[widgetId];
- if (layoutSpec && typeof widget.transparency !== 'undefined') {
- if (!layoutSpec.style) {
- layoutSpec.style = {};
- }
- if (typeof layoutSpec.style.opacity === 'undefined') {
- layoutSpec.style.opacity = widget.transparency;
- }
- delete widget.transparency;
- }
- // transparency now stored on a different node, remove it from existing dashboards/stories on load.
- if (widget && widget.content) {
- widget.content = this._removeOpacity(widget.content);
- }
- }.bind(this));
- }
- },
- _findLayoutSpecById: function _findLayoutSpecById(layoutSpec, id) {
- var spec;
- if (layoutSpec.id === id) {
- spec = layoutSpec;
- }
- if (!spec && layoutSpec.items) {
- for (var i = 0; !spec && i < layoutSpec.items.length; i++) {
- spec = this._findLayoutSpecById(layoutSpec.items[i], id);
- }
- }
- return spec;
- },
- _removeOpacity: function _removeOpacity(content) {
- var contentWithoutOpacity = content.replace(RegExp('[ ]*opacity:[ ]*[0-9.]+[ ]*;?[ ]*'), '');
- // remove empty style attributes
- contentWithoutOpacity = contentWithoutOpacity.replace(RegExp('[ ]?style=""'), '');
- return contentWithoutOpacity;
- },
- fixTextAutosize: function fixTextAutosize(boardSpec) {
- if (boardSpec && boardSpec.widgets) {
- _.each(boardSpec.widgets, function (widget) {
- // remove any font-size styles if isResponsive is true
- if (widget && widget.content && widget.type === 'text' && widget.isResponsive) {
- var $content = $(widget.content);
- $content.find('[style*="font-size"]').css('font-size', '');
- widget.content = $content[0].outerHTML;
- }
- });
- }
- },
- down: function down(spec) {
- // no downgrade at this time; return as is
- return Promise.resolve(spec);
- }
- });
- return new Upgrade();
- });
- //# sourceMappingURL=9.js.map
|