CreateNewModuleHandler.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: Modeling UI
  5. *
  6. * Copyright IBM Corp. 2017, 2019
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['bi/glass/core/Class', 'underscore'], function (BaseClass, _) {
  11. var ModuleCreatelHandler = BaseClass.extend({
  12. init: function() {
  13. ModuleCreatelHandler.inherited('init', this, arguments);
  14. },
  15. doAction: function(context) {
  16. return this._passSecurityCheck(context)
  17. ? Promise.resolve(this.onSelectItem(context))
  18. : Promise.reject();
  19. },
  20. onSelectItem: function(context) {
  21. if (!context.target.activeObject) {
  22. require(['ca-modeller/create'], function(Create) {
  23. Create.default(context.glassContext);
  24. });
  25. return;
  26. }
  27. var application = context.glassContext;
  28. if (application.currentAppView.perspective === 'ca-modeller') {
  29. // launch the glass open dialog
  30. application.getCurrentContentView().openModel();
  31. return;
  32. }
  33. application.closeAppView('ca-modeller').then( function() {
  34. require(['ca-modeller/create'], function(Create) {
  35. // create a new module containing the selection
  36. Create.createEntryModule(context).then(function(response) {
  37. // open that new module
  38. application.openAppView('ca-modeller', {
  39. content: {
  40. tid: response.data.id,
  41. id: response.data.id,
  42. sessionModule: response.module
  43. }
  44. });
  45. });
  46. });
  47. });
  48. },
  49. _hasCapabilities: function(context, selection) {
  50. var userCapabilities = context.glassContext.services.userProfile.capabilities;
  51. return userCapabilities.indexOf('canUseWebBasedModeling') >= 0;
  52. },
  53. _passSecurityCheck: function(context) {
  54. var aPerm = ['read'];
  55. var selection =
  56. context &&
  57. context.target &&
  58. context.target.activeObject &&
  59. context.target.activeObject.aSelectedContext;
  60. return (
  61. selection &&
  62. selection.length &&
  63. _.intersection(selection[0].permissions, aPerm).length === aPerm.length &&
  64. this._hasCapabilities(context, selection)
  65. )
  66. },
  67. /**
  68. * Method returns all supported asset types for creating a data module
  69. * @param {enableFeatureFlaggedAssets} boolean to toggle inclusion of featureFlagged asset types
  70. * @return array of supported asset types
  71. */
  72. _getSupportedTypes: function(enableFeatureFlaggedAssets) {
  73. var assetTypes = ['module', 'uploadedFile', 'package', 'dataSet2'];
  74. if (enableFeatureFlaggedAssets) {
  75. // Flagged features to to enable
  76. var flaggedFeatures = [];
  77. flaggedFeatures.forEach(function(feature){ assetTypes.splice(assetTypes.length, 0, feature)});
  78. }
  79. return assetTypes;
  80. },
  81. /**
  82. * Method invoked when rendering glass Menu, ContextMenu and GlassPlugin classes to determine if the item should be displayed
  83. * @param {context} which contains the following:
  84. * <ul>
  85. * <li>glassContext</li>
  86. * <li>target: object containing info on the target: plugin and itemId</li>
  87. * <li>activeObject: object for which the menu is displayed, used for the context menu</li>
  88. * </ul>
  89. * @return true or false
  90. */
  91. isItemVisible: function(context) {
  92. var assetTypes = this._getSupportedTypes(true);
  93. return (
  94. !context.target.activeObject ||
  95. ( context.target.activeObject.aSelectedContext.length > 0 &&
  96. context.target.activeObject.aSelectedContext.every(
  97. function(ev) { return ev.disabled !== true && assetTypes.some(
  98. function(sv) { return sv === ev.type }
  99. ) }
  100. ) &&
  101. this._passSecurityCheck(context)
  102. )
  103. );
  104. }
  105. });
  106. return ModuleCreatelHandler;
  107. });