From 5435f53702160660e52f38d5b62dcc833b5fc664 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 18 Dec 2015 15:08:09 -0800 Subject: [PATCH 1/2] Passing a controller object to widget --- panoramix/static/panoramix.js | 15 ++++++++++++--- panoramix/static/widgets/viz_table.js | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index a408514017f20..c4f0ca016cb3d 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -25,7 +25,8 @@ var px = (function() { dttm += 10; $('#timer').text(Math.round(dttm/10)/100 + " sec"); } - var done = function (data) { + var controler = { + done: function (data) { clearInterval(timer); token.find("img.loading").hide(); if(data !== undefined) @@ -33,11 +34,19 @@ var px = (function() { $('#timer').removeClass('btn-warning'); $('span.query').removeClass('disabled'); $('#timer').addClass('btn-success'); - } + }, + error: function (data) { + clearInterval(timer); + token.find("img.loading").hide(); + $('#timer').removeClass('btn-warning'); + $('span.query').removeClass('disabled'); + $('#timer').addClass('btn-error'); + } + }; widget = { render: function() { timer = setInterval(stopwatch, 10); - user_defined_widget.render(done); + user_defined_widget.render(controler); }, resize: function() { user_defined_widget.resize(); diff --git a/panoramix/static/widgets/viz_table.js b/panoramix/static/widgets/viz_table.js index 5f628a28d2fd0..024addd2ca0a0 100644 --- a/panoramix/static/widgets/viz_table.js +++ b/panoramix/static/widgets/viz_table.js @@ -55,7 +55,7 @@ px.registerWidget('table', function(data_attribute) { var err = '
' + xhr.responseText + '
'; token.html(err); token.show(); - done(); + ctrl.done(); }); } From c1080638ae5c94b7a6e1f213f0125a4daa35a059 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Fri, 18 Dec 2015 15:21:10 -0800 Subject: [PATCH 2/2] Passing a ctrl to the js --- panoramix/models.py | 4 ++-- panoramix/static/panoramix.js | 6 ++++-- panoramix/static/widgets/viz_bignumber.js | 8 +++----- panoramix/static/widgets/viz_directed_force.js | 8 +++----- panoramix/static/widgets/viz_markup.js | 4 ++-- panoramix/static/widgets/viz_nvd3.js | 8 +++----- panoramix/static/widgets/viz_pivot_table.js | 8 +++----- panoramix/static/widgets/viz_sankey.js | 8 +++----- panoramix/static/widgets/viz_sunburst.js | 7 +++---- panoramix/static/widgets/viz_table.js | 9 +++------ panoramix/static/widgets/viz_wordcloud.js | 8 +++----- panoramix/static/widgets/viz_world_map.js | 8 +++----- 12 files changed, 35 insertions(+), 51 deletions(-) diff --git a/panoramix/models.py b/panoramix/models.py index a8eb617f260a1..c8814c9e4a13b 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -433,14 +433,14 @@ def query( select_exprs.append(s) metrics_exprs = [] - if is_timeseries and groupby: + if is_timeseries: select_exprs += [timestamp] groupby_exprs += [timestamp] select_exprs += metrics_exprs qry = select(select_exprs) from_clause = table(self.table_name) - if groupby: + if not columns: qry = qry.group_by(*groupby_exprs) time_filter = [ diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index c4f0ca016cb3d..7099d3d9db5a0 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -35,12 +35,14 @@ var px = (function() { $('span.query').removeClass('disabled'); $('#timer').addClass('btn-success'); }, - error: function (data) { + error: function (msg) { clearInterval(timer); token.find("img.loading").hide(); + var err = '
' + msg + '
'; + token.html(err); $('#timer').removeClass('btn-warning'); $('span.query').removeClass('disabled'); - $('#timer').addClass('btn-error'); + $('#timer').addClass('btn-danger'); } }; widget = { diff --git a/panoramix/static/widgets/viz_bignumber.js b/panoramix/static/widgets/viz_bignumber.js index ce271a4b28d51..89ec925535d1f 100644 --- a/panoramix/static/widgets/viz_bignumber.js +++ b/panoramix/static/widgets/viz_bignumber.js @@ -4,14 +4,12 @@ px.registerWidget('big_number', function(data_attribute) { var json_callback = data_attribute['json_endpoint']; var div = d3.select('#' + token_name); - function render(done) { + function render(ctrl) { d3.json(json_callback, function(error, payload){ //Define the percentage bounds that define color from red to green div.html(""); if (error != null){ - var err = '
' + error.responseText + '
'; - div.html(err); - done(payload); + ctrl.error(error.responseText); return ''; } json = payload.data; @@ -137,7 +135,7 @@ px.registerWidget('big_number', function(data_attribute) { div.select('g.digits').transition().duration(500).attr('opacity', 1); div.select('g.axis').transition().duration(500).attr('opacity', 0); }); - done(payload); + ctrl.done(payload); }); }; diff --git a/panoramix/static/widgets/viz_directed_force.js b/panoramix/static/widgets/viz_directed_force.js index 33bb53a1194d1..d3368799f3572 100644 --- a/panoramix/static/widgets/viz_directed_force.js +++ b/panoramix/static/widgets/viz_directed_force.js @@ -16,13 +16,11 @@ function viz_directed_force(data_attribute) { if (charge === undefined){ charge = -500; } - var render = function(done) { + var render = function(ctrl) { d3.json(data_attribute.json_endpoint, function(error, json) { if (error != null){ - var err = '
' + error.responseText + '
'; - token.html(err); - done(); + ctrl.error(error.responseText); return ''; } links = json.data; @@ -152,7 +150,7 @@ function viz_directed_force(data_attribute) { .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; }); } - done(json); + ctrl.done(json); }); } return { diff --git a/panoramix/static/widgets/viz_markup.js b/panoramix/static/widgets/viz_markup.js index be6bef7e7b9e8..2936d3fa50f9b 100644 --- a/panoramix/static/widgets/viz_markup.js +++ b/panoramix/static/widgets/viz_markup.js @@ -1,8 +1,8 @@ px.registerWidget('markup', function(data_attribute) { - function refresh(done) { + function refresh(ctrl) { $('#code').attr('rows', '15') - done(); + ctrl.done(); } return { render: refresh, diff --git a/panoramix/static/widgets/viz_nvd3.js b/panoramix/static/widgets/viz_nvd3.js index 5211afbe7a8fd..7c7ac772a2f91 100644 --- a/panoramix/static/widgets/viz_nvd3.js +++ b/panoramix/static/widgets/viz_nvd3.js @@ -29,7 +29,7 @@ function viz_nvd3(data_attribute) { var jtoken = $('#' + token_name); var chart_div = $('#' + token_name).find("div.chart"); - var refresh = function(done) { + var refresh = function(ctrl) { chart_div.hide(); $.getJSON(json_callback, function(payload) { var data = payload.data; @@ -161,13 +161,11 @@ function viz_nvd3(data_attribute) { return chart; }); chart_div.show(); - done(data); + ctrl.done(data); }) .fail(function(xhr) { - var err = '
' + xhr.responseText + '
'; - done(data); chart_div.show(); - chart_div.html(err); + ctrl.error(xhr.responseText); }); }; var resize = function() { diff --git a/panoramix/static/widgets/viz_pivot_table.js b/panoramix/static/widgets/viz_pivot_table.js index 42382daad0910..b5051c2fe431a 100644 --- a/panoramix/static/widgets/viz_pivot_table.js +++ b/panoramix/static/widgets/viz_pivot_table.js @@ -3,7 +3,7 @@ px.registerWidget('pivot_table', function(data_attribute) { var token = $('#' + token_name); var form_data = data_attribute.form_data; - function refresh(done) { + function refresh(ctrl) { $.getJSON(data_attribute.json_endpoint, function(json){ token.html(json.data); if (form_data.groupby.length == 1){ @@ -14,12 +14,10 @@ px.registerWidget('pivot_table', function(data_attribute) { table.column('-1').order( 'desc' ).draw(); } token.show(); - done(json); + ctrl.done(json); }).fail(function(xhr){ - var err = '
' + xhr.responseText + '
'; - token.html(err); token.show(); - done(); + ctrl.error(xhr.responseText); }); } return { diff --git a/panoramix/static/widgets/viz_sankey.js b/panoramix/static/widgets/viz_sankey.js index 06ae414012863..62c4739c16bd9 100644 --- a/panoramix/static/widgets/viz_sankey.js +++ b/panoramix/static/widgets/viz_sankey.js @@ -5,7 +5,7 @@ function viz_sankey(data_attribute) { var width = xy.width; var height = xy.height - 25; - var render = function(done) { + var render = function(ctrl) { var margin = {top: 1, right: 1, bottom: 6, left: 1}; width = width - margin.left - margin.right; height = height - margin.top - margin.bottom; @@ -28,9 +28,7 @@ function viz_sankey(data_attribute) { d3.json(data_attribute.json_endpoint, function(error, json) { if (error != null){ - var err = '
' + error.responseText + '
'; - token.html(err); - done(); + ctrl.error(error.responseText); return ''; } links = json.data; @@ -98,7 +96,7 @@ function viz_sankey(data_attribute) { link.attr("d", path); } token.select("img.loading").remove(); - done(json); + ctrl.done(json); }); } return { diff --git a/panoramix/static/widgets/viz_sunburst.js b/panoramix/static/widgets/viz_sunburst.js index 9aef8335d5c92..dcd654af2dc3d 100644 --- a/panoramix/static/widgets/viz_sunburst.js +++ b/panoramix/static/widgets/viz_sunburst.js @@ -4,7 +4,7 @@ Modified from http://bl.ocks.org/kerryrodden/7090426 function viz_sunburst(data_attribute) { var token = d3.select('#' + data_attribute.token); - var render = function(done) { + var render = function(ctrl) { // Breadcrumb dimensions: width, height, spacing, width of tip/tail. var b = { w: 100, h: 30, s: 3, t: 10 @@ -42,13 +42,12 @@ function viz_sunburst(data_attribute) { d3.json(data_attribute.json_endpoint, function(error, json){ if (error != null){ - var err = '
' + error.responseText + '
'; - token.html(err); + ctrl.error(error.responseText); return ''; } var tree = buildHierarchy(json.data); createVisualization(tree); - done(json); + ctrl.done(json); }); // Main function to draw and set up the visualization, once we have the data. diff --git a/panoramix/static/widgets/viz_table.js b/panoramix/static/widgets/viz_table.js index 024addd2ca0a0..17e923233775a 100644 --- a/panoramix/static/widgets/viz_table.js +++ b/panoramix/static/widgets/viz_table.js @@ -3,7 +3,7 @@ px.registerWidget('table', function(data_attribute) { var token_name = data_attribute['token']; var token = $('#' + token_name); - function refresh(done) { + function refresh(ctrl) { $.getJSON(data_attribute.json_endpoint, function(json){ var data = json.data; var metrics = json.form_data.metrics; @@ -50,12 +50,9 @@ px.registerWidget('table', function(data_attribute) { var main_metric = data_attribute.form_data.metrics[0]; datatable.column(data.columns.indexOf(main_metric)).order( 'desc' ).draw(); } - done(json); + ctrl.done(json); }).fail(function(xhr){ - var err = '
' + xhr.responseText + '
'; - token.html(err); - token.show(); - ctrl.done(); + ctrl.error(xhr.responseText); }); } diff --git a/panoramix/static/widgets/viz_wordcloud.js b/panoramix/static/widgets/viz_wordcloud.js index b2b7d4e7bf1ac..fe3d991513d2b 100644 --- a/panoramix/static/widgets/viz_wordcloud.js +++ b/panoramix/static/widgets/viz_wordcloud.js @@ -4,12 +4,10 @@ px.registerWidget('word_cloud', function(data_attribute) { var json_callback = data_attribute['json_endpoint']; var token = d3.select('#' + token_name); - function refresh(done) { + function refresh(ctrl) { d3.json(json_callback, function(error, json) { if (error != null){ - var err = '
' + error.responseText + '
'; - token.html(err); - done(); + ctrl.error(error.responseText); return ''; } var data = json.data; @@ -63,7 +61,7 @@ px.registerWidget('word_cloud', function(data_attribute) { }) .text(function(d) { return d.text; }); } - done(data); + ctrl.done(data); }); } diff --git a/panoramix/static/widgets/viz_world_map.js b/panoramix/static/widgets/viz_world_map.js index c57c372f61225..6e4da074e369f 100644 --- a/panoramix/static/widgets/viz_world_map.js +++ b/panoramix/static/widgets/viz_world_map.js @@ -4,7 +4,7 @@ function viz_world_map(data_attribute) { var token = d3.select('#' + data_attribute.token); - var render = function(done) { + var render = function(ctrl) { // Breadcrumb dimensions: width, height, spacing, width of tip/tail. var div = token; var xy = div.node().getBoundingClientRect(); @@ -14,10 +14,8 @@ function viz_world_map(data_attribute) { d3.json(data_attribute.json_endpoint, function(error, json){ if (error != null){ - var err = '
' + error.responseText + '
'; - token.html(err); + ctrl.error(error.responseText); return ''; - done(); } var ext = d3.extent(json.data, function(d){return d.m1}); var extRadius = d3.extent(json.data, function(d){return d.m2}); @@ -81,7 +79,7 @@ function viz_world_map(data_attribute) { map.bubbles(json.data); token.selectAll("circle.datamaps-bubble").style('fill', '#005a63'); } - done(json); + ctrl.done(json); }); }