mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 10:16:03 +00:00
server connections
This commit is contained in:
@@ -5,7 +5,7 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
opened: [],
|
opened: [],
|
||||||
closed: [],
|
closed: {},
|
||||||
|
|
||||||
handle_databases(conid, { databases }) {
|
handle_databases(conid, { databases }) {
|
||||||
const existing = this.opened.find((x) => x.conid == conid);
|
const existing = this.opened.find((x) => x.conid == conid);
|
||||||
@@ -40,7 +40,7 @@ module.exports = {
|
|||||||
disconnected: false,
|
disconnected: false,
|
||||||
};
|
};
|
||||||
this.opened.push(newOpened);
|
this.opened.push(newOpened);
|
||||||
this.closed = this.closed.filter((x) => x != conid);
|
delete this.closed[conid];
|
||||||
socket.emitChanged(`server-status-changed`);
|
socket.emitChanged(`server-status-changed`);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
subprocess.on('message', ({ msgtype, ...message }) => {
|
subprocess.on('message', ({ msgtype, ...message }) => {
|
||||||
@@ -49,21 +49,24 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
subprocess.on('exit', () => {
|
subprocess.on('exit', () => {
|
||||||
if (newOpened.disconnected) return;
|
if (newOpened.disconnected) return;
|
||||||
this.opened = this.opened.filter((x) => x.conid != conid);
|
this.close(conid, false);
|
||||||
this.closed.push(conid);
|
|
||||||
socket.emitChanged(`server-status-changed`);
|
|
||||||
});
|
});
|
||||||
subprocess.send({ msgtype: 'connect', ...connection });
|
subprocess.send({ msgtype: 'connect', ...connection });
|
||||||
return newOpened;
|
return newOpened;
|
||||||
},
|
},
|
||||||
|
|
||||||
close(conid) {
|
close(conid, kill = true) {
|
||||||
const existing = this.opened.find((x) => x.conid == conid);
|
const existing = this.opened.find((x) => x.conid == conid);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing.disconnected = true;
|
existing.disconnected = true;
|
||||||
existing.subprocess.kill();
|
if (kill) existing.subprocess.kill();
|
||||||
|
const last = this.opened.find((x) => x.conid == conid);
|
||||||
this.opened = this.opened.filter((x) => x.conid != conid);
|
this.opened = this.opened.filter((x) => x.conid != conid);
|
||||||
this.closed.push(conid);
|
this.closed[conid] = {
|
||||||
|
...(last && last.status),
|
||||||
|
name: 'error',
|
||||||
|
};
|
||||||
|
socket.emitChanged(`server-status-changed`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -76,15 +79,7 @@ module.exports = {
|
|||||||
serverStatus_meta: 'get',
|
serverStatus_meta: 'get',
|
||||||
async serverStatus() {
|
async serverStatus() {
|
||||||
return {
|
return {
|
||||||
...this.closed.reduce(
|
...this.closed,
|
||||||
(res, conid) => ({
|
|
||||||
...res,
|
|
||||||
[conid]: {
|
|
||||||
name: 'error',
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
..._.mapValues(_.keyBy(this.opened, 'conid'), 'status'),
|
..._.mapValues(_.keyBy(this.opened, 'conid'), 'status'),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ async function handleRefresh() {
|
|||||||
lastDatabases = databasesString;
|
lastDatabases = databasesString;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setStatusName('error');
|
setStatus({
|
||||||
console.error(err);
|
name: 'error',
|
||||||
process.exit(1);
|
message: err.message,
|
||||||
|
});
|
||||||
|
// console.error(err);
|
||||||
|
setTimeout(() => process.exit(1), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,9 +52,12 @@ async function handleConnect(connection) {
|
|||||||
handleRefresh();
|
handleRefresh();
|
||||||
setInterval(handleRefresh, 30 * 1000);
|
setInterval(handleRefresh, 30 * 1000);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setStatusName('error');
|
setStatus({
|
||||||
console.error(err);
|
name: 'error',
|
||||||
process.exit(1);
|
message: err.message,
|
||||||
|
});
|
||||||
|
// console.error(err);
|
||||||
|
setTimeout(() => process.exit(1), 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,30 @@ function AppObjectListItem({ makeAppObj, data, filter, appobj, onObjectClick, Su
|
|||||||
const [isExpanded, setIsExpanded] = React.useState(false);
|
const [isExpanded, setIsExpanded] = React.useState(false);
|
||||||
const [isHover, setIsHover] = React.useState(false);
|
const [isHover, setIsHover] = React.useState(false);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!appobj.isExpandable) {
|
||||||
|
// if (data._id == '6pOY2iFY8Gsq7mk6') console.log('COLLAPSE1');
|
||||||
|
setIsExpanded(false);
|
||||||
|
}
|
||||||
|
}, [appobj && appobj.isExpandable]);
|
||||||
|
|
||||||
// const { matcher } = appobj;
|
// const { matcher } = appobj;
|
||||||
// if (matcher && !matcher(filter)) return null;
|
// if (matcher && !matcher(filter)) return null;
|
||||||
if (onObjectClick) appobj.onClick = onObjectClick;
|
|
||||||
|
if (onObjectClick)
|
||||||
|
appobj = {
|
||||||
|
...appobj,
|
||||||
|
onClick: onObjectClick,
|
||||||
|
};
|
||||||
if (SubItems) {
|
if (SubItems) {
|
||||||
const oldClick = appobj.onClick;
|
const oldClick = appobj.onClick;
|
||||||
appobj.onClick = () => {
|
appobj = {
|
||||||
|
...appobj,
|
||||||
|
onClick: () => {
|
||||||
if (oldClick) oldClick();
|
if (oldClick) oldClick();
|
||||||
setIsExpanded(!isExpanded);
|
// if (data._id == '6pOY2iFY8Gsq7mk6') console.log('COLLAPSE2');
|
||||||
|
setIsExpanded((v) => !v);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export function AppObjectCore({
|
|||||||
component = 'div',
|
component = 'div',
|
||||||
prefix = null,
|
prefix = null,
|
||||||
statusIcon,
|
statusIcon,
|
||||||
|
statusTitle,
|
||||||
...other
|
...other
|
||||||
}) {
|
}) {
|
||||||
const appObjectParams = useAppObjectParams();
|
const appObjectParams = useAppObjectParams();
|
||||||
@@ -71,7 +72,7 @@ export function AppObjectCore({
|
|||||||
{title}
|
{title}
|
||||||
{statusIcon && (
|
{statusIcon && (
|
||||||
<StatusIconWrap>
|
<StatusIconWrap>
|
||||||
<FontIcon icon={statusIcon} />
|
<FontIcon icon={statusIcon} title={statusTitle} />
|
||||||
</StatusIconWrap>
|
</StatusIconWrap>
|
||||||
)}
|
)}
|
||||||
</Component>
|
</Component>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import ConnectionModal from '../modals/ConnectionModal';
|
|||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import { filterName } from '@dbgate/datalib';
|
import { filterName } from '@dbgate/datalib';
|
||||||
|
|
||||||
function Menu({ data, setOpenedConnections }) {
|
function Menu({ data, setOpenedConnections, openedConnections }) {
|
||||||
const handleEdit = () => {
|
const handleEdit = () => {
|
||||||
showModal((modalState) => <ConnectionModal modalState={modalState} connection={data} />);
|
showModal((modalState) => <ConnectionModal modalState={modalState} connection={data} />);
|
||||||
};
|
};
|
||||||
@@ -24,8 +24,12 @@ function Menu({ data, setOpenedConnections }) {
|
|||||||
<>
|
<>
|
||||||
<DropDownMenuItem onClick={handleEdit}>Edit</DropDownMenuItem>
|
<DropDownMenuItem onClick={handleEdit}>Edit</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={handleDelete}>Delete</DropDownMenuItem>
|
<DropDownMenuItem onClick={handleDelete}>Delete</DropDownMenuItem>
|
||||||
|
{openedConnections.includes(data._id) && data.status && (
|
||||||
<DropDownMenuItem onClick={handleRefresh}>Refresh</DropDownMenuItem>
|
<DropDownMenuItem onClick={handleRefresh}>Refresh</DropDownMenuItem>
|
||||||
|
)}
|
||||||
|
{openedConnections.includes(data._id) && (
|
||||||
<DropDownMenuItem onClick={handleDisconnect}>Disconnect</DropDownMenuItem>
|
<DropDownMenuItem onClick={handleDisconnect}>Disconnect</DropDownMenuItem>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -47,13 +51,16 @@ const connectionAppObject = (flags) => (
|
|||||||
: null;
|
: null;
|
||||||
const onClick = () => setOpenedConnections((c) => [...c, _id]);
|
const onClick = () => setOpenedConnections((c) => [...c, _id]);
|
||||||
|
|
||||||
// let isBusy = false;
|
|
||||||
let statusIcon = null;
|
let statusIcon = null;
|
||||||
|
let statusTitle = null;
|
||||||
if (openedConnections.includes(_id)) {
|
if (openedConnections.includes(_id)) {
|
||||||
if (!status) statusIcon = 'fas fa-spinner fa-spin';
|
if (!status) statusIcon = 'fas fa-spinner fa-spin';
|
||||||
else if (status.name == 'pending') statusIcon = 'fas fa-spinner fa-spin';
|
else if (status.name == 'pending') statusIcon = 'fas fa-spinner fa-spin';
|
||||||
else if (status.name == 'ok') statusIcon = 'fas fa-check-circle green';
|
else if (status.name == 'ok') statusIcon = 'fas fa-check-circle green';
|
||||||
else statusIcon = 'fas fa-times-circle red';
|
else statusIcon = 'fas fa-times-circle red';
|
||||||
|
if (status && status.name == 'error') {
|
||||||
|
statusTitle = status.message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -65,8 +72,8 @@ const connectionAppObject = (flags) => (
|
|||||||
isBold,
|
isBold,
|
||||||
isExpandable,
|
isExpandable,
|
||||||
onClick,
|
onClick,
|
||||||
// isBusy,
|
|
||||||
statusIcon,
|
statusIcon,
|
||||||
|
statusTitle,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,15 +26,12 @@ export function FontIcon({ icon, ...props }) {
|
|||||||
|
|
||||||
let className = props.className || '';
|
let className = props.className || '';
|
||||||
|
|
||||||
// if (_.startsWith(name, 'bs-')) className += ` glyphicon glyphicon-${name.substr(3)}`;
|
|
||||||
if (type == 'fas' || type == 'far') className += ` ${type} ${name} ${parts.join(' ')}`;
|
if (type == 'fas' || type == 'far') className += ` ${type} ${name} ${parts.join(' ')}`;
|
||||||
|
|
||||||
if (_.includes(parts, 'spin')) className += ' fa-spin';
|
|
||||||
|
|
||||||
const style = { ...props.style };
|
const style = { ...props.style };
|
||||||
|
|
||||||
const last = parts[parts.length - 1];
|
const last = parts[parts.length - 1];
|
||||||
if (last && last != 'spin') {
|
if (last && last != 'fa-spin') {
|
||||||
style['color'] = last;
|
style['color'] = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import _ from 'lodash';
|
|||||||
import { AppObjectList } from '../appobj/AppObjectList';
|
import { AppObjectList } from '../appobj/AppObjectList';
|
||||||
import connectionAppObject from '../appobj/connectionAppObject';
|
import connectionAppObject from '../appobj/connectionAppObject';
|
||||||
import databaseAppObject from '../appobj/databaseAppObject';
|
import databaseAppObject from '../appobj/databaseAppObject';
|
||||||
import { useSetCurrentDatabase, useCurrentDatabase } from '../utility/globalState';
|
import { useSetCurrentDatabase, useCurrentDatabase, useOpenedConnections } from '../utility/globalState';
|
||||||
import InlineButton from './InlineButton';
|
import InlineButton from './InlineButton';
|
||||||
import databaseObjectAppObject from '../appobj/databaseObjectAppObject';
|
import databaseObjectAppObject from '../appobj/databaseObjectAppObject';
|
||||||
import { useSqlObjectList, useDatabaseList, useConnectionList, useServerStatus } from '../utility/metadataLoaders';
|
import { useSqlObjectList, useDatabaseList, useConnectionList, useServerStatus } from '../utility/metadataLoaders';
|
||||||
import { SearchBoxWrapper, InnerContainer, Input, MainContainer, OuterContainer, WidgetTitle } from './WidgetStyles';
|
import { SearchBoxWrapper, InnerContainer, Input, MainContainer, OuterContainer, WidgetTitle } from './WidgetStyles';
|
||||||
|
import axios from '../utility/axios';
|
||||||
|
|
||||||
function SubDatabaseList({ data }) {
|
function SubDatabaseList({ data }) {
|
||||||
const setDb = useSetCurrentDatabase();
|
const setDb = useSetCurrentDatabase();
|
||||||
@@ -32,8 +33,17 @@ function SubDatabaseList({ data }) {
|
|||||||
function ConnectionList() {
|
function ConnectionList() {
|
||||||
const connections = useConnectionList();
|
const connections = useConnectionList();
|
||||||
const serverStatus = useServerStatus();
|
const serverStatus = useServerStatus();
|
||||||
|
const openedConnections = useOpenedConnections();
|
||||||
const connectionsWithStatus =
|
const connectionsWithStatus =
|
||||||
connections && serverStatus && connections.map((conn) => ({ ...conn, status: serverStatus[conn._id] }));
|
connections && serverStatus
|
||||||
|
? connections.map((conn) => ({ ...conn, status: serverStatus[conn._id] }))
|
||||||
|
: connections;
|
||||||
|
|
||||||
|
const handleRefreshConnections = () => {
|
||||||
|
for (const conid of openedConnections) {
|
||||||
|
axios.post('server-connections/refresh', { conid });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const [filter, setFilter] = React.useState('');
|
const [filter, setFilter] = React.useState('');
|
||||||
return (
|
return (
|
||||||
@@ -41,7 +51,7 @@ function ConnectionList() {
|
|||||||
<WidgetTitle>Connections</WidgetTitle>
|
<WidgetTitle>Connections</WidgetTitle>
|
||||||
<SearchBoxWrapper>
|
<SearchBoxWrapper>
|
||||||
<Input type="text" placeholder="Search connection" value={filter} onChange={(e) => setFilter(e.target.value)} />
|
<Input type="text" placeholder="Search connection" value={filter} onChange={(e) => setFilter(e.target.value)} />
|
||||||
<InlineButton>Refresh</InlineButton>
|
<InlineButton onClick={handleRefreshConnections}>Refresh</InlineButton>
|
||||||
</SearchBoxWrapper>
|
</SearchBoxWrapper>
|
||||||
|
|
||||||
<InnerContainer>
|
<InnerContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user