123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- // Licensed Materials - Property of IBM
- // IBM Cognos Products: rs
- // (C) Copyright IBM Corp. 2016, 2020
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- define([
- 'bi/glass/app/plugins/MenuActionInterface',
- 'jquery',
- 'q',
- 'bi/authoring/utils/rsOpenHelper',
- 'bi/authoring/utils/rsShareHelper',
- 'bi/authoring/utils/rsPerformance',
- 'bi/authoring/utils/rsSaveReportView'
- ],
- function(MenuActionInterface, $, Q, OpenHelper, ShareHelper, rsPerformance, rsSaveReportView) {
- 'use strict';
- var rsContextMenuActions = MenuActionInterface.extend({
-
-
- isItemVisible: function(context) {
- // console.log("rsContextMenuActions.isItemVisible");
- if (! context.target )
- {
- return false;
- }
- else if (! context.target.activeObject && ! context.target.objectInformation)
- {
- return false;
- }
-
- var v_oCMInfo;
- if (context.target.activeObject)
- {
- var v_aSelectedContext = context.target.activeObject.aSelectedContext;
- if (v_aSelectedContext.length !== 1)
- {
- return false;
- }
- v_oCMInfo = v_aSelectedContext[0];
- }
- else if (context.target.objectInformation)
- {
- v_oCMInfo = context.target.objectInformation;
- }
-
- // Search results provide the context object(s) in a for where boolean properties are strings
- // Make it consistent with context provided by content
- if (typeof v_oCMInfo.disabled == 'string')
- {
- v_oCMInfo.disabled = v_oCMInfo.disabled == 'true' ? true : (v_oCMInfo.disabled == 'false' ? false : v_oCMInfo.disabled);
- }
-
- // This is what we really should be doing but until we work out the 'disabled' story product wide or for reporting
- // we will reduce the impact to match what dashboard is doing which is prevent creation of new objects from a disabled package or module
- //if (!!v_oCMInfo.disabled)
- //{
- // return false;
- //}
-
- var v_sCapabilityToCheck = 'canUseReportStudio';
- var v_sPermission = 'read';
- switch(context.target.itemId)
- {
- case "com.ibm.bi.authoring.convertToReport":
- if (['analysis', 'query'].indexOf( v_oCMInfo.type ) === -1)
- {
- return false;
- }
- break;
-
- case "com.ibm.bi.authoring.createReportFromModule":
- if (v_oCMInfo.type !== "module")
- {
- return false;
- }
- // See comment above regarding disabled
- if (!!v_oCMInfo.disabled)
- {
- return false;
- }
- break;
-
- case "com.ibm.bi.authoring.createReportFromPackage":
- if (v_oCMInfo.type !== "package")
- {
- return false;
- }
- // See comment above regarding disabled
- if (!!v_oCMInfo.disabled)
- {
- return false;
- }
- if (!v_oCMInfo.effectiveUserCapabilities || v_oCMInfo.effectiveUserCapabilities.indexOf(v_sCapabilityToCheck) === -1)
- {
- return false;
- }
- break;
-
- case "com.ibm.bi.datasets.editDataset":
- if (v_oCMInfo.type !== "dataSet2")
- {
- return false;
- }
- v_sCapabilityToCheck = 'canUseMyDataSets';
- break;
- case "com.ibm.bi.authoring.editReport":
- if (['interactiveReport', 'report', 'reportTemplate'].indexOf( v_oCMInfo.type ) === -1)
- {
- return false;
- }
- if (v_oCMInfo.type === 'report' && v_oCMInfo.metadataModelPackage && v_oCMInfo.metadataModelPackage[0]
- && v_oCMInfo.metadataModelPackage[0].effectiveUserCapabilities)
- {
- if (v_oCMInfo.metadataModelPackage[0].effectiveUserCapabilities.indexOf(v_sCapabilityToCheck) === -1 )
- {
- return false;
- }
- }
- break;
-
- case "com.ibm.bi.authoring.saveAsReportView":
- if (['interactiveReport', 'report', 'query', 'analysis'].indexOf( v_oCMInfo.type ) === -1)
- {
- return false;
- }
- v_sCapabilityToCheck = undefined;
- v_sPermission = undefined;
- break;
-
- case "com.ibm.bi.authoring.saveAsPowerPlayView":
- if (v_oCMInfo.type !== 'powerPlay8Report')
- {
- return false;
- }
- v_sCapabilityToCheck = undefined;
- v_sPermission = undefined;
- break;
-
- case "com.ibm.bi.contentApps.action.runAs":
- if ( ['interactiveReport', 'report', 'reportView', 'query', 'analysis', 'powerPlay8Report', 'powerPlay8ReportView'].indexOf( v_oCMInfo.type ) === -1)
- {
- return false;
- }
- v_sCapabilityToCheck = 'canUseCognosViewerRunWithOptions';
- v_sPermission = 'execute';
- if (v_oCMInfo.type === 'reportView')
- {
- if (v_oCMInfo.base === null)
- {
- // base report of report view no longer exists
- return false;
- }
- else if (v_oCMInfo.base[0] && v_oCMInfo.base[0].permissions && v_oCMInfo.base[0].permissions.indexOf(v_sPermission) === -1)
- {
- return false;
- }
- }
- break;
-
- case "com.ibm.bi.contentApps.defaultAction.interactiveReport":
- case "com.ibm.bi.contentApps.defaultAction.report":
- case "com.ibm.bi.contentApps.defaultAction.dataSet2":
- case "com.ibm.bi.contentApps.defaultAction.reportTemplate":
- case "com.ibm.bi.contentApps.defaultAction.reportView":
- case "com.ibm.bi.contentApps.defaultAction.query":
- case "com.ibm.bi.contentApps.defaultAction.analysis":
- return context.target.itemId.indexOf(v_oCMInfo.type) > 0 &&
- OpenHelper.determineDefaultAction(context.target.itemId, v_oCMInfo, context.glassContext) !== null;
-
-
- case "com.ibm.bi.datasets.createDataSetFromModule":
- if (v_oCMInfo.type !== "module")
- {
- return false;
- }
- // See comment above regarding disabled
- if (!!v_oCMInfo.disabled)
- {
- return false;
- }
- v_sCapabilityToCheck = 'canUseMyDataSets';
- break;
-
- case "com.ibm.bi.datasets.createDataSetFromPackage":
- if (v_oCMInfo.type !== "package")
- {
- return false;
- }
- // See comment above regarding disabled
- if (!!v_oCMInfo.disabled)
- {
- return false;
- }
- v_sCapabilityToCheck = 'canUseMyDataSets';
- break;
- case "com.ibm.bi.datasets.datasets-divider-top":
- case "com.ibm.bi.datasets.datasets-divider-bottom":
- return true;
-
- default:
- return false;
- }
-
- if (v_sCapabilityToCheck && !context.glassContext.hasCapability( v_sCapabilityToCheck ))
- {
- return false;
- }
-
- var v_aPermissions = v_oCMInfo.permissions;
-
- if (!v_aPermissions)
- {
- return false;
- }
-
- if (v_sPermission && v_aPermissions.indexOf(v_sPermission) == -1)
- {
- return false;
- }
- return true;
- },
-
- isVisible: function(context) {
- var v_bShareable = false;
- // Ensure we are being called with expected info
- if (context && context.target && context.target.itemId && context.glassContext)
- {
- switch(context.target.itemId)
- {
- case "com.ibm.bi.glass.common.shareContextual":
- v_bShareable = true;
- break;
- case "com.ibm.bi.glass.common.embedContextual":
- // Don't embed datasets
- if (context.target.activeObject)
- {
- var v_oCmProperties = context.target.activeObject.aSelectedContext[0];
- if (v_oCmProperties && v_oCmProperties.type !== 'dataSet2')
- {
- v_bShareable = true;
- }
- }
- break;
-
- case "com.ibm.bi.glass.common.operations.shareCurrent":
- case "com.ibm.bi.glass.common.operations.embedCurrent":
- //Meaning, we are sharing from overflow menu of authoring.
- var v_oCurrentContentView = context.glassContext.currentAppView.currentContentView;
- v_bShareable = ShareHelper.isShareable(v_oCurrentContentView, context.target.itemId === "com.ibm.bi.glass.common.operations.embedCurrent");
- break;
-
- default:
- //Remains invisible unless action implemented otherwise.
- console.log('Unsupported isVisible menu action item : ' + context.target.itemId);
- }
- }
- return v_bShareable;
- },
- execute: function(context) {
- // console.log('rsContextMenuActions.execute ...');
- var deferred = Q.defer();
- var v_oCmProperties;
- if (context.target && context.target.activeObject)
- {
- v_oCmProperties = context.target.activeObject.aSelectedContext[0];
- }
- else if (context.target && context.target.objectInformation)
- {
- v_oCmProperties = context.target.objectInformation;
- }
- var v_oCurrentContentView = context.glassContext && context.glassContext.currentAppView && context.glassContext.currentAppView.currentContentView;
- var v_oOpenSpec = {
- cmProperties: v_oCmProperties,
- mode: context.mode,
- glassContext: context.glassContext,
- contentView: v_oCurrentContentView
- };
- var v_fExecute;
- if (context.mode == 'defaultAction') {
- // This call is used to process a request that has no perspective defined
- // e.g. share link or openAppView( undefined, {...} )
- // It updates the urlMap with the perspective as well as any further information
- // needed to properly process the request.
- // If we have no cmProperties from the target, create oe using the info from the urlMap
- v_oOpenSpec.cmProperties = v_oOpenSpec.cmProperties || { id: context.urlMap.id, type: context.urlMap.type };
- v_oOpenSpec.urlMap = context.urlMap;
- v_fExecute = OpenHelper.getPerspective;
- }
- else {
- // This call generates the share link based on the current context
- // If we have no cmProperties, use the current view's cm properties.
- v_oOpenSpec.cmProperties = v_oOpenSpec.cmProperties || v_oCurrentContentView.cmProperties;
- v_fExecute = ShareHelper.getShareUrlMap;
- }
- v_fExecute(v_oOpenSpec)
- .catch(function(err) {
- console.log("rsContextMenuActions.execte ... FAILED.");
- deferred.reject(err);
- })
- .done(function(v_oUrlMap){
- deferred.resolve(v_oUrlMap);
- });
- return deferred.promise;
- },
-
- doAction: function(context) {
- // console.log('rsContextMenuActions.doAction ...');
-
- // doAction() is called from glass components.
- // glass uses jQuery deferreds and promises
- // convert the standard promise into jquery for the glass
- var $dfd = $.Deferred();
-
- this.onSelectItem(context)
- .catch( function(err){
- console.log('rsContextMenuActions.doAction ... FAILED');
- $dfd.reject(err);
- })
- .done( function(result){
- // console.log('rsContextMenuActions.doAction ... succeeded');
- $dfd.resolve(result);
- });
-
- return $dfd.promise();
- },
-
- canExecute: function(context) {
- //console.log('rsContextMenuActions.canExecute');
- return this.isItemVisible(context);
- },
-
- onSelectItem: function(context) {
- rsPerformance.clearMeasures();
- rsPerformance.clearMarks();
- rsPerformance.mark('authoring-selectItemAndDraw-start');
- rsPerformance.mark('rsContextMenuActions.onSelectItem');
- //console.log('rsContextMenuActions.onSelectItem ...');
- console.time('rsperf: total_RunReport');
- console.time('rsperf: onSelectItem->render');
-
- var deferred = Q.defer();
- var v_oCmProperties;
- if (context.target && context.target.activeObject)
- {
- v_oCmProperties = context.target.activeObject.aSelectedContext[0];
- }
- else if (context.target && context.target.objectInformation)
- {
- v_oCmProperties = context.target.objectInformation;
- }
- else
- {
- console.log('rsContextMenuActions.onSelectItem ... FAILED -- no target');
- deferred.reject(new Error('unexpected context.target: ' + context.target ? context.target.toString() : '<null>'));
- return deferred.promise;
- }
- if (context.target.itemId === "com.ibm.bi.authoring.saveAsReportView" ||
- context.target.itemId === "com.ibm.bi.authoring.saveAsPowerPlayView")
- {
- rsSaveReportView.saveReportView(v_oCmProperties, context)
- .catch(function(err){
- deferred.reject(err);
- })
- .done(function(result){
- deferred.resolve(result);
- });
- }
- else
- {
- OpenHelper.openView({
- cmProperties: v_oCmProperties,
- actionId: context.target.itemId,
- glassContext: context.glassContext,
- runOptions: context.target.runOptions })
- .catch(function(err){
- console.log('rsContextMenuActions.onSelectItem ... FAILED');
- deferred.reject(err);
- })
- .done(function(result){
- //console.log('rsContextMenuActions.onSelectItem ... succeeded');
- deferred.resolve(result);
- });
- }
- return deferred.promise;
- },
- getShareableItems: function(context) {
- var items = [];
- var view = context.glassContext.getCurrentContentView();
- if (view && view.getShareableItemsForCollaboration)
- {
- items = view.getShareableItemsForCollaboration();
- }
- return Q.resolve(items);
- }
- });
- return rsContextMenuActions;
- });
|