diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 5895a10bf..b2459a574 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -8,7 +8,7 @@ class Admin::Poll::PollsController < Admin::BaseController end def show - @poll = Poll.includes(:questions, booth_assignments: [:booth], officers: [:user]).order('poll_questions.title', 'poll_booths.name', 'users.username').find(params[:id]) + @poll = Poll.includes(:questions, booth_assignments: [:booth, :final_recounts, :recounts], officers: [:user]).order('poll_questions.title', 'poll_booths.name', 'users.username').find(params[:id]) end def new diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index dc192be5f..a2a204662 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -17,4 +17,9 @@ (<%= @poll.officers.uniq.count %>) <% end %> +
  • + <%= link_to "#tab-recounts" do %> + <%= t("admin.polls.show.recounts_tab") %> + <% end %> +
  • diff --git a/app/views/admin/poll/polls/_recounting.html.erb b/app/views/admin/poll/polls/_recounting.html.erb new file mode 100644 index 000000000..ed5680936 --- /dev/null +++ b/app/views/admin/poll/polls/_recounting.html.erb @@ -0,0 +1,36 @@ +

    <%= t("admin.polls.show.recounting_title") %>

    + +<% if @poll.booth_assignments.empty? %> +
    + <%= t("admin.polls.show.no_recounts") %> +
    +<% else %> + + + + + + + + <% @poll.booth_assignments.each do |booth_assignment| %> + + + <% if booth_assignment.recounts.any? %> + + <% else %> + + <% end %> + <% if booth_assignment.final_recounts.any? %> + + <% else %> + + <% end %> + + <% end %> + +
    <%= t("admin.polls.show.table_booth_name") %><%= t("admin.polls.show.table_recounts") %><%= t("admin.polls.show.table_final_recount") %>
    + + <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %> + + <%= booth_assignment.recounts.to_a.sum(&:count) %> - <%= booth_assignment.final_recounts.to_a.sum(&:count) %> -
    +<% end %> diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index 363d14630..0c622c627 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -33,4 +33,8 @@ <%= render "search_officers" %> <%= render 'officers' %> + +
    + <%= render 'recounting' %> +
    diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index f0d937e29..49b597563 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -311,13 +311,16 @@ en: questions_tab: Questions booths_tab: Booths officers_tab: Officers + recounts_tab: Recounting no_booths: "There are no booths assigned to this poll." no_questions: "There are no questions assigned to this poll." no_officers: "There are no officers assigned to this poll." + no_recounts: "There is nothing to be recounted" remove_booth: "Remove booth from poll" booths_title: "List of booths" officers_title: "List of officers" questions_title: "List of questions" + recounting_title: "Recounts" remove_question: "Remove question from poll" add_booth: "Assign booth" add_question: "Include question" @@ -330,6 +333,9 @@ en: table_name: "Name" table_location: "Location" table_email: "Email" + table_booth_name: "Booth" + table_final_recount: "Final recount" + table_recounts: "Accumulated daily recounts" flash: question_added: "Question added to this poll" error_on_question_added: "Question could not be assigned to this poll" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index b9d764ff9..bc9ad6399 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -311,13 +311,16 @@ es: questions_tab: Preguntas booths_tab: Urnas officers_tab: Presidentes de mesa + recounts_tab: Recuentos no_booths: "No hay urnas asignadas a esta votación." no_questions: "No hay preguntas asignadas a esta votación." no_officers: "No hay presidentes de mesa asignados a esta votación." + no_recounts: "No hay nada de lo que hacer recuento" remove_booth: "Desasignar urna" booths_title: "Listado de urnas asignadas" officers_title: "Listado de presidentes de mesa asignados" questions_title: "Listado de preguntas asignadas" + recounting_title: "Recuentos" remove_question: "Desasignar pregunta" add_booth: "Asignar urna" add_question: "Incluir pregunta" @@ -330,6 +333,9 @@ es: table_name: "Nombre" table_location: "Ubicación" table_email: "Email" + table_booth_name: "Urna" + table_final_recount: "Recuento final" + table_recounts: "Recuentos diarios acumulados" flash: question_added: "Pregunta añadida a esta votación" error_on_question_added: "No se pudo asignar la pregunta" diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 95bf9bc9a..10b1b2e92 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -165,6 +165,7 @@ feature 'Admin polls' do end context "Questions" do + context "Poll show" do scenario "Question list", :js do @@ -240,5 +241,67 @@ feature 'Admin polls' do end end + context "Recounting" do + context "Poll show" do + scenario "No recounts", :js do + poll = create(:poll) + visit admin_poll_path(poll) + click_link "Recounting" + + expect(page).to have_content "There is nothing to be recounted" + end + + scenario "Recounts list", :js do + poll = create(:poll) + booth_assignment = create(:poll_booth_assignment, poll: poll) + booth_assignment_recounted = create(:poll_booth_assignment, poll: poll) + booth_assignment_final_recounted = create(:poll_booth_assignment, poll: poll) + + 3.times { |i| create(:poll_recount, + booth_assignment: booth_assignment, + date: poll.starts_at + i.days, + count: 33) } + + 3.times { |i| create(:poll_final_recount, + booth_assignment: booth_assignment, + date: poll.starts_at + i.days, + count: 21) } + + create(:poll_recount, + booth_assignment: booth_assignment_recounted, + date: poll.ends_at, + count: 777) + + create(:poll_final_recount, + booth_assignment: booth_assignment_final_recounted, + date: poll.ends_at, + count: 55555) + + visit admin_poll_path(poll) + + click_link "Recounting" + + expect(page).to have_css ".booth_recounts", count: 3 + + within("#poll_booth_assignment_#{booth_assignment.id}_recounts") do + expect(page).to have_content(booth_assignment.booth.name) + expect(page).to have_content('99') + expect(page).to have_content('63') + end + + within("#poll_booth_assignment_#{booth_assignment_recounted.id}_recounts") do + expect(page).to have_content(booth_assignment_recounted.booth.name) + expect(page).to have_content('777') + expect(page).to have_content('-') + end + + within("#poll_booth_assignment_#{booth_assignment_final_recounted.id}_recounts") do + expect(page).to have_content(booth_assignment_final_recounted.booth.name) + expect(page).to have_content('-') + expect(page).to have_content('55555') + end + end + end + end end \ No newline at end of file