mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
load database list
This commit is contained in:
@@ -6,21 +6,25 @@ module.exports = {
|
|||||||
opened: [],
|
opened: [],
|
||||||
|
|
||||||
handle_databases(id, { databases }) {
|
handle_databases(id, { databases }) {
|
||||||
const existing = this.opened.find(x => x.connection.id == id);
|
const existing = this.opened.find(x => x.id == id);
|
||||||
if (!existing) return;
|
if (!existing) return;
|
||||||
existing.databases = databases;
|
existing.databases = databases;
|
||||||
socket.emit(`database-list-changed-${id}`);
|
socket.emit(`database-list-changed-${id}`);
|
||||||
},
|
},
|
||||||
|
handle_error(id, { error }) {
|
||||||
|
console.log(error);
|
||||||
|
},
|
||||||
|
|
||||||
async ensureOpened(id) {
|
async ensureOpened(id) {
|
||||||
const existing = this.opened.find(x => x.connection.id == id);
|
const existing = this.opened.find(x => x.id == id);
|
||||||
if (existing) return existing;
|
if (existing) return existing;
|
||||||
const connection = await connections.get(id);
|
const connection = await connections.get({ id });
|
||||||
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
|
const subprocess = fork(`${__dirname}/../proc/serverConnectionProcess.js`);
|
||||||
const newOpened = {
|
const newOpened = {
|
||||||
id,
|
id,
|
||||||
subprocess,
|
subprocess,
|
||||||
databases: [],
|
databases: [],
|
||||||
|
connection,
|
||||||
};
|
};
|
||||||
this.opened.push(newOpened);
|
this.opened.push(newOpened);
|
||||||
subprocess.on('message', ({ msgtype, ...message }) => {
|
subprocess.on('message', ({ msgtype, ...message }) => {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const io = require('socket.io');
|
|||||||
|
|
||||||
const useController = require('./utility/useController');
|
const useController = require('./utility/useController');
|
||||||
const connections = require('./controllers/connections');
|
const connections = require('./controllers/connections');
|
||||||
|
const serverConnections = require('./controllers/serverConnections');
|
||||||
const socket = require('./utility/socket');
|
const socket = require('./utility/socket');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -21,5 +22,6 @@ app.get('/', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useController(app, '/connections', connections);
|
useController(app, '/connections', connections);
|
||||||
|
useController(app, '/server-connections', serverConnections);
|
||||||
|
|
||||||
server.listen(3000);
|
server.listen(3000);
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ async function handleRefreshDatabases() {
|
|||||||
|
|
||||||
async function handleConnect(connection) {
|
async function handleConnect(connection) {
|
||||||
storedConnection = connection;
|
storedConnection = connection;
|
||||||
const driver = require(`../engines/${storedConnection.engine}/index`);
|
|
||||||
|
const driver = engines(storedConnection);
|
||||||
systemConnection = await driver.connect(storedConnection);
|
systemConnection = await driver.connect(storedConnection);
|
||||||
setInterval(handleRefreshDatabases, 30 * 1000);
|
handleRefreshDatabases();
|
||||||
|
// setInterval(handleRefreshDatabases, 30 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageHandlers = {
|
const messageHandlers = {
|
||||||
|
|||||||
20
web/src/appobj/AppObjectList.js
Normal file
20
web/src/appobj/AppObjectList.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { showMenu } from '../modals/DropDownMenu';
|
||||||
|
import { AppObjectCore } from './AppObjects';
|
||||||
|
|
||||||
|
export function AppObjectList({ list, makeAppObj, SubItems }) {
|
||||||
|
return (list || []).map(x => {
|
||||||
|
const appobj = makeAppObj(x);
|
||||||
|
let res = <AppObjectCore key={appobj.key} {...appobj} data={x} makeAppObj={makeAppObj} />;
|
||||||
|
if (SubItems) {
|
||||||
|
res = (
|
||||||
|
<>
|
||||||
|
{res}
|
||||||
|
<SubItems data={x} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -36,10 +36,3 @@ export function AppObjectControl({ data, makeAppObj }) {
|
|||||||
const appobj = makeAppObj(data);
|
const appobj = makeAppObj(data);
|
||||||
return <AppObjectCore {...appobj} data={data} makeAppObj={makeAppObj} />;
|
return <AppObjectCore {...appobj} data={data} makeAppObj={makeAppObj} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AppObjectList({ list, makeAppObj }) {
|
|
||||||
return (list || []).map(x => {
|
|
||||||
const appobj = makeAppObj(x);
|
|
||||||
return <AppObjectCore key={appobj.key} {...appobj} data={x} makeAppObj={makeAppObj} />;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
29
web/src/appobj/databaseAppObject.js
Normal file
29
web/src/appobj/databaseAppObject.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { MicrosoftIcon, SqliteIcon, PostgreSqlIcon, MySqlIcon, ServerIcon, DatabaseIcon } from '../icons';
|
||||||
|
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
||||||
|
import showModal from '../modals/showModal';
|
||||||
|
import ConnectionModal from '../modals/ConnectionModal';
|
||||||
|
import axios from '../utility/axios';
|
||||||
|
|
||||||
|
function Menu({ data, makeAppObj }) {
|
||||||
|
const handleEdit = () => {
|
||||||
|
showModal(modalState => <ConnectionModal modalState={modalState} connection={data} />);
|
||||||
|
};
|
||||||
|
const handleDelete = () => {
|
||||||
|
axios.post('connections/delete', data);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DropDownMenuItem onClick={handleEdit}>Edit</DropDownMenuItem>
|
||||||
|
<DropDownMenuItem onClick={handleDelete}>Delete</DropDownMenuItem>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function databaseAppObject({ name }) {
|
||||||
|
const title = name;
|
||||||
|
const key = name;
|
||||||
|
const Icon = DatabaseIcon;
|
||||||
|
|
||||||
|
return { title, key, Icon, Menu };
|
||||||
|
}
|
||||||
@@ -2,8 +2,18 @@ import React from 'react';
|
|||||||
import useModalState from '../modals/useModalState';
|
import useModalState from '../modals/useModalState';
|
||||||
import ConnectionModal from '../modals/ConnectionModal';
|
import ConnectionModal from '../modals/ConnectionModal';
|
||||||
import useFetch from '../utility/useFetch';
|
import useFetch from '../utility/useFetch';
|
||||||
import { AppObjectList } from '../appobj/AppObjects';
|
import { AppObjectList } from '../appobj/AppObjectList';
|
||||||
import connectionAppObject from '../appobj/connectionAppObject';
|
import connectionAppObject from '../appobj/connectionAppObject';
|
||||||
|
import databaseAppObject from '../appobj/databaseAppObject';
|
||||||
|
|
||||||
|
function SubDatabaseList({ data }) {
|
||||||
|
const { _id } = data;
|
||||||
|
const databases = useFetch({
|
||||||
|
url: `server-connections/list-databases?id=${_id}`,
|
||||||
|
reloadTrigger: `database-list-changed-${_id}`,
|
||||||
|
});
|
||||||
|
return <AppObjectList list={databases} makeAppObj={databaseAppObject} />
|
||||||
|
}
|
||||||
|
|
||||||
export default function DatabaseWidget() {
|
export default function DatabaseWidget() {
|
||||||
const modalState = useModalState();
|
const modalState = useModalState();
|
||||||
@@ -15,7 +25,7 @@ export default function DatabaseWidget() {
|
|||||||
<>
|
<>
|
||||||
<ConnectionModal modalState={modalState} />
|
<ConnectionModal modalState={modalState} />
|
||||||
<button onClick={modalState.open}>Add connection</button>
|
<button onClick={modalState.open}>Add connection</button>
|
||||||
<AppObjectList list={connections} makeAppObj={connectionAppObject} />
|
<AppObjectList list={connections} makeAppObj={connectionAppObject} SubItems={SubDatabaseList} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user