adds poll results to admin
simple page shows results by question, white and null results
This commit is contained in:
@@ -8,7 +8,13 @@ class Admin::Poll::PollsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
@poll = Poll.includes(:questions, booth_assignments: [:booth, :final_recounts, :recounts], 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
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class Poll < ActiveRecord::Base
|
||||
has_many :booth_assignments, class_name: "Poll::BoothAssignment"
|
||||
has_many :booths, through: :booth_assignments
|
||||
has_many :partial_results, through: :booth_assignments
|
||||
has_many :white_results, through: :booth_assignments
|
||||
has_many :null_results, through: :booth_assignments
|
||||
has_many :voters
|
||||
has_many :officer_assignments, through: :booth_assignments
|
||||
has_many :officers, through: :officer_assignments
|
||||
|
||||
@@ -9,5 +9,7 @@ class Poll
|
||||
has_many :officers, through: :officer_assignments
|
||||
has_many :voters
|
||||
has_many :partial_results
|
||||
has_many :white_results
|
||||
has_many :null_results
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,4 +22,9 @@
|
||||
<%= t("admin.polls.show.recounts_tab") %>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="tabs-title">
|
||||
<%= link_to "#tab-results" do %>
|
||||
<%= t("admin.polls.show.results_tab") %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
45
app/views/admin/poll/polls/_results.html.erb
Normal file
45
app/views/admin/poll/polls/_results.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<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 %>
|
||||
@@ -37,4 +37,8 @@
|
||||
<div class="tabs-panel" id="tab-recounts">
|
||||
<%= render 'recounting' %>
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-results">
|
||||
<%= render 'results' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user