Adds ballot sheets controller and main views

This commit is contained in:
María Checa
2018-06-21 18:09:50 +02:00
committed by Javi Martín
parent 3ccdf039e4
commit ccf8d3a8e2
14 changed files with 275 additions and 9 deletions

View File

@@ -0,0 +1,77 @@
class Officing::BallotSheetsController < Officing::BaseController
before_action :verify_booth
before_action :load_poll
before_action :load_officer_assignments, only: [:new, :create]
helper_method :namespace
def index
load_ballot_sheets
end
def show
load_ballot_sheet
end
def new
end
def create
load_officer_assignment
check_officer_assignment
@ballot_sheet = Poll::BallotSheet.new(ballot_sheet_params)
if @ballot_sheet.save
redirect_to officing_poll_ballot_sheet_path(@poll, @ballot_sheet)
else
render :new
end
end
private
def namespace
"officing"
end
def load_poll
@poll = Poll.find(params[:poll_id])
end
def load_ballot_sheets
@ballot_sheets = Poll::BallotSheet.where(poll: @poll)
end
def load_ballot_sheet
@ballot_sheet = Poll::BallotSheet.find(params[:id])
end
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment.
includes(booth_assignment: [:booth]).
joins(:booth_assignment).
final.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll.id).
where(date: Date.current)
end
def load_officer_assignment
@officer_assignment = current_user.poll_officer.officer_assignments.final
.find_by(id: ballot_sheet_params[:officer_assignment_id])
end
def check_officer_assignment
if @officer_assignment.blank?
flash.now[:alert] = t("officing.results.flash.error_wrong_booth")
render :new
end
end
def ballot_sheet_params
params.permit(:data, :poll_id, :officer_assignment_id)
end
end

View File

@@ -13,6 +13,12 @@ class Officing::BaseController < ApplicationController
raise CanCan::AccessDenied unless current_user.try(:poll_officer?) raise CanCan::AccessDenied unless current_user.try(:poll_officer?)
end end
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
def load_officer_assignment def load_officer_assignment
@officer_assignments ||= current_user.poll_officer. @officer_assignments ||= current_user.poll_officer.
officer_assignments. officer_assignments.

View File

@@ -0,0 +1,61 @@
class Officing::PollBallotSheetsController < Officing::BaseController
before_action :verify_booth
before_action :load_poll
before_action :load_ballot_sheets, only: :index
before_action :load_ballot_sheet, only: :show
before_action :load_officer_assignments, only: :new
before_action :load_officer_assignment, only: :create
before_action :check_officer_assignment, only: :create
helper_method :namespace
def index
end
def show
end
def new
end
def create
Poll::BallotSheet.create(ballot_sheet_params)
render :show
end
private
def namespace
"officing"
end
def load_poll
@poll = Poll.find(params[:poll_id])
end
def load_ballot_sheets
@ballot_sheets = Poll::BallotSheet.where(poll: @poll)
end
def load_ballot_sheet
@ballot_sheet = Poll::BallotSheet.find(params[:ballot_sheet_id])
end
def load_officer_assignments
@officer_assignments = ::Poll::OfficerAssignment.
includes(booth_assignment: [:booth]).
joins(:booth_assignment).
final.
where(id: current_user.poll_officer.officer_assignment_ids).
where("poll_booth_assignments.poll_id = ?", @poll_budget.id).
where(date: Date.current)
end
def ballot_sheet_params
params.permit(:csv_data, :poll_id, :officer_assignment_id)
end
end

View File

@@ -33,12 +33,6 @@ class Officing::ResultsController < Officing::BaseController
private private
def check_officer_assignment
if @officer_assignment.blank?
go_back_to_new(t("officing.results.flash.error_wrong_booth"))
end
end
def build_results def build_results
@results = [] @results = []

View File

@@ -0,0 +1,26 @@
<h2><%= t("officing.poll_budgets.index.title", poll_budget: @poll_budget) %></h2>
<% if @ballot_sheets.any? %>
<table class="fixed">
<thead>
<tr>
<th colspan="2"><%= t("officing.poll_budgets.index.ballot_sheet_name") %></th>
<th colspan="2"><%= t("officing.poll_budgets.index.ballot_sheet_author") %></th>
<th colspan="2"><%= t("officing.poll_budgets.index.ballot_sheet_creation_date") %></th>
</tr>
</thead>
<tbody>
<% @ballot_sheets.each do |ballot_sheet| %>
<tr id="<%= dom_id(ballot_sheet) %>" class="ballot_sheet">
<td></td>
<td></td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="callout primary">
<%= t("officing.poll_budgets.index.empty_results") %>
</div>
<% end %>

View File

@@ -0,0 +1,16 @@
<% if @officer_assignments.any? %>
<h2><%= t("officing.poll_budgets.new.title", poll: @poll.name) %></h2>
<%= form_tag(officing_poll_ballot_sheets_path(@poll)) do %>
<label><%= t("officing.poll_budgets.new.booth") %></label>
<%= select_tag :officer_assignment_id,
booths_for_officer_select_options(@officer_assignments),
{ prompt: t("officing.poll_budgets.new.select_booth"),
label: false } %>
<label><%= t("officing.poll_budgets.new.csv_data") %></label>
<%= text_area_tag :csv_data, nil, rows: 10 %>
<%= submit_tag t("officing.poll_budgets.new.submit"), class: "button" %>
<% end %>
<% end %>

View File

@@ -14,9 +14,19 @@
</strong> </strong>
</td> </td>
<td class="text-right"> <td class="text-right">
<% if poll.budget.present? %>
<%= link_to t("officing.poll_budgets.see_ballot_sheets"),
officing_poll_ballot_sheets_path(poll),
class: "button" %>
<%= link_to t("officing.polls.final.add_results"),
new_officing_poll_ballot_sheet_path(poll),
class: "button hollow" %>
<% else %>
<%= link_to t("officing.polls.final.add_results"), <%= link_to t("officing.polls.final.add_results"),
new_officing_poll_result_path(poll), new_officing_poll_result_path(poll),
class: "button hollow" %> class: "button hollow" %>
<% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>

View File

@@ -61,6 +61,9 @@ en:
poll/officer: poll/officer:
one: "officer" one: "officer"
other: "officers" other: "officers"
poll/ballot_sheet:
one: Ballot sheet
other: Ballot sheets
proposal: proposal:
one: "Citizen proposal" one: "Citizen proposal"
other: "Citizen proposals" other: "Citizen proposals"
@@ -208,6 +211,10 @@ en:
external_url: "Link to additional documentation" external_url: "Link to additional documentation"
poll/question/translation: poll/question/translation:
title: "Question" title: "Question"
poll/ballot_sheet:
data: CSV data
poll_id: Poll
officer_assignment_id: Officer assignment
signature_sheet: signature_sheet:
signable_type: "Signable type" signable_type: "Signable type"
signable_id: "Signable ID" signable_id: "Signable ID"

View File

@@ -16,6 +16,20 @@ en:
no_polls: You are not officing final recounts in any active poll no_polls: You are not officing final recounts in any active poll
select_poll: Select poll select_poll: Select poll
add_results: Add results add_results: Add results
poll_budgets:
see_ballot_sheets: See ballot sheets list
index:
title: "%{poll_budget} - Ballot sheets list"
ballot_sheet_name: Name
ballot_sheet_author: Author
ballot_sheet_creation_date: Creation date
empty_results: There are no ballot sheets for this poll yet
new:
title: "%{poll_budget} - New ballot sheet"
booth: Booth
select_booth: Select booth
csv_data: CSV data
submit: Save
booth: booth:
new: new:
title: "Choose your booth" title: "Choose your booth"

View File

@@ -61,6 +61,9 @@ es:
poll/officer: poll/officer:
one: "presidente de mesa" one: "presidente de mesa"
other: "presidentes de mesa" other: "presidentes de mesa"
poll/ballot_sheet:
one: Papeleta de votación
other: Papeletas de votación
proposal: proposal:
one: "Propuesta ciudadana" one: "Propuesta ciudadana"
other: "Propuestas ciudadanas" other: "Propuestas ciudadanas"
@@ -208,6 +211,10 @@ es:
external_url: "Enlace a documentación adicional" external_url: "Enlace a documentación adicional"
poll/question/translation: poll/question/translation:
title: "Pregunta" title: "Pregunta"
poll/ballot_sheet:
data: Datos de CSV
poll_id: Votación
officer_assignment_id: Turno
signature_sheet: signature_sheet:
signable_type: "Tipo de hoja de firmas" signable_type: "Tipo de hoja de firmas"
signable_id: "ID Propuesta ciudadana/Proyecto de gasto" signable_id: "ID Propuesta ciudadana/Proyecto de gasto"

View File

@@ -16,6 +16,20 @@ es:
no_polls: No tienes permiso para recuento final en ninguna votación reciente no_polls: No tienes permiso para recuento final en ninguna votación reciente
select_poll: Selecciona votación select_poll: Selecciona votación
add_results: Añadir resultados add_results: Añadir resultados
poll_budgets:
see_ballot_sheets: Ver lista de papeletas de votación
index:
title: "%{poll_budget} - Listado de papeletas de votación"
ballot_sheet_name: Nombre
ballot_sheet_author: Autor
ballot_sheet_creation_date: Fecha de creación
empty_results: Aún no se han subido papeletas de votación
new:
title: "%{poll_budget} - Nueva papeleta de votación"
booth: Urna
select_booth: Elegir urna
csv_data: Datos de CSV
submit: Guardar
booth: booth:
new: new:
title: "Escoge tu urna" title: "Escoge tu urna"

View File

@@ -2,6 +2,8 @@ namespace :officing do
resources :polls, only: [:index] do resources :polls, only: [:index] do
get :final, on: :collection get :final, on: :collection
resources :results, only: [:new, :create, :index] resources :results, only: [:new, :create, :index]
resources :ballot_sheets, only: [:new, :create, :show, :index]
end end
resource :booth, controller: "booth", only: [:new, :create] resource :booth, controller: "booth", only: [:new, :create]

View File

@@ -0,0 +1,32 @@
require "rails_helper"
feature "Poll budget ballot sheets" do
let(:budget) { create(:budget) }
let(:poll) { create(:poll, budget: budget, ends_at: 1.day.ago) }
let(:booth) { create(:poll_booth) }
let(:poll_officer) { create(:poll_officer) }
background do
create(:poll_booth_assignment, poll: poll, booth: booth)
create(:poll_shift, :recount_scrutiny_task, officer: poll_officer, booth: booth, date: Date.current)
create(:poll_officer_assignment, officer: poll_officer)
login_as(poll_officer.user)
set_officing_booth(booth)
end
scenario "Budget polls are visible in 'Recounts and results' view" do
visit root_path
click_link "Polling officers"
within("#side_menu") do
click_link "Total recounts and results"
end
within("#poll_#{poll.id}") do
expect(page).to have_content("#{poll.name}")
expect(page).to have_content("See ballot sheets list")
expect(page).to have_content("Add results")
end
end
end