From 0122c68228b0cf3f1ec152481bcb7c22248248d3 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 14 May 2019 16:12:21 +0200 Subject: Statistics - JS and templates to manage graphs and tables --- ishtar_common/models.py | 9 +- ishtar_common/static/js/ishtar-map.js | 35 +++ ishtar_common/static/js/ishtar.js | 279 +++++++++++++++++++++ ishtar_common/templates/base.html | 14 ++ .../templates/blocks/DataTables-tabs.html | 14 ++ ishtar_common/templates/blocks/DataTables.html | 64 +---- ishtar_common/views_item.py | 31 ++- 7 files changed, 379 insertions(+), 67 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 7aa8706b3..8e5983a45 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1931,10 +1931,13 @@ class TemplateItem: class StatisticItem: - STATISTIC_MODALITIES = [] # example: "operation type", "material type" + STATISTIC_MODALITIES = [] # example: "year", "operation_type__label" + STATISTIC_MODALITIES_OPTIONS = OrderedDict() # example: + # OrderedDict([('year', _("Year")), + # ("operation_type__label", _("Operation type"))]) STATISTIC_SUM_VARIABLE = OrderedDict( - (("pk", _("number")),) - ) # example: "price", "volume" + (("pk", _("Number")),) + ) # example: "Price", "Volume" class BaseHistorizedItem(StatisticItem, TemplateItem, FullSearch, Imported, diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index 1b0d4384b..a93813e61 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -27,6 +27,41 @@ var geolocation = {}; var geoloc_feature = {}; var geoloc_activated = {}; +var fetching_msg = "Fetching data..."; + +var _map_submit_search = function(query_vars, name, source){ + var modal_base_text = $('.modal-progress .modal-header').html(); + $('.modal-progress .modal-header').html(fetching_msg); + $('.modal-progress').modal('show'); + var data = search_get_query_data(query_vars, name); + var nb_select = jQuery("#id_" + name + "-length_map").val(); + if (!nb_select) nb_select = 10; + + var url = source + "json-map?length=" + nb_select + "&submited=1&" + data; + var use_map_limit = false; + if(data.indexOf("no_limit=true") == -1){ + url += "&limit=" + current_map_limit; + use_map_limit = true; + } + $.getJSON(url, function(data) { + var timestamp = Math.floor(Date.now() / 1000); + var map_id = "map-" + timestamp; + $('.modal-progress .modal-header').html("{% trans 'Render map...' %}"); + + var html = render_map(map_id, use_map_limit); + $("#tab-content-map-" + name).html(html); + $("#id_" + name + "-length_map").change(map_submit_search); + if ($('.modal-progress').length > 0){ + $('.modal-progress').modal('hide'); + $('.modal-progress .modal-header').html(modal_base_text); + } + register_map(map_id, data); + }); + + return false; + +}; + var geoloc_activated_message = function(map_id){ setTimeout(function(){ diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js index 2527c1bd7..54823968c 100644 --- a/ishtar_common/static/js/ishtar.js +++ b/ishtar_common/static/js/ishtar.js @@ -1095,6 +1095,33 @@ var get_hover_div = function(table_cols, data){ return hover; }; +var _gallery_submit_search = function(image_page, query_vars, name, source){ + if (image_page) { + current_image_page = image_page; + } else { + current_image_page = 1; + } + $('.modal-progress').modal('show'); + var data = search_get_query_data(query_vars, name); + var nb_select = jQuery("#id_" + name + "-length_image").val(); + if (!nb_select) nb_select = 10; + + var url = source + "json-image?length=" + nb_select + "&submited=1&" + data; + $.getJSON(url, function(data) { + var timestamp = Math.floor(Date.now() / 1000); + var gallery_id = "gallery-" + timestamp; + $("#tab-content-gallery-" + name).html( + render_gallery(data, name, nb_select, gallery_id)); + $("#id_" + name + "-length_image").change(gallery_submit_search); + register_image_gallery(gallery_id); + $('.card[data-toggle="tooltip"]').tooltip(); + if ($('.modal-progress').length > 0){ + $('.modal-progress').modal('hide'); + } + }); + return false; +} + var render_gallery = function(data_table, table_name, nb_select, gallery_id){ var html = '