diff --git a/api/src/controllers/connections.js b/api/src/controllers/connections.js
index b53f3087e..93a0fbcc7 100644
--- a/api/src/controllers/connections.js
+++ b/api/src/controllers/connections.js
@@ -14,7 +14,7 @@ module.exports = {
const dir = await datadir();
this.datastore = nedb.create(path.join(dir, 'connections.jsonl'));
},
-
+
list_meta: 'get',
async list() {
return this.datastore.find();
@@ -32,7 +32,15 @@ module.exports = {
save_meta: 'post',
async save(connection) {
- const res = await this.datastore.insert(connection);
- return res;
+ if (connection._id) {
+ return await this.datastore.update(_.pick(connection, '_id'), connection);
+ } else {
+ return await this.datastore.insert(connection);
+ }
+ },
+
+ delete_meta: 'post',
+ async delete(connection) {
+ return await this.datastore.remove(_.pick(connection, '_id'));
},
};
diff --git a/api/src/engines/postgre/connect.js b/api/src/engines/postgres/connect.js
similarity index 100%
rename from api/src/engines/postgre/connect.js
rename to api/src/engines/postgres/connect.js
diff --git a/web/src/appobj/AppObjects.js b/web/src/appobj/AppObjects.js
new file mode 100644
index 000000000..72a3f33a0
--- /dev/null
+++ b/web/src/appobj/AppObjects.js
@@ -0,0 +1,41 @@
+import React from 'react';
+import styled from 'styled-components';
+import { showMenu } from '../modals/DropDownMenu';
+
+const AppObjectDiv = styled.div`
+ margin: 5px;
+`;
+
+const IconWrap = styled.span`
+ margin-right: 10px;
+`;
+
+export function AppObjectCore({ title, Icon, Menu, data, makeAppObj }) {
+ const handleContextMenu = event => {
+ if (!Menu) return;
+
+ event.preventDefault();
+ showMenu(event.pageX, event.pageY,
);
+ };
+
+ return (
+
+
+
+
+ {title}
+
+ );
+}
+
+export function AppObjectControl({ data, makeAppObj }) {
+ const appobj = makeAppObj(data);
+ return ;
+}
+
+export function AppObjectList({ list, makeAppObj }) {
+ return (list || []).map(x => {
+ const appobj = makeAppObj(x);
+ return ;
+ });
+}
diff --git a/web/src/appobj/connectionAppObject.js b/web/src/appobj/connectionAppObject.js
new file mode 100644
index 000000000..3c2798645
--- /dev/null
+++ b/web/src/appobj/connectionAppObject.js
@@ -0,0 +1,43 @@
+import React from 'react';
+import { MicrosoftIcon, SqliteIcon, PostgreSqlIcon, MySqlIcon, ServerIcon } from '../icons';
+import { DropDownMenuItem } from '../modals/DropDownMenu';
+import showModal from '../modals/showModal';
+import ConnectionModal from '../modals/ConnectionModal';
+import axios from '../utility/axios';
+
+function getIcon(engine) {
+ switch (engine) {
+ case 'mssql':
+ return MicrosoftIcon;
+ case 'sqlite':
+ return SqliteIcon;
+ case 'postgres':
+ return PostgreSqlIcon;
+ case 'mysql':
+ return MySqlIcon;
+ }
+ return ServerIcon;
+}
+
+function Menu({ data, makeAppObj }) {
+ const handleEdit = () => {
+ showModal(modalState => );
+ };
+ const handleDelete = () => {
+ axios.post('connections/delete', data);
+ };
+ return (
+ <>
+ Edit
+ Delete
+ >
+ );
+}
+
+export default function connectionAppObject({ _id, server, displayName, engine }) {
+ const title = displayName || server;
+ const key = _id;
+ const Icon = getIcon(engine);
+
+ return { title, key, Icon, Menu };
+}
diff --git a/web/src/modals/ConnectionModal.js b/web/src/modals/ConnectionModal.js
index de7d3687e..7e4e9c3ef 100644
--- a/web/src/modals/ConnectionModal.js
+++ b/web/src/modals/ConnectionModal.js
@@ -1,16 +1,16 @@
import React from 'react';
-import axios from 'axios';
+import axios from '../utility/axios';
import ModalBase from './ModalBase';
import { FormRow, FormButton, FormTextField, FormSelectField, FormSubmit } from '../utility/forms';
import { TextField } from '../utility/inputs';
import { Formik, Form } from 'formik';
// import FormikForm from '../utility/FormikForm';
-export default function ConnectionModal({ modalState }) {
+export default function ConnectionModal({ modalState, connection }) {
const [sqlConnectResult, setSqlConnectResult] = React.useState('Not connected');
const handleTest = async values => {
- const resp = await axios.post('http://localhost:3000/connections/test', values);
+ const resp = await axios.post('connections/test', values);
console.log('resp.data', resp.data);
const { error, version } = resp.data;
@@ -20,20 +20,19 @@ export default function ConnectionModal({ modalState }) {
};
const handleSubmit = async values => {
- const resp = await axios.post('http://localhost:3000/connections/save', values);
- console.log('resp.data', resp.data);
+ const resp = await axios.post('connections/save', values);
// modalState.close();
};
return (
- Add connection
-
+ {connection ? 'Edit connection' : 'Add connection'}
+