adds index view for poll results in officing

This commit is contained in:
Juanjo Bazán
2017-02-02 16:10:40 +01:00
parent d9fa4bdc29
commit ec8d45f3cd
7 changed files with 120 additions and 3 deletions

View File

@@ -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

View 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 %>

View File

@@ -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 %>