diff --git a/src/components/Main.js b/src/components/Main.js
index c68163e..ae01199 100644
--- a/src/components/Main.js
+++ b/src/components/Main.js
@@ -285,7 +285,7 @@ class Main extends Component {
_onQuerySubmit= (e) => {
e.preventDefault();
- InfluxAPI.getQueryResults(this.state.server.url, this.state.database, this.state.queryText);
+ InfluxAPI.getQueryResults(this.state.server.url,this.state.server.username, this.state.server.password, this.state.database, this.state.queryText);
}
// Data changed:
@@ -307,4 +307,4 @@ class Main extends Component {
};
}
-export default Main;
\ No newline at end of file
+export default Main;
diff --git a/src/components/NavBar.js b/src/components/NavBar.js
index 1498d62..19663e0 100644
--- a/src/components/NavBar.js
+++ b/src/components/NavBar.js
@@ -7,7 +7,7 @@ import {
Nav,
NavItem,
NavLink,
- NavDropdown,
+ Dropdown,
DropdownToggle,
DropdownItem,
DropdownMenu,
@@ -114,7 +114,7 @@ class NavServerList extends Component {
let currentServer = this.props.currentserver.name;
return (
-
+
Server: {currentServer}
@@ -123,7 +123,7 @@ class NavServerList extends Component {
return {server.name};
}, this)}
-
+
);
}
@@ -165,7 +165,7 @@ class NavDatabaseList extends Component {
let currentDatabase = this.props.currentdatabase;
return (
-
+
Database: {currentDatabase}
@@ -174,7 +174,7 @@ class NavDatabaseList extends Component {
return {database};
}, this)}
-
+
);
}
diff --git a/src/components/Settings.js b/src/components/Settings.js
index e75cec2..e0f244b 100644
--- a/src/components/Settings.js
+++ b/src/components/Settings.js
@@ -55,12 +55,14 @@ class Settings extends Component {
Name |
Url |
+ Username |
+ Password |
Actions |
{this.state.Servers.map(function(server, index) {
- return {server.name} | {server.url} | |
;
+ return {server.name} | {server.url} | {server.username} | {server.password && "*"} | |
;
}, this)}
@@ -78,6 +80,16 @@ class Settings extends Component {
+
+
+
+
+
+
+
+
+
+
@@ -107,6 +119,18 @@ class Settings extends Component {
});
}
+ _onAddServerUsernameChange = (e) => {
+ this.setState({
+ AddServerUsername: e.target.value
+ });
+ }
+
+ _onAddServerPasswordChange = (e) => {
+ this.setState({
+ AddServerPassword: e.target.value
+ });
+ }
+
_onAddServerClick = (e) => {
e.preventDefault();
@@ -126,7 +150,7 @@ class Settings extends Component {
// Add the server
console.log("Adding server..." + this.state.AddServerName);
- SettingsAPI.addServer(this.state.AddServerName, serverUrl);
+ SettingsAPI.addServer(this.state.AddServerName, serverUrl, this.state.AddServerUsername, this.state.AddServerPassword);
// If we have a current server:
if(SettingsStore.haveCurrentServer()){
@@ -134,14 +158,16 @@ class Settings extends Component {
let currentServer = SettingsStore.getCurrentServer();
// Reset the database list:
- InfluxAPI.getDatabaseList(currentServer.url);
+ InfluxAPI.getDatabaseList(currentServer.url, currentServer.username, currentServer.password);
}
// Clear the add server fields:
this.setState(
{
AddServerName: "",
- AddServerUrl: ""
+ AddServerUrl: "",
+ AddServerUsername: "",
+ AddServerPassword: "",
}
);
diff --git a/src/utils/InfluxAPI.js b/src/utils/InfluxAPI.js
index d03dc76..5e7313b 100644
--- a/src/utils/InfluxAPI.js
+++ b/src/utils/InfluxAPI.js
@@ -5,7 +5,7 @@ import SettingsActions from '../actions/SettingsActions';
class InfluxAPI {
// Executes a query and gets the results
- getQueryResults(serverurl, database, query){
+ getQueryResults(serverurl,username, password, database, query){
if(serverurl === "" || database === "")
{
@@ -16,8 +16,14 @@ class InfluxAPI {
// Set the request
QueryActions.receiveQueryRequest(query, serverurl, database);
+ // build auth query params
+ let auth = ""
+ if (username !== undefined && username !== "" && password !== undefined && username !== "") {
+ auth = "&u=" + username + "&p=" + password
+ }
+
// Encode and Interpolate the values
- let url = `${serverurl}/query?q=${encodeURIComponent(query)}&db=${database}`;
+ let url = `${serverurl}/query?q=${encodeURIComponent(query)}`+auth+`&db=${database}`;
url = url.replace(/%20/g, "+");
fetch(url,
@@ -40,16 +46,22 @@ class InfluxAPI {
}
// Gets the list of databases for the given server
- getDatabaseList(serverurl) {
+ getDatabaseList(serverurl, username, password) {
if(!serverurl)
{
console.log("Can't execute query: server is blank");
return;
}
+
+ // build auth query params
+ let auth = ""
+ if(username !== undefined && password !== undefined){
+ auth = "&u="+username+"&p="+password
+ }
// Encode and Interpolate the values
- let url = `${serverurl}/query?q=SHOW+DATABASES&db=`;
+ let url = `${serverurl}/query?q=SHOW+DATABASES`+auth+`&db=`;
url = url.replace(/%20/g, "+");
fetch(url,
@@ -75,4 +87,4 @@ class InfluxAPI {
}
- export default new InfluxAPI();
\ No newline at end of file
+ export default new InfluxAPI();
diff --git a/src/utils/SettingsAPI.js b/src/utils/SettingsAPI.js
index 2913fdd..eb89c02 100644
--- a/src/utils/SettingsAPI.js
+++ b/src/utils/SettingsAPI.js
@@ -19,7 +19,7 @@ class SettingsAPI {
}
// Adds a server to the list
- addServer(name, url) {
+ addServer(name, url, username, password) {
// First, get the current list of servers
let servers = store.get('servers') || [];
@@ -29,6 +29,8 @@ class SettingsAPI {
let newServer = {};
newServer.name = name;
newServer.url = url;
+ newServer.username = username;
+ newServer.password = password;
servers.push(newServer);
}
@@ -72,4 +74,4 @@ class SettingsAPI {
}
- export default new SettingsAPI();
\ No newline at end of file
+ export default new SettingsAPI();