adds index view for poll results in officing
This commit is contained in:
@@ -18,6 +18,17 @@ class Officing::ResultsController < Officing::BaseController
|
||||
redirect_to new_officing_poll_result_path(@poll), notice: notice
|
||||
end
|
||||
|
||||
def index
|
||||
@booth_assignment = ::Poll::BoothAssignment.includes(:booth).find(index_params[:booth_assignment_id])
|
||||
if current_user.poll_officer.officer_assignments.final.
|
||||
where(booth_assignment_id: @booth_assignment.id).exists?
|
||||
|
||||
@partial_results = ::Poll::PartialResult.includes(:question).
|
||||
where(booth_assignment_id: index_params[:booth_assignment_id]).
|
||||
where(date: index_params[:date])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_booth_and_date
|
||||
@@ -93,4 +104,8 @@ class Officing::ResultsController < Officing::BaseController
|
||||
params.permit(:officer_assignment_id, :date, :questions)
|
||||
end
|
||||
|
||||
def index_params
|
||||
params.permit(:booth_assignment_id, :date)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
30
app/views/officing/results/index.html.erb
Normal file
30
app/views/officing/results/index.html.erb
Normal file
@@ -0,0 +1,30 @@
|
||||
<%= back_link_to new_officing_poll_result_path(@poll) %>
|
||||
<h2><%= @poll.name %> - <%= t("officing.results.index.results") %></h2>
|
||||
|
||||
<% if @partial_results.present? %>
|
||||
<div class="callout primary">
|
||||
<h3><%= @booth_assignment.booth.name %> - <%= l @partial_results.first.date, format: :long %></h3>
|
||||
</div>
|
||||
|
||||
<% by_question = @partial_results.group_by(&:question_id) %>
|
||||
<% @poll.questions.each do |question| %>
|
||||
<h3><%= question.title %></h3>
|
||||
|
||||
<table>
|
||||
<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><%= by_answer[answer].present? ? by_answer[answer].first.amount : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="callout primary">
|
||||
<%= t("officing.results.index.no_results") %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -81,13 +81,13 @@
|
||||
<% results_by_booth[booth_assignment].group_by(&:date).keys.each do |date| %>
|
||||
<tr id="results_<%= booth_assignment %>_<%= date.strftime('%Y%m%d') %>">
|
||||
<td>
|
||||
<%= l(date.to_date, format: :long) %>
|
||||
<%= l(date, format: :long) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= results_by_booth[booth_assignment].first.booth_assignment.booth.name %>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<%= link_to t("officing.results.new.see_results"), officing_poll_results_path(@poll, date: l(date), booth_assignment_id: booth_assignment) %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user