mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
Getting the SQL view back in a working state (#327)
This commit is contained in:
@@ -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');
|
||||
@@ -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() {
|
||||
@@ -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);
|
||||
|
||||
41
caravel/assets/stylesheets/sql.css
Normal file
41
caravel/assets/stylesheets/sql.css
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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">
|
||||
@@ -84,7 +35,7 @@
|
||||
</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>
|
||||
|
||||
@@ -719,14 +719,15 @@ class Caravel(BaseView):
|
||||
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>/")
|
||||
@@ -754,6 +755,11 @@ class Caravel(BaseView):
|
||||
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()
|
||||
@@ -772,7 +778,7 @@ class Caravel(BaseView):
|
||||
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">'
|
||||
|
||||
Reference in New Issue
Block a user