DeveloperWidgetRefreshAction.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (APIFactory, stringResources, ContentActionsProviderAPI) {
  9. var DeveloperWidgetRefreshAction = function () {
  10. function DeveloperWidgetRefreshAction(_ref) {
  11. var features = _ref.features;
  12. _classCallCheck(this, DeveloperWidgetRefreshAction);
  13. this.dashboard = features.API;
  14. this.icons = features.Icons;
  15. features.ContentActions.registerProvider('developerWidgetRefreshAction', this.getAPI());
  16. }
  17. DeveloperWidgetRefreshAction.prototype.getAPI = function getAPI() {
  18. return APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  19. };
  20. DeveloperWidgetRefreshAction.prototype.getContentActionList = function getContentActionList(idList) {
  21. var contentId = idList[0];
  22. var content = this.dashboard.getCanvas().getContent(contentId);
  23. var refreshIcon = this.icons.getIcon('refreshIcon');
  24. if (this._supportAction(idList, content)) {
  25. return [{
  26. name: 'developerWidgetRefreshAction',
  27. label: stringResources.get('toolbarActionRefreshDeveloperWidget'),
  28. icon: refreshIcon.id,
  29. type: 'Button',
  30. actions: {
  31. apply: this.refreshDeveloperWidget.bind(this, content)
  32. }
  33. }];
  34. }
  35. return [];
  36. };
  37. DeveloperWidgetRefreshAction.prototype._supportAction = function _supportAction(idList, content) {
  38. if (idList && idList.length != 1) {
  39. // does not support multi-widget selections (for now?)
  40. return false;
  41. }
  42. if (this.dashboard.getMode() !== this.dashboard.MODES.EDIT) {
  43. return false;
  44. }
  45. if (!this._isDeveloperWidget(content)) {
  46. return false;
  47. }
  48. if (!this._hasPermissions()) {
  49. return false;
  50. }
  51. return true;
  52. };
  53. DeveloperWidgetRefreshAction.prototype._isDeveloperWidget = function _isDeveloperWidget(content) {
  54. var visualization = content.getFeature('Visualization');
  55. if (!visualization) {
  56. return false;
  57. }
  58. var definition = visualization.getDefinition();
  59. var isErrorState = !!definition.getState().getError();
  60. var id = definition.getId();
  61. if (isErrorState) {
  62. var error = content.getFeature('state').getError();
  63. var errorParams = error && error.getParams && error.getParams();
  64. id = errorParams && errorParams.errorInfo && errorParams.errorInfo.id;
  65. }
  66. return id === 'visualizationPreview';
  67. };
  68. DeveloperWidgetRefreshAction.prototype._hasPermissions = function _hasPermissions() {
  69. var userCapabilities = this.dashboard.getGlassCoreSvc('.UserProfile').capabilities;
  70. return userCapabilities.indexOf('canDevelopVisualizations') !== -1;
  71. };
  72. DeveloperWidgetRefreshAction.prototype.refreshDeveloperWidget = function refreshDeveloperWidget(content) {
  73. content.getFeature('Visualization').getDefinition().refresh();
  74. this.dashboard.getFeature('UndoRedo').clearStack();
  75. };
  76. return DeveloperWidgetRefreshAction;
  77. }();
  78. return DeveloperWidgetRefreshAction;
  79. });
  80. //# sourceMappingURL=DeveloperWidgetRefreshAction.js.map