Skip to content

Commit

Permalink
Datasource dropdown in Explore view
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 6, 2016
1 parent 65e72d0 commit 062f2b8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
6 changes: 6 additions & 0 deletions caravel/assets/javascripts/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,16 @@ function initExploreView() {
}
});
});

$("#viz_type").change(function () {
$("#query").submit();
});

$("#datasource_id").change(function () {
var url = $(this).find('option:selected').attr('url');
window.location = url;
});

var collapsed_fieldsets = get_collapsed_fieldsets();
for (var i = 0; i < collapsed_fieldsets.length; i++) {
toggle_fieldset($('legend:contains("' + collapsed_fieldsets[i] + '")'), false);
Expand Down
11 changes: 8 additions & 3 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,16 @@ def html(self):
def name(self):
return self.table_name

@property
def explore_url(self):
if self.default_endpoint:
return self.default_endpoint
else:
return "/caravel/explore/{self.type}/{self.id}/".format(self=self)

@property
def table_link(self):
url = "/caravel/explore/{self.type}/{self.id}/".format(self=self)
return '<a href="{url}">{self.table_name}</a>'.format(
url=url, self=self)
return '<a href="{self.explore_url}">{self.table_name}</a>'.format(self=self)

@property
def metrics_combo(self):
Expand Down
20 changes: 9 additions & 11 deletions caravel/templates/caravel/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@
<div class="datasource container-fluid">
<form id="query" method="GET" style="display: none;">
<div class="header">
<span class="btn btn-default notbtn" title="datasource" data-toggle="tooltip">
{{ datasource.full_name }}
{% if datasource.description %}
<a data-toggle="modal" data-target="#sourceinfo_modal">
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="bottom" title="{{ datasource.description }}"></i>
</a>
{% endif %}
<a class="" href="/{{ datasource.baselink }}/edit/{{ datasource.id }}" data-toggle="tooltip" title="Edit">
<i class="fa fa-edit"></i>
</a>
<span title="Data Source" data-toggle="tooltip">
<select id="datasource_id" class="select2">
{% for ds in datasources %}
<option url="{{ ds.explore_url }}" {{ "selected" if ds.id == datasource.id }} value="{{ ds.id }}">{{ ds.full_name }}<i class="fa fa-info"></i></option>
{% endfor %}
</select>
</span>
<span title="Visualization Type" data-toggle="tooltip">
{{ form.get_field("viz_type")(class_="select2") }}
</span>
<span>{{ form.get_field("viz_type")(class_="select2") }}</span>
{% if slice %}
<span class="btn btn-default notbtn" title="Slice" data-toggle="tooltip" data-placement="bottom">
<span class="favstar" class_name="Slice" obj_id="{{ slice.id }}"></span>
Expand Down
13 changes: 8 additions & 5 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,14 @@ class Caravel(BaseView):
def explore(self, datasource_type, datasource_id):
datasource_class = models.SqlaTable \
if datasource_type == "table" else models.DruidDatasource
datasource = (
datasources = (
db.session
.query(datasource_class)
.filter_by(id=datasource_id)
.first()
.all()
)
datasources = sorted(datasources, key=lambda ds: ds.full_name)
datasource = [ds for ds in datasources if int(datasource_id) == ds.id]
datasource = datasource[0] if datasource else None
slice_id = request.args.get("slice_id")
slc = None
if slice_id:
Expand All @@ -450,7 +452,7 @@ def explore(self, datasource_type, datasource_id):
.first()
)
if not datasource:
flash("The datasource seem to have been deleted", "alert")
flash("The datasource seems to have been deleted", "alert")

all_datasource_access = self.appbuilder.sm.has_access(
'all_datasource_access', 'all_datasource_access')
Expand Down Expand Up @@ -503,7 +505,8 @@ def explore(self, datasource_type, datasource_id):
else:
template = "caravel/explore.html"

resp = self.render_template(template, viz=obj, slice=slc)
resp = self.render_template(
template, viz=obj, slice=slc, datasources=datasources)
try:
pass
except Exception as e:
Expand Down
3 changes: 3 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ attempt it: ::
C:\> set INCLUDE=C:\OpenSSL-1.0.1f-64bit\include;%INCLUDE%
C:\> pip install cryptography

# You may also have to create C:\Temp
C:\> md C:\Temp


Caravel installation and initialization
---------------------------------------
Expand Down

0 comments on commit 062f2b8

Please sign in to comment.