From 4b75654d8298c04ebf1194ccf4f43cfe46d2e7a7 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 2 Jun 2022 14:37:50 +0200 Subject: [PATCH 1/2] dataviz: factorize querystring building code (#62533) --- combo/apps/dataviz/models.py | 3 ++ combo/apps/dataviz/static/js/chartngcell.js | 12 ++++++ .../dataviz/templates/combo/chartngcell.html | 37 ++----------------- 3 files changed, 18 insertions(+), 34 deletions(-) create mode 100644 combo/apps/dataviz/static/js/chartngcell.js diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py index 7b36d6e2..9419ca24 100644 --- a/combo/apps/dataviz/models.py +++ b/combo/apps/dataviz/models.py @@ -276,6 +276,9 @@ class ChartNgCell(CellBase): class Meta: verbose_name = _('Chart') + class Media: + js = ('js/chartngcell.js',) + @classmethod def is_enabled(cls): return settings.KNOWN_SERVICES.get('bijoe') or settings.STATISTICS_PROVIDERS diff --git a/combo/apps/dataviz/static/js/chartngcell.js b/combo/apps/dataviz/static/js/chartngcell.js new file mode 100644 index 00000000..1ab6bb5c --- /dev/null +++ b/combo/apps/dataviz/static/js/chartngcell.js @@ -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('&'); +}; diff --git a/combo/apps/dataviz/templates/combo/chartngcell.html b/combo/apps/dataviz/templates/combo/chartngcell.html index ae9bed14..97373f11 100644 --- a/combo/apps/dataviz/templates/combo/chartngcell.html +++ b/combo/apps/dataviz/templates/combo/chartngcell.html @@ -5,17 +5,9 @@ -- 2.30.2