Skip to content

Commit

Permalink
ENGINE-628: add query string parameters for automatically connecting …
Browse files Browse the repository at this point in the history
…to a particular host. Includes the parseUri library from http://blog.stevenlevithan.com/archives/parseuri (MIT).
  • Loading branch information
alambert committed Jan 4, 2012
1 parent 6238d6e commit 5167a6f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ On top of that it is possible to set refresh interval and time window for the ch

Supports elasticsearch 0.17.x and 0.18.x

To immediately connect to a particular host, add the <code>host</code>, <code>port</code>, and <code>go</code> parameters to the query string: <code>index.html?host=search.example.com&port=9200&go</code>
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@
<script src="js/lib/mustache/mustache.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lib/jQueryMustache/jQueryMustache.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lib/highcharts/highcharts.js" type="text/javascript" charset="utf-8"></script>
<script src="js/lib/parseUri/parseuri.js" type="text/javascript" charset="utf-8"></script>
<script src="js/charts.js" type="text/javascript" charset="utf-8"></script>
<script src="js/bigdesk.js" type="text/javascript" charset="utf-8"></script>

</body>
</html>
</html>
14 changes: 14 additions & 0 deletions js/bigdesk.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
redrawCharts(charts);
});

parsedUri = parseUri(document.location.href);

if (typeof parsedUri.queryKey.host !== 'undefined') {
host.val(parsedUri.queryKey.host);
}

if (typeof parsedUri.queryKey.port !== 'undefined') {
port.val(parsedUri.queryKey.port);
}

if (typeof parsedUri.queryKey.go !== 'undefined') {
button.click();
}

// build all charts
charts = [
// process chart
Expand Down
32 changes: 32 additions & 0 deletions js/lib/parseUri/parseuri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License

function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;

while (i--) uri[o.key[i]] = m[i] || "";

uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2;
});

return uri;
};

parseUri.options = {
strictMode: false,
key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
q: {
name: "queryKey",
parser: /(?:^|&)([^&=]*)=?([^&]*)/g
},
parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
};

0 comments on commit 5167a6f

Please sign in to comment.