diff --git a/tally_ho/apps/tally/static/js/data_table.js b/tally_ho/apps/tally/static/js/data_table.js index 8c8726fcd..138b842ce 100644 --- a/tally_ho/apps/tally/static/js/data_table.js +++ b/tally_ho/apps/tally/static/js/data_table.js @@ -74,11 +74,13 @@ $(document).ready(function () { let data = []; let selectOneIds = $('select#centers').val(); let selectTwoIds = $('select#stations').val(); + let raceTypeNames = $('select#filter-out-race-types').val(); if (selectOneIds || selectTwoIds) { const items = { select_1_ids: selectOneIds !== null ? selectOneIds : [], select_2_ids: selectTwoIds !== null ? selectTwoIds : [], + race_type_names: raceTypeNames !== null ? raceTypeNames : [], }; data = items; @@ -148,6 +150,140 @@ $(document).ready(function () { }); }); + $('#in-report').on('click', '#filter-in-report', function () { + const table = $('.datatable').DataTable(); + + table.destroy(); + let data = []; + let selectOneIds = $('select#filter-in-centers').val(); + let selectTwoIds = $('select#filter-in-stations').val(); + let raceTypeNames = $('select#filter-in-race-types').val(); + + if (selectOneIds || selectTwoIds) { + const items = { + select_1_ids: selectOneIds !== null ? selectOneIds : [], + select_2_ids: selectTwoIds !== null ? selectTwoIds : [], + race_type_names: raceTypeNames !== null ? raceTypeNames : [], + filter_in: "True" + }; + + data = items; + } + + data = data.length + ? data.filter((item) => + Object.values(item).every((value) => typeof value !== 'undefined') + ) + : data; + + $('.datatable').dataTable({ + language: dt_language, + order: [[0, 'desc']], + lengthMenu: [ + [10, 25, 50, 100, 500], + [10, 25, 50, 100, 500], + ], + columnDefs: [ + { + orderable: true, + searchable: true, + className: 'center', + targets: [0, 1], + }, + ], + searching: true, + processing: true, + serverSide: true, + stateSave: true, + ajax: { + url: LIST_JSON_URL, + type: 'POST', + data: { data: JSON.stringify(data) }, + traditional: true, + dataType: 'json', + }, + dom: + "<'row'<'col-sm-1'B><'col-sm-6'l><'col-sm-5'f>>" + + "<'row'<'col-sm-12'tr>>" + + "<'row'<'col-sm-5'i><'col-sm-7'p>>", + buttons: [ + { + extend: 'csv', + filename: exportFileName, + action: exportAction, + exportOptions: { + columns: ':visible :not(.actions)', + }, + }, + ], + responsive: true, + }); + }); + $('#race-report').on('click', '#filter-race-report', function () { + const table = $('.datatable').DataTable(); + + table.destroy(); + let data = []; + let raceTypeNames = $('select#filter-in-race-types').val(); + + if (raceTypeNames ) { + const items = { + race_type_names: raceTypeNames !== null ? raceTypeNames : [], + }; + + data = items; + } + + data = data.length + ? data.filter((item) => + Object.values(item).every((value) => typeof value !== 'undefined') + ) + : data; + + $('.datatable').dataTable({ + language: dt_language, + order: [[0, 'desc']], + lengthMenu: [ + [10, 25, 50, 100, 500], + [10, 25, 50, 100, 500], + ], + columnDefs: [ + { + orderable: true, + searchable: true, + className: 'center', + targets: [0, 1], + }, + ], + searching: true, + processing: true, + serverSide: true, + stateSave: true, + ajax: { + url: LIST_JSON_URL, + type: 'POST', + data: { data: JSON.stringify(data) }, + traditional: true, + dataType: 'json', + }, + dom: + "<'row'<'col-sm-1'B><'col-sm-6'l><'col-sm-5'f>>" + + "<'row'<'col-sm-12'tr>>" + + "<'row'<'col-sm-5'i><'col-sm-7'p>>", + buttons: [ + { + extend: 'csv', + filename: exportFileName, + action: exportAction, + exportOptions: { + columns: ':visible :not(.actions)', + }, + }, + ], + responsive: true, + }); + }); + $('#report').on('click', '#reset', function () { const table = $('.datatable').DataTable(); diff --git a/tally_ho/apps/tally/static/js/get_centers_stations.js b/tally_ho/apps/tally/static/js/get_centers_stations.js index 88dd5579b..7f98996ec 100644 --- a/tally_ho/apps/tally/static/js/get_centers_stations.js +++ b/tally_ho/apps/tally/static/js/get_centers_stations.js @@ -1,6 +1,6 @@ $(document).ready(function () { $('#centers').change(function () { - const center_ids = $('.selectpicker').val(); + const center_ids = $('#centers').val(); if (center_ids) { $.ajax({ @@ -23,4 +23,27 @@ $(document).ready(function () { $('.center-stations').selectpicker('refresh'); } }); + $('#filter-in-centers').change(function () { + const center_ids = $('#filter-in-centers').val(); + if (center_ids) { + $.ajax({ + url: getCentersStationsUrl, + data: { + data: JSON.stringify({ + center_ids: center_ids, + tally_id: tallyId, + }), + }, + traditional: true, + dataType: 'json', + success: (data) => { + const { station_ids } = data; + $('.filter-in-center-stations').selectpicker('val', station_ids); + }, + }); + } else { + $('.filter-in-center-stations').selectpicker('deselectAll'); + $('.filter-in-center-stations').selectpicker('refresh'); + } + }); }); diff --git a/tally_ho/apps/tally/templates/reports/form_results.html b/tally_ho/apps/tally/templates/reports/form_results.html index 31754606a..3bad9ea2c 100644 --- a/tally_ho/apps/tally/templates/reports/form_results.html +++ b/tally_ho/apps/tally/templates/reports/form_results.html @@ -26,15 +26,23 @@
Centers
+{% trans 'Races' %}
+ +{% trans 'Centers' %}
{% trans 'Stations' %}
{% trans 'Filter out Centers and Stations from results.' %}
+{% trans 'Filter Out.' %}
{% trans 'Reset' %}{% trans 'Races' %}
+ +{% trans 'Centers' %}
+ +{% trans 'Stations' %}
+ +{% trans 'Filter In.' %}
+ + {% trans 'Reset' %} +