12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: BI Dashboard
- *| (C) Copyright IBM Corp. 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../../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() {},
- /**
- * 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);
- }
- // for safety, make sure we're upgrading the right thing
- var containsInfographic = this._containsInfographic(spec.layout.templateName);
- if (!containsInfographic) {
- return Promise.resolve(spec);
- }
- var templateName = spec.layout.templateName;
- delete spec.layout.templateName;
- spec.layout.type = 'singlePage';
- // note: infographics have only one page
- spec.layout.items[0].title = 'Untitled 1';
- spec.layout.items[0].templateName = templateName;
- return Promise.resolve(spec);
- },
- down: function down(spec) {
- if (!spec) {
- return Promise.resolve(spec);
- }
- // for safety, make sure we're upgrading the right thing
- var containsInfographic = this._containsInfographic(spec.layout.items[0].templateName);
- if (!containsInfographic) {
- return Promise.resolve(spec);
- }
- var templateName = spec.layout.items[0].templateName;
- spec.layout.templateName = templateName;
- spec.layout.type = 'container';
- delete spec.layout.items[0].title;
- delete spec.layout.items[0].templateName;
- return Promise.resolve(spec);
- },
- /**
- * Check whether the spec contains an infographic layout
- *
- * @param {object} templateName - template name (ex: Infographics1)
- *
- * @return {boolean}
- */
- _containsInfographic: function _containsInfographic(templateName) {
- if (!templateName) {
- return false;
- }
- // startsWith('Infographics')
- return templateName.lastIndexOf('Infographics', 0) === 0;
- }
- });
- return new Upgrade();
- });
- //# sourceMappingURL=wa_infographic.js.map
|