Skip to content

Commit

Permalink
Getting the SQL view back in a working state
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 12, 2016
1 parent 9ac979a commit 797d41b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 59 deletions.
13 changes: 8 additions & 5 deletions caravel/assets/javascripts/sql.js
Expand Up @@ -2,7 +2,8 @@ var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
var showModal = require('./modules/utils.js').showModal;

require('select2');
require('./caravel-select2.js');

require('datatables.net-bs');
require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
require('bootstrap');
Expand All @@ -11,12 +12,14 @@ var ace = require('brace');
require('brace/mode/sql');
require('brace/theme/crimson_editor');

require('../stylesheets/sql.css');

$(document).ready(function () {
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, " "));
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function initSqlEditorView() {
Expand Down Expand Up @@ -53,9 +56,9 @@ $(document).ready(function () {

function selectStarOnClick() {
$.ajax('/caravel/select_star/' + database_id + '/' + $("#dbtable").val() + '/')
.done(function (msg) {
editor.setValue(msg);
});
.done(function (msg) {
editor.setValue(msg);
});
}

$("#select_star").click(selectStarOnClick);
Expand Down
41 changes: 41 additions & 0 deletions caravel/assets/stylesheets/sql.css
@@ -0,0 +1,41 @@
.topsql {
height: 250px;
}
.dataTables_filter {
padding-top: 5px;
padding-right: 5px;
}
.bordered {
padding: 0px 0px;
border: 1px solid grey;
border-radius: 5px;
background-color: #EEE;
}
div.alert {
padding: 5px;
margin: 0px;
}
.metadata {
overflow: auto;
width: 300px;
height: 100px;
}
.fillup {
width: 100%;
height: 100%;
}
.fillheight {
height: 100%;
}
.interactions {
padding-bottom: 10px;
}
#results {
overflow: auto;
font-size: 12px;
margin-bottom: 5px;
}
table tbody tr td {
padding: 1px 4px;
font-size: small;
}
51 changes: 1 addition & 50 deletions caravel/templates/caravel/sql.html
@@ -1,54 +1,5 @@
{% extends "caravel/basic.html" %}

{% block head_css %}
{{super()}}
<link rel="stylesheet" type="text/css" href="/static/assets/vendor/dataTables/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="/static/assets/vendor/dataTables/dataTables.bootstrap.css" />
<style type="text/css">
.topsql {
height: 250px;
}
.dataTables_filter {
padding-top: 5px;
padding-right: 5px;
}
.bordered {
padding: 0px 0px;
border: 1px solid grey;
border-radius: 5px;
background-color: #EEE;
}
div.alert {
padding: 5px;
margin: 0px;
}
.metadata {
overflow: auto;
width: 300px;
height: 100px;
}
.fillup {
width: 100%;
height: 100%;
}
.fillheight {
height: 100%;
}
.interactions {
padding-bottom: 10px;
}
#results {
overflow: auto;
font-size: 12px;
margin-bottom: 5px;
}
table tbody tr td {
padding: 1px 4px;
font-size: small;
}

</style>
{% endblock %}

{% block body %}
<div class="container-fluid">
Expand Down Expand Up @@ -84,7 +35,7 @@ <h3>db: [{{ db }}]</h3>
</div>
<div id="results_section">
<hr/>
<img id="loading" width="25" style="display: none;" src="/static/img/loading.gif">
<img id="loading" width="25" style="display: none;" src="/static/assets/images/loading.gif">
</div>
<div>
<div id="results" class="bordered" style="display: none;"></div>
Expand Down
14 changes: 10 additions & 4 deletions caravel/views.py
Expand Up @@ -718,14 +718,15 @@ def table(self, database_id, table_name):
cols = mydb.get_columns(table_name)
df = pd.DataFrame([(c['name'], c['type']) for c in cols])
df.columns = ['col', 'type']
tbl_cls = (
"dataframe table table-striped table-bordered "
"table-condensed sql_results").split(' ')
return self.render_template(
"caravel/ajah.html",
content=df.to_html(
index=False,
na_rep='',
classes=(
"dataframe table table-striped table-bordered "
"table-condensed sql_results")))
classes=tbl_cls))

@has_access
@expose("/select_star/<database_id>/<table_name>/")
Expand Down Expand Up @@ -753,6 +754,11 @@ def runsql(self):
sql = data.get('sql')
database_id = data.get('database_id')
mydb = session.query(models.Database).filter_by(id=database_id).first()

if (
not self.appbuilder.sm.has_access(
'all_datasource_access', 'all_datasource_access')):
raise Exception("test")
content = ""
if mydb:
eng = mydb.get_sqla_engine()
Expand All @@ -771,7 +777,7 @@ def runsql(self):
na_rep='',
classes=(
"dataframe table table-striped table-bordered "
"table-condensed sql_results"))
"table-condensed sql_results").split(' '))
except Exception as e:
content = (
'<div class="alert alert-danger">'
Expand Down

0 comments on commit 797d41b

Please sign in to comment.