Skip to content

Commit

Permalink
Fixing bug when datasource has been deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 3, 2016
1 parent ef45c20 commit aec3c0b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
17 changes: 11 additions & 6 deletions caravel/assets/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ var Dashboard = function (dashboardData) {
var sliceObjects = [],
dash = this;
dashboard.slices.forEach(function (data) {
var slice = px.Slice(data, dash);
$("#slice_" + data.slice_id).find('a.refresh').click(function () {
slice.render(true);
});
sliceObjects.push(slice);
slice.render();
if (data.error) {
var html = '<div class="alert alert-danger">' + data.error + '</div>';
$("#slice_" + data.slice_id).find('.token').html(html);
} else {
var slice = px.Slice(data, dash);
$("#slice_" + data.slice_id).find('a.refresh').click(function () {
slice.render(true);
});
sliceObjects.push(slice);
slice.render();
}
});
this.slices = sliceObjects;
},
Expand Down
14 changes: 9 additions & 5 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,8 @@ def datasource_edit_url(self):
@utils.memoized
def viz(self):
d = json.loads(self.params)
viz = viz_types[self.viz_type](
self.datasource,
form_data=d)
return viz
viz_class = viz_types[self.viz_type]
return viz_class(self.datasource, form_data=d)

@property
def description_markeddown(self):
Expand All @@ -166,7 +164,13 @@ def datasource_id(self):

@property
def data(self):
d = self.viz.data
d = {}
self.token = ''
try:
d = self.viz.data
self.token = d.get('token')
except Exception as e:
d['error'] = str(e)
d['slice_id'] = self.id
return d

Expand Down
10 changes: 5 additions & 5 deletions caravel/templates/caravel/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ <h2>
<ul>
{% for slice in dashboard.slices %}
{% set pos = pos_dict.get(slice.id, {}) %}
{% set viz = slice.viz %}


<li
id="slice_{{ slice.id }}"
slice_id="{{ slice.id }}"
class="widget {{ slice.viz.viz_type }}"
class="widget {{ slice.viz_type }}"
data-row="{{ pos.row or 1 }}"
data-col="{{ pos.col or loop.index }}"
data-sizex="{{ pos.size_x or 4 }}"
data-sizey="{{ pos.size_y or 4 }}">

<div class="chart-header">
<div class="row">
<div class="col-md-12 text-center header">
Expand Down Expand Up @@ -124,9 +124,9 @@ <h2>
</div>
<div class="row chart-container">
<input type="hidden" slice_id="{{ slice.id }}" value="false">
<div id="{{ viz.token }}" class="token col-md-12">
<div id="{{ slice.token }}" class="token col-md-12">
<img src="{{ url_for("static", filename="assets/images/loading.gif") }}" class="loading" alt="loading">
<div class="slice_container" id="{{ viz.token }}_con"></div>
<div class="slice_container" id="{{ slice.token }}_con"></div>
</div>
</div>
</li>
Expand Down
1 change: 0 additions & 1 deletion caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ def dashboard(self, dashboard_id):
qry = qry.filter_by(slug=dashboard_id)

templates = session.query(models.CssTemplate).all()

dash = qry.first()

# Hack to log the dashboard_id properly, even when getting a slug
Expand Down
2 changes: 2 additions & 0 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class BaseViz(object):

def __init__(self, datasource, form_data, slice=None):
self.orig_form_data = form_data
if not datasource:
raise Exception("Viz is missing a datasource")
self.datasource = datasource
self.request = request
self.viz_type = form_data.get("viz_type")
Expand Down

0 comments on commit aec3c0b

Please sign in to comment.