rsContextMenuActions.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. // Licensed Materials - Property of IBM
  2. // IBM Cognos Products: rs
  3. // (C) Copyright IBM Corp. 2016, 2020
  4. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  5. define([
  6. 'bi/glass/app/plugins/MenuActionInterface',
  7. 'jquery',
  8. 'q',
  9. 'bi/authoring/utils/rsOpenHelper',
  10. 'bi/authoring/utils/rsShareHelper',
  11. 'bi/authoring/utils/rsPerformance',
  12. 'bi/authoring/utils/rsSaveReportView'
  13. ],
  14. function(MenuActionInterface, $, Q, OpenHelper, ShareHelper, rsPerformance, rsSaveReportView) {
  15. 'use strict';
  16. var rsContextMenuActions = MenuActionInterface.extend({
  17. isItemVisible: function(context) {
  18. // console.log("rsContextMenuActions.isItemVisible");
  19. if (! context.target )
  20. {
  21. return false;
  22. }
  23. else if (! context.target.activeObject && ! context.target.objectInformation)
  24. {
  25. return false;
  26. }
  27. var v_oCMInfo;
  28. if (context.target.activeObject)
  29. {
  30. var v_aSelectedContext = context.target.activeObject.aSelectedContext;
  31. if (v_aSelectedContext.length !== 1)
  32. {
  33. return false;
  34. }
  35. v_oCMInfo = v_aSelectedContext[0];
  36. }
  37. else if (context.target.objectInformation)
  38. {
  39. v_oCMInfo = context.target.objectInformation;
  40. }
  41. // Search results provide the context object(s) in a for where boolean properties are strings
  42. // Make it consistent with context provided by content
  43. if (typeof v_oCMInfo.disabled == 'string')
  44. {
  45. v_oCMInfo.disabled = v_oCMInfo.disabled == 'true' ? true : (v_oCMInfo.disabled == 'false' ? false : v_oCMInfo.disabled);
  46. }
  47. // This is what we really should be doing but until we work out the 'disabled' story product wide or for reporting
  48. // we will reduce the impact to match what dashboard is doing which is prevent creation of new objects from a disabled package or module
  49. //if (!!v_oCMInfo.disabled)
  50. //{
  51. // return false;
  52. //}
  53. var v_sCapabilityToCheck = 'canUseReportStudio';
  54. var v_sPermission = 'read';
  55. switch(context.target.itemId)
  56. {
  57. case "com.ibm.bi.authoring.convertToReport":
  58. if (['analysis', 'query'].indexOf( v_oCMInfo.type ) === -1)
  59. {
  60. return false;
  61. }
  62. break;
  63. case "com.ibm.bi.authoring.createReportFromModule":
  64. if (v_oCMInfo.type !== "module")
  65. {
  66. return false;
  67. }
  68. // See comment above regarding disabled
  69. if (!!v_oCMInfo.disabled)
  70. {
  71. return false;
  72. }
  73. break;
  74. case "com.ibm.bi.authoring.createReportFromPackage":
  75. if (v_oCMInfo.type !== "package")
  76. {
  77. return false;
  78. }
  79. // See comment above regarding disabled
  80. if (!!v_oCMInfo.disabled)
  81. {
  82. return false;
  83. }
  84. if (!v_oCMInfo.effectiveUserCapabilities || v_oCMInfo.effectiveUserCapabilities.indexOf(v_sCapabilityToCheck) === -1)
  85. {
  86. return false;
  87. }
  88. break;
  89. case "com.ibm.bi.datasets.editDataset":
  90. if (v_oCMInfo.type !== "dataSet2")
  91. {
  92. return false;
  93. }
  94. v_sCapabilityToCheck = 'canUseMyDataSets';
  95. break;
  96. case "com.ibm.bi.authoring.editReport":
  97. if (['interactiveReport', 'report', 'reportTemplate'].indexOf( v_oCMInfo.type ) === -1)
  98. {
  99. return false;
  100. }
  101. if (v_oCMInfo.type === 'report' && v_oCMInfo.metadataModelPackage && v_oCMInfo.metadataModelPackage[0]
  102. && v_oCMInfo.metadataModelPackage[0].effectiveUserCapabilities)
  103. {
  104. if (v_oCMInfo.metadataModelPackage[0].effectiveUserCapabilities.indexOf(v_sCapabilityToCheck) === -1 )
  105. {
  106. return false;
  107. }
  108. }
  109. break;
  110. case "com.ibm.bi.authoring.saveAsReportView":
  111. if (['interactiveReport', 'report', 'query', 'analysis'].indexOf( v_oCMInfo.type ) === -1)
  112. {
  113. return false;
  114. }
  115. v_sCapabilityToCheck = undefined;
  116. v_sPermission = undefined;
  117. break;
  118. case "com.ibm.bi.authoring.saveAsPowerPlayView":
  119. if (v_oCMInfo.type !== 'powerPlay8Report')
  120. {
  121. return false;
  122. }
  123. v_sCapabilityToCheck = undefined;
  124. v_sPermission = undefined;
  125. break;
  126. case "com.ibm.bi.contentApps.action.runAs":
  127. if ( ['interactiveReport', 'report', 'reportView', 'query', 'analysis', 'powerPlay8Report', 'powerPlay8ReportView'].indexOf( v_oCMInfo.type ) === -1)
  128. {
  129. return false;
  130. }
  131. v_sCapabilityToCheck = 'canUseCognosViewerRunWithOptions';
  132. v_sPermission = 'execute';
  133. if (v_oCMInfo.type === 'reportView')
  134. {
  135. if (v_oCMInfo.base === null)
  136. {
  137. // base report of report view no longer exists
  138. return false;
  139. }
  140. else if (v_oCMInfo.base[0] && v_oCMInfo.base[0].permissions && v_oCMInfo.base[0].permissions.indexOf(v_sPermission) === -1)
  141. {
  142. return false;
  143. }
  144. }
  145. break;
  146. case "com.ibm.bi.contentApps.defaultAction.interactiveReport":
  147. case "com.ibm.bi.contentApps.defaultAction.report":
  148. case "com.ibm.bi.contentApps.defaultAction.dataSet2":
  149. case "com.ibm.bi.contentApps.defaultAction.reportTemplate":
  150. case "com.ibm.bi.contentApps.defaultAction.reportView":
  151. case "com.ibm.bi.contentApps.defaultAction.query":
  152. case "com.ibm.bi.contentApps.defaultAction.analysis":
  153. return context.target.itemId.indexOf(v_oCMInfo.type) > 0 &&
  154. OpenHelper.determineDefaultAction(context.target.itemId, v_oCMInfo, context.glassContext) !== null;
  155. case "com.ibm.bi.datasets.createDataSetFromModule":
  156. if (v_oCMInfo.type !== "module")
  157. {
  158. return false;
  159. }
  160. // See comment above regarding disabled
  161. if (!!v_oCMInfo.disabled)
  162. {
  163. return false;
  164. }
  165. v_sCapabilityToCheck = 'canUseMyDataSets';
  166. break;
  167. case "com.ibm.bi.datasets.createDataSetFromPackage":
  168. if (v_oCMInfo.type !== "package")
  169. {
  170. return false;
  171. }
  172. // See comment above regarding disabled
  173. if (!!v_oCMInfo.disabled)
  174. {
  175. return false;
  176. }
  177. v_sCapabilityToCheck = 'canUseMyDataSets';
  178. break;
  179. case "com.ibm.bi.datasets.datasets-divider-top":
  180. case "com.ibm.bi.datasets.datasets-divider-bottom":
  181. return true;
  182. default:
  183. return false;
  184. }
  185. if (v_sCapabilityToCheck && !context.glassContext.hasCapability( v_sCapabilityToCheck ))
  186. {
  187. return false;
  188. }
  189. var v_aPermissions = v_oCMInfo.permissions;
  190. if (!v_aPermissions)
  191. {
  192. return false;
  193. }
  194. if (v_sPermission && v_aPermissions.indexOf(v_sPermission) == -1)
  195. {
  196. return false;
  197. }
  198. return true;
  199. },
  200. isVisible: function(context) {
  201. var v_bShareable = false;
  202. // Ensure we are being called with expected info
  203. if (context && context.target && context.target.itemId && context.glassContext)
  204. {
  205. switch(context.target.itemId)
  206. {
  207. case "com.ibm.bi.glass.common.shareContextual":
  208. v_bShareable = true;
  209. break;
  210. case "com.ibm.bi.glass.common.embedContextual":
  211. // Don't embed datasets
  212. if (context.target.activeObject)
  213. {
  214. var v_oCmProperties = context.target.activeObject.aSelectedContext[0];
  215. if (v_oCmProperties && v_oCmProperties.type !== 'dataSet2')
  216. {
  217. v_bShareable = true;
  218. }
  219. }
  220. break;
  221. case "com.ibm.bi.glass.common.operations.shareCurrent":
  222. case "com.ibm.bi.glass.common.operations.embedCurrent":
  223. //Meaning, we are sharing from overflow menu of authoring.
  224. var v_oCurrentContentView = context.glassContext.currentAppView.currentContentView;
  225. v_bShareable = ShareHelper.isShareable(v_oCurrentContentView, context.target.itemId === "com.ibm.bi.glass.common.operations.embedCurrent");
  226. break;
  227. default:
  228. //Remains invisible unless action implemented otherwise.
  229. console.log('Unsupported isVisible menu action item : ' + context.target.itemId);
  230. }
  231. }
  232. return v_bShareable;
  233. },
  234. execute: function(context) {
  235. // console.log('rsContextMenuActions.execute ...');
  236. var deferred = Q.defer();
  237. var v_oCmProperties;
  238. if (context.target && context.target.activeObject)
  239. {
  240. v_oCmProperties = context.target.activeObject.aSelectedContext[0];
  241. }
  242. else if (context.target && context.target.objectInformation)
  243. {
  244. v_oCmProperties = context.target.objectInformation;
  245. }
  246. var v_oCurrentContentView = context.glassContext && context.glassContext.currentAppView && context.glassContext.currentAppView.currentContentView;
  247. var v_oOpenSpec = {
  248. cmProperties: v_oCmProperties,
  249. mode: context.mode,
  250. glassContext: context.glassContext,
  251. contentView: v_oCurrentContentView
  252. };
  253. var v_fExecute;
  254. if (context.mode == 'defaultAction') {
  255. // This call is used to process a request that has no perspective defined
  256. // e.g. share link or openAppView( undefined, {...} )
  257. // It updates the urlMap with the perspective as well as any further information
  258. // needed to properly process the request.
  259. // If we have no cmProperties from the target, create oe using the info from the urlMap
  260. v_oOpenSpec.cmProperties = v_oOpenSpec.cmProperties || { id: context.urlMap.id, type: context.urlMap.type };
  261. v_oOpenSpec.urlMap = context.urlMap;
  262. v_fExecute = OpenHelper.getPerspective;
  263. }
  264. else {
  265. // This call generates the share link based on the current context
  266. // If we have no cmProperties, use the current view's cm properties.
  267. v_oOpenSpec.cmProperties = v_oOpenSpec.cmProperties || v_oCurrentContentView.cmProperties;
  268. v_fExecute = ShareHelper.getShareUrlMap;
  269. }
  270. v_fExecute(v_oOpenSpec)
  271. .catch(function(err) {
  272. console.log("rsContextMenuActions.execte ... FAILED.");
  273. deferred.reject(err);
  274. })
  275. .done(function(v_oUrlMap){
  276. deferred.resolve(v_oUrlMap);
  277. });
  278. return deferred.promise;
  279. },
  280. doAction: function(context) {
  281. // console.log('rsContextMenuActions.doAction ...');
  282. // doAction() is called from glass components.
  283. // glass uses jQuery deferreds and promises
  284. // convert the standard promise into jquery for the glass
  285. var $dfd = $.Deferred();
  286. this.onSelectItem(context)
  287. .catch( function(err){
  288. console.log('rsContextMenuActions.doAction ... FAILED');
  289. $dfd.reject(err);
  290. })
  291. .done( function(result){
  292. // console.log('rsContextMenuActions.doAction ... succeeded');
  293. $dfd.resolve(result);
  294. });
  295. return $dfd.promise();
  296. },
  297. canExecute: function(context) {
  298. //console.log('rsContextMenuActions.canExecute');
  299. return this.isItemVisible(context);
  300. },
  301. onSelectItem: function(context) {
  302. rsPerformance.clearMeasures();
  303. rsPerformance.clearMarks();
  304. rsPerformance.mark('authoring-selectItemAndDraw-start');
  305. rsPerformance.mark('rsContextMenuActions.onSelectItem');
  306. //console.log('rsContextMenuActions.onSelectItem ...');
  307. console.time('rsperf: total_RunReport');
  308. console.time('rsperf: onSelectItem->render');
  309. var deferred = Q.defer();
  310. var v_oCmProperties;
  311. if (context.target && context.target.activeObject)
  312. {
  313. v_oCmProperties = context.target.activeObject.aSelectedContext[0];
  314. }
  315. else if (context.target && context.target.objectInformation)
  316. {
  317. v_oCmProperties = context.target.objectInformation;
  318. }
  319. else
  320. {
  321. console.log('rsContextMenuActions.onSelectItem ... FAILED -- no target');
  322. deferred.reject(new Error('unexpected context.target: ' + context.target ? context.target.toString() : '<null>'));
  323. return deferred.promise;
  324. }
  325. if (context.target.itemId === "com.ibm.bi.authoring.saveAsReportView" ||
  326. context.target.itemId === "com.ibm.bi.authoring.saveAsPowerPlayView")
  327. {
  328. rsSaveReportView.saveReportView(v_oCmProperties, context)
  329. .catch(function(err){
  330. deferred.reject(err);
  331. })
  332. .done(function(result){
  333. deferred.resolve(result);
  334. });
  335. }
  336. else
  337. {
  338. OpenHelper.openView({
  339. cmProperties: v_oCmProperties,
  340. actionId: context.target.itemId,
  341. glassContext: context.glassContext,
  342. runOptions: context.target.runOptions })
  343. .catch(function(err){
  344. console.log('rsContextMenuActions.onSelectItem ... FAILED');
  345. deferred.reject(err);
  346. })
  347. .done(function(result){
  348. //console.log('rsContextMenuActions.onSelectItem ... succeeded');
  349. deferred.resolve(result);
  350. });
  351. }
  352. return deferred.promise;
  353. },
  354. getShareableItems: function(context) {
  355. var items = [];
  356. var view = context.glassContext.getCurrentContentView();
  357. if (view && view.getShareableItemsForCollaboration)
  358. {
  359. items = view.getShareableItemsForCollaboration();
  360. }
  361. return Q.resolve(items);
  362. }
  363. });
  364. return rsContextMenuActions;
  365. });