refactors poll results into partial
This commit is contained in:
37
app/views/admin/poll/results/_result.html.erb
Normal file
37
app/views/admin/poll/results/_result.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<table class="margin">
|
||||
<thead>
|
||||
<th><%= t("admin.results.index.table_whites") %></th>
|
||||
<th><%= t("admin.results.index.table_nulls") %></th>
|
||||
<th><%= t("admin.results.index.table_total") %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="white_results"><%= @poll.recounts.sum(:white_amount) %></td>
|
||||
<td id="null_results"><%= @poll.recounts.sum(:null_amount) %></td>
|
||||
<td id="total_results"><%= @poll.recounts.sum(:total_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.question_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.title %></td>
|
||||
<td class="text-center"><%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
@@ -9,44 +9,6 @@
|
||||
<%= 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>
|
||||
<th><%= t("admin.results.index.table_total") %></th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td id="white_results"><%= @poll.recounts.sum(:white_amount) %></td>
|
||||
<td id="null_results"><%= @poll.recounts.sum(:null_amount) %></td>
|
||||
<td id="total_results"><%= @poll.recounts.sum(:total_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.question_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.title %></td>
|
||||
<td class="text-center"><%= by_answer[answer.title].present? ? by_answer[answer.title].sum(&:amount) : 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
<%= render "result" %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user