diff options
| -rw-r--r-- | main.js | 33 | ||||
| -rw-r--r-- | new-connection.html | 3 | ||||
| -rw-r--r-- | new-connection.js | 18 | ||||
| -rw-r--r-- | query-executor.js | 23 | ||||
| -rw-r--r-- | styles/instance-manager.css | 1 | ||||
| -rw-r--r-- | styles/new-connection.css | 4 |
6 files changed, 62 insertions, 20 deletions
@@ -43,7 +43,7 @@ app.on("activate", () => { function createNewConnectionDialog() { newConnectionDialog = new BrowserWindow({ width: 400, - height: 540 + height: 600 }); newConnectionDialog.loadURL(url.format({ pathname: path.join(__dirname, "new-connection.html"), @@ -83,17 +83,32 @@ ipcMain.on("newConnection.createConnection", (event, payload) => { }); -ipcMain.on("queryExecutor.initialiseConnectionCallback", (event, executorId) => { - // TODO - handle connection initialisation errors +ipcMain.on("queryExecutor.initialiseConnectionCallback", (event, payload) => { + + if (payload.error !== undefined) { + queryExecutors.pop().close(); + newConnectionDialog.webContents.send("newConnection.initialisationFailed", payload.error); + } + else { + let connectionConfig = getQueryExecutorInstance().connectionConfig; + + if(connectionConfig.isTest) { + newConnectionDialog.webContents.send("newConnection.connectionTestOk"); + queryExecutors.pop().close(); + } + else{ + uiWindow.webContents.send("instanceManager.registerNewInstance", { assignedQueryExecutorId: payload.executorId, connectionName: connectionConfig.name }); + newConnectionDialog.close(); + } + } - // Bit of a hack, cant guarantee this was the executor which just got initalised.executor - // Should pass it back from the executor via the payload - let connectionName = queryExecutors[queryExecutors.length -1].connectionConfig.name; - - uiWindow.webContents.send("instanceManager.registerNewInstance", {assignedQueryExecutorId: executorId, connectionName: connectionName}); - newConnectionDialog.close(); }); +function getQueryExecutorInstance() { + // Bit of a hack, cant guarantee this was the executor which just got initalised + // Should pass it back from the executor via the payload + return queryExecutors[queryExecutors.length - 1]; +} const { webContents } = require('electron'); diff --git a/new-connection.html b/new-connection.html index 1ac6c89..ddfb380 100644 --- a/new-connection.html +++ b/new-connection.html @@ -8,7 +8,7 @@ </head> <body> - <h4 class="title is-4" >Add new connection</h4> + <h4 class="title is-4" >Add new connection</h4> <form> <div class="field"> <label class="label is-small" for="name">Connection name</label> @@ -53,6 +53,7 @@ <input name="password" class="input is-small" type="text"/> </div> </div> + <div id="status-message" class="field"></div> <div class="field is-grouped"> <div class="control"> <input id="create-connection" type="button" class="button is-link is-small" value="Add"></input> diff --git a/new-connection.js b/new-connection.js index 2493c25..e517370 100644 --- a/new-connection.js +++ b/new-connection.js @@ -26,18 +26,30 @@ function parseForm() { return formData; } -function createConnection() { +function createConnection(isTest) { + $("#status-message").empty(); let connectionProps = parseForm(); + connectionProps.isTest = isTest; ipcRenderer.send("newConnection.createConnection", connectionProps); } +ipcRenderer.on("newConnection.initialisationFailed", (event, error) => { + let errorMsg = $("<div class='notification is-danger'></div>").text(error.cause); + $("#status-message").append(errorMsg); +}); + +ipcRenderer.on("newConnection.connectionTestOk", (event) => { + let status = $("<div class='notification is-success'></div>").text("Connection OK"); + $("#status-message").append(status); +}); + $(document).ready(() => { $("#create-connection").click(() => { - createConnection(); + createConnection(false); }); $("#test-connection").click(() => { - //TODO + createConnection(true); }); $("#cancel").click(() => { diff --git a/query-executor.js b/query-executor.js index 88df7e1..ee7552b 100644 --- a/query-executor.js +++ b/query-executor.js @@ -3,6 +3,8 @@ const { remote, ipcRenderer } = require("electron"); const { Pool } = require("pg"); +const connectionTestQuery = "SELECT now()"; + const executorId = require("uuid/v1")(); const connectionConfig = remote.getCurrentWindow().connectionConfig; @@ -15,8 +17,19 @@ const connectionPool = new Pool({ port: connectionConfig.port }); -// Initialisation completed -ipcRenderer.send("queryExecutor.initialiseConnectionCallback", executorId); +// Test the newly initialised connection +connectionPool.query(connectionTestQuery, (err, res) => { + setErrorCauseIfExists(err); + ipcRenderer.send("queryExecutor.initialiseConnectionCallback", {error: err, executorId: executorId}); +}); + +function setErrorCauseIfExists(error) { + if (error !== undefined) { + // The IPC payload is serialised to JSON before transmission, so the prototype chain is lost. + // So store the nicely formatted error message as a property. + error.cause = error.toString(); + } +} ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { @@ -25,11 +38,7 @@ ipcRenderer.on("queryExecutor.runQuery", (event, payload) => { console.log(err, res); - if(err !== undefined) { - // The IPC payload is serialised to JSON beofre transmisison, so the protoype chain is lost. - // So store the nicely formatted error message as a property. - err.cause = err.toString(); - } + setErrorCauseIfExists(err); ipcRenderer.send("queryExecutor.runQueryComplete", { "error": err, diff --git a/styles/instance-manager.css b/styles/instance-manager.css index c49c8a3..51bf62c 100644 --- a/styles/instance-manager.css +++ b/styles/instance-manager.css @@ -21,6 +21,7 @@ body { .etabs-views { border: none; height: calc(100vh - 52px); + background-color: #282a36; } .etabs-buttons button { diff --git a/styles/new-connection.css b/styles/new-connection.css index 97aaae6..2160594 100644 --- a/styles/new-connection.css +++ b/styles/new-connection.css @@ -1,3 +1,7 @@ html, body { padding: 8px; +} + +.notification { + padding: 5px 10px; }
\ No newline at end of file |