Skip to content

Commit

Permalink
Allowing to make certain widgets immune to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Feb 29, 2016
1 parent 9f809e9 commit bd06f99
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
49 changes: 23 additions & 26 deletions panoramix/assets/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,49 @@ require('brace/theme/crimson_editor');

require('select2');
require('../node_modules/gridster/dist/jquery.gridster.min.js');
require('../node_modules/gridster/dist/jquery.gridster.min.js');

var dashboard;

var Dashboard = function(id){
var dash = {
slices: [],
filters: {},
id: id,
addFilter: function(slice_id, filters) {
var Dashboard = function(obj){
obj['slices'] = [];
obj['filters'] = {};
obj['addFilter'] = function(slice_id, filters) {
this.filters[slice_id] = filters;
this.refreshExcept(slice_id);
},
readFilters: function() {
};
obj['readFilters'] = function() {
// Returns a list of human readable active filters
return JSON.stringify(this.filters, null, 4);
},
refreshExcept: function(slice_id) {
this.slices.forEach(function(slice){
if(slice.data.slice_id != slice_id){
slice.render();
}
});
},
clearFilter: function(slice_id) {
};
obj['refreshExcept'] = function(slice_id) {
this.slices.forEach(function(slice){
if(slice.data.slice_id != slice_id && obj.metadata.filter_immune_slices.indexOf(slice.data.slice_id) == -1){
slice.render();
}
});
};
obj['clearFilter'] = function(slice_id) {
delete this.filters[slice_id];
this.refreshExcept(slice_id);
},
getSlice: function(slice_id) {
};
obj['getSlice'] = function(slice_id) {
for(var i=0; i<this.slices.length; i++){
if (this.slices[i].data.slice_id == slice_id)
return this.slices[i];
}
}
}

$('.dashboard li.widget').each(function() {
var data = $(this).data('slice');
var slice = px.Slice(data, dash);
var slice = px.Slice(data, obj);
$(this).find('a.refresh').click(function(){
slice.render();
});
dash.slices.push(slice);
obj.slices.push(slice);
slice.render();
});
dashboard = dash;
return dash;
dashboard = obj;
return obj;
}

function initDashboardView() {
Expand Down Expand Up @@ -151,5 +148,5 @@ function initDashboardView() {

$(document).ready(function() {
initDashboardView();
var dashboard = Dashboard($('#dashboard_id').val());
var dashboard = Dashboard($('.dashboard').data('dashboard'));
});
9 changes: 9 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def css_files(self):
l += o.css_files
return list(set(l))

@property
def json_data(self):
return json.dumps({
'id': self.id,
'metadata': self.metadata_dejson,
'dashboard_title': self.dashboard_title,
'slug': self.slug,
})


class Queryable(object):
@property
Expand Down
2 changes: 1 addition & 1 deletion panoramix/templates/panoramix/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% endblock %}

{% block body %}
<div class="dashboard">
<div class="dashboard container-fluid" data-dashboard="{{ dashboard.json_data }}">

<!-- Modal -->
<div class="modal fade" id="css_modal" tabindex="-1" role="dialog">
Expand Down
8 changes: 5 additions & 3 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,11 @@ def save_dash(self, dashboard_id):
dash = session.query(Dash).filter_by(id=dashboard_id).first()
dash.slices = [o for o in dash.slices if o.id in slice_ids]
dash.position_json = json.dumps(data['positions'], indent=4)
dash.json_metadata = json.dumps({
'expanded_slices': data['expanded_slices'],
}, indent=4)
md = dash.metadata_dejson
if 'filter_immune_slices' not in md:
md['filter_immune_slices'] = []
md['expanded_slices'] = data['expanded_slices']
dash.json_metadata = json.dumps(md, indent=4)
dash.css = data['css']
session.merge(dash)
session.commit()
Expand Down

0 comments on commit bd06f99

Please sign in to comment.