mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 23:56:00 +00:00
change database status command
This commit is contained in:
43
packages/web/src/commands/changeDatabaseStatusCommand.ts
Normal file
43
packages/web/src/commands/changeDatabaseStatusCommand.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import _ from 'lodash';
|
||||
import { currentDatabase, getCurrentDatabase } from '../stores';
|
||||
import getElectron from '../utility/getElectron';
|
||||
import registerCommand from './registerCommand';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
|
||||
const electron = getElectron();
|
||||
|
||||
registerCommand({
|
||||
id: 'database.changeState',
|
||||
category: 'Database',
|
||||
name: 'Change status',
|
||||
getSubCommands: () => {
|
||||
const current = getCurrentDatabase();
|
||||
if (!current) return [];
|
||||
const { connection, name } = current;
|
||||
const dbid = {
|
||||
conid: connection._id,
|
||||
database: name,
|
||||
};
|
||||
return [
|
||||
{
|
||||
text: 'Sync model',
|
||||
onClick: () => {
|
||||
axiosInstance.post('database-connections/sync-model', dbid);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Reopen',
|
||||
onClick: () => {
|
||||
axiosInstance.post('database-connections/refresh', dbid);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: 'Disconnect',
|
||||
onClick: () => {
|
||||
if (electron) axiosInstance.post('database-connections/disconnect', dbid);
|
||||
currentDatabase.set(null);
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
});
|
||||
@@ -26,3 +26,9 @@ export function runGroupCommand(group) {
|
||||
const real = values.find(x => x.group == group && !x.isGroupCommand && x.enabled);
|
||||
if (real && real.onClick) real.onClick();
|
||||
}
|
||||
|
||||
export function findCommand(id) {
|
||||
const commandsValue = getCommands();
|
||||
const command = commandsValue[id];
|
||||
return command;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { openElectronFile } from '../utility/openElectronFile';
|
||||
import { getDefaultFileFormat } from '../plugins/fileformats';
|
||||
import { getCurrentConfig, getCurrentDatabase } from '../stores';
|
||||
import './recentDatabaseSwitch';
|
||||
import './changeDatabaseStatusCommand';
|
||||
import hasPermission from '../utility/hasPermission';
|
||||
import axiosInstance from '../utility/axiosInstance';
|
||||
import _ from 'lodash';
|
||||
|
||||
Reference in New Issue
Block a user