Skip to content

Commit

Permalink
Getting the back button to work
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 4, 2016
1 parent 9c47415 commit 3b9b81f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
26 changes: 18 additions & 8 deletions panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ var px = (function() {
var visualizations = {};
var dashboard = undefined;

function getParam(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function UTC(dttm){
return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds());
Expand Down Expand Up @@ -333,12 +339,6 @@ var px = (function() {
for(var i=0; i < collapsed_fieldsets.length; i++){
toggle_fieldset($('legend:contains("' + collapsed_fieldsets[i] + '")'), false);
}
function getParam(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

$(".select2").select2({dropdownAutoWidth : true});
$(".select2Sortable").select2({dropdownAutoWidth : true});
Expand Down Expand Up @@ -445,6 +445,8 @@ var px = (function() {

function initSqlEditorView() {
var editor = ace.edit("sql");
editor.$blockScrolling = Infinity

var textarea = $('#sql').hide();
editor.setTheme("ace/theme/crimson_editor");
editor.setOptions({
Expand All @@ -453,7 +455,6 @@ var px = (function() {
});
editor.getSession().setMode("ace/mode/sql");
editor.focus();

$("select").select2({dropdownAutoWidth : true});
function showTableMetadata() {
$(".metadata").load('/panoramix/table/' + $("#dbtable").val() + '/');
Expand All @@ -468,10 +469,19 @@ var px = (function() {
editor.setValue(msg);
});
});
$("#select_star").click();
editor.setValue(getParam('sql'));
$(window).bind("popstate", function(event) {
// Browser back button
var returnLocation = history.location || document.location;
// Could do something more lightweight here, but we're not optimizing
// for the use of the back button anyways
editor.setValue(getParam('sql'));
$("#run").click();
});
$("#run").click(function() {
$('#results').hide(0);
$('#loading').show(0);
history.pushState({}, document.title, '?sql=' + encodeURIComponent(editor.getValue()));
$.ajax({
type: "POST",
url: '/panoramix/runsql/',
Expand Down
3 changes: 1 addition & 2 deletions panoramix/templates/panoramix/sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ <h2>db: [{{ db }}]</h2>
</div>
<div class="topsql row">
<div class="col-xs-7 fillheight">
<textarea id="sql" class="fillup">SELECT * FROM information_schema.tables;
</textarea>
<textarea id="sql" class="fillup"></textarea>
</div>
<div class="col-xs-5 fillheight">
<div class="metadata fillup bordered">
Expand Down

0 comments on commit 3b9b81f

Please sign in to comment.