From 8129131a3c298e8e14ad4e3351062a288f651e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 19:09:19 +0100 Subject: [PATCH 1/3] adds pagination to officer assignments --- .../admin/poll/officer_assignments_controller.rb | 7 ++++++- app/views/admin/poll/officer_assignments/index.html.erb | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/officer_assignments_controller.rb b/app/controllers/admin/poll/officer_assignments_controller.rb index b14f99a6a..f3102172c 100644 --- a/app/controllers/admin/poll/officer_assignments_controller.rb +++ b/app/controllers/admin/poll/officer_assignments_controller.rb @@ -5,7 +5,12 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController before_action :load_booth_assignment, only: [:create] def index - @officers = @poll.officer_assignments.includes(officer: :user).select(:officer_id).distinct.map(&:officer) + @officers = ::Poll::Officer. + includes(:user). + order('users.username'). + where( + id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id) + ).page(params[:page]).per(50) end def by_officer diff --git a/app/views/admin/poll/officer_assignments/index.html.erb b/app/views/admin/poll/officer_assignments/index.html.erb index e4c3e3052..f6e75c602 100644 --- a/app/views/admin/poll/officer_assignments/index.html.erb +++ b/app/views/admin/poll/officer_assignments/index.html.erb @@ -37,5 +37,7 @@ <% end %> + + <%= paginate @officers %> <% end %> \ No newline at end of file From 2b68f02b955f4dfded18eabeef02f343526ec436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 19:09:31 +0100 Subject: [PATCH 2/3] paginates booths --- app/controllers/admin/poll/booth_assignments_controller.rb | 2 +- app/views/admin/poll/booth_assignments/index.html.erb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 926aae786..f81382bf8 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -3,7 +3,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController before_action :load_poll, except: [:create, :destroy] def index - @booth_assignments = @poll.booth_assignments.includes(:booth) + @booth_assignments = @poll.booth_assignments.includes(:booth).order('poll_booths.name').page(params[:page]).per(50) end def search_booths diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb index c96f6ba3d..f14e59ef1 100644 --- a/app/views/admin/poll/booth_assignments/index.html.erb +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -5,7 +5,7 @@

<%= t("admin.poll_booth_assignments.index.booths_title") %>

- <% if @poll.booth_assignments.empty? %> + <% if @booth_assignments.empty? %>
<%= t("admin.poll_booth_assignments.index.no_booths") %>
@@ -17,7 +17,7 @@ <%= t("admin.poll_booth_assignments.index.table_assignment") %> - <% @poll.booth_assignments.each do |booth_assignment| %> + <% @booth_assignments.each do |booth_assignment| %> @@ -37,5 +37,7 @@ <% end %> + + <%= paginate @booth_assignments %> <% end %> From d68be1f6f007a39ddb3866b28906274c0b85111a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 19:44:19 +0100 Subject: [PATCH 3/3] adds automatic recount to admin poll and paginates recounts --- .../admin/poll/recounts_controller.rb | 5 +++- app/helpers/poll_recounts_helper.rb | 8 ++++++ app/views/admin/poll/recounts/index.html.erb | 25 ++++++++++++++----- config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + spec/features/admin/poll/polls_spec.rb | 4 +++ 6 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb index 6df6e8ed5..12b78aa3f 100644 --- a/app/controllers/admin/poll/recounts_controller.rb +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -2,7 +2,10 @@ class Admin::Poll::RecountsController < Admin::BaseController before_action :load_poll def index - @booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts) + @booth_assignments = @poll.booth_assignments. + includes(:booth, :recounts, :final_recounts, :voters). + order(created_at: :desc). + page(params[:page]).per(50) end private diff --git a/app/helpers/poll_recounts_helper.rb b/app/helpers/poll_recounts_helper.rb index 95ce54341..c47402163 100644 --- a/app/helpers/poll_recounts_helper.rb +++ b/app/helpers/poll_recounts_helper.rb @@ -4,4 +4,12 @@ module PollRecountsHelper recounts.select {|r| r.date == date}.first end + def booth_assignment_sum_recounts(ba) + ba.recounts.any? ? ba.recounts.to_a.sum(&:count) : nil + end + + def booth_assignment_sum_final_recounts(ba) + ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) :nil + end + end \ No newline at end of file diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb index bb1f90364..98055f553 100644 --- a/app/views/admin/poll/recounts/index.html.erb +++ b/app/views/admin/poll/recounts/index.html.erb @@ -14,32 +14,45 @@ <%= t("admin.recounts.index.table_booth_name") %> <%= t("admin.recounts.index.table_recounts") %> <%= t("admin.recounts.index.table_final_recount") %> + <%= t("admin.recounts.index.table_system_count") %> <% @booth_assignments.each do |booth_assignment| %> + <% recount = booth_assignment_sum_recounts(booth_assignment) %> + <% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %> + <% system_count = booth_assignment.voters.size %> <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %> - - <% if booth_assignment.recounts.any? %> - <%= booth_assignment.recounts.to_a.sum(&:count) %> + + <% if recount.present? %> + <%= recount %> + <% else %> + - + <% end %> + + + <% if final_recount.present? %> + <%= final_recount %> <% else %> - <% end %> - <% if booth_assignment.final_recounts.any? %> - <%= booth_assignment.final_recounts.to_a.sum(&:count) %> + <% if system_count.present? %> + <%= system_count %> <% else %> - - + 0 <% end %> <% end %> + + <%= paginate @booth_assignments %> <% end %> \ No newline at end of file diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 8d5e113cd..564137a09 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -381,6 +381,7 @@ en: table_booth_name: "Booth" table_recounts: "Accumulated daily recounts (by officer)" table_final_recount: "Final recount (by officer)" + table_system_count: "Votes (automatic)" results: index: title: "Results" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 2b087f385..aaf83e275 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -381,6 +381,7 @@ es: table_booth_name: "Urna" table_recounts: "Recuentos diarios acumulados (presidente de mesa)" table_final_recount: "Recuento final (presidente de mesa)" + table_system_count: "Votos (automático)" results: index: title: "Resultados" diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index ebe21b335..cb5a34265 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -258,6 +258,9 @@ feature 'Admin polls' do date: poll.starts_at + i.days, count: 21) } + 2.times { create(:poll_voter, + booth_assignment: booth_assignment_final_recounted) } + create(:poll_recount, booth_assignment: booth_assignment_recounted, date: poll.ends_at, @@ -290,6 +293,7 @@ feature 'Admin polls' do expect(page).to have_content(booth_assignment_final_recounted.booth.name) expect(page).to have_content('-') expect(page).to have_content('55555') + expect(page).to have_content('2') end end end