diff --git a/app.js b/app.js index e4d37a2..da6b254 100644 --- a/app.js +++ b/app.js @@ -25,14 +25,23 @@ $(function() { if (window.location.hash) { var external_where = parseHash(); } else { - db_host = prompt('Host:', 'http://127.0.0.1:8123/'); + if (!db_host) { + db_host = localGetKey('lighthouse_host'); //get + if (!db_host) { + db_host = prompt('Host:', 'http://127.0.0.1:8123/'); + } + } if (!db_host) { alert('You must enter host name. The interface will not work without it. Reload page and try again.'); return; } window.location.hash = db_host; } - + if (db_host) { + addHost(db_host); + localSetKey('lighthouse_host', db_host); //set + updateHostsSelection(); + } registerAltKeys(); $('#query').keydown(function(ev) { @@ -534,7 +543,7 @@ function query(key, str, callback) { res = {data: {err: e}}; } } - + var fields = []; var types = {}; var statistics = res.statistics || {}; @@ -656,7 +665,7 @@ function reloadDatabases() { default_database = saved_database; } } - + var lst = ['']; for (var i = 0; i < data.rows.length; i++) { var name = data.rows[i][0]; @@ -668,6 +677,44 @@ function reloadDatabases() { }); } +function getHosts() { + var hosts = localGetKey('lighhouse_hosts'); + if (hosts) { + hosts = JSON.parse(hosts); + } else { + hosts = {}; + } + return hosts; +} + +function updateHostsSelection() { + var hosts = getHosts(); + var lst = ['']; + $.each(hosts, function(key, name) { + lst.push(''); + }); + + $('#hostname').html(lst.join("\n")); +} + +function selectHostName(host) { + addHost(host); + localSetKey('lighthouse_host', host); //set + window.location.hash = host; +} + +function addHost(host) { + if (host == "") { + return + } + var hosts = getHosts(); + if (!hosts) { + hosts = {} + } + hosts[host] = host; + localSetKey('lighhouse_hosts', JSON.stringify(hosts)); +} + function filterTables() { var q = $('#search').val(); var tables = [] diff --git a/index.html b/index.html index e9ea637..82091ca 100644 --- a/index.html +++ b/index.html @@ -52,7 +52,7 @@ font-size: 0.85em; } - #database { + .selector-left { max-width: 180px; margin: 10px; } @@ -126,12 +126,16 @@ line-height: 0.9; border-radius: 10px; } +
- + +
+
+