Skip to content

Commit

Permalink
Extract scripts into javascript file.
Browse files Browse the repository at this point in the history
  • Loading branch information
akuhn committed Oct 2, 2015
1 parent 367c256 commit ad1ebaa
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 175 deletions.
164 changes: 164 additions & 0 deletions panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
@@ -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();
});
}
2 changes: 2 additions & 0 deletions panoramix/static/widgets/viz_nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions panoramix/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ <h2>Gallery</h2>
{% block tail_js %}
{{ super() }}
<script>
$( document ).ready(function() {
$(document).ready(function() {
$('#carousel').carousel();
console.log($('#carousel'));
});
</script>
{% endblock %}
9 changes: 7 additions & 2 deletions panoramix/templates/panoramix/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% block head_css %}
{{super()}}
<link rel="shortcut icon" href="{{ url_for('static', filename='chaudron.png') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="panoramix.css") }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='chaudron.png') }}" />
<link rel="stylesheet" type="text/css" href="/static/panoramix.css" />
{% endblock %}

{% block tail_js %}
{{ super() }}
<script src="/static/panoramix.js"></script>
{% endblock %}
51 changes: 2 additions & 49 deletions panoramix/templates/panoramix/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,56 +76,9 @@ <h2>
{% for js in dashboard.js_files %}
<script src="{{ url_for('static', filename=js) }}"></script>
{% endfor %}
<script src="{{ url_for("static", filename="jquery.gridster.with-extras.min.js") }}"></script>
<script src="/static/jquery.gridster.with-extras.min.js"></script>
<script>
f = d3.format(".4s");
</script>
<script>
$( document ).ready(function() {
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();
console.log(data);
$.ajax({
type: "POST",
url: '/panoramix/save_dash/{{ dashboard.id }}/',
data: {data: JSON.stringify(data)},
success: function(){console.log('Sucess!')},
});
});
$("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();
});
});
$(document).ready(initializeDashboardView);
</script>
{% for slice in dashboard.slices %}
{% set viz = slice.viz %}
Expand Down
123 changes: 1 addition & 122 deletions panoramix/templates/panoramix/datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,127 +137,6 @@ <h4 class="modal-title" id="myModalLabel">Query</h4>
{% block tail_js %}
{{ super() }}
<script>
$( document ).ready(function() {
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").slideDown("slow");
$('[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).slideDown("slow");
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().slideUp("slow", function(){$(this).remove()});
});
}

function druidify(){
var i = 1;

// removing empty filters
$("#filters > div").each(function(){
if ($(this).find("#flt_eq_0").val() == '')
$(this).slideUp();
});

// 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) {
if ($(data).filter(function() {
return this.text.localeCompare(term)===0;
}).length===0)
{return {id:term, text:term};}
}
$(".select2_free_since").select2({
createSearchChoice: create_choices,
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'},
{id: '{{ viz.form.data.since }}', text: '{{ viz.form.data.since }}'},
]
});
$(".select2_free_until").select2({
createSearchChoice: create_choices,
multiple: false,
data: [
{id: '{{ viz.form.data.until }}', text: '{{ viz.form.data.until }}'},
{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,
multiple: false,
data: [
{id: '{{ viz.form.data.granularity }}', text: '{{ viz.form.data.granularity }}'},
{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'},
]
});
});
$(document).ready(initializeDatasourceView);
</script>
{% endblock %}

0 comments on commit ad1ebaa

Please sign in to comment.