Merge pull request #1421 from consul/admin-polls-improvements

Admin polls improvements
This commit is contained in:
Raimond Garcia
2017-02-14 19:58:00 +01:00
committed by GitHub
10 changed files with 50 additions and 11 deletions

View File

@@ -3,7 +3,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController
before_action :load_poll, except: [:create, :destroy]
def index
@booth_assignments = @poll.booth_assignments.includes(:booth)
@booth_assignments = @poll.booth_assignments.includes(:booth).order('poll_booths.name').page(params[:page]).per(50)
end
def search_booths

View File

@@ -5,7 +5,12 @@ class Admin::Poll::OfficerAssignmentsController < Admin::BaseController
before_action :load_booth_assignment, only: [:create]
def index
@officers = @poll.officer_assignments.includes(officer: :user).select(:officer_id).distinct.map(&:officer)
@officers = ::Poll::Officer.
includes(:user).
order('users.username').
where(
id: @poll.officer_assignments.select(:officer_id).distinct.map(&:officer_id)
).page(params[:page]).per(50)
end
def by_officer

View File

@@ -2,7 +2,10 @@ class Admin::Poll::RecountsController < Admin::BaseController
before_action :load_poll
def index
@booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts)
@booth_assignments = @poll.booth_assignments.
includes(:booth, :recounts, :final_recounts, :voters).
order(created_at: :desc).
page(params[:page]).per(50)
end
private

View File

@@ -4,4 +4,12 @@ module PollRecountsHelper
recounts.select {|r| r.date == date}.first
end
def booth_assignment_sum_recounts(ba)
ba.recounts.any? ? ba.recounts.to_a.sum(&:count) : nil
end
def booth_assignment_sum_final_recounts(ba)
ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) :nil
end
end

View File

@@ -5,7 +5,7 @@
<h3><%= t("admin.poll_booth_assignments.index.booths_title") %></h3>
<% if @poll.booth_assignments.empty? %>
<% if @booth_assignments.empty? %>
<div class="callout primary margin-top">
<%= t("admin.poll_booth_assignments.index.no_booths") %>
</div>
@@ -17,7 +17,7 @@
<th class="text-right"><%= t("admin.poll_booth_assignments.index.table_assignment") %></th>
</thead>
<tbody>
<% @poll.booth_assignments.each do |booth_assignment| %>
<% @booth_assignments.each do |booth_assignment| %>
<tr id="<%= dom_id(booth_assignment) %>" class="booth">
<td>
<strong>
@@ -37,5 +37,7 @@
<% end %>
</tbody>
</table>
<%= paginate @booth_assignments %>
<% end %>
</div>

View File

@@ -37,5 +37,7 @@
<% end %>
</tbody>
</table>
<%= paginate @officers %>
<% end %>
</div>

View File

@@ -14,32 +14,45 @@
<th><%= t("admin.recounts.index.table_booth_name") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_recounts") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_system_count") %></th>
</thead>
<tbody>
<% @booth_assignments.each do |booth_assignment| %>
<% recount = booth_assignment_sum_recounts(booth_assignment) %>
<% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %>
<% system_count = booth_assignment.voters.size %>
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
</strong>
</td>
<td class="text-center">
<% if booth_assignment.recounts.any? %>
<%= booth_assignment.recounts.to_a.sum(&:count) %>
<td class="text-center <%= 'count-error' if recount.to_i != system_count %>">
<% if recount.present? %>
<%= recount %>
<% else %>
<span>-</span>
<% end %>
</td>
<td class="text-center <%= 'count-error' if final_recount.to_i != system_count %>">
<% if final_recount.present? %>
<strong><%= final_recount %></strong>
<% else %>
<span>-</span>
<% end %>
</td>
<td class="text-center">
<% if booth_assignment.final_recounts.any? %>
<strong><%= booth_assignment.final_recounts.to_a.sum(&:count) %></strong>
<% if system_count.present? %>
<strong><%= system_count %></strong>
<% else %>
<span>-</span>
<span>0</span>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @booth_assignments %>
<% end %>
</div>

View File

@@ -381,6 +381,7 @@ en:
table_booth_name: "Booth"
table_recounts: "Accumulated daily recounts (by officer)"
table_final_recount: "Final recount (by officer)"
table_system_count: "Votes (automatic)"
results:
index:
title: "Results"

View File

@@ -381,6 +381,7 @@ es:
table_booth_name: "Urna"
table_recounts: "Recuentos diarios acumulados (presidente de mesa)"
table_final_recount: "Recuento final (presidente de mesa)"
table_system_count: "Votos (automático)"
results:
index:
title: "Resultados"

View File

@@ -258,6 +258,9 @@ feature 'Admin polls' do
date: poll.starts_at + i.days,
count: 21) }
2.times { create(:poll_voter,
booth_assignment: booth_assignment_final_recounted) }
create(:poll_recount,
booth_assignment: booth_assignment_recounted,
date: poll.ends_at,
@@ -290,6 +293,7 @@ feature 'Admin polls' do
expect(page).to have_content(booth_assignment_final_recounted.booth.name)
expect(page).to have_content('-')
expect(page).to have_content('55555')
expect(page).to have_content('2')
end
end
end