adds recounting to officing

This commit is contained in:
Juanjo Bazán
2017-01-03 22:23:54 +01:00
parent 09dac72471
commit 0953a536af
9 changed files with 150 additions and 57 deletions

View File

@@ -0,0 +1,45 @@
class Officing::RecountsController < Officing::BaseController
before_action :load_poll
before_action :load_officer_assignment, only: :create
def new
@officer_assignments = ::Poll::OfficerAssignment.
includes(:recount, booth_assignment: :booth).
joins(:booth_assignment).
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id).
order(date: :asc)
@recounted = @officer_assignments.select {|oa| oa.recount.present?}.reverse
end
def create
@recount = ::Poll::Recount.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id, date: @officer_assignment.date)
@recount.officer_assignment_id = @officer_assignment.id
@recount.count = recount_params[:count]
if @recount.save
notice = t("officing.recounts.flash.create")
else
notice = t("officing.recounts.flash.error_create")
end
redirect_to new_officing_poll_recount_path(@poll), notice: notice
end
private
def load_poll
@poll = Poll.current.find(params[:poll_id])
end
def load_officer_assignment
@officer_assignment = current_user.poll_officer.
officer_assignments.find_by(id: recount_params[:officer_assignment_id])
if @officer_assignment.blank?
redirect_to new_officing_poll_recount_path(@poll), notice: t("officing.recounts.flash.error_create")
end
end
def recount_params
params.permit(:officer_assignment_id, :count)
end
end

View File

@@ -1,15 +0,0 @@
class Officing::ResultsController < Officing::BaseController
layout 'admin'
before_action :authenticate_user!
def index
end
def show
end
def new
end
end

View File

@@ -1,7 +1,4 @@
class Officing::VotersController < Officing::BaseController class Officing::VotersController < Officing::BaseController
layout 'admin'
before_action :authenticate_user!
def new def new
end end

View File

@@ -0,0 +1,11 @@
module OfficingHelper
def officer_assignments_select_options(officer_assignments)
options = []
officer_assignments.each do |oa|
options << ["#{oa.booth_assignment.booth.name}: #{l(oa.date.to_date, format: :long)}", oa.id]
end
options_for_select(options)
end
end

View File

@@ -0,0 +1,63 @@
<% if @officer_assignments.any? %>
<h2><%= t("officing.recounts.new.title", poll: @poll.name) %></h2>
<%= form_tag(officing_poll_recounts_path(@poll), {id: "officer_assignment_form"}) do %>
<!-- Maybe this fields pre filled and disabled? -->
<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.recounts.new.booth_date") %></label>
<%= select_tag :officer_assignment_id,
officer_assignments_select_options(@officer_assignments),
{ prompt: t("officing.recounts.new.select_booth_date"),
label: false } %>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<label><%= t("officing.recounts.new.count") %></label>
<%= text_field_tag :count, nil, placeholder: t("officing.recounts.new.count_placeholder") %>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<%= submit_tag t("officing.recounts.new.submit"), class: "button expanded" %>
</div>
</div>
<% end %>
<% else %>
<h2><%= @poll.name %></h2>
<div class="callout alert">
<%= t("officing.recounts.new.not_allowed") %>
</div>
<% end %>
<% if @recounted.any? %>
<hr>
<h3><%= t("officing.recounts.new.recount_list") %></h3>
<table>
<thead>
<th><%= t("officing.recounts.new.date") %></th>
<th><%= t("officing.recounts.new.booth") %></th>
<th><%= t("officing.recounts.new.count") %></th>
</thead>
<tbody>
<% @recounted.each do |oa| %>
<tr id="<%= dom_id(oa.recount) %>">
<td>
<%= l(oa.date.to_date, format: :long) %>
</td>
<td>
<%= oa.booth_assignment.booth.name %>
</td>
<td>
<strong><%= oa.recount.count %></strong>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@@ -1,38 +0,0 @@
<h2><%= t("officing.results.new.title") %></h2>
<form>
<!-- Maybe this fields pre filled and disabled? -->
<div class="row">
<div class="small-12 medium-6 column">
<label><%= t("officing.shared.booth") %></label>
<input type="text" value="Booth Name (N)">
</div>
<div class="small-12 medium-6 column">
<label><%= t("officing.shared.date") %></label>
<input type="datetime" value="<%= Date.today %>">
</div>
</div>
<div class="row">
<div class="small-12 column">
<label><%= t("officing.shared.officer") %></label>
<input type="text" value="Officer Name (officer@email.com)" disabled>
</div>
</div>
<!-- /. Maybe this fields pre fill and disabled? -->
<hr>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<label><%= t("officing.shared.votes_number") %></label>
<input type="text" placeholder="<%= t("officing.shared.votes_number") %>">
</div>
</div>
<div class="row">
<div class="small-12 medium-6 large-4 column">
<input type="submit" value="<%= t("officing.results.new.submit") %>" class="button expanded">
</div>
</div>
</form>

View File

@@ -14,6 +14,21 @@ en:
no_polls: You are not officing in any active poll no_polls: You are not officing in any active poll
select_poll: Select poll select_poll: Select poll
add_recount: Add recount add_recount: Add recount
recounts:
flash:
create: "Data added"
error_create: "Count NOT added. Error in data."
new:
title: "%{poll} - Add daily recount"
not_allowed: "You are not a poll officer for this poll"
booth_date: "Booth and date"
select_booth_date: "Select booth and date"
count: "Vote count"
count_placeholder: "Vote count"
submit: Save
recount_list: "Your recounts"
booth: "Booth"
date: "Date"
voters: voters:
new: new:
title: Validate document title: Validate document

View File

@@ -14,6 +14,21 @@ es:
no_polls: "No eres presidente de mesa en ninguna votación activa" no_polls: "No eres presidente de mesa en ninguna votación activa"
select_poll: "Selecciona votación" select_poll: "Selecciona votación"
add_recount: "Añadir recuento" add_recount: "Añadir recuento"
recounts:
flash:
create: "Datos añadidos"
error_create: "Recuento NO añadido. Error en los datos"
new:
title: "%{poll} - Añadir recuento diario"
not_allowed: "No eres presidente de mesa en esta votación"
booth_date: "Fecha y urna"
select_booth_date: "Elige fecha y urna"
count: "Número de votos"
count_placeholder: "Número de votos"
submit: "Guardar"
recount_list: "Tus recuentos"
booth: "Urna"
date: "Fecha"
voters: voters:
new: new:
title: Validar documento title: Validar documento

View File

@@ -290,8 +290,8 @@ Rails.application.routes.draw do
namespace :officing do namespace :officing do
resources :polls, only: [:index] do resources :polls, only: [:index] do
resources :recounts, only: [:new, :create]
resources :voters, only: [:new, :show] resources :voters, only: [:new, :show]
resources :results, only: [:new, :index, :show]
end end
root to: "dashboard#index" root to: "dashboard#index"
end end