Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -534,7 +543,7 @@ function query(key, str, callback) {
res = {data: {err: e}};
}
}

var fields = [];
var types = {};
var statistics = res.statistics || {};
Expand Down Expand Up @@ -656,7 +665,7 @@ function reloadDatabases() {
default_database = saved_database;
}
}

var lst = ['<option value="">Select database...</option>'];
for (var i = 0; i < data.rows.length; i++) {
var name = data.rows[i][0];
Expand All @@ -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 = ['<option value="">Select hostname...</option>'];
$.each(hosts, function(key, name) {
lst.push('<option value="' + htmlspecialchars(name) + '"' + (name == db_host ? ' selected="selected"' : '') + '>' + htmlspecialchars(name) + '</option>');
});

$('#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 = []
Expand Down
8 changes: 6 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
font-size: 0.85em;
}

#database {
.selector-left {
max-width: 180px;
margin: 10px;
}
Expand Down Expand Up @@ -126,12 +126,16 @@
line-height: 0.9;
border-radius: 10px;
}

</style>
</head>
<body onbeforeunload="saveLastQuery()">
<div style="width: 200px; max-width: 200px; height: 100vh; padding: 0px; margin: 0px; position: absolute; top: 0px; left: 0px; flex-direction: column; display: flex;">
<div>
<select id="database" onchange="selectDatabase(this.value)"></select>
<select class="selector-left" id="hostname" onchange="selectHostName(this.value)"></select>
</div>
<div>
<select class="selector-left" id="database" onchange="selectDatabase(this.value)"></select>
</div>
<div>
<input type="text" id="search" placeholder="Filter" class="span2 search-query" />
Expand Down