dataviz: factorize querystring building code (#62533)
This commit is contained in:
parent
79f061c471
commit
7f7d75c509
|
@ -276,6 +276,9 @@ class ChartNgCell(CellBase):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Chart')
|
verbose_name = _('Chart')
|
||||||
|
|
||||||
|
class Media:
|
||||||
|
js = ('js/chartngcell.js',)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_enabled(cls):
|
def is_enabled(cls):
|
||||||
return settings.KNOWN_SERVICES.get('bijoe') or settings.STATISTICS_PROVIDERS
|
return settings.KNOWN_SERVICES.get('bijoe') or settings.STATISTICS_PROVIDERS
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
function get_graph_querystring(extra_context, width=undefined) {
|
||||||
|
qs = [];
|
||||||
|
if ($('#chart-filters'))
|
||||||
|
qs.push($('#chart-filters').serialize());
|
||||||
|
if (extra_context)
|
||||||
|
qs.push('ctx=' + extra_context);
|
||||||
|
if (window.location.search)
|
||||||
|
qs.push(window.location.search.slice(1));
|
||||||
|
if (width)
|
||||||
|
qs.push('width=' + width);
|
||||||
|
return '?' + qs.join('&');
|
||||||
|
};
|
|
@ -5,17 +5,9 @@
|
||||||
<script>
|
<script>
|
||||||
$(function() {
|
$(function() {
|
||||||
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
|
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
|
||||||
var chart_filters_form = $('#chart-filters');
|
|
||||||
$(window).on('combo:refresh-graphs', function() {
|
$(window).on('combo:refresh-graphs', function() {
|
||||||
qs = [];
|
|
||||||
if(chart_filters_form)
|
|
||||||
qs.push(chart_filters_form.serialize());
|
|
||||||
if(extra_context)
|
|
||||||
qs.push('ctx=' + extra_context);
|
|
||||||
if (window.location.search)
|
|
||||||
qs.push(window.location.search.slice(1));
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "{% url 'combo-dataviz-graph' cell=cell.id %}?" + qs.join('&'),
|
url : "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context),
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('#chart-{{cell.id}}').html(data);
|
$('#chart-{{cell.id}}').html(data);
|
||||||
|
@ -32,40 +24,17 @@ $(function() {
|
||||||
$(function() {
|
$(function() {
|
||||||
var last_width = 1;
|
var last_width = 1;
|
||||||
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
|
var extra_context = $('#chart-{{cell.id}}').parents('.cell').data('extra-context');
|
||||||
var chart_filters_form = $('#chart-filters');
|
|
||||||
$(window).on('load resize gadjo:sidepage-toggled combo:resize-graphs', function() {
|
$(window).on('load resize gadjo:sidepage-toggled combo:resize-graphs', function() {
|
||||||
var chart_cell = $('#chart-{{cell.id}}').parent();
|
var chart_cell = $('#chart-{{cell.id}}').parent();
|
||||||
var new_width = Math.floor($(chart_cell).width());
|
var new_width = Math.floor($(chart_cell).width());
|
||||||
var ratio = new_width / last_width;
|
var ratio = new_width / last_width;
|
||||||
var qs;
|
|
||||||
if (window.location.search) {
|
|
||||||
qs = window.location.search + '&';
|
|
||||||
} else {
|
|
||||||
qs = '?';
|
|
||||||
}
|
|
||||||
qs += 'width=' + new_width
|
|
||||||
if(chart_filters_form)
|
|
||||||
qs += '&' + chart_filters_form.serialize()
|
|
||||||
if(extra_context)
|
|
||||||
qs += '&ctx=' + extra_context
|
|
||||||
if (ratio > 1.2 || ratio < 0.8) {
|
if (ratio > 1.2 || ratio < 0.8) {
|
||||||
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + qs);
|
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context, new_width));
|
||||||
last_width = new_width;
|
last_width = new_width;
|
||||||
}
|
}
|
||||||
}).trigger('combo:resize-graphs');
|
}).trigger('combo:resize-graphs');
|
||||||
$(window).on('combo:refresh-graphs', function() {
|
$(window).on('combo:refresh-graphs', function() {
|
||||||
var qs;
|
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + get_graph_querystring(extra_context, last_width));
|
||||||
if (window.location.search) {
|
|
||||||
qs = window.location.search + '&';
|
|
||||||
} else {
|
|
||||||
qs = '?';
|
|
||||||
}
|
|
||||||
qs += 'width=' + last_width
|
|
||||||
if(chart_filters_form)
|
|
||||||
qs += '&' + chart_filters_form.serialize()
|
|
||||||
if(extra_context)
|
|
||||||
qs += '&ctx=' + extra_context
|
|
||||||
$('#chart-{{cell.id}}').attr('src', "{% url 'combo-dataviz-graph' cell=cell.id %}" + qs);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue