EditNotebookAction.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: Notebook
  7. *| (C) Copyright IBM Corp. 2019, 2020
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. define(['../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../app/util/ErrorUtils', '../../../../app/nls/StringResources'], function (Utils, APIFactory, ContentActionsProviderAPI, ErrorUtils, stringResources) {
  14. // NOTE: DashboardWidget in jupyter-client relies on getAPI() for the hooks:
  15. // - this.selectedWidget.allowReconfigure()
  16. // - this.selectedWidget.editConfig()
  17. var EditNotebookAction = function () {
  18. function EditNotebookAction(_ref) {
  19. var features = _ref.features;
  20. _classCallCheck(this, EditNotebookAction);
  21. this._dashboard = features.API;
  22. features.ContentActions.registerProvider('editNotebook', this.getAPI());
  23. this._dashboardState = features.DashboardState;
  24. this._icons = features.Icons;
  25. }
  26. EditNotebookAction.prototype.getAPI = function getAPI() {
  27. if (!this._api) {
  28. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  29. }
  30. return this._api;
  31. };
  32. EditNotebookAction.prototype.destroy = function destroy() {
  33. this._dashboard = null;
  34. this._dashboardState = null;
  35. this._api = null;
  36. };
  37. EditNotebookAction.prototype._isAvailable = function _isAvailable(idList) {
  38. var canAuthor = idList.length === 1 && this._dashboardState.getUiState().authoring === true && ErrorUtils.hasCapability(this._dashboard, 'canAuthorDashboard');
  39. if (canAuthor) {
  40. this._selectedWidget = this._dashboard.getCanvas().getWidget(idList[0]);
  41. return this._selectedWidget && typeof this._selectedWidget.allowReconfigure === 'function' && this._selectedWidget.allowReconfigure();
  42. }
  43. return false;
  44. };
  45. EditNotebookAction.prototype.getContentActionList = function getContentActionList(idList) {
  46. if (this._isAvailable(idList)) {
  47. return [{
  48. name: 'editNotebook',
  49. label: stringResources.get('editNotebook'),
  50. icon: this._icons.getIcon('edit').id,
  51. type: 'Button',
  52. actions: {
  53. apply: this.triggerEdit.bind(this)
  54. }
  55. }];
  56. } else {
  57. return [];
  58. }
  59. };
  60. EditNotebookAction.prototype.triggerEdit = function triggerEdit() /* event */{
  61. this._selectedWidget.editConfig();
  62. };
  63. return EditNotebookAction;
  64. }();
  65. return EditNotebookAction;
  66. });
  67. //# sourceMappingURL=EditNotebookAction.js.map