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
|
||||
|
||||
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
|
||||
|
||||
def menu_profiles?
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<strong><%= t("admin.menu.title_polls") %></strong>
|
||||
</a>
|
||||
<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 %>
|
||||
</li>
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to "#tab-results" do %>
|
||||
<%= link_to admin_poll_results_path(@poll) do %>
|
||||
<%= t("admin.polls.show.results_tab") %>
|
||||
<% end %>
|
||||
</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 "questions" %>
|
||||
|
||||
<div class="tabs-panel" id="tab-results">
|
||||
<%= render 'results' %>
|
||||
</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>
|
||||
Reference in New Issue
Block a user