Files
cloudbeaver/webapp/packages/plugin-devtools/src/DevToolsService.ts
T
Alexeyanddariamarutkina 64040bc3a3 CB-3372 feat: codemirror6 autocomplete (#1646)
* CB-3372 feat: codemirror6 autocomplete

* CB-3372 feat: autocomplete icons

* CB-3371 feat: sql editor syntax highlight

* CB-3371 fix: syntax highlight blinking

* CB-3371 fix: editor extensions state

* CB-3372 chore: code cleanup

* CB-3372 fix: remove useSqlDIalectAutocompletion

* CB-3372 fix: add useSqlDIalectAutocompletion

* CB-3372 feat: experimental context menu

* CB-3372 feat: use new sql editor

* CB-3372 chore: remove sql script parser

* CB-3372 fix: rounded menu

* CB-3372 fix: event preventDefault on dialog

* CB-3372 fix: context menu styles

* CB-3372 feat: remove old codemirror

* CB-3372 fix: numbers completion & extensions caching

* CB-3372 fix: table display

* CB-3372 fix: decrease sql editor font size

* CB-3372 fix: copy in readonly mode & autocompletion in safari on MacOS

* CB-3372 fix: value panel styles

* CB-3372 fix: menu bar styles

* CB-3372 fix: menu bar and inline editor styles

* CB-3372 fix: menu and inline editor styles

* CB-3372 chore: update bundle

---------

Co-authored-by: dariamarutkina <125263541+dariamarutkina@users.noreply.github.com>
2023-05-17 17:32:09 +03:00

71 lines
1.8 KiB
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 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 { makeObservable, observable } from 'mobx';
import { injectable } from '@cloudbeaver/core-di';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { LocalStorageSaveService } from '@cloudbeaver/core-settings';
interface IDevToolsSettings {
enabled: boolean;
distributed: boolean;
}
const DEVTOOLS = 'devtools';
@injectable()
export class DevToolsService {
get isEnabled(): boolean {
return this.settings.enabled;
}
get isDistributed(): boolean {
return this.settings.distributed;
}
private readonly settings: IDevToolsSettings;
constructor(
private readonly serverConfigResource: ServerConfigResource,
private readonly autoSaveService: LocalStorageSaveService,
) {
this.settings = getDefaultDevToolsSettings();
makeObservable<this, 'settings'>(this, {
settings: observable,
});
this.autoSaveService.withAutoSave(DEVTOOLS, this.settings, getDefaultDevToolsSettings);
this.serverConfigResource.onDataUpdate.addHandler(this.syncDistributedMode.bind(this));
}
switch() {
this.settings.enabled = !this.settings.enabled;
this.syncDistributedMode();
}
setDistributedMode(distributed: boolean) {
this.settings.distributed = distributed;
this.syncDistributedMode();
}
private syncDistributedMode() {
if (this.isEnabled) {
if (this.serverConfigResource.data) {
this.serverConfigResource.data.distributed = this.isDistributed;
}
}
}
}
function getDefaultDevToolsSettings(): IDevToolsSettings {
return {
enabled: false,
distributed: false,
};
}