diff --git a/app/controllers/officing/recounts_controller.rb b/app/controllers/officing/recounts_controller.rb new file mode 100644 index 000000000..0e0a79d69 --- /dev/null +++ b/app/controllers/officing/recounts_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb deleted file mode 100644 index 03e638366..000000000 --- a/app/controllers/officing/results_controller.rb +++ /dev/null @@ -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 \ No newline at end of file diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index 6d7ad8512..6cf321beb 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -1,7 +1,4 @@ class Officing::VotersController < Officing::BaseController - layout 'admin' - - before_action :authenticate_user! def new end diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb new file mode 100644 index 000000000..d1436c515 --- /dev/null +++ b/app/helpers/officing_helper.rb @@ -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 \ No newline at end of file diff --git a/app/views/officing/recounts/new.html.erb b/app/views/officing/recounts/new.html.erb new file mode 100644 index 000000000..dc78ccf89 --- /dev/null +++ b/app/views/officing/recounts/new.html.erb @@ -0,0 +1,63 @@ +<% if @officer_assignments.any? %> +

<%= t("officing.recounts.new.title", poll: @poll.name) %>

+ + <%= form_tag(officing_poll_recounts_path(@poll), {id: "officer_assignment_form"}) do %> + +
+
+ + <%= select_tag :officer_assignment_id, + officer_assignments_select_options(@officer_assignments), + { prompt: t("officing.recounts.new.select_booth_date"), + label: false } %> +
+
+ +
+
+ + <%= text_field_tag :count, nil, placeholder: t("officing.recounts.new.count_placeholder") %> +
+
+ +
+
+ <%= submit_tag t("officing.recounts.new.submit"), class: "button expanded" %> +
+
+ <% end %> +<% else %> +

<%= @poll.name %>

+
+ <%= t("officing.recounts.new.not_allowed") %> +
+<% end %> + + +<% if @recounted.any? %> +
+

<%= t("officing.recounts.new.recount_list") %>

+ + + + + + + + + <% @recounted.each do |oa| %> + + + + + + <% end %> + +
<%= t("officing.recounts.new.date") %><%= t("officing.recounts.new.booth") %><%= t("officing.recounts.new.count") %>
+ <%= l(oa.date.to_date, format: :long) %> + + <%= oa.booth_assignment.booth.name %> + + <%= oa.recount.count %> +
+<% end %> diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb deleted file mode 100644 index 178efbadd..000000000 --- a/app/views/officing/results/new.html.erb +++ /dev/null @@ -1,38 +0,0 @@ -

<%= t("officing.results.new.title") %>

- -
- -
-
- - -
- -
- - -
-
- -
-
- - -
-
- -
- -
-
- - "> -
-
- -
-
- " class="button expanded"> -
-
-
diff --git a/config/locales/officing.en.yml b/config/locales/officing.en.yml index 87d4e77c4..fad63ee4e 100644 --- a/config/locales/officing.en.yml +++ b/config/locales/officing.en.yml @@ -14,6 +14,21 @@ en: no_polls: You are not officing in any active poll select_poll: Select poll 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: new: title: Validate document diff --git a/config/locales/officing.es.yml b/config/locales/officing.es.yml index 0831ba821..1a8bccb13 100644 --- a/config/locales/officing.es.yml +++ b/config/locales/officing.es.yml @@ -14,6 +14,21 @@ es: no_polls: "No eres presidente de mesa en ninguna votación activa" select_poll: "Selecciona votación" 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: new: title: Validar documento diff --git a/config/routes.rb b/config/routes.rb index 98011d005..ef064513e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -290,8 +290,8 @@ Rails.application.routes.draw do namespace :officing do resources :polls, only: [:index] do + resources :recounts, only: [:new, :create] resources :voters, only: [:new, :show] - resources :results, only: [:new, :index, :show] end root to: "dashboard#index" end