diff --git a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorBootstrap.ts b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorBootstrap.ts index f670ffc007..6890f7293f 100644 --- a/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorBootstrap.ts +++ b/webapp/packages/plugin-sql-editor-navigation-tab/src/SqlEditorBootstrap.ts @@ -12,15 +12,16 @@ import { ConnectionSchemaManagerService, isObjectCatalogProvider, isObjectSchemaProvider, DATA_CONTEXT_NAV_NODE, NavigationTabsService } from '@cloudbeaver/core-app'; -import { isConnectionProvider } from '@cloudbeaver/core-connections'; +import { ConnectionsManagerService, IConnectionHandlerData, isConnectionProvider } from '@cloudbeaver/core-connections'; import { Bootstrap, injectable } from '@cloudbeaver/core-di'; import { CommonDialogService, DialogueStateResult, RenameDialog } from '@cloudbeaver/core-dialogs'; -import type { IExecutorHandler } from '@cloudbeaver/core-executor'; +import { ExecutorInterrupter, IExecutionContextProvider, IExecutorHandler } from '@cloudbeaver/core-executor'; import { ExtensionUtils } from '@cloudbeaver/core-extensions'; import { ISessionAction, sessionActionContext, SessionActionService } from '@cloudbeaver/core-root'; import { ActionService, ACTION_RENAME, DATA_CONTEXT_MENU_NESTED, menuExtractActions, MenuService, ViewService } from '@cloudbeaver/core-view'; +import { AuthenticationService, LogoutState } from '@cloudbeaver/plugin-authentication'; import { DATA_CONTEXT_CONNECTION } from '@cloudbeaver/plugin-connections'; -import { DATA_CONTEXT_SQL_EDITOR_STATE } from '@cloudbeaver/plugin-sql-editor'; +import { DATA_CONTEXT_SQL_EDITOR_STATE, SqlResultTabsService } from '@cloudbeaver/plugin-sql-editor'; import { ACTION_SQL_EDITOR_OPEN } from './ACTION_SQL_EDITOR_OPEN'; import { DATA_CONTEXT_SQL_EDITOR_TAB } from './DATA_CONTEXT_SQL_EDITOR_TAB'; @@ -41,12 +42,19 @@ export class SqlEditorBootstrap extends Bootstrap { private readonly menuService: MenuService, private readonly sessionActionService: SessionActionService, private readonly commonDialogService: CommonDialogService, - private readonly sqlEditorTabService: SqlEditorTabService + private readonly sqlEditorTabService: SqlEditorTabService, + private readonly authenticationService: AuthenticationService, + private readonly sqlResultTabsService: SqlResultTabsService, + private readonly connectionsManagerService: ConnectionsManagerService, ) { super(); } register(): void { + this.authenticationService.onLogout.addHandler(this.logoutHandler.bind(this)); + this.connectionsManagerService.onDisconnect.addHandler(this.connectionHandler.bind(this)); + this.connectionsManagerService.onDelete.addHandler(this.connectionHandler.bind(this)); + this.mainMenuService.registerRootItem( { id: 'sql-editor', @@ -186,4 +194,37 @@ export class SqlEditorBootstrap extends Bootstrap { } } }; + + private async logoutHandler(data: LogoutState, contexts: IExecutionContextProvider) { + if (data === 'before') { + for (const tab of this.sqlEditorTabService.sqlEditorTabs) { + const canLogout = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState); + + if (!canLogout) { + ExecutorInterrupter.interrupt(contexts); + return; + } + } + } + } + + private async connectionHandler( + data: IConnectionHandlerData, + contexts: IExecutionContextProvider + ) { + if (data.state === 'before') { + for (const tab of this.sqlEditorTabService.sqlEditorTabs) { + if (tab.handlerState.executionContext?.connectionId !== data.connectionId) { + continue; + } + + const canPerformAction = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState); + + if (!canPerformAction) { + ExecutorInterrupter.interrupt(contexts); + return; + } + } + } + } } diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditorMenuService.ts b/webapp/packages/plugin-sql-editor/src/MenuBootstrap.ts similarity index 96% rename from webapp/packages/plugin-sql-editor/src/SqlEditorMenuService.ts rename to webapp/packages/plugin-sql-editor/src/MenuBootstrap.ts index 719b10e517..2612bd9999 100644 --- a/webapp/packages/plugin-sql-editor/src/SqlEditorMenuService.ts +++ b/webapp/packages/plugin-sql-editor/src/MenuBootstrap.ts @@ -6,7 +6,7 @@ * you may not use this file except in compliance with the License. */ -import { injectable } from '@cloudbeaver/core-di'; +import { Bootstrap, injectable } from '@cloudbeaver/core-di'; import { ActionService, KeyBindingService, MenuService, IAction, IDataContextProvider } from '@cloudbeaver/core-view'; import { ACTION_SQL_EDITOR_EXECUTE } from './actions/ACTION_SQL_EDITOR_EXECUTE'; @@ -22,12 +22,14 @@ import { KEY_BINDING_SQL_EDITOR_SHOW_EXECUTION_PLAN } from './actions/bindings/K import { DATA_CONTEXT_SQL_EDITOR_DATA } from './SqlEditor/DATA_CONTEXT_SQL_EDITOR_DATA'; @injectable() -export class SqlEditorMenuService { +export class MenuBootstrap extends Bootstrap { constructor( private readonly actionService: ActionService, private readonly keyBindingService: KeyBindingService, private readonly menuService: MenuService - ) { } + ) { + super(); + } register(): void { this.actionService.addHandler({ @@ -122,4 +124,6 @@ export class SqlEditorMenuService { break; } } + + load(): void | Promise { } } \ No newline at end of file diff --git a/webapp/packages/plugin-sql-editor/src/SqlEditorBootstrap.ts b/webapp/packages/plugin-sql-editor/src/SqlEditorBootstrap.ts deleted file mode 100644 index c5a59e8e42..0000000000 --- a/webapp/packages/plugin-sql-editor/src/SqlEditorBootstrap.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2022 DBeaver Corp and others - * - * Licensed under the Apache License, Version 2.0. - * you may not use this file except in compliance with the License. - */ - -import { ConnectionsManagerService, IConnectionHandlerData } from '@cloudbeaver/core-connections'; -import { Bootstrap, injectable } from '@cloudbeaver/core-di'; -import { ExecutorInterrupter, IExecutionContextProvider } from '@cloudbeaver/core-executor'; -import { IServerConfigSaveData, ServerConfigurationService } from '@cloudbeaver/plugin-administration'; -import { AuthenticationService, LogoutState } from '@cloudbeaver/plugin-authentication'; -import { SqlEditorTabService } from '@cloudbeaver/plugin-sql-editor-navigation-tab'; - -import { SqlEditorMenuService } from './SqlEditorMenuService'; -import { SqlResultTabsService } from './SqlResultTabs/SqlResultTabsService'; - -@injectable() -export class SqlEditorBootstrap extends Bootstrap { - constructor( - private readonly authenticationService: AuthenticationService, - private readonly sqlEditorTabService: SqlEditorTabService, - private readonly sqlResultTabsService: SqlResultTabsService, - private readonly sqlEditorMenuService: SqlEditorMenuService, - private readonly connectionsManagerService: ConnectionsManagerService, - private readonly serverConfigurationService: ServerConfigurationService - ) { - super(); - } - - register(): void { - this.sqlEditorMenuService.register(); - - this.authenticationService.onLogout.addHandler(this.logoutHandler.bind(this)); - this.connectionsManagerService.onDisconnect.addHandler(this.connectionHandler.bind(this)); - this.connectionsManagerService.onDelete.addHandler(this.connectionHandler.bind(this)); - this.serverConfigurationService.saveTask.addHandler(this.saveHandler.bind(this)); - } - - load(): void | Promise { } - - private async saveHandler(data: IServerConfigSaveData, contexts: IExecutionContextProvider) { - for (const tab of this.sqlEditorTabService.sqlEditorTabs) { - const canSave = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState); - - if (!canSave) { - ExecutorInterrupter.interrupt(contexts); - return; - } - } - } - - private async logoutHandler(data: LogoutState, contexts: IExecutionContextProvider) { - if (data === 'before') { - for (const tab of this.sqlEditorTabService.sqlEditorTabs) { - const canLogout = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState); - - if (!canLogout) { - ExecutorInterrupter.interrupt(contexts); - return; - } - } - } - } - - private async connectionHandler( - data: IConnectionHandlerData, - contexts: IExecutionContextProvider - ) { - if (data.state === 'before') { - for (const tab of this.sqlEditorTabService.sqlEditorTabs) { - if (tab.handlerState.executionContext?.connectionId !== data.connectionId) { - continue; - } - - const canPerformAction = await this.sqlResultTabsService.canCloseResultTabs(tab.handlerState); - - if (!canPerformAction) { - ExecutorInterrupter.interrupt(contexts); - return; - } - } - } - } -} \ No newline at end of file diff --git a/webapp/packages/plugin-sql-editor/src/manifest.ts b/webapp/packages/plugin-sql-editor/src/manifest.ts index 8e48120cee..8b8f9b8de3 100644 --- a/webapp/packages/plugin-sql-editor/src/manifest.ts +++ b/webapp/packages/plugin-sql-editor/src/manifest.ts @@ -9,10 +9,9 @@ import type { PluginManifest } from '@cloudbeaver/core-di'; import { LocaleService } from './LocaleService'; +import { MenuBootstrap } from './MenuBootstrap'; import { SqlDialectInfoService } from './SqlDialectInfoService'; import { SQLCodeEditorPanelBootstrap } from './SqlEditor/SQLCodeEditorPanel/SQLCodeEditorPanelBootstrap'; -import { SqlEditorBootstrap } from './SqlEditorBootstrap'; -import { SqlEditorMenuService } from './SqlEditorMenuService'; import { SqlEditorModeService } from './SqlEditorModeService'; import { SqlEditorService } from './SqlEditorService'; import { SqlEditorSettingsService } from './SqlEditorSettingsService'; @@ -29,9 +28,7 @@ export const sqlEditorPluginManifest: PluginManifest = { providers: [ LocaleService, - SqlEditorBootstrap, SqlEditorService, - SqlEditorMenuService, SqlDialectInfoService, SqlQueryResultService, SqlQueryService, @@ -41,5 +38,6 @@ export const sqlEditorPluginManifest: PluginManifest = { SqlEditorModeService, SQLCodeEditorPanelBootstrap, SqlEditorView, + MenuBootstrap, ], };