extracts results from admin's poll/show
This commit is contained in:
13
app/controllers/admin/poll/results_controller.rb
Normal file
13
app/controllers/admin/poll/results_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class Admin::Poll::ResultsController < Admin::BaseController
|
||||||
|
before_action :load_poll
|
||||||
|
|
||||||
|
def index
|
||||||
|
@partial_results = @poll.partial_results
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_poll
|
||||||
|
@poll = ::Poll.includes(:questions).find(params[:poll_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -25,7 +25,7 @@ module AdminHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def menu_polls?
|
def menu_polls?
|
||||||
["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts"].include? controller_name
|
["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def menu_profiles?
|
def menu_profiles?
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
<strong><%= t("admin.menu.title_polls") %></strong>
|
<strong><%= t("admin.menu.title_polls") %></strong>
|
||||||
</a>
|
</a>
|
||||||
<ul id="polls_menu" <%= "class=is-active" if menu_polls? %>>
|
<ul id="polls_menu" <%= "class=is-active" if menu_polls? %>>
|
||||||
<li <%= 'class=active' if ["polls", "officer_assignments", "booth_assignments", "recounts"].include? controller_name %>>
|
<li <%= 'class=active' if ["polls", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name %>>
|
||||||
<%= link_to t('admin.menu.polls'), admin_polls_path %>
|
<%= link_to t('admin.menu.polls'), admin_polls_path %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to "#tab-results" do %>
|
<%= link_to admin_poll_results_path(@poll) do %>
|
||||||
<%= t("admin.polls.show.results_tab") %>
|
<%= t("admin.polls.show.results_tab") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
<h3><%= t("admin.polls.show.results_title") %></h3>
|
|
||||||
|
|
||||||
<% if @poll.partial_results.empty? %>
|
|
||||||
<div class="callout primary margin-top">
|
|
||||||
<%= t("admin.polls.show.no_results") %>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
|
|
||||||
<table class="margin">
|
|
||||||
<thead>
|
|
||||||
<th><%= t("admin.polls.show.table_whites") %></th>
|
|
||||||
<th><%= t("admin.polls.show.table_nulls") %></th>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td id="white_results"><%= @poll.white_results.sum(:amount) %></td>
|
|
||||||
<td id="null_results"><%= @poll.null_results.sum(:amount) %></td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
<% by_question = @poll.partial_results.group_by(&:question_id) %>
|
|
||||||
<% @poll.questions.each do |question| %>
|
|
||||||
<h3><%= question.title %></h3>
|
|
||||||
<table class="margin">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th><%= t("admin.polls.show.table_answer") %></th>
|
|
||||||
<th class="text-center"><%= t("admin.polls.show.table_votes") %></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% question.valid_answers.each_with_index do |answer, i| %>
|
|
||||||
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
|
|
||||||
<tr id="question_<%= question.id %>_<%= i %>_result">
|
|
||||||
<td><%= answer %></td>
|
|
||||||
<td class="text-center"><%= by_answer[answer].present? ? by_answer[answer].sum(&:amount) : 0 %></td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% end %>
|
|
||||||
@@ -5,8 +5,4 @@
|
|||||||
|
|
||||||
<%= render "search_questions" %>
|
<%= render "search_questions" %>
|
||||||
<%= render "questions" %>
|
<%= render "questions" %>
|
||||||
|
|
||||||
<div class="tabs-panel" id="tab-results">
|
|
||||||
<%= render 'results' %>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
50
app/views/admin/poll/results/index.html.erb
Normal file
50
app/views/admin/poll/results/index.html.erb
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<%= render "/admin/poll/polls/poll_header" %>
|
||||||
|
<div id="poll-resources">
|
||||||
|
<%= render "/admin/poll/polls/filter_subnav" %>
|
||||||
|
|
||||||
|
<h3><%= t("admin.results.index.title") %></h3>
|
||||||
|
|
||||||
|
<% if @partial_results.empty? %>
|
||||||
|
<div class="callout primary margin-top">
|
||||||
|
<%= t("admin.results.index.no_results") %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
|
||||||
|
<table class="margin">
|
||||||
|
<thead>
|
||||||
|
<th><%= t("admin.results.index.table_whites") %></th>
|
||||||
|
<th><%= t("admin.results.index.table_nulls") %></th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td id="white_results"><%= @poll.white_results.sum(:amount) %></td>
|
||||||
|
<td id="null_results"><%= @poll.null_results.sum(:amount) %></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<% by_question = @partial_results.group_by(&:question_id) %>
|
||||||
|
<% @poll.questions.each do |question| %>
|
||||||
|
<h3><%= question.title %></h3>
|
||||||
|
<table class="margin">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.results.index.table_answer") %></th>
|
||||||
|
<th class="text-center"><%= t("admin.results.index.table_votes") %></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% question.valid_answers.each_with_index do |answer, i| %>
|
||||||
|
<% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %>
|
||||||
|
<tr id="question_<%= question.id %>_<%= i %>_result">
|
||||||
|
<td><%= answer %></td>
|
||||||
|
<td class="text-center"><%= by_answer[answer].present? ? by_answer[answer].sum(&:amount) : 0 %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@@ -338,18 +338,12 @@ 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_results: "There are no results"
|
|
||||||
questions_title: "List of questions"
|
questions_title: "List of questions"
|
||||||
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_whites: "Blank ballots"
|
|
||||||
table_nulls: "Invalid ballots"
|
|
||||||
table_answer: Answer
|
|
||||||
table_votes: Votes
|
|
||||||
flash:
|
flash:
|
||||||
question_added: "Question added to this poll"
|
question_added: "Question added to this poll"
|
||||||
error_on_question_added: "Question could not be assigned to this poll"
|
error_on_question_added: "Question could not be assigned to this poll"
|
||||||
@@ -387,6 +381,14 @@ en:
|
|||||||
table_booth_name: "Booth"
|
table_booth_name: "Booth"
|
||||||
table_recounts: "Accumulated daily recounts (by officer)"
|
table_recounts: "Accumulated daily recounts (by officer)"
|
||||||
table_final_recount: "Final recount (by officer)"
|
table_final_recount: "Final recount (by officer)"
|
||||||
|
results:
|
||||||
|
index:
|
||||||
|
title: "Results"
|
||||||
|
no_results: "There are no results"
|
||||||
|
table_whites: "Blank ballots"
|
||||||
|
table_nulls: "Invalid ballots"
|
||||||
|
table_answer: Answer
|
||||||
|
table_votes: Votes
|
||||||
booths:
|
booths:
|
||||||
index:
|
index:
|
||||||
title: "List of booths"
|
title: "List of booths"
|
||||||
|
|||||||
@@ -338,18 +338,12 @@ 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_results: "No hay resultados"
|
|
||||||
questions_title: "Listado de preguntas asignadas"
|
questions_title: "Listado de preguntas asignadas"
|
||||||
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_whites: Papeletas en blanco
|
|
||||||
table_nulls: Papeletas nulas
|
|
||||||
table_answer: Respuesta
|
|
||||||
table_votes: Votos
|
|
||||||
flash:
|
flash:
|
||||||
question_added: "Pregunta añadida a esta votación"
|
question_added: "Pregunta añadida a esta votación"
|
||||||
error_on_question_added: "No se pudo asignar la pregunta"
|
error_on_question_added: "No se pudo asignar la pregunta"
|
||||||
@@ -387,6 +381,14 @@ es:
|
|||||||
table_booth_name: "Urna"
|
table_booth_name: "Urna"
|
||||||
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
|
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
|
||||||
table_final_recount: "Recuento final (presidente de mesa)"
|
table_final_recount: "Recuento final (presidente de mesa)"
|
||||||
|
results:
|
||||||
|
index:
|
||||||
|
title: "Resultados"
|
||||||
|
no_results: "No hay resultados"
|
||||||
|
table_whites: Papeletas en blanco
|
||||||
|
table_nulls: Papeletas nulas
|
||||||
|
table_answer: Respuesta
|
||||||
|
table_votes: Votos
|
||||||
booths:
|
booths:
|
||||||
index:
|
index:
|
||||||
title: "Lista de urnas"
|
title: "Lista de urnas"
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :recounts, only: :index
|
resources :recounts, only: :index
|
||||||
|
resources :results, only: :index
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :officers do
|
resources :officers do
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ feature 'Admin officer assignments in poll' do
|
|||||||
booth = officer_assignment.booth_assignment.booth
|
booth = officer_assignment.booth_assignment.booth
|
||||||
officer = officer_assignment.officer
|
officer = officer_assignment.officer
|
||||||
|
|
||||||
visit admin_officer_assignments_path(poll: poll, officer: officer)
|
visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id)
|
||||||
|
|
||||||
expect(page).to_not have_content 'This user has no officing shifts in this poll'
|
expect(page).to_not have_content 'This user has no officing shifts in this poll'
|
||||||
within("#poll_officer_assignment_#{officer_assignment.id}") do
|
within("#poll_officer_assignment_#{officer_assignment.id}") do
|
||||||
@@ -89,7 +89,7 @@ feature 'Admin officer assignments in poll' do
|
|||||||
date: poll.ends_at,
|
date: poll.ends_at,
|
||||||
count: 9876)
|
count: 9876)
|
||||||
|
|
||||||
visit admin_officer_assignments_path(poll: poll, officer: officer)
|
visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id)
|
||||||
|
|
||||||
within('#recount_list') { expect(page).to have_content('77') }
|
within('#recount_list') { expect(page).to have_content('77') }
|
||||||
within('#final_recount_list') { expect(page).to have_content('9876') }
|
within('#final_recount_list') { expect(page).to have_content('9876') }
|
||||||
|
|||||||
Reference in New Issue
Block a user