123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: Modeling UI
- *
- * Copyright IBM Corp. 2017, 2019
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['bi/glass/core/Class', 'underscore'], function (BaseClass, _) {
- var ModuleCreatelHandler = BaseClass.extend({
- init: function() {
- ModuleCreatelHandler.inherited('init', this, arguments);
- },
- doAction: function(context) {
- return this._passSecurityCheck(context)
- ? Promise.resolve(this.onSelectItem(context))
- : Promise.reject();
- },
- onSelectItem: function(context) {
- if (!context.target.activeObject) {
- require(['ca-modeller/create'], function(Create) {
- Create.default(context.glassContext);
- });
- return;
- }
- var application = context.glassContext;
- if (application.currentAppView.perspective === 'ca-modeller') {
- // launch the glass open dialog
- application.getCurrentContentView().openModel();
- return;
- }
- application.closeAppView('ca-modeller').then( function() {
- require(['ca-modeller/create'], function(Create) {
- // create a new module containing the selection
- Create.createEntryModule(context).then(function(response) {
- // open that new module
- application.openAppView('ca-modeller', {
- content: {
- tid: response.data.id,
- id: response.data.id,
- sessionModule: response.module
- }
- });
- });
- });
- });
- },
- _hasCapabilities: function(context, selection) {
- var userCapabilities = context.glassContext.services.userProfile.capabilities;
- return userCapabilities.indexOf('canUseWebBasedModeling') >= 0;
- },
- _passSecurityCheck: function(context) {
- var aPerm = ['read'];
- var selection =
- context &&
- context.target &&
- context.target.activeObject &&
- context.target.activeObject.aSelectedContext;
- return (
- selection &&
- selection.length &&
- _.intersection(selection[0].permissions, aPerm).length === aPerm.length &&
- this._hasCapabilities(context, selection)
- )
- },
- /**
- * Method returns all supported asset types for creating a data module
- * @param {enableFeatureFlaggedAssets} boolean to toggle inclusion of featureFlagged asset types
- * @return array of supported asset types
- */
- _getSupportedTypes: function(enableFeatureFlaggedAssets) {
- var assetTypes = ['module', 'uploadedFile', 'package', 'dataSet2'];
- if (enableFeatureFlaggedAssets) {
- // Flagged features to to enable
- var flaggedFeatures = [];
- flaggedFeatures.forEach(function(feature){ assetTypes.splice(assetTypes.length, 0, feature)});
- }
- return assetTypes;
- },
- /**
- * Method invoked when rendering glass Menu, ContextMenu and GlassPlugin classes to determine if the item should be displayed
- * @param {context} which contains the following:
- * <ul>
- * <li>glassContext</li>
- * <li>target: object containing info on the target: plugin and itemId</li>
- * <li>activeObject: object for which the menu is displayed, used for the context menu</li>
- * </ul>
- * @return true or false
- */
- isItemVisible: function(context) {
- var assetTypes = this._getSupportedTypes(true);
- return (
- !context.target.activeObject ||
- ( context.target.activeObject.aSelectedContext.length > 0 &&
- context.target.activeObject.aSelectedContext.every(
- function(ev) { return ev.disabled !== true && assetTypes.some(
- function(sv) { return sv === ev.type }
- ) }
- ) &&
- this._passSecurityCheck(context)
- )
- );
- }
- });
- return ModuleCreatelHandler;
- });
|