ShareActionHandler.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. *
  5. * IBM Cognos Products: BI Dashboard
  6. *
  7. * Copyright IBM Corp. 2016, 2020
  8. *
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../app/nls/StringResources'], function (BaseClass, stringResources) {
  12. var VIDA_MAP_ANIM_TIMEOUT_MILLIS = 10000; // milliseconds
  13. var ShareActionHandler = BaseClass.extend({
  14. /**
  15. * @param {options} set of initial properties
  16. */
  17. init: function init(options) {
  18. this.vidaMapAnimTimeout = options && options.vidaMapAnimTimeout || VIDA_MAP_ANIM_TIMEOUT_MILLIS;
  19. },
  20. execute: function execute(context) {
  21. if (context.urlMap.objRef) {
  22. var persp = context && context.target && context.target.activeObject && context.target.activeObject.aSelectedContext && context.target.activeObject.aSelectedContext[0].tags && context.target.activeObject.aSelectedContext[0].tags.indexOf('story') !== -1 ? 'story' : 'dashboard';
  23. var share = {
  24. perspective: persp,
  25. objRef: context.urlMap.objRef,
  26. action: 'view',
  27. mode: context.urlMap.mode ? context.urlMap.mode : 'dashboard'
  28. };
  29. var view = context.glassContext.appController.getCurrentContentView();
  30. if (view.perspective === 'dashboard' && typeof view.boardController.layoutController.getCurrentSubViewId === 'function') {
  31. share.subView = view.boardController.layoutController.getCurrentSubViewId();
  32. }
  33. return share;
  34. } else {
  35. throw new Error('Unable to resolve share context. Missing objRef.');
  36. }
  37. },
  38. getShareableItems: function getShareableItems(context) {
  39. var els = [];
  40. var view = context.glassContext.appController.getCurrentContentView();
  41. if (view.perspective === 'dashboard') {
  42. var item = {};
  43. item.el = view.el;
  44. if (typeof view.boardController.layoutController.getCurrentSubViewTitle === 'function') {
  45. item.label = stringResources.get('screenshot_label_tab', { title: view.getTitle(),
  46. tabName: view.boardController.layoutController.getCurrentSubViewTitle() });
  47. } else {
  48. item.label = stringResources.get('screenshot_label', { title: view.getTitle() });
  49. }
  50. els.push(item);
  51. }
  52. return this.reRenderMaps(view).then(function () {
  53. return els;
  54. });
  55. },
  56. /*
  57. * Returns true if there is a selected context of a dashboard or story or if there is no context (i.e. when we are in a perspective view)
  58. * @param {object} context
  59. */
  60. isEnabled: function isEnabled(_ref) {
  61. var context = _ref.context;
  62. if (context) {
  63. var tags = context.length === 1 && context[0] && context[0].tags;
  64. return tags && (tags.indexOf('dashboard') !== -1 || tags.indexOf('story') !== -1);
  65. }
  66. return true;
  67. },
  68. _triggerDataPlayerEvent: function _triggerDataPlayerEvent(eventName, contentView) {
  69. var dashboardApi = contentView.dashboardApi;
  70. if (dashboardApi) {
  71. dashboardApi.triggerDashboardEvent(eventName);
  72. }
  73. },
  74. enterShareState: function enterShareState(context) {
  75. var _this = this;
  76. return Promise.resolve().then(function () {
  77. var contentView = context.glassContext.appController.getCurrentContentView();
  78. _this._triggerDataPlayerEvent('open:sharePanel', contentView);
  79. });
  80. },
  81. leaveShareState: function leaveShareState(context) {
  82. var _this2 = this;
  83. return Promise.resolve().then(function () {
  84. var contentView = context.glassContext.appController.getCurrentContentView();
  85. _this2._triggerDataPlayerEvent('close:sharePanel', contentView);
  86. });
  87. },
  88. /**
  89. * Re-render map widgets for screen capture. Allow sub-classes to access.
  90. * @protected
  91. * @param view the content view
  92. * @return {Promise}
  93. */
  94. reRenderMaps: function reRenderMaps(view) {
  95. var layoutController = view.boardController.layoutController;
  96. var currentLayout = view.boardModel.getSelectedLayout();
  97. var widgetsOnCurrentPage = view.dashboardApi.getCanvas().getContent(currentLayout).findContent({ type: 'widget' });
  98. var mapWidgetList = widgetsOnCurrentPage.filter(function (widget) {
  99. var vis = widget.getFeature('Visualization');
  100. if (vis) {
  101. if (vis.getType() === 'Tiledmap') {
  102. return true;
  103. }
  104. }
  105. return false;
  106. });
  107. var mapWidgetIds = mapWidgetList.map(function (widget) {
  108. return widget.getId();
  109. });
  110. if (mapWidgetIds.length > 0) {
  111. return Promise.map(mapWidgetIds, function (widgetId) {
  112. var mapWidget = layoutController.widgetLoader.getWidget(widgetId);
  113. return mapWidget.mapVizRenderForPrint();
  114. }).delay(this.vidaMapAnimTimeout); //Timeout is needed for the VIDA map animation.
  115. } else {
  116. return Promise.resolve();
  117. }
  118. },
  119. /**
  120. * Returns true if export to pdf for dashboard is allowed.
  121. *
  122. * @param {*} context.glassContext the Glass context
  123. */
  124. canExportToPDF: function canExportToPDF() /* options */{
  125. return true;
  126. },
  127. getInstrumentation: function getInstrumentation(context) {
  128. return context.glassContext.appController.getCurrentContentView().getDashboardApi().getFeature('segment').getInfo({ type: 'Shared Object' });
  129. },
  130. /**
  131. * Creates a PDF.
  132. *
  133. * @param {*} context.glassContext the Glass context
  134. * @param {*} pageSize an object representing the page size
  135. * @param {*} printFilters print filters.
  136. * @return {Promise}
  137. */
  138. exportToPDF: function exportToPDF(context, pageSize, printFilters) {
  139. var dashApi = context.glassContext.appController.getCurrentContentView().getDashboardApi();
  140. var printFeature = dashApi.getFeature('Print');
  141. var pageOptions = {
  142. pageSize: pageSize,
  143. printFilters: printFilters
  144. };
  145. var id = dashApi.getCanvas().getContent().getId();
  146. return printFeature.print(id, context.glassContext.appController, pageOptions);
  147. }
  148. });
  149. return ShareActionHandler;
  150. });
  151. //# sourceMappingURL=ShareActionHandler.js.map