SelectDrillTargetActionHandler.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: CA
  7. *| (C) Copyright IBM Corp. 2018
  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', '../../widgets/livewidget/nls/StringResources', 'underscore'], function (BaseClass, StringResources, _) {
  13. 'use strict';
  14. /**
  15. * Class to open content dialog and to pick a drill through target.
  16. */
  17. var SelectDrillTargetActionHandler = BaseClass.extend({
  18. init: function init(dashboardApi) {
  19. SelectDrillTargetActionHandler.inherited('init', this, arguments);
  20. this.dashboardApi = dashboardApi;
  21. },
  22. /**
  23. * This method will show an open dialog to select a drill target.
  24. */
  25. selectTarget: function selectTarget(context) {
  26. var _this = this;
  27. context = context || {};
  28. if (!context.handlers || !context.handlers.onSelect) {
  29. throw new Error('onSelect handler must be provided');
  30. }
  31. var typesToOpen = ['report', 'reportView', 'exploration'];
  32. var options = {
  33. 'typesToOpen': typesToOpen,
  34. 'dataManipulationCallback': this._filterOutExploration.bind(this),
  35. 'extraUrlParameters': ['base'],
  36. 'multiSelect': false,
  37. 'dialogTitle': StringResources.get('selectTargetDialogTitle'),
  38. 'primaryBtnText': StringResources.get('dlg_ok'),
  39. 'onOpenCallback': function onOpenCallback(selectedItems) {
  40. _this._addDrillTarget(context.handlers.onSelect, selectedItems);
  41. }
  42. };
  43. this.dashboardApi.prepareGlassOptions(options);
  44. try {
  45. return this._selectTargetFromOpenDialog(options);
  46. } catch (error) {
  47. throw new Error(error);
  48. }
  49. },
  50. /**
  51. * The open dialog should contain dashboards, stories and reports.
  52. * However, the 'typesToOpen' value 'exploration' includes explorations, dashboards and stories.
  53. * Filtering manually here is the only way offered by ContentNav to achieve this.
  54. */
  55. _filterOutExploration: function _filterOutExploration(response) {
  56. if (response.data && response.data.length) {
  57. response.data = response.data.filter(function (result) {
  58. return !result.tags || result.type !== 'exploration' || result.tags.indexOf('dashboard') !== -1 || result.tags.indexOf('story') !== -1;
  59. });
  60. }
  61. },
  62. _selectTargetFromOpenDialog: function _selectTargetFromOpenDialog(options) {
  63. return this.dashboardApi.getGlassSvc('.ContentDialogFactory').then(function (dialogFactory) {
  64. return new Promise(function (resolve, reject) {
  65. var openDialog = dialogFactory.createOpenDialog(_extends({}, options, {
  66. resolve: resolve,
  67. reject: reject
  68. }));
  69. openDialog.open();
  70. });
  71. });
  72. },
  73. /**
  74. * @param selectedItems - an array of CM object items. When multiSelect is false, the array has only one selected item
  75. */
  76. _addDrillTarget: function _addDrillTarget(callback, selectedItems) {
  77. // There is only 1 selected item in this function because multiSelect is set to false
  78. var selectedItem = selectedItems[0];
  79. var perspective = 'authoring';
  80. if (selectedItem.type === 'exploration') {
  81. perspective = selectedItem.tags.indexOf('story') !== -1 ? 'story' : 'dashboard';
  82. }
  83. var drillTarget = {
  84. 'assetId': selectedItem.id,
  85. 'name': selectedItem.defaultName,
  86. 'type': selectedItem.type,
  87. 'searchPath': selectedItem.searchPath,
  88. 'isOlapPackage': selectedItem.userInterfaces && _.indexOf(selectedItem.userInterfaces, 'analysisStudio') >= 0,
  89. 'modificationTime': selectedItem.modificationTime,
  90. 'perspective': perspective
  91. };
  92. callback(drillTarget);
  93. }
  94. });
  95. return SelectDrillTargetActionHandler;
  96. });
  97. //# sourceMappingURL=SelectDrillTargetActionHandler.js.map