ResetDashboardAction.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(['../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', '../../../../app/ui/dialogs/ConfirmationDialog'], function (APIFactory, ContentActionsProviderAPI, ConfirmationDialog) {
  9. var ResetDashboardAction = function () {
  10. function ResetDashboardAction(_ref) {
  11. var features = _ref.features;
  12. _classCallCheck(this, ResetDashboardAction);
  13. this._dashboard = features.API;
  14. this._dashboardState = features.DashboardState;
  15. this._contentActions = features.ContentActions;
  16. this._icons = features.Icons;
  17. }
  18. ResetDashboardAction.prototype.initialize = function initialize() {
  19. this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
  20. this._contentActions.registerProvider('ResetDashboard', this.getAPI());
  21. };
  22. ResetDashboardAction.prototype.getAPI = function getAPI() {
  23. return this._api;
  24. };
  25. ResetDashboardAction.prototype._isItemVisible = function _isItemVisible() {
  26. var contentView = this._dashboard.getCurrentContentView();
  27. var isThereASavedInst = !!contentView.getSavedInstance();
  28. var isDirty = this._dashboardState.getUiState().dirty;
  29. return isThereASavedInst && isDirty;
  30. };
  31. ResetDashboardAction.prototype._resetDashboard = function _resetDashboard() {
  32. var contentView = this._dashboard.getCurrentContentView();
  33. var savedInstance = contentView.getSavedInstance();
  34. contentView.clearTransientState();
  35. var extOptions = {
  36. isAuthoringMode: false,
  37. clearDirtyFlag: true
  38. };
  39. return contentView.reloadFromJSONSpec(JSON.parse(savedInstance), extOptions);
  40. };
  41. ResetDashboardAction.prototype._onReset = function _onReset() {
  42. var _this = this;
  43. var contentView = this._dashboard.getCurrentContentView();
  44. var stringService = contentView.stringService;
  45. var resetMessage = stringService.get('dashboardResetToast');
  46. var confirmDlg = new ConfirmationDialog('warning', stringService.get('dashboardResetTitle'), stringService.get('dashboardResetMessage'));
  47. confirmDlg.confirm(function () {
  48. return _this._resetDashboard().then(function () {
  49. // After resetting dashboard, the ResetDashboardAction will be destroyed,
  50. // so the action has already been destroyed at this point, and this._dashboard
  51. // is undefined, so we need to get the new dashboard api from the content view
  52. return contentView.getDashboardApi().showToast(resetMessage, {
  53. type: 'success',
  54. preventDuplicates: true
  55. });
  56. });
  57. });
  58. };
  59. ResetDashboardAction.prototype.getContentActionList = function getContentActionList(idList) {
  60. var _this2 = this;
  61. var contentView = this._dashboard.getCurrentContentView();
  62. var stringService = contentView.stringService;
  63. var uiState = this._dashboardState.getUiState();
  64. if (uiState.authoring === false && this._isItemVisible() && uiState.dirty && idList.length === 0) {
  65. return [{
  66. name: 'ResetDashboard',
  67. type: 'Button',
  68. label: stringService.get('dashboardResetTitle'),
  69. icon: this._icons.getIcon('restore').id,
  70. actions: {
  71. apply: function apply() {
  72. return _this2._onReset();
  73. }
  74. }
  75. }];
  76. } else {
  77. return [];
  78. }
  79. };
  80. return ResetDashboardAction;
  81. }();
  82. return ResetDashboardAction;
  83. });
  84. //# sourceMappingURL=ResetDashboardAction.js.map