VisExpandMode.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Dashboard
  7. *| (C) Copyright IBM Corp. 2014, 2020
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. // this Class should be removed completely when the focus mode epic 276983 is completed
  14. define(['../../../widgets/livewidget/nls/StringResources', '../visSwitcher/VisChangerView', '../../../DynamicFileLoader', '../../../visualizations/vipr/VIPRLibraries', '../../../widgets/livewidget/util/VisUtil', '../../../lib/@waca/dashboard-common/dist/api/Error', 'jquery', 'underscore'], function (resources, VisChangerView, DynamicFileLoader, VIPRLibraries, VisUtil, APIError, $, _) {
  15. /**
  16. * INTENT: VisExpandMode should be used as the entry point to expand mode (also known as focus mode) processing.
  17. * //TODO: This function is just roughed in to partition code out of the widget.
  18. * //TODO: In the general widget code, it is known as expandview so perhaps this should be renamed to match...but in some respects this is more of a controller
  19. */
  20. return function () {
  21. function VisExpandMode() {
  22. _classCallCheck(this, VisExpandMode);
  23. var options = arguments.length <= 0 ? undefined : arguments[0];
  24. this.dashboard = options.dashboardApi;
  25. this.visualization = options.visualization;
  26. this.widgetApi = options.widgetApi;
  27. this.iconsFeature = this.dashboard.getFeature('Icons');
  28. this.ownerWidget = options.ownerWidget;
  29. this.$el = options.$el;
  30. this.$parent = this.$el.parent();
  31. this.visualization.on('change:type', this._updateVizTypeTitle, this);
  32. }
  33. VisExpandMode.prototype.destroy = function destroy() {
  34. if (this.dataSlotsView) {
  35. this.dataSlotsView.remove();
  36. this.dataSlotsView = null;
  37. }
  38. if (this.visChangeView) {
  39. this.visChangeView.remove();
  40. this.visChangeView = null;
  41. }
  42. this.visualization.off('change:Type', this._updateVizTypeTitle, this);
  43. };
  44. VisExpandMode.prototype.onDrop = function onDrop(dragObject) {
  45. if (this.dataSlotsView && this.dataSlotsView.isSlotSelected()) {
  46. if (this.dataSlotsView.isSelectedSlotLocalFilters()) {
  47. this.dataSlotsView.onDropContext(dragObject);
  48. } else {
  49. this.dataSlotsView.onDrop(dragObject, this.dataSlotsView.getFocusSlot());
  50. }
  51. return true; //expand mode processed the drop
  52. }
  53. return false; //this isn't expand mode.
  54. };
  55. VisExpandMode.prototype.onRestore = function onRestore() {
  56. this.$parent.prepend(this.$header);
  57. if (this.dataSlotsView) {
  58. this.dataSlotsView.remove();
  59. this.dataSlotsView = null;
  60. }
  61. if (this.ownerWidget._currVis) {
  62. this.ownerWidget._currVis.onRestore();
  63. }
  64. };
  65. VisExpandMode.prototype.renderSlotsView = function renderSlotsView() {
  66. return this.dataSlotsView && this.dataSlotsView.render();
  67. };
  68. VisExpandMode.prototype.getExpandModeContent = function getExpandModeContent($container) {
  69. var _this = this;
  70. this.ownerWidget.trigger('expandedView:visible');
  71. $container.addClass('widgetExpanded');
  72. // close the conditional histogram
  73. if (this.ownerWidget._currVis) {
  74. this.ownerWidget._currVis.setInExpandedMode();
  75. }
  76. var boardFillColor = this.ownerWidget.boardModel.layout.fillColor;
  77. var boardBackgroundColorClass = boardFillColor ? this.ownerWidget.getThemeColorClassName(boardFillColor, 'fill') : '';
  78. this.$parent = this.$el.parent();
  79. this.$header = this.$parent.find('.widgetHeader');
  80. this.$previewMessage = this.$parent.find('.customVisPreviewMessage');
  81. var changeVisIcon = this.iconsFeature.getIcon('visualizations-changeVisualization');
  82. var chevronLeftIcon = this.iconsFeature.getIcon('common-chevron_left');
  83. var resizePanel = this.iconsFeature.getIcon('resizePanel');
  84. var $content = $('<div class="expandModeContainer"></div>');
  85. //Chart region
  86. var $preview = $('<div class="preview"></div>');
  87. var visualisationBtnDescriptionId = _.uniqueId('VisExpandModeVisualisationBtnDesc_');
  88. var $visualisationBtn = $('<div class="allVisualizations" tabindex="0" role="button" aria-describedby="' + visualisationBtnDescriptionId + '">' + '<svg class="svgIcon" role="img" focusable="false">' + '<use style="pointer-events: none;" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + changeVisIcon.id + '">' + '</use></svg><span class="title" id="' + visualisationBtnDescriptionId + '">' + resources.get('toolbarChangeVisualization') + '</span>' + '<svg class="svgChevron" role="img" focusable="false">' + '<use style="pointer-events: none;" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#' + chevronLeftIcon.id + '">' + '</use></svg></div></div>');
  89. var $toolbar = $('<div class="vizToolbar" role="application"></div>');
  90. var $columns = $('<div class="columns"></div>');
  91. var $sidebar = $('<div class="focusSidebar" role="application" style="visibility:hidden"></div>');
  92. var $dragSidebar = $('<div class="resize-handle ui-resizable-handle ui-resizable-e" role="application"><svg class="svgIcon dimensions" role="img" focusable="false"><use xlink:href="#' + resizePanel.id + '" x="-11" y="65.5" width="30" height="25"/></svg></div>');
  93. var $expandPageViewContent = $('<div class="expandPageViewContent"></div>');
  94. var $expandPage = $('<div class="expandPage ' + boardBackgroundColorClass + '"></div>');
  95. var $widgetContainer = $('<div class="liveWidget widget "></div>');
  96. $toolbar.append($visualisationBtn);
  97. this.$toolbar = $toolbar; // to get ref from vizSelector
  98. this.ownerWidget._restoreToParent = this.ownerWidget.$el.parent();
  99. this.ownerWidget.$placeholder = $('<div></div>');
  100. this.ownerWidget.$placeholder.css({
  101. width: this.ownerWidget.$el.outerWidth(),
  102. height: this.ownerWidget.$el.outerHeight()
  103. });
  104. $widgetContainer.append(this.$previewMessage).append(this.$header).append(this.$el);
  105. $expandPage.append($widgetContainer);
  106. $expandPageViewContent.append($expandPage);
  107. $preview.append($toolbar).append($expandPageViewContent);
  108. $sidebar.append($columns).append($dragSidebar);
  109. $content.append($sidebar).append($preview);
  110. this.ownerWidget._restoreToParent.append(this.$placeholder);
  111. this.ownerWidget.applyCommonProperties();
  112. $container.append($content);
  113. this._$focusView = $content;
  114. this._container = $container;
  115. var content = this.dashboard.getCanvas().getContent(this.ownerWidget.id);
  116. var stateAPI = content && content.getFeature('state.internal');
  117. if (stateAPI) {
  118. var error = stateAPI.getError();
  119. if (error && error.getParams) {
  120. var params = error.getParams() || {};
  121. if (params.errorInfo && params.errorInfo.errorCode === VIPRLibraries.LOAD_DEFINITION_ERROR) {
  122. stateAPI.clearError();
  123. }
  124. }
  125. }
  126. var readyPromise = void 0;
  127. return VisUtil.validateVisDefinition(content, this.dashboard, { visId: this.ownerWidget.model.visId }).then(function (isValid) {
  128. var visualization = content.getFeature('Visualization');
  129. var definition = visualization.getDefinition();
  130. if (isValid) {
  131. if (!_this.dataSlotsView) {
  132. var slotsView = _this.ownerWidget._isShapeEnabledWidget() ? 'DataShapeSlotsView' : 'DataSlotsView';
  133. readyPromise = DynamicFileLoader.load(['dashboard-analytics/widgets/livewidget/expandmode/' + slotsView]).then(function (modules) {
  134. var SlotsView = modules[0];
  135. _this.dataSlotsView = new SlotsView({
  136. dashboardApi: _this.dashboard,
  137. visualizationApi: visualization,
  138. dndManager: _this.dashboard.getFeature('DashboardDnd.internal'),
  139. widget: _this.ownerWidget,
  140. el: $columns,
  141. missingFilters: _this.ownerWidget.getUnavailableLocalFilter()
  142. });
  143. return _this.dataSlotsView.render( /* resize= */false);
  144. });
  145. } else {
  146. readyPromise = Promise.resolve();
  147. }
  148. var vizTitle = definition.getLabel();
  149. var allVisualizations = _this.$toolbar.find('.allVisualizations');
  150. _this._setVisTypeTitle(vizTitle);
  151. allVisualizations.attr('tabindex', '0').on('primaryaction', function () {
  152. var currVis = _this.visualization.isTypeLocked() ? _this.visualization.getDefinition().getId() : 'auto';
  153. if (!_this.visChangeView) {
  154. _this.visChangeView = new VisChangerView({
  155. currentVis: currVis,
  156. widgetId: _this.ownerWidget.getId(),
  157. dashboard: _this.dashboard
  158. });
  159. }
  160. _this.visChangeView.render({
  161. currentVis: currVis,
  162. inFocusView: true
  163. }).then(_this._updateVizTypeTitle.bind(_this));
  164. });
  165. $sidebar.css({
  166. visibility: 'visible'
  167. });
  168. $sidebar.resizable({
  169. handles: [$dragSidebar],
  170. minWidth: 250,
  171. width: 368,
  172. maxWidth: 1000,
  173. stop: function () {
  174. if (this.dataSlotsView) {
  175. this.dataSlotsView.render();
  176. }
  177. }.bind(_this)
  178. });
  179. } else {
  180. readyPromise = Promise.resolve();
  181. $sidebar.remove();
  182. $toolbar.remove();
  183. }
  184. return readyPromise;
  185. }).finally(function () {
  186. readyPromise.then(function () {
  187. // focus on the first with a tabindex. (should be the interactive chart)
  188. var el = _this.$el.find('*[tabindex="0"]');
  189. if (el.length) {
  190. el[0].focus();
  191. }
  192. });
  193. });
  194. };
  195. VisExpandMode.prototype.updateExpandedViewContent = function updateExpandedViewContent(isValidVisDef) {
  196. if (!isValidVisDef) {
  197. if (this._$focusView && this._$focusView.length > 0) {
  198. var $dataSlotsViewNode = this._$focusView.find('.focusSidebar');
  199. if ($dataSlotsViewNode.length > 0) {
  200. $dataSlotsViewNode.remove();
  201. }
  202. }
  203. if (this.$toolbar && this.$toolbar.length > 0) {
  204. this.$toolbar.remove();
  205. }
  206. }
  207. };
  208. VisExpandMode.prototype.getFocusModeContainer = function getFocusModeContainer() {
  209. return this._container;
  210. };
  211. VisExpandMode.prototype._getVisTypeTitle = function _getVisTypeTitle() {
  212. return this.visualization.getDefinition().getLabel();
  213. };
  214. VisExpandMode.prototype._setVisTypeTitle = function _setVisTypeTitle(title) {
  215. var $changeVisButton = this.$toolbar.find('.allVisualizations');
  216. var $changeVisLabel = $changeVisButton.find('span');
  217. $changeVisButton.prop('title', resources.get('toolbarChangeVisualization')).attr('aria-label', resources.get('toolbarChangeVisualization')).attr('aria-describedBy', $changeVisLabel[0].id);
  218. $changeVisLabel.text(title).prop('title', title).attr('aria-label', title);
  219. };
  220. VisExpandMode.prototype._updateVizTypeTitle = function _updateVizTypeTitle() {
  221. // Only update the expanded mode title if the widget is in expanded mode
  222. if (this.ownerWidget.isWidgetMaximized()) {
  223. this._setVisTypeTitle(this._getVisTypeTitle());
  224. }
  225. };
  226. return VisExpandMode;
  227. }();
  228. });
  229. //# sourceMappingURL=VisExpandMode.js.map