Skip to content

Commit

Permalink
Save and embed
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 12, 2015
1 parent 5f20a08 commit e755854
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 31 deletions.
19 changes: 17 additions & 2 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ class Slice(Model, AuditMixin):
"""A slice is essentially a report or a view on data"""
__tablename__ = 'slices'
id = Column(Integer, primary_key=True)
params = Column(JSONEncodedDict)
datasource = Column(String(250))
slice_name = Column(String(250))
datasource_id = Column(Integer)
datasource_type = Column(String(200))
datasource_name = Column(String(2000))
viz_type = Column(String(250))
params = Column(Text)

@property
def slice_link(self):
d = json.loads(self.params)
kwargs = "&".join([k + '=' + v for k, v in d.iteritems()])
url = (
"/panoramix/{self.datasource_type}/"
"{self.datasource_id}/?{kwargs}").format(**locals())
return '<a href="{url}">{self.slice_name}</a>'.format(**locals())


class Queryable(object):
Expand Down Expand Up @@ -72,6 +84,8 @@ def get_table(self, table_name):


class Table(Model, Queryable, AuditMixin):
type = "table"

__tablename__ = 'tables'
id = Column(Integer, primary_key=True)
table_name = Column(String(255), unique=True)
Expand Down Expand Up @@ -446,6 +460,7 @@ def refresh_datasources(self):


class Datasource(Model, AuditMixin, Queryable):
type = "datasource"

baselink = "datasourcemodelview"

Expand Down
10 changes: 9 additions & 1 deletion panoramix/templates/panoramix/datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ <h4>Filters</h4>
<button type="button" class="btn btn-default" id="bookmark">Bookmark</button>
<hr style="margin-bottom: 0px;">
<img src="{{ url_for("static", filename="tux_panoramix.png") }}" width=250>
<input type="hidden" id="slice_name" name="slice_name" value="TEST">
<input type="hidden" name="datasource_name" value="{{ datasource.name }}">
<input type="hidden" name="datasource_id" value="{{ datasource.id }}">
<input type="hidden" name="datasource_type" value="{{ datasource.type }}">
</form><br>
</div>

Expand Down Expand Up @@ -191,7 +195,11 @@ <h4 class="modal-title" id="myModalLabel">Query</h4>
});
}
$("#plus").click(add_filter);
$("#bookmark").click(function () {alert("Not implemented yet...");})
$("#bookmark").click(function () {
var slice_name = prompt("Name your slice!");
$("#slice_name").val(slice_name);
$.get( "/panoramix/save/", $("#query").serialize() );
})
add_filter();
$("#druidify").click(function () {
var i = 1;
Expand Down
5 changes: 5 additions & 0 deletions panoramix/templates/panoramix/viz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if standalone %}
{% extends 'panoramix/viz_standalone.html' %}
{% else %}
{% extends 'panoramix/datasource.html' %}
{% endif %}
52 changes: 26 additions & 26 deletions panoramix/templates/panoramix/viz_highcharts.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{% extends "panoramix/datasource.html" %}
{% extends "panoramix/viz.html" %}
{% block viz %}
{{ super() }}
<div id="chart"></div>
{% endblock %}

{% block tail %}
{{ super() }}
{% if viz.stockchart %}
<script src="{{ url_for("static", filename="highstock.js") }}"></script>
{% else %}
<script src="{{ url_for("static", filename="highcharts.js") }}"></script>
{% endif %}
<script src="{{ url_for("static", filename="highcharts-more.js") }}"></script>
<script>
$( document ).ready(function() {
Highcharts.setOptions({
colors: [
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
],
global: {
useUTC: false
},
});
$("#viz_type").click(function(){
$("#queryform").submit();
})
{% if chart_js %}
{{ chart_js|safe }}
{{ super() }}
{% if viz.stockchart %}
<script src="{{ url_for("static", filename="highstock.js") }}"></script>
{% else %}
<script src="{{ url_for("static", filename="highcharts.js") }}"></script>
{% endif %}
});
</script>
<script src="{{ url_for("static", filename="highcharts-more.js") }}"></script>
<script>
$( document ).ready(function() {
Highcharts.setOptions({
colors: [
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
],
global: {
useUTC: false
},
});
$("#viz_type").click(function(){
$("#queryform").submit();
})
{% if chart_js %}
{{ chart_js|safe }}
{% endif %}
});
</script>
{% endblock %}
9 changes: 9 additions & 0 deletions panoramix/templates/panoramix/viz_standalone.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "appbuilder/baselayout.html" %}
{% block body %}
{% block viz %}
{% endblock %}
{% endblock %}
{% block tail %}
{{ super() }}
{% endblock %}

2 changes: 1 addition & 1 deletion panoramix/templates/panoramix/viz_table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "panoramix/datasource.html" %}
{% extends "panoramix/viz.html" %}

{% block head_css %}
{{super()}}
Expand Down
31 changes: 30 additions & 1 deletion panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ class ClusterModelView(ModelView, DeleteMixin):
category_icon='fa-cogs',)


class SliceModelView(ModelView, DeleteMixin):
datamodel = SQLAInterface(models.Slice)
list_columns = ['slice_link', 'viz_type', 'created_by']

appbuilder.add_view(
SliceModelView,
"Slices",
icon="fa-bar-chart",
category="",
category_icon='',)


class DatabaseView(ModelView, DeleteMixin):
datamodel = SQLAInterface(models.Database)
list_columns = ['database_name']
Expand Down Expand Up @@ -176,7 +188,6 @@ class Panoramix(BaseView):
@has_access
@expose("/table/<table_id>/")
def table(self, table_id):

table = (
db.session
.query(models.Table)
Expand Down Expand Up @@ -226,6 +237,24 @@ def datasource(self, datasource_name):

return obj.check_and_render()

@has_access
@expose("/save/")
def save(self):
session = db.session()
obj = models.Slice(
params=json.dumps(request.args.to_dict()),
viz_type=request.args.get('viz_type'),
datasource_name=request.args.get('datasource_name'),
datasource_id=request.args.get('datasource_id'),
datasource_type=request.args.get('datasource_type'),
slice_name=request.args.get('slice_name', 'junk'),
)
session.add(obj)
session.commit()
session.close()

return "super!"

@has_access
@expose("/refresh_datasources/")
def refresh_datasources(self):
Expand Down
1 change: 1 addition & 0 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def render(self, *args, **kwargs):
return self.view.render_template(
self.template, form=form, viz=self, datasource=self.datasource,
results=self.results,
standalone=request.args.get('standalone') == 'true',
*args, **kwargs)


Expand Down

0 comments on commit e755854

Please sign in to comment.