extracts recounting from admin's poll/show

This commit is contained in:
Juanjo Bazán
2017-02-14 14:07:22 +01:00
parent 19ec7f93b3
commit bedb9f29e7
10 changed files with 81 additions and 65 deletions

View File

@@ -8,9 +8,7 @@ class Admin::Poll::PollsController < Admin::BaseController
end end
def show def show
@poll = Poll.includes(:questions, @poll = Poll.includes(:questions).
booth_assignments: [:final_recounts,
:recounts]).
order('poll_questions.title'). order('poll_questions.title').
find(params[:id]) find(params[:id])
end end
@@ -46,7 +44,7 @@ class Admin::Poll::PollsController < Admin::BaseController
else else
notice = t("admin.polls.flash.error_on_question_added") notice = t("admin.polls.flash.error_on_question_added")
end end
redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice redirect_to admin_poll_path(@poll), notice: notice
end end
def remove_question def remove_question
@@ -58,7 +56,7 @@ class Admin::Poll::PollsController < Admin::BaseController
else else
notice = t("admin.polls.flash.error_on_question_removed") notice = t("admin.polls.flash.error_on_question_removed")
end end
redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice redirect_to admin_poll_path(@poll), notice: notice
end end
def search_questions def search_questions

View File

@@ -0,0 +1,13 @@
class Admin::Poll::RecountsController < Admin::BaseController
before_action :load_poll
def index
@booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts)
end
private
def load_poll
@poll = ::Poll.find(params[:poll_id])
end
end

View File

@@ -34,7 +34,7 @@
<tbody> <tbody>
<% @booth_assignment.officers.uniq.each do |officer| %> <% @booth_assignment.officers.uniq.each do |officer| %>
<tr id="officer_<%= officer.id %>" class="officer"> <tr id="officer_<%= officer.id %>" class="officer">
<td><%= link_to officer.name, admin_officer_assignments_path(officer: officer, poll: @poll) %></td> <td><%= link_to officer.name, by_officer_admin_poll_officer_assignments_path(@poll, officer_id: officer.id) %></td>
<td><%= officer.email %></td> <td><%= officer.email %></td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -18,7 +18,7 @@
<% end %> <% end %>
</li> </li>
<li> <li>
<%= link_to "#tab-recounts" do %> <%= link_to admin_poll_recounts_path(@poll) do %>
<%= t("admin.polls.show.recounts_tab") %> <%= t("admin.polls.show.recounts_tab") %>
<% end %> <% end %>
</li> </li>

View File

@@ -1,40 +0,0 @@
<h3><%= t("admin.polls.show.recounting_title") %></h3>
<% if @poll.booth_assignments.empty? %>
<div class="callout primary margin-top">
<%= t("admin.polls.show.no_recounts") %>
</div>
<% else %>
<table class="fixed margin">
<thead>
<th><%= t("admin.polls.show.table_booth_name") %></th>
<th class="text-center"><%= t("admin.polls.show.table_recounts") %></th>
<th class="text-center"><%= t("admin.polls.show.table_final_recount") %></th>
</thead>
<tbody>
<% @poll.booth_assignments.each do |booth_assignment| %>
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
</strong>
</td>
<td class="text-center">
<% if booth_assignment.recounts.any? %>
<%= booth_assignment.recounts.to_a.sum(&:count) %>
<% else %>
<span>-</span>
<% end %>
</td>
<td class="text-center">
<% if booth_assignment.final_recounts.any? %>
<strong><%= booth_assignment.final_recounts.to_a.sum(&:count) %></strong>
<% else %>
<span>-</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -3,14 +3,8 @@
<div id="poll-resources"> <div id="poll-resources">
<%= render "filter_subnav" %> <%= render "filter_subnav" %>
<div class="tabs-panel" id="tab-questions"> <%= render "search_questions" %>
<%= render "search_questions" %> <%= render "questions" %>
<%= render "questions" %>
</div>
<div class="tabs-panel" id="tab-recounts">
<%= render 'recounting' %>
</div>
<div class="tabs-panel" id="tab-results"> <div class="tabs-panel" id="tab-results">
<%= render 'results' %> <%= render 'results' %>

View File

@@ -0,0 +1,45 @@
<%= render "/admin/poll/polls/poll_header" %>
<div id="poll-resources">
<%= render "/admin/poll/polls/filter_subnav" %>
<h3><%= t("admin.recounts.index.title") %></h3>
<% if @booth_assignments.empty? %>
<div class="callout primary margin-top">
<%= t("admin.recounts.index.no_recounts") %>
</div>
<% else %>
<table class="fixed margin">
<thead>
<th><%= t("admin.recounts.index.table_booth_name") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_recounts") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
</thead>
<tbody>
<% @booth_assignments.each do |booth_assignment| %>
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
</strong>
</td>
<td class="text-center">
<% if booth_assignment.recounts.any? %>
<%= booth_assignment.recounts.to_a.sum(&:count) %>
<% else %>
<span>-</span>
<% end %>
</td>
<td class="text-center">
<% if booth_assignment.final_recounts.any? %>
<strong><%= booth_assignment.final_recounts.to_a.sum(&:count) %></strong>
<% else %>
<span>-</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>

View File

@@ -338,19 +338,14 @@ en:
recounts_tab: Recounting recounts_tab: Recounting
results_tab: Results results_tab: Results
no_questions: "There are no questions assigned to this poll." no_questions: "There are no questions assigned to this poll."
no_recounts: "There is nothing to be recounted"
no_results: "There are no results" no_results: "There are no results"
questions_title: "List of questions" questions_title: "List of questions"
recounting_title: "Recounts"
results_title: "Results" results_title: "Results"
remove_question: "Remove question from poll" remove_question: "Remove question from poll"
add_question: "Include question" add_question: "Include question"
table_title: "Title" table_title: "Title"
table_assignment: "Assignment" table_assignment: "Assignment"
table_name: "Name" table_name: "Name"
table_booth_name: "Booth"
table_final_recount: "Final recount (by officer)"
table_recounts: "Accumulated daily recounts (by officer)"
table_whites: "Blank ballots" table_whites: "Blank ballots"
table_nulls: "Invalid ballots" table_nulls: "Invalid ballots"
table_answer: Answer table_answer: Answer
@@ -385,6 +380,13 @@ en:
valid_answers: Valid answers valid_answers: Valid answers
description: Description description: Description
preview: View on website preview: View on website
recounts:
index:
title: "Recounts"
no_recounts: "There is nothing to be recounted"
table_booth_name: "Booth"
table_recounts: "Accumulated daily recounts (by officer)"
table_final_recount: "Final recount (by officer)"
booths: booths:
index: index:
title: "List of booths" title: "List of booths"

View File

@@ -338,19 +338,14 @@ es:
recounts_tab: Recuentos recounts_tab: Recuentos
results_tab: Resultados results_tab: Resultados
no_questions: "No hay preguntas asignadas a esta votación." no_questions: "No hay preguntas asignadas a esta votación."
no_recounts: "No hay nada de lo que hacer recuento"
no_results: "No hay resultados" no_results: "No hay resultados"
questions_title: "Listado de preguntas asignadas" questions_title: "Listado de preguntas asignadas"
recounting_title: "Recuentos"
results_title: "Resultados" results_title: "Resultados"
remove_question: "Desasignar pregunta" remove_question: "Desasignar pregunta"
add_question: "Incluir pregunta" add_question: "Incluir pregunta"
table_title: "Título" table_title: "Título"
table_assignment: "Asignación" table_assignment: "Asignación"
table_name: "Nombre" table_name: "Nombre"
table_booth_name: "Urna"
table_final_recount: "Recuento final (presidente de mesa)"
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
table_whites: Papeletas en blanco table_whites: Papeletas en blanco
table_nulls: Papeletas nulas table_nulls: Papeletas nulas
table_answer: Respuesta table_answer: Respuesta
@@ -385,6 +380,13 @@ es:
valid_answers: Respuestas válidas valid_answers: Respuestas válidas
description: Descripción description: Descripción
preview: Ver en la web preview: Ver en la web
recounts:
index:
title: "Recuentos"
no_recounts: "No hay nada de lo que hacer recuento"
table_booth_name: "Urna"
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
table_final_recount: "Recuento final (presidente de mesa)"
booths: booths:
index: index:
title: "Lista de urnas" title: "Lista de urnas"

View File

@@ -221,6 +221,8 @@ Rails.application.routes.draw do
get :search_officers, on: :collection get :search_officers, on: :collection
get :by_officer, on: :collection get :by_officer, on: :collection
end end
resources :recounts, only: :index
end end
resources :officers do resources :officers do