OpenActionHandler.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Content Explorer
  6. *| (C) Copyright IBM Corp. 2015, 2020
  7. *|
  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', '../../../app/util/ErrorUtils', 'underscore', '../util/InstrumentationUtil'], function (BaseClass, Utils, _, InstrumentationUtil) {
  13. var ActionHandler = BaseClass.extend({
  14. /**
  15. * Public API to indicate if the Action should be shown
  16. */
  17. isItemVisible: function isItemVisible(options) {
  18. return this.canExecute(options);
  19. },
  20. /**
  21. * Public API to indicate if the Action can be executed.
  22. */
  23. canExecute: function canExecute(options) {
  24. var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext;
  25. var isSelectionAllowed = false;
  26. if (selection.length === 1) {
  27. isSelectionAllowed = this._isSelectionValid(options, true);
  28. }
  29. return isSelectionAllowed && Utils.hasCapability(options.glassContext);
  30. },
  31. /**
  32. * Public API to perform the action.
  33. */
  34. doAction: function doAction(context) {
  35. return this._openDashboardView(context);
  36. },
  37. /**
  38. * Handle the open dashboard action
  39. */
  40. onSelectItem: function onSelectItem(context) {
  41. return this._openDashboardView(context);
  42. },
  43. _openDashboardView: function _openDashboardView(context) {
  44. var id = context.target.activeObject.aSelectedContext[0].id;
  45. return this._getTargetPerspective(id, context).then(function (perspective) {
  46. InstrumentationUtil.track(context.glassContext, 'viewed', {
  47. objectType: perspective,
  48. object: id,
  49. type: 'Read Object'
  50. });
  51. return context.glassContext.appController.openAppView(perspective, {
  52. id: id,
  53. content: {
  54. boardId: id,
  55. isAuthoringMode: false,
  56. // build a complete urlMap context for dashboard/story
  57. objRef: id
  58. }
  59. });
  60. });
  61. },
  62. _getTargetPerspective: function _getTargetPerspective() {
  63. return Promise.resolve('dashboard');
  64. },
  65. _hasValidTags: function _hasValidTags(item) {
  66. var tags = item.tags || [];
  67. return tags.indexOf('dashboard') !== -1;
  68. },
  69. _isSelectionValid: function _isSelectionValid(options, defaultValue) {
  70. var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext;
  71. if (selection) {
  72. for (var _iterator = selection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  73. var _ref;
  74. if (_isArray) {
  75. if (_i >= _iterator.length) break;
  76. _ref = _iterator[_i++];
  77. } else {
  78. _i = _iterator.next();
  79. if (_i.done) break;
  80. _ref = _i.value;
  81. }
  82. var item = _ref;
  83. if (!this._hasValidTags(item)) {
  84. return false;
  85. }
  86. // The item must be either module or uploaded File
  87. var aType = ['exploration', 'page_asset'];
  88. if (_.intersection([item.type], aType).length < 1) {
  89. return false;
  90. }
  91. // The item must have read permission
  92. var aPerm = ['read', 'execute'];
  93. if (_.intersection(item.permissions, aPerm).length < aPerm.length) {
  94. return false;
  95. }
  96. // The item must not be disabled
  97. if (item.disabled && item.disabled.toString().toLowerCase() === 'true') {
  98. return false;
  99. }
  100. }
  101. return true;
  102. }
  103. return defaultValue || false;
  104. }
  105. });
  106. return ActionHandler;
  107. });
  108. //# sourceMappingURL=OpenActionHandler.js.map