Save AS and Overwrite
This commit is contained in:
parent
618e117374
commit
b9d7253a48
|
|
@ -277,6 +277,8 @@ class FormFactory(object):
|
|||
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 ['']
|
||||
|
|
|
|||
|
|
@ -80,20 +80,21 @@ class Slice(Model, AuditMixinNullable):
|
|||
|
||||
@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):
|
||||
|
|
@ -250,7 +251,7 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
|
|||
|
||||
@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
|
||||
|
|
@ -694,9 +695,7 @@ class Datasource(Model, AuditMixinNullable, Queryable):
|
|||
|
||||
@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):
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,14 +77,21 @@
|
|||
<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 }}">
|
||||
|
|
@ -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 %}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -302,7 +304,7 @@ class Panoramix(BaseView):
|
|||
"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
|
||||
|
|
@ -326,19 +328,29 @@ class Panoramix(BaseView):
|
|||
|
||||
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:
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class BaseViz(object):
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue