NewDashboardActionHandler.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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: Content Explorer
  7. *| (C) Copyright IBM Corp. 2015, 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. define(['../../../app/util/ErrorUtils', 'underscore'], function (Utils, _) {
  14. var ActionHandler = function () {
  15. function ActionHandler() {
  16. _classCallCheck(this, ActionHandler);
  17. }
  18. /**
  19. * Menu item handler
  20. */
  21. ActionHandler.prototype.onSelectItem = function onSelectItem(context) {
  22. this._openCreateView(context);
  23. };
  24. /**
  25. * Determine when we show/hide the menu item
  26. */
  27. ActionHandler.prototype.isItemVisible = function isItemVisible(options) {
  28. return this.canExecute(options);
  29. };
  30. /**
  31. * Default action handler
  32. */
  33. ActionHandler.prototype.doAction = function doAction(context) {
  34. return this._openCreateView(context);
  35. };
  36. /**
  37. * Determine if we can execute the action based on the selection
  38. */
  39. ActionHandler.prototype.canExecute = function canExecute(options) {
  40. var isSelectionAllowed = this._isSelectionValid(options, true);
  41. return Utils.hasCapability(options.glassContext, 'canAuthorDashboard') && isSelectionAllowed;
  42. };
  43. ActionHandler.prototype._openCreateView = function _openCreateView(context) {
  44. var perspectiveOptions = {
  45. content: {}
  46. };
  47. var sources = this._getSources(context);
  48. if (sources && sources.length > 0) {
  49. perspectiveOptions.content.sources = sources;
  50. }
  51. return context.glassContext.appController.openAppView('createBoard', perspectiveOptions);
  52. };
  53. ActionHandler.prototype._getSources = function _getSources(options) {
  54. var isSelectionValid = this._isSelectionValid(options, false);
  55. var dataSourcesArray = null;
  56. if (isSelectionValid) {
  57. dataSourcesArray = [];
  58. var selections = options.target.activeObject.aSelectedContext;
  59. for (var i = 0; i < selections.length; i++) {
  60. dataSourcesArray.push({
  61. assetId: selections[i].id,
  62. type: selections[i].type,
  63. name: selections[i].defaultName,
  64. searchPath: selections[i].searchPath,
  65. isOlapPackage: selections[i].userInterfaces && _.indexOf(selections[i].userInterfaces, 'analysisStudio') >= 0
  66. });
  67. }
  68. }
  69. return dataSourcesArray;
  70. };
  71. ActionHandler.prototype._isSelectionValid = function _isSelectionValid(options, defaultValue) {
  72. var typesToOpen = ['module', 'dataSet2', 'uploadedFile', 'package', 'data_asset'];
  73. var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext;
  74. if (selection) {
  75. for (var i = 0; i < selection.length; i++) {
  76. // The item must be either module or uploaded File
  77. var aType = typesToOpen;
  78. if (_.intersection([selection[i].type], aType).length < 1) {
  79. return false;
  80. }
  81. // The item must have read permission
  82. var aPerm = ['read'];
  83. if (_.intersection(selection[i].permissions, aPerm).length < aPerm.length) {
  84. return false;
  85. }
  86. // The item must not be disabled
  87. if (selection[i].disabled && selection[i].disabled.toString().toLowerCase() === 'true') {
  88. return false;
  89. }
  90. }
  91. return true;
  92. }
  93. return defaultValue || false;
  94. };
  95. return ActionHandler;
  96. }();
  97. return ActionHandler;
  98. });
  99. //# sourceMappingURL=NewDashboardActionHandler.js.map