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

Refactor #158

Merged
merged 3 commits into from
Mar 2, 2016
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
110 changes: 73 additions & 37 deletions panoramix/assets/javascripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,79 @@ require('select2');
require('../node_modules/gridster/dist/jquery.gridster.min.js');


var Dashboard = function (dashboardData) {
var Dashboard = function(dashboardData) {
var dashboard = $.extend(dashboardData, {
filters: {},
init: function () {
init: function() {
this.initDashboardView();
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();
});
sliceObjects.push(slice);
dashboard.slices.forEach(function(data) {
var slice = px.Slice(data, dash);
$("#slice_" + data.slice_id).find('a.refresh').click(function() {
slice.render();
});
this.slices = sliceObjects;
sliceObjects.push(slice);
slice.render();
});
this.slices = sliceObjects;
},
addFilter: function (slice_id, filters) {
this.filters[slice_id] = filters;
setFilter: function(slice_id, col, vals) {
console.log([slice_id, col, vals]);
this.addFilter(slice_id, col, vals, false);
},
addFilter: function(slice_id, col, vals, merge) {
if (merge === undefined) {
merge = true;
}
if (!(slice_id in this.filters)) {
this.filters[slice_id] = {};
}
if (!(col in this.filters[slice_id]) || !merge) {
this.filters[slice_id][col] = vals;
} else {
this.filters[slice_id][col] = d3.merge([this.filters[slice_id][col], vals]);
}
this.refreshExcept(slice_id);
},
readFilters: function () {
readFilters: function() {
// Returns a list of human readable active filters
return JSON.stringify(this.filters, null, 4);
},
refreshExcept: function (slice_id) {
refreshExcept: function(slice_id) {
var immune = this.metadata.filter_immune_slices;
this.slices.forEach(function (slice) {
if(slice.data.slice_id !== slice_id && immune.indexOf(slice.data.slice_id) === -1) {
this.slices.forEach(function(slice) {
if (slice.data.slice_id !== slice_id && immune.indexOf(slice.data.slice_id) === -1) {
slice.render();
}
});
},
clearFilter: function (slice_id) {
clearFilters: function(slice_id) {
delete this.filters[slice_id];
this.refreshExcept(slice_id);
},
getSlice: function (slice_id) {
this.slices.forEach(function (slice, i) {
removeFilter: function(slice_id, col, vals) {
if (slice_id in this.filters) {
if (col in this.filters[slice_id]) {
var a = [];
this.filters[slice_id][col].forEach(function(v) {
if (vals.indexOf(v) < 0) {
a.push(v);
}
});
this.filters[slice_id][col] = a;
}
}
this.refreshExcept(slice_id);
},
getSlice: function(slice_id) {
this.slices.forEach(function(slice, i) {
if (slice.slice_id === slice_id) {
return slice;
}
});
},
initDashboardView: function () {
initDashboardView: function() {
dashboard = this;
var gridster = $(".gridster ul").gridster({
widget_margins: [5, 5],
Expand All @@ -66,12 +94,12 @@ var Dashboard = function (dashboardData) {
},
resize: {
enabled: true,
stop: function (e, ui, element) {
stop: function(e, ui, element) {
var slice_data = $(element).data('slice');
dashboard.getSlice(slice_data.slice_id).resize();
}
},
serialize_params: function (_w, wgd) {
serialize_params: function(_w, wgd) {
return {
slice_id: $(_w).attr('slice_id'),
col: wgd.col,
Expand All @@ -82,12 +110,12 @@ var Dashboard = function (dashboardData) {
},
}).data('gridster');
$("div.gridster").css('visibility', 'visible');
$("#savedash").click(function () {
$("#savedash").click(function() {
var expanded_slices = {};
$.each($(".slice_info"), function (i, d) {
$.each($(".slice_info"), function(i, d) {
var widget = $(this).parents('.widget');
var slice_description = widget.find('.slice_description');
if(slice_description.is(":visible"))
if (slice_description.is(":visible"))
expanded_slices[$(d).attr('slice_id')] = true;
});
var data = {
Expand All @@ -98,9 +126,15 @@ var Dashboard = function (dashboardData) {
$.ajax({
type: "POST",
url: '/panoramix/save_dash/' + dashboard.id + '/',
data: {'data': JSON.stringify(data)},
success: function () {alert("Saved!");},
error: function () {alert("Error :(");},
data: {
'data': JSON.stringify(data)
},
success: function() {
alert("Saved!");
},
error: function() {
alert("Error :(");
},
});
});

Expand All @@ -114,34 +148,36 @@ var Dashboard = function (dashboardData) {
});
editor.getSession().setMode("ace/mode/css");

$(".select2").select2({dropdownAutoWidth : true});
$("#css_template").on("change", function () {
$(".select2").select2({
dropdownAutoWidth: true
});
$("#css_template").on("change", function() {
var css = $(this).find('option:selected').data('css');
editor.setValue(css);
$('#dash_css').val(css);
$("#user_style").html(css);
});
$('#filters').click( function () {
$('#filters').click(function() {
alert(dashboard.readFilters());
});
$("a.closeslice").click(function () {
$("a.closeslice").click(function() {
var li = $(this).parents("li");
gridster.remove_widget(li);
});
$(".slice_info").click(function () {
$(".slice_info").click(function() {
var widget = $(this).parents('.widget');
var slice_description = widget.find('.slice_description');
slice_description.slideToggle(500, function () {
slice_description.slideToggle(500, function() {
widget.find('.refresh').click();
});
});
$("table.slice_header").mouseover(function () {
$("table.slice_header").mouseover(function() {
$(this).find("td.icons nobr").show();
});
$("table.slice_header").mouseout(function () {
$("table.slice_header").mouseout(function() {
$(this).find("td.icons nobr").hide();
});
editor.on("change", function () {
editor.on("change", function() {
var css = editor.getValue();
$('#dash_css').val(css);
$("#user_style").html(css);
Expand All @@ -152,6 +188,6 @@ var Dashboard = function (dashboardData) {
return dashboard;
};

$(document).ready(function () {
$(document).ready(function() {
var dashboard = Dashboard($('.dashboard').data('dashboard'));
});
Loading