CustomVisAction.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['jquery', './CustomUtil'], function ($, CustomUtil) {
  9. var INPUT_FILE_BROWSE_DIALOG = '<input type="file" id="custom-vis-uploadfiles" style="display: none;" accept="application/zip,application/x-zip-compressed,multipart/x-zip,application/x-compressed" onclick="this.value=null;">';
  10. return function () {
  11. function CustomVisAction(options) {
  12. _classCallCheck(this, CustomVisAction);
  13. this.dashboardApi = options.dashboardApi;
  14. this.refreshCustomVis = options.refreshCustomVis;
  15. this.enabled = this.dashboardApi.getConfiguration('enableCustomVisualizations') === true;
  16. this._loadUserCapabilities();
  17. }
  18. CustomVisAction.prototype.openSelectBundleFileDialog = function openSelectBundleFileDialog(item) {
  19. this.item = item;
  20. this.$uploadFileButton.click();
  21. };
  22. CustomVisAction.prototype.bundleFileSelected = function bundleFileSelected(event, refreshCustomVisDefinitionsCallback) {
  23. var _this = this;
  24. var viprBundleMethod = this.item ? CustomUtil.updateCustomVis : CustomUtil.addCustomVis;
  25. return viprBundleMethod(event, this.dashboardApi, refreshCustomVisDefinitionsCallback, this.item).then(function (items) {
  26. if (items) {
  27. _this.setItems(items);
  28. }
  29. });
  30. };
  31. CustomVisAction.prototype.setItems = function setItems() {
  32. var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  33. //First clear the items
  34. this.customVisualsContentComponent.setState({
  35. items: []
  36. });
  37. //Now re-render with new list
  38. this.customVisualsContentComponent.setState({
  39. items: items
  40. });
  41. };
  42. CustomVisAction.prototype.shouldRefreshCustomPanel = function shouldRefreshCustomPanel() {
  43. return this.canDevelop() || this.canManage();
  44. };
  45. CustomVisAction.prototype.createUploadFileNode = function createUploadFileNode(refreshCustomVisDefinitionsCallback) {
  46. var _this2 = this;
  47. //Ensure the existing got removed before creating new one
  48. this.removeUploadFileNode();
  49. this.$uploadFileButton = $(INPUT_FILE_BROWSE_DIALOG);
  50. $('body').append(this.$uploadFileButton);
  51. this.$uploadFileButton.on('change', function (event) {
  52. _this2.bundleFileSelected(event, refreshCustomVisDefinitionsCallback);
  53. });
  54. this.$uploadFileButton.on('onClick', function () {
  55. _this2.$uploadFileButton.value = null;
  56. });
  57. };
  58. CustomVisAction.prototype.removeUploadFileNode = function removeUploadFileNode() {
  59. if (this.$uploadFileButton && this.$uploadFileButton.length > 0) {
  60. this.$uploadFileButton.remove();
  61. this.$uploadFileButton = null;
  62. }
  63. };
  64. CustomVisAction.prototype.setCustomVisualsContentComponent = function setCustomVisualsContentComponent(component) {
  65. this.customVisualsContentComponent = component;
  66. };
  67. CustomVisAction.prototype.destroy = function destroy() {
  68. this.removeUploadFileNode();
  69. this.customVisualsContentComponent = null;
  70. this.dashboardApi = null;
  71. this.refreshCustomVis = null;
  72. };
  73. CustomVisAction.prototype.canDevelop = function canDevelop() {
  74. return this.capabilities.canDevelop;
  75. };
  76. CustomVisAction.prototype.canManage = function canManage() {
  77. return this.capabilities.canManage;
  78. };
  79. CustomVisAction.prototype.canManageOnly = function canManageOnly() {
  80. return this.capabilities.canManageOnly;
  81. };
  82. CustomVisAction.prototype.canUseOnly = function canUseOnly() {
  83. return this.capabilities.canUseOnly;
  84. };
  85. CustomVisAction.prototype.isEnabled = function isEnabled() {
  86. return this.enabled;
  87. };
  88. CustomVisAction.prototype._loadUserCapabilities = function _loadUserCapabilities() {
  89. // __glassAppController.glassContext.getCoreSvc('.FeatureChecker').addRules({'dashboard':{'canDevelopVisualizations': 'enabled'}})
  90. //__glassAppController.glassContext.getCoreSvc('.FeatureChecker').addRules({'dashboard':{'canManageVisualizations': 'enabled'}})
  91. var userCapabilities = this.dashboardApi.getGlassCoreSvc('.UserProfile').capabilities;
  92. var canDevelop = userCapabilities.indexOf('canDevelopVisualizations') !== -1 || this.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'canDevelopVisualizations', 'enabled');
  93. var canManage = userCapabilities.indexOf('canManageVisualizations') !== -1 || this.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'canManageVisualizations', 'enabled');
  94. this.capabilities = {
  95. canDevelop: canDevelop,
  96. canManage: canManage,
  97. canManageOnly: !canDevelop && canManage,
  98. canUseOnly: !canDevelop && !canManage
  99. };
  100. };
  101. return CustomVisAction;
  102. }();
  103. });
  104. //# sourceMappingURL=CustomVisAction.js.map