diff --git a/TODO.md b/TODO.md index 23df1bc2ca..6cbc7e6d18 100644 --- a/TODO.md +++ b/TODO.md @@ -11,11 +11,11 @@ List of TODO items for Panoramix the same way that you can groupby for series, you could chart by. The form fieldset would be common and use a single field to "grid by", a limit number of chart as an N * N grid size. * **Free form SQL editor:** Having an Airpal-like easy SQL editor -* **Advanced dashboard configuration:** define which slices are immune to which filters, how often widgets should refresh, +* **Advanced dashboard configuration:** define which slices are immune to which filters, how often widgets should refresh, maybe this should start as a json blob... * **Getting proper JS testing:** unit tests on the Python side are pretty solid, but now we need a test suite for the JS part of the site, testing all the ajax-type calls -* **Annotations layers:** allow for people to maintain data annotations, +* **Annotations layers:** allow for people to maintain data annotations, attached to a layer and time range. These layers can be added on top of some visualizations as annotations. An example of a layer might be "holidays" or "site outages", ... * **Worth doing? User defined groups:** People could define mappings in the UI of say "Countries I follow" and apply it to different datasets. For now, this is done by writing CASE-WHEN-type expression which is probably good enough. diff --git a/panoramix/templates/panoramix/sql.html b/panoramix/templates/panoramix/sql.html new file mode 100644 index 0000000000..e378d107d9 --- /dev/null +++ b/panoramix/templates/panoramix/sql.html @@ -0,0 +1,105 @@ +{% extends "panoramix/base.html" %} + +{% block head_css %} + {{super()}} + + + +{% endblock %} + +{% block content %} +

db: [{{ db }}]

+
+
+ +
+
+ +
+
+
+ + + +
+
+
+ +
+
+
+
+{% endblock %} + +{% block tail_js %} +{{ super() }} + + + + +{% endblock %} diff --git a/panoramix/views.py b/panoramix/views.py index 95f64db704..a3536465a2 100644 --- a/panoramix/views.py +++ b/panoramix/views.py @@ -552,6 +552,38 @@ class Panoramix(BaseView): templates=templates, pos_dict=pos_dict) + @has_access + @expose("/sql//") + @utils.log_this + def sql(self, database_id): + mydb = db.session.query(models.Database).filter_by(id=database_id).first() + return self.render_template( + "panoramix/sql.html", + database_id=database_id, + db=mydb) + + @has_access + @expose("/runsql/", methods=['POST', 'GET']) + @utils.log_this + def runsql(self): + session = db.session() + data = json.loads(request.form.get('data')) + sql = data.get('sql') + database_id = data.get('database_id') + mydb = session.query(models.Database).filter_by(id=database_id).first() + content = "" + if mydb: + print("SUPER!") + from pandas import read_sql_query + eng = mydb.get_sqla_engine() + df = read_sql_query(sql=sql, con=eng) + content = df.to_html( + classes="dataframe table table-striped table-bordered table-condensed") + else: + print("ELSE") + session.commit() + return content + @has_access @expose("/refresh_datasources/") def refresh_datasources(self):