From 4d0b58a7a5fb77fafabc6c6fcda0023483b9add4 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 23 Sep 2019 15:26:39 +0000 Subject: [PATCH] Bug 23626: [alternate] Use svc/reports to fetch chart data We have a method for getting json report data via svc, and this has a built in limiter in the sysprefs. We can utilise this for our charts to avoid passing all data in memory To test: 1 - Write a report that can be charted, for example: SELECT RIGHT(barcode,2), COUNT(*) FROM items WHERE RIGHT(barcode,1) != <> GROUP BY RIGHT(barcode,2) 2 - Set the 'Cache expiry' to 1 for this report 3 - Run it and click 'Create chart' on results page Chart type: Pie x column RIGHT(barcode,2) Include all rows: UNCHECKED 4 - Note you get a nice pie chart 5 - Click 'Create chart', same except check 'Include all rows' 6 - Note you get a different pie 7 - Apply patch 8 - Repeat above - note that 'all rows' is now 'Fetch additional rows' and notes the sys pref control 9 - Increase SvcMaxReportRows and note chart changes Signed-off-by: Kyle M Hall --- .../intranet-tmpl/prog/en/includes/chart.inc | 2 +- .../modules/reports/guided_reports_start.tt | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc index cb1f6d3b55..7c08bca28c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/chart.inc @@ -34,7 +34,7 @@
  • - +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt index de0409868a..d8f841c56d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt @@ -1190,7 +1190,29 @@ canned reports and writing custom SQL reports.

    [% IF results && !errors %] $('#draw-chart').click(function() { + var results = []; + if ($('input[name="chart-include-all"]').prop('checked')) { + $.getJSON("/cgi-bin/koha/svc/report?id=[% id %][%- FOREACH param IN sql_params %]&sql_params=[% param | uri %][% END %][%- FOREACH param_name IN param_names %]&param_name=[% param_name | uri %][% END %]",function(data){ + $.each(data, function(row_index,row_value){ + var row = []; + row_value.forEach(function(cell_value,cell_index){ + row.push({ cell: cell_value }); + }); + + results.push({ cells : row }); + }); + results.cells = results; + drawchart(results); + } + ); + } + else { + results = [% results.json | $raw %]; + drawchart(results); + } + }); + function drawchart(results){ var x_elements = $('select[name="x"]').val(); var y_elements = []; var groups = []; @@ -1199,14 +1221,6 @@ canned reports and writing custom SQL reports.

    headers = [% header_row.json | $raw %]; - var results; - if ($('input[name="chart-include-all"]').prop('checked')) { - results = [% allresults.json | $raw %] - } - else { - results = [% results.json | $raw %] - } - if ($('input[name="chart-exclude-last"]').prop('checked')) { results.splice(-1, 1); } @@ -1257,7 +1271,7 @@ canned reports and writing custom SQL reports.

    $("#download-chart,#toggle_chart_settings_hid,#chart").show(); $("#toggle_chart_settings_vis").hide(); $("#chartModal").modal("hide"); - }); + }; [% END %] [% IF ( create ) %] load_group_subgroups(); -- 2.21.0 (Apple Git-122)