From ad1ebaa6dadc843748d98375bdab420000970c58 Mon Sep 17 00:00:00 2001 From: Adrian Kuhn Date: Thu, 1 Oct 2015 17:51:52 -0700 Subject: [PATCH] Extract scripts into javascript file. --- panoramix/static/panoramix.js | 164 ++++++++++++++++++ panoramix/static/widgets/viz_nvd3.js | 2 + panoramix/templates/index.html | 3 +- panoramix/templates/panoramix/base.html | 9 +- panoramix/templates/panoramix/dashboard.html | 51 +----- panoramix/templates/panoramix/datasource.html | 123 +------------ 6 files changed, 177 insertions(+), 175 deletions(-) create mode 100644 panoramix/static/panoramix.js diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js new file mode 100644 index 0000000000000..a7a59271cf4fe --- /dev/null +++ b/panoramix/static/panoramix.js @@ -0,0 +1,164 @@ +function initializeDatasourceView() { + function getParam(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + $(".select2").select2(); + $("form").show(); + $('[data-toggle="tooltip"]').tooltip({container: 'body'}); + + function set_filters(){ + for (var i = 1; i < 10; i++){ + var eq = getParam("flt_eq_" + i); + if (eq != ''){ + add_filter(i); + } + } + } + set_filters(); + + function add_filter(i) { + cp = $("#flt0").clone(); + $(cp).appendTo("#filters"); + $(cp).show(); + if (i != undefined){ + $(cp).find("#flt_eq_0").val(getParam("flt_eq_" + i)); + $(cp).find("#flt_op_0").val(getParam("flt_op_" + i)); + $(cp).find("#flt_col_0").val(getParam("flt_col_" + i)); + } + $(cp).find('select').select2(); + $(cp).find('.remove').click(function() { + $(this).parent().parent().remove(); + }); + } + + function druidify(){ + var i = 1; + // Assigning the right id to form elements in filters + $("#filters > div").each(function() { + $(this).attr("id", function() {return "flt_" + i;}) + $(this).find("#flt_col_0") + .attr("id", function() {return "flt_col_" + i;}) + .attr("name", function() {return "flt_col_" + i;}); + $(this).find("#flt_op_0") + .attr("id", function() {return "flt_op_" + i;}) + .attr("name", function() {return "flt_op_" + i;}); + $(this).find("#flt_eq_0") + .attr("id", function() {return "flt_eq_" + i;}) + .attr("name", function() {return "flt_eq_" + i;}); + i++; + }); + $("#query").submit(); + } + + $("#plus").click(add_filter); + $("#save").click(function () { + var slice_name = prompt("Name your slice!"); + if (slice_name != "" && slice_name != null) { + $("#slice_name").val(slice_name); + $("#action").val("save"); + druidify(); + } + }) + add_filter(); + $("#druidify").click(druidify); + + function create_choices(term, data) { + var filtered = $(data).filter(function() { + return this.text.localeCompare(term) === 0; + }); + if (filtered.length === 0) { + return {id: term, text: term}; + } + } + function initSelectionToValue(element, callback) { + callback({id: element.val(), text: element.val()}); + } + $(".select2_free_since").select2({ + createSearchChoice: create_choices, + initSelection: initSelectionToValue, + multiple: false, + data: [ + {id: '-1 hour', text: '-1 hour'}, + {id: '-12 hours', text: '-12 hours'}, + {id: '-1 day', text: '-1 day'}, + {id: '-7 days', text: '-7 days'}, + {id: '-28 days', text: '-28 days'}, + {id: '-90 days', text: '-90 days'}, + ] + }); + $(".select2_free_until").select2({ + createSearchChoice: create_choices, + initSelection: initSelectionToValue, + multiple: false, + data: [ + {id: 'now', text: 'now'}, + {id: '-1 day', text: '-1 day'}, + {id: '-7 days', text: '-7 days'}, + {id: '-28 days', text: '-28 days'}, + {id: '-90 days', text: '-90 days'}, + ] + }); + $(".select2_free_granularity").select2({ + createSearchChoice: create_choices, + initSelection: initSelectionToValue, + multiple: false, + data: [ + {id: 'all', text: 'all'}, + {id: '5 seconds', text: '5 seconds'}, + {id: '30 seconds', text: '30 seconds'}, + {id: '1 minute', text: '1 minute'}, + {id: '5 minutes', text: '5 minutes'}, + {id: '1 day', text: '1 day'}, + {id: '7 days', text: '7 days'}, + ] + }); +} + +function initializeDashboardView() { + var gridster = $(".gridster ul").gridster({ + widget_margins: [5, 5], + widget_base_dimensions: [100, 100], + draggable: { + handle: '.drag', + }, + resize: { + enabled: true, + stop: function(e, ui, _widget) { + _widget.find("a.refresh").click(); + } + }, + serialize_params: function(_w, wgd) { + return { + slice_id: $(_w).attr('slice_id'), + col: wgd.col, + row: wgd.row, + size_x: wgd.size_x, + size_y: wgd.size_y + }; + }, + }).data('gridster'); + $("div.gridster").css('visibility', 'visible'); + $("#savedash").click(function() { + var data = gridster.serialize(); + $.ajax({ + type: "POST", + url: '/panoramix/save_dash/{{ dashboard.id }}/', + data: {data: JSON.stringify(data)}, + success: function() {}, + }); + }); + $("a.closewidget").click(function() { + var li = $(this).parents("li"); + gridster.remove_widget(li); + }); + $("table.widget_header").mouseover(function() { + $(this).find("td.icons nobr").show(); + }); + $("table.widget_header").mouseout(function() { + $(this).find("td.icons nobr").hide(); + }); +} diff --git a/panoramix/static/widgets/viz_nvd3.js b/panoramix/static/widgets/viz_nvd3.js index 6d16edc9ee5df..7f4b90b427387 100644 --- a/panoramix/static/widgets/viz_nvd3.js +++ b/panoramix/static/widgets/viz_nvd3.js @@ -120,6 +120,8 @@ function viz_nvd3(token_name, json_callback) { chart.xScale(d3.scale.log()); } + chart.duration(0); + token.select('.chart').append("svg") .datum(data.chart_data) .transition().duration(500) diff --git a/panoramix/templates/index.html b/panoramix/templates/index.html index c28a51698b9ea..9551ad490012b 100644 --- a/panoramix/templates/index.html +++ b/panoramix/templates/index.html @@ -109,9 +109,8 @@

Gallery

{% block tail_js %} {{ super() }} {% endblock %} diff --git a/panoramix/templates/panoramix/base.html b/panoramix/templates/panoramix/base.html index 6028706482930..9471c1822d5ef 100644 --- a/panoramix/templates/panoramix/base.html +++ b/panoramix/templates/panoramix/base.html @@ -2,6 +2,11 @@ {% block head_css %} {{super()}} - - + + +{% endblock %} + +{% block tail_js %} +{{ super() }} + {% endblock %} diff --git a/panoramix/templates/panoramix/dashboard.html b/panoramix/templates/panoramix/dashboard.html index a2468a14e1903..fa93480e53744 100644 --- a/panoramix/templates/panoramix/dashboard.html +++ b/panoramix/templates/panoramix/dashboard.html @@ -76,56 +76,9 @@

{% for js in dashboard.js_files %} {% endfor %} - + - {% for slice in dashboard.slices %} {% set viz = slice.viz %} diff --git a/panoramix/templates/panoramix/datasource.html b/panoramix/templates/panoramix/datasource.html index 751115178a307..7beb01c0f9f83 100644 --- a/panoramix/templates/panoramix/datasource.html +++ b/panoramix/templates/panoramix/datasource.html @@ -137,127 +137,6 @@

{% block tail_js %} {{ super() }} {% endblock %}