adds creation of null and white results by poll officers

This commit is contained in:
Juanjo Bazán
2017-02-03 19:11:04 +01:00
parent c9c4b30ffc
commit 2a902c68eb
8 changed files with 211 additions and 7 deletions

View File

@@ -26,6 +26,8 @@ class Officing::ResultsController < Officing::BaseController
@partial_results = ::Poll::PartialResult.includes(:question).
where(booth_assignment_id: index_params[:booth_assignment_id]).
where(date: index_params[:date])
@whites = ::Poll::WhiteResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
@nulls = ::Poll::NullResult.where(booth_assignment_id: @booth_assignment.id, date: index_params[:date]).sum(:amount)
end
end
@@ -65,6 +67,33 @@ class Officing::ResultsController < Officing::BaseController
end
end
end
build_white_results
build_null_results
end
def build_white_results
if results_params[:whites].present?
white_result = ::Poll::WhiteResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date])
white_result.officer_assignment_id = @officer_assignment.id
white_result.amount = results_params[:whites].to_i
white_result.author = current_user
white_result.origin = 'booth'
@results << white_result
end
end
def build_null_results
if results_params[:nulls].present?
white_result = ::Poll::WhiteResult.find_or_initialize_by(booth_assignment_id: @officer_assignment.booth_assignment_id,
date: results_params[:date])
white_result.officer_assignment_id = @officer_assignment.id
white_result.amount = results_params[:nulls].to_i
white_result.author = current_user
white_result.origin = 'booth'
@results << white_result
end
end
def go_back_to_new(alert = nil)
@@ -102,7 +131,7 @@ class Officing::ResultsController < Officing::BaseController
end
def results_params
params.permit(:officer_assignment_id, :date, :questions)
params.permit(:officer_assignment_id, :date, :questions, :whites, :nulls)
end
def index_params

View File

@@ -8,8 +8,24 @@
</h3>
</div>
<div class="row">
<div class="small-12 medium-9 column">
<table>
<thead>
<tr>
<th><%= t("officing.results.index.table_whites") %></th>
<th><%= t("officing.results.index.table_nulls") %></th>
</tr>
</thead>
<tbody>
<tr>
<td id="white_results"><%= @whites %></td>
<td id="null_results"><%= @nulls %></td>
</tr>
</tbody>
</table>
<% by_question = @partial_results.group_by(&:question_id) %>
<% @poll.questions.each do |question| %>
<h3><%= question.title %></h3>
@@ -31,7 +47,6 @@
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>

View File

@@ -39,13 +39,13 @@
<div class="row">
<div class="small-12 medium-6 large-3 column">
<h3><%= t("officing.results.new.ballots_blank") %></h3>
<%= text_field_tag :count, nil, placeholder: "0" %>
<h3><%= t("officing.results.new.ballots_white") %></h3>
<%= text_field_tag :whites, params[:whites].presence, placeholder: "0" %>
</div>
<div class="small-12 medium-6 large-3 column end">
<h3><%= t("officing.results.new.ballots_null") %></h3>
<%= text_field_tag :count, nil, placeholder: "0" %>
<%= text_field_tag :nulls, params[:nulls].presence, placeholder: "0" %>
</div>
</div>
<hr>