Write current sql query after input query change

This commit is contained in:
Dan Sosedoff 2015-08-02 19:21:42 -05:00
parent fb13ce8b07
commit 639ca96caa
2 changed files with 13 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -291,9 +291,6 @@ function runQuery() {
return;
}
// Automatically save last executed query so its not lost
localStorage.setItem("pgweb_query", query);
executeQuery(query, function(data) {
buildTable(data);
@ -358,6 +355,7 @@ function exportToCSV() {
}
function initEditor() {
var writeQueryTimeout = null;
editor = ace.edit("custom_query");
editor.getSession().setMode("ace/mode/pgsql");
@ -384,6 +382,16 @@ function initEditor() {
}
}]);
editor.on("change", function() {
if (writeQueryTimeout) {
clearTimeout(writeQueryTimeout);
}
writeQueryTimeout = setTimeout(function() {
localStorage.setItem("pgweb_query", editor.getValue());
}, 1000);
});
var query = localStorage.getItem("pgweb_query");
if (query && query.length > 0) {
editor.setValue(query);