wa_infographic.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 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(['../../../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. /**
  16. * Perform upgrade
  17. *
  18. * @param {object} spec - spec to perform upgrade on
  19. *
  20. * @return {Promise} Promise to be resolved when upgrade performed
  21. */
  22. up: function up(spec) {
  23. if (!spec) {
  24. return Promise.resolve(spec);
  25. }
  26. // for safety, make sure we're upgrading the right thing
  27. var containsInfographic = this._containsInfographic(spec.layout.templateName);
  28. if (!containsInfographic) {
  29. return Promise.resolve(spec);
  30. }
  31. var templateName = spec.layout.templateName;
  32. delete spec.layout.templateName;
  33. spec.layout.type = 'singlePage';
  34. // note: infographics have only one page
  35. spec.layout.items[0].title = 'Untitled 1';
  36. spec.layout.items[0].templateName = templateName;
  37. return Promise.resolve(spec);
  38. },
  39. down: function down(spec) {
  40. if (!spec) {
  41. return Promise.resolve(spec);
  42. }
  43. // for safety, make sure we're upgrading the right thing
  44. var containsInfographic = this._containsInfographic(spec.layout.items[0].templateName);
  45. if (!containsInfographic) {
  46. return Promise.resolve(spec);
  47. }
  48. var templateName = spec.layout.items[0].templateName;
  49. spec.layout.templateName = templateName;
  50. spec.layout.type = 'container';
  51. delete spec.layout.items[0].title;
  52. delete spec.layout.items[0].templateName;
  53. return Promise.resolve(spec);
  54. },
  55. /**
  56. * Check whether the spec contains an infographic layout
  57. *
  58. * @param {object} templateName - template name (ex: Infographics1)
  59. *
  60. * @return {boolean}
  61. */
  62. _containsInfographic: function _containsInfographic(templateName) {
  63. if (!templateName) {
  64. return false;
  65. }
  66. // startsWith('Infographics')
  67. return templateName.lastIndexOf('Infographics', 0) === 0;
  68. }
  69. });
  70. return new Upgrade();
  71. });
  72. //# sourceMappingURL=wa_infographic.js.map