Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing for [Save AS] and [Overwrite] #69

Merged
merged 1 commit into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions panoramix/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ class QueryForm(OmgWtForm):
standalone = HiddenField()
async = HiddenField()
json = HiddenField()
slice_id = HiddenField()
slice_name = HiddenField()
previous_viz_type = HiddenField(default=viz.viz_type)

filter_cols = datasource.filterable_column_names or ['']
Expand Down
19 changes: 9 additions & 10 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ def viz(self):

@property
def datasource_id(self):
datasource = self.datasource
return datasource.id if datasource else None
return self.table_id or self.druid_datasource_id

@property
def slice_url(self):
try:
d = json.loads(self.params)
slice_params = json.loads(self.params)
except Exception as e:
d = {}
slice_params = {}
slice_params['slice_id'] = self.id
slice_params['slice_name'] = self.slice_name
from werkzeug.urls import Href
href = Href(
"/panoramix/datasource/{self.datasource_type}/"
"/panoramix/explore/{self.datasource_type}/"
"{self.datasource_id}/".format(self=self))
return href(d)
return href(slice_params)

@property
def edit_url(self):
Expand Down Expand Up @@ -250,7 +251,7 @@ def name(self):

@property
def table_link(self):
url = "/panoramix/datasource/{self.type}/{self.id}/".format(self=self)
url = "/panoramix/explore/{self.type}/{self.id}/".format(self=self)
return '<a href="{url}">{self.table_name}</a>'.format(**locals())

@property
Expand Down Expand Up @@ -694,9 +695,7 @@ def __repr__(self):

@property
def datasource_link(self):
url = (
"/panoramix/datasource/"
"{self.type}/{self.id}/").format(self=self)
url = "/panoramix/explore/{self.type}/{self.id}/".format(self=self)
return '<a href="{url}">{self.datasource_name}</a>'.format(**locals())

def get_metric_obj(self, metric_name):
Expand Down
11 changes: 9 additions & 2 deletions panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ function initializeDatasourceView() {
}

$("#plus").click(add_filter);
$("#save").click(function () {
$("#btn_save").click(function () {
var slice_name = prompt("Name your slice!");
if (slice_name != "" && slice_name != null) {
$("#slice_name").val(slice_name);
$("#action").val("save");
druidify();
}
})
});
$("#btn_overwrite").click(function () {
var flag = confirm("Overwrite slice [" + $("#slice_name").val() + "] !?");
if (flag) {
$("#action").val("overwrite");
druidify();
}
});
add_filter();
$(".druidify").click(druidify);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,21 @@ <h4>Filters</h4>
<i class="fa fa-bolt"></i>
Slice!
</button>
<button type="button" class="btn btn-default" id="save">
<i class="fa fa-save"></i>
Save as Slice
{% if viz.form_data.slice_id %}
<button type="button" class="btn btn-default" id="btn_overwrite">
<i class="fa fa-save"></i>
Overwrite
</button>
{% endif %}
<button type="button" class="btn btn-default" id="btn_save">
<i class="fa fa-plus-circle"></i>
Save as
</button>
<hr style="margin-bottom: 0px;">
<img src="{{ url_for("static", filename="img/tux_panoramix.png") }}" width=250>
<input type="hidden" id="slice_name" name="slice_name" value="TEST">
<input type="hidden" id="action" name="action" value="">
{{ form.slice_id() }}
{{ form.slice_name() }}
<input type="hidden" name="action" id="action" value="">
<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 }}">
Expand Down
2 changes: 1 addition & 1 deletion panoramix/templates/panoramix/viz.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% if viz.request.args.get("standalone") == "true" %}
{% extends 'panoramix/viz_standalone.html' %}
{% else %}
{% extends 'panoramix/datasource.html' %}
{% extends 'panoramix/explore.html' %}
{% endif %}


Expand Down
42 changes: 27 additions & 15 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ def ping():


class Panoramix(BaseView):

@has_access
@expose("/datasource/<datasource_type>/<datasource_id>/")
def datasource(self, datasource_type, datasource_id):
@expose("/explore/<datasource_type>/<datasource_id>/")
@expose("/datasource/<datasource_type>/<datasource_id>/") # Legacy url
def explore(self, datasource_type, datasource_id):
if datasource_type == "table":
datasource = (
db.session
Expand All @@ -302,7 +304,7 @@ def datasource(self, datasource_type, datasource_id):
"danger")
return redirect('/slicemodelview/list/')
action = request.args.get('action')
if action == 'save':
if action in ('save', 'overwrite'):
session = db.session()

# TODO use form processing form wtforms
Expand All @@ -326,19 +328,29 @@ def datasource(self, datasource_type, datasource_id):

slice_name = request.args.get('slice_name')

obj = models.Slice(
params=json.dumps(d, indent=4, sort_keys=True),
viz_type=request.args.get('viz_type'),
datasource_name=request.args.get('datasource_name'),
druid_datasource_id=druid_datasource_id,
table_id=table_id,
datasource_type=datasource_type,
slice_name=slice_name,
)
session.add(obj)
if action == "save":
slc = models.Slice()
msg = "Slice [{}] has been saved".format(slice_name)
elif action == "overwrite":
slc = (
session.query(models.Slice)
.filter_by(id=request.args.get("slice_id"))
.first()
)
msg = "Slice [{}] has been overwritten".format(slice_name)

slc.params = json.dumps(d, indent=4, sort_keys=True)
slc.datasource_name = request.args.get('datasource_name')
slc.viz_type = request.args.get('viz_type')
slc.druid_datasource_id = druid_datasource_id
slc.table_id = table_id
slc.datasource_type = datasource_type
slc.slice_name = slice_name

session.merge(slc)
session.commit()
flash("Slice <{}> has been added to the pie".format(slice_name), "info")
return redirect(obj.slice_url)
flash(msg, "info")
return redirect(slc.slice_url)


if not datasource:
Expand Down
2 changes: 1 addition & 1 deletion panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_url(self, **kwargs):
if d[key] == False:
del d[key]
href = Href(
'/panoramix/datasource/{self.datasource.type}/'
'/panoramix/explore/{self.datasource.type}/'
'{self.datasource.id}/'.format(**locals()))
return href(d)

Expand Down