LiveWidgetPreview.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: Dashboard
  9. *| (C) Copyright IBM Corp. 2018, 2021
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. /**
  16. * @class LiveWidgetPreview
  17. *
  18. * @classdesc Live widget preview class that is used to create and control a live widget instance without tying it to a specific dashboard canvas.
  19. * This class is used to render a visualization anywhere in the user interface and not necessarily inside of a dashboard.
  20. * Each live widget instance correspands to a rendered instance of the live widget
  21. *
  22. * @example
  23. * // Create an instance of the LiveWidgetAPI by providing :
  24. * 1 - The node where the content will render. The visualization will be maximized to fit the size of the given node.
  25. * 2 - The glass context
  26. * 3 - the live widget spec. This could be a complete or partial spec with just the data section and/or filters.
  27. * Any missing parts will be filled by the viz recommender (e.g. mappings, vizType)
  28. *
  29. * // Example #1 - the dataView contains a modelRef that is referencing an existing source in the currently opened dashboard application
  30. * let LiveWidget = new LiveWidgetAPI({
  31. * node: document.getElementById('containerDivId'),
  32. * glassContext: this.glassContext,
  33. * spec: {
  34. * "data": {
  35. * "dataViews": [
  36. * {
  37. * "modelRef": "model000001610f7b9e74_00000002",
  38. * "dataItems": [
  39. * {
  40. * "itemId": "HollywoodMovies_xls.Year_",
  41. *
  42. * },
  43. * {
  44. * "itemId": "HollywoodMovies_xls.Rotten_Tomatoes"
  45. * }
  46. * ]
  47. * }
  48. * ]
  49. * }
  50. * }
  51. * });
  52. *
  53. *
  54. * // Example #2 - the dataView contains a model with an assetID (ContentManager id) that is referencing a module ID.
  55. * The model type is also needed. It could be either "uploadedFile", "module" or "package"
  56. * let LiveWidget = new LiveWidgetAPI({
  57. * node: document.getElementById('containerDivId'),
  58. * glassContext: this.glassContext,
  59. * spec: {
  60. * "data": {
  61. * "dataViews": [
  62. * {
  63. * "model":{
  64. * "assetId": "iB3884FE9ACF64BD2B8F0879A8C34B978",
  65. * "type": "uploadedFile"
  66. * }
  67. * "dataItems": [
  68. * {
  69. * "itemId": "HollywoodMovies_xls.Year_",
  70. *
  71. * },
  72. * {
  73. * "itemId": "HollywoodMovies_xls.Rotten_Tomatoes"
  74. * }
  75. * ]
  76. * }
  77. * ]
  78. * }
  79. * }
  80. * });
  81. *
  82. *
  83. * // Render the live widget instance after creation. The content will be rendered in the given node.
  84. * liveWidget.render();
  85. *
  86. *
  87. */
  88. define(['./error/ErrorView', 'jquery', 'underscore', '../lib/@waca/core-client/js/core-client/utils/BrowserUtils', '../widgets/livewidget/StandaloneLiveWidget'], function (ErrorView, $, _, BrowserUtils, StandaloneLiveWidget) {
  89. var STATICVIEW = {
  90. 'com.ibm.vis.rave2bundletiledmap': 'dashboard-analytics/images/placeholders/map.svg'
  91. };
  92. var LiveWidgetPreview = function (_StandaloneLiveWidget) {
  93. _inherits(LiveWidgetPreview, _StandaloneLiveWidget);
  94. function LiveWidgetPreview(options) {
  95. _classCallCheck(this, LiveWidgetPreview);
  96. return _possibleConstructorReturn(this, _StandaloneLiveWidget.call(this, options));
  97. }
  98. /**
  99. * Render the live widget preview instance.
  100. * @function LiveWidgetAPI#render
  101. * @return {Promise} promise that will be resolved when the render is complete or reject in the case of an error
  102. */
  103. LiveWidgetPreview.prototype.render = function render() {
  104. this.contentNode = document.createElement('div');
  105. this.contentNode.setAttribute('class', 'liveWidgetPreview');
  106. this.contentNode.setAttribute('style', 'width:100%;height:100%; padding:0px');
  107. this.contentNode.setAttribute('data-vis-id', this.spec.visId);
  108. if (this._isStaticView()) {
  109. var staticView = this._getStaticView();
  110. this.contentNode.appendChild(staticView);
  111. this.node.appendChild(this.contentNode);
  112. return Promise.resolve();
  113. } else {
  114. var options = {
  115. id: this.spec.id,
  116. el: this.contentNode,
  117. errorView: new ErrorView(),
  118. // Disable all extra features by default
  119. featureSet: this.featureSet || [],
  120. interactivitySettings: this.interactivitySettings,
  121. optimizeForSize: true,
  122. forceDisabledThumbnail: true,
  123. isPreview: true,
  124. isPredictPreview: this.isPredictPreview,
  125. predictData: this.predictData,
  126. managesOwnQueries: this._managesOwnQueries
  127. };
  128. return _StandaloneLiveWidget.prototype.render.call(this, options);
  129. }
  130. };
  131. LiveWidgetPreview.prototype._isStaticView = function _isStaticView() {
  132. if (BrowserUtils.isIE() && STATICVIEW[this.spec.visId]) {
  133. return true;
  134. }
  135. return false;
  136. };
  137. LiveWidgetPreview.prototype._getStaticView = function _getStaticView() {
  138. var iconUrl = STATICVIEW[this.spec.visId];
  139. if (iconUrl) {
  140. return $('<div class="vis-icon-view-snapshot-container"><img class="snapshot" src="' + STATICVIEW[this.spec.visId] + '"></img></div>')[0];
  141. }
  142. };
  143. return LiveWidgetPreview;
  144. }(StandaloneLiveWidget);
  145. return LiveWidgetPreview;
  146. });
  147. //# sourceMappingURL=LiveWidgetPreview.js.map