From d4125f98aaaa6ecbf6ea654de3b06cc4c5334068 Mon Sep 17 00:00:00 2001 From: Rodrigo Assis Date: Fri, 3 Dec 2021 19:38:26 -0300 Subject: [PATCH] institution edits date range --- app/assets/javascripts/stats.js | 22 +++++++++---- app/controllers/admin/stats_controller.rb | 12 ++++++- app/views/admin/stats/_edit_stats.html.erb | 38 +++++++++++++++------- app/views/admin/stats/_stat_list.html.erb | 1 - 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/stats.js b/app/assets/javascripts/stats.js index 28e452975..84bbdee05 100644 --- a/app/assets/javascripts/stats.js +++ b/app/assets/javascripts/stats.js @@ -1,13 +1,23 @@ $(document).ready(function(){ $('#institution_id').change(function(){ - var id = $(this).val() - loadStatsForInstitution(id) - }) + loadStatsForInstitution(); + }); + + $('#start_date, #end_date').change(function() { + loadStatsForInstitution(); + }); + + function loadStatsForInstitution(){ + var institutionId = $("#institution_id").val() || 0 + let start_date = $("#start_date").val() || 0; + let end_date = $("#end_date").val() || 0; - function loadStatsForInstitution(institutionId){ - id = institutionId || 0 $.ajax({ - url: "/admin/stats/" + id + "/institution" + url: "/admin/stats/" + institutionId + "/institution", + data: { + start_date: start_date, + end_date: end_date + }, }); } }) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 558f03c1b..62366a8d2 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -11,6 +11,16 @@ def index def institution id = params[:id] ||= 0 - @stats = StatsService.new(current_user).transcript_edits(id) + @stats = StatsService.new(current_user, start_date, end_date).transcript_edits(id) + end + + private + + def start_date + params[:start_date].to_i > 0 ? params[:start_date] : nil + end + + def end_date + params[:end_date].to_i > 0 ? params[:end_date] : nil end end diff --git a/app/views/admin/stats/_edit_stats.html.erb b/app/views/admin/stats/_edit_stats.html.erb index 2a47512cc..835b044c5 100644 --- a/app/views/admin/stats/_edit_stats.html.erb +++ b/app/views/admin/stats/_edit_stats.html.erb @@ -1,19 +1,33 @@

Institution edits

-
-
+
-

Institution: - <%= collection_select(:institution, :id, institutions, - :id, :name, - include_blank: 'Select an institution') %> -

+
+
+
+ + <%= collection_select(:institution, :id, institutions, :id, :name, include_blank: 'Select an institution') %> +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+
+
- -
-
+
- - diff --git a/app/views/admin/stats/_stat_list.html.erb b/app/views/admin/stats/_stat_list.html.erb index 9bf7b60ed..e417f6674 100644 --- a/app/views/admin/stats/_stat_list.html.erb +++ b/app/views/admin/stats/_stat_list.html.erb @@ -4,4 +4,3 @@
<%= value[_key].to_i %>
<% end %> -