123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2018
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/upgrades/UpgradeBase', '../../../lib/@waca/dashboard-common/dist/core/Model', '../../../app/nls/StringResources', './ContainerPageIdUpgradeHelper'], function (_, Class, UpgradeBase, Model, StringResources, ContainerPageIdUpgradeHelper) {
- var SinglePageDashboardsUpgradeHelper = function () {
- function SinglePageDashboardsUpgradeHelper() {
- _classCallCheck(this, SinglePageDashboardsUpgradeHelper);
- }
- /**
- * Perform upgrade
- *
- * @param {object} spec - spec to perform upgrade on
- *
- * @return {Promise} Promise to be resolved when upgrade performed
- */
- SinglePageDashboardsUpgradeHelper.prototype.upgrade = function upgrade(spec) {
- this._containerPageIdUpgrader = new ContainerPageIdUpgradeHelper();
- if (!spec) {
- return Promise.resolve(spec);
- }
- if (!this._isSinglePageDashboard(spec)) {
- return Promise.resolve(spec);
- }
- this.upgradeSinglePageDashboard(spec);
- return Promise.resolve(spec);
- };
- /**
- * Check whether the spec is a single page dashboard
- *
- * @param {object} spec - dashboard spec
- *
- * @return {boolean}
- */
- SinglePageDashboardsUpgradeHelper.prototype._isSinglePageDashboard = function _isSinglePageDashboard(spec) {
- if (!spec || !spec.layout) {
- return false;
- }
- var type = spec.layout.type;
- if (type === 'absolute' || type === 'container') {
- var template = spec.layout.templateName;
- var isInfographic = template.lastIndexOf('Infographics', 0) === 0;
- return !isInfographic; //If we don't have an infographic, then we have a single page dashboard.
- }
- return false;
- };
- /**
- * Upgrade a single page dashboard spec to a tabbed dashboard with a single tab that is hidden
- *
- * @param {object} spec - dashboard spec
- */
- SinglePageDashboardsUpgradeHelper.prototype.upgradeSinglePageDashboard = function upgradeSinglePageDashboard(spec) {
- var tabLayout = {
- id: new Model().id,
- type: 'tab',
- items: [{
- title: StringResources.get('defaultTabTitle', {
- index: 1
- })
- }],
- style: {
- height: '100%'
- },
- hideTab: true
- };
- //Move the page properties into the new first tab.
- var layout = spec.layout;
- var firstTab = tabLayout.items[0];
- firstTab.id = layout.id;
- firstTab.type = layout.type;
- firstTab.items = layout.items;
- firstTab.templateName = layout.templateName;
- delete layout.templateName;
- if (layout.style) {
- firstTab.style = layout.style;
- }
- if (layout.css && layout.css.indexOf('gridCapable') !== -1) {
- //Clean up an unneeded css class which will cause problems if present on the tab layout.
- var newCss = layout.css.replace('gridCapable', '');
- if (newCss) {
- layout.css = newCss;
- } else {
- delete layout.css;
- }
- }
- //Merge in the new tab layout into the spec.
- _.extend(layout, tabLayout);
- if (this._isRelativeSinglePage(spec)) {
- var currentId = spec.layout.items[0].items[0].id;
- var newId = spec.layout.items[0].id;
- this._upgradeContainerPageIds(spec, currentId, newId);
- }
- };
- /**
- * check if the single page is a relative: check if the only item is of type container
- * @param {Object} spec
- * @return true if the single page is a relative one
- */
- SinglePageDashboardsUpgradeHelper.prototype._isRelativeSinglePage = function _isRelativeSinglePage(spec) {
- return spec.layout.items[0].type === 'container';
- };
- SinglePageDashboardsUpgradeHelper.prototype._upgradeContainerPageIds = function _upgradeContainerPageIds(spec, currentId, newId) {
- var containerPageIdMap = {};
- containerPageIdMap[currentId] = newId;
- this._containerPageIdUpgrader.upgrade(spec, containerPageIdMap);
- };
- return SinglePageDashboardsUpgradeHelper;
- }();
- return SinglePageDashboardsUpgradeHelper;
- });
- //# sourceMappingURL=SinglePageDashboardsUpgradeHelper.js.map
|