From 20e31133a8dc589354aeaaba788ea778f5713189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 13:00:19 +0100 Subject: [PATCH 1/8] extracts booth_assignment from admin's poll/show --- .../poll/booth_assignments_controller.rb | 49 ++++++++++++++----- .../admin/poll/polls_controller.rb | 7 --- .../_search_booths.html.erb | 2 +- .../_search_booths_results.html.erb | 17 +++---- .../poll/booth_assignments/index.html.erb | 41 ++++++++++++++++ .../search_booths.js.erb | 0 .../poll/booth_assignments/show.html.erb | 2 +- app/views/admin/poll/polls/_booths.html.erb | 35 ------------- .../admin/poll/polls/_filter_subnav.html.erb | 22 ++++----- .../admin/poll/polls/_poll_header.html.erb | 17 +++++++ .../polls/_search_officers_results.html.erb | 4 +- .../polls/_search_questions_results.html.erb | 4 +- app/views/admin/poll/polls/show.html.erb | 27 ++-------- config/locales/admin.en.yml | 28 ++++++----- config/locales/admin.es.yml | 28 ++++++----- config/routes.rb | 6 +-- 16 files changed, 156 insertions(+), 133 deletions(-) rename app/views/admin/poll/{polls => booth_assignments}/_search_booths.html.erb (81%) rename app/views/admin/poll/{polls => booth_assignments}/_search_booths_results.html.erb (55%) create mode 100644 app/views/admin/poll/booth_assignments/index.html.erb rename app/views/admin/poll/{polls => booth_assignments}/search_booths.js.erb (100%) delete mode 100644 app/views/admin/poll/polls/_booths.html.erb create mode 100644 app/views/admin/poll/polls/_poll_header.html.erb diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 2c9755d6a..a6d9eecd0 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -1,31 +1,44 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController + before_action :load_poll, except: [:create, :destroy] + + def index + @booth_assignments = @poll.booth_assignments.includes(:booth) + end + + def search_booths + load_search + @booths = ::Poll::Booth.search(@search) + respond_to do |format| + format.js + end + end + + def show + @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id]) + @voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date} + end + def create @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll], booth_id: booth_assignment_params[:booth]) if @booth_assignment.save - notice = t("admin.booth_assignments.flash.create") + notice = t("admin.poll_booth_assignments.flash.create") else - notice = t("admin.booth_assignments.flash.error_create") + notice = t("admin.poll_booth_assignments.flash.error_create") end - redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice + redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice end def destroy @booth_assignment = ::Poll::BoothAssignment.find(params[:id]) if @booth_assignment.destroy - notice = t("admin.booth_assignments.flash.destroy") + notice = t("admin.poll_booth_assignments.flash.destroy") else - notice = t("admin.booth_assignments.flash.error_destroy") + notice = t("admin.poll_booth_assignments.flash.error_destroy") end - redirect_to admin_poll_path(@booth_assignment.poll_id, anchor: 'tab-booths'), notice: notice - end - - def show - @poll = ::Poll.find(params[:poll_id]) - @booth_assignment = @poll.booth_assignments.includes(:recounts, :final_recounts, :voters, officer_assignments: [officer: [:user]]).find(params[:id]) - @voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date} + redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice end private @@ -38,4 +51,16 @@ class Admin::Poll::BoothAssignmentsController < Admin::BaseController params.permit(:booth, :poll) end + def load_poll + @poll = ::Poll.find(params[:poll_id]) + end + + def search_params + params.permit(:poll_id, :search) + end + + def load_search + @search = search_params[:search] + end + end \ No newline at end of file diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 66a831d72..340cbec71 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -63,13 +63,6 @@ class Admin::Poll::PollsController < Admin::BaseController redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice end - def search_booths - @booths = ::Poll::Booth.search(@search) - respond_to do |format| - format.js - end - end - def search_questions @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}).order(title: :asc) respond_to do |format| diff --git a/app/views/admin/poll/polls/_search_booths.html.erb b/app/views/admin/poll/booth_assignments/_search_booths.html.erb similarity index 81% rename from app/views/admin/poll/polls/_search_booths.html.erb rename to app/views/admin/poll/booth_assignments/_search_booths.html.erb index a02c9e6ec..e96e334c7 100644 --- a/app/views/admin/poll/polls/_search_booths.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths.html.erb @@ -1,6 +1,6 @@
- <%= form_tag(search_booths_admin_poll_path(@poll), method: :get, remote: true) do |f| %> + <%= form_tag(search_booths_admin_poll_booth_assignments_path(@poll), method: :get, remote: true) do |f| %>
<%= text_field_tag :search, @search, diff --git a/app/views/admin/poll/polls/_search_booths_results.html.erb b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb similarity index 55% rename from app/views/admin/poll/polls/_search_booths_results.html.erb rename to app/views/admin/poll/booth_assignments/_search_booths_results.html.erb index 3768fa222..8f11ff5ae 100644 --- a/app/views/admin/poll/polls/_search_booths_results.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb @@ -1,18 +1,18 @@ <% if @booths.blank? %>
- <%= t('admin.polls.show.no_search_results') %> + <%= t('admin.shared.no_search_results') %>
<% else %> -

<%= t('admin.polls.show.search_results') %>

+

<%= t('admin.shared.search_results') %>

<% end %> <% if @booths.any? %> - - - + + + @@ -26,13 +26,12 @@ +
<%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_location") %><%= t("admin.polls.show.table_assignment") %><%= t("admin.poll_booth_assignments.index.table_name") %><%= t("admin.poll_booth_assignments.index.table_location") %><%= t("admin.poll_booth_assignments.index.table_assignment") %>
<% if @poll.booth_ids.include?(booth.id) %> - <%= link_to t("admin.polls.show.remove_booth"), - admin_booth_assignment_path(poll: @poll, booth: booth), + <%= link_to t("admin.poll_booth_assignments.index.remove_booth"), method: :delete, class: "button hollow alert" %> <% else %> - <%= link_to t("admin.polls.show.add_booth"), - admin_booth_assignments_path(poll: @poll, booth: booth), + <%= link_to t("admin.poll_booth_assignments.index.add_booth"), + admin_poll_booth_assignments_path(poll: @poll, booth: booth), method: :post, class: "button hollow" %> <% end %> diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb new file mode 100644 index 000000000..e17281c98 --- /dev/null +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -0,0 +1,41 @@ +<%= render "/admin/poll/polls/poll_header" %> +
+ <%= render "/admin/poll/polls/filter_subnav" %> + <%= render "search_booths" %> + +

<%= t("admin.poll_booth_assignments.index.booths_title") %>

+ + <% if @poll.booth_assignments.empty? %> +
+ <%= t("admin.poll_booth_assignments.index.no_booths") %> +
+ <% else %> + + + + + + + + <% @poll.booth_assignments.each do |booth_assignment| %> + + + + + + <% end %> + +
<%= t("admin.poll_booth_assignments.index.table_name") %><%= t("admin.poll_booth_assignments.index.table_location") %><%= t("admin.poll_booth_assignments.index.table_assignment") %>
+ + <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %> + + + <%= booth_assignment.booth.location %> + + <%= link_to t("admin.poll_booth_assignments.index.remove_booth"), + admin_poll_booth_assignment_path(@poll, booth_assignment), + method: :delete, + class: "button hollow alert" %> +
+ <% end %> +
diff --git a/app/views/admin/poll/polls/search_booths.js.erb b/app/views/admin/poll/booth_assignments/search_booths.js.erb similarity index 100% rename from app/views/admin/poll/polls/search_booths.js.erb rename to app/views/admin/poll/booth_assignments/search_booths.js.erb diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index 7ce61791a..d8ca6eda5 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -1,4 +1,4 @@ -<%= link_to admin_poll_path(@poll, anchor: 'tab-booths') do %> +<%= link_to admin_poll_booth_assignments_path(@poll) do %> <%= @poll.name %> <% end %> diff --git a/app/views/admin/poll/polls/_booths.html.erb b/app/views/admin/poll/polls/_booths.html.erb deleted file mode 100644 index bea23b874..000000000 --- a/app/views/admin/poll/polls/_booths.html.erb +++ /dev/null @@ -1,35 +0,0 @@ -

<%= t("admin.polls.show.booths_title") %>

- -<% if @poll.booth_assignments.empty? %> -
- <%= t("admin.polls.show.no_booths") %> -
-<% else %> - - - - - - - - <% @poll.booth_assignments.each do |booth_assignment| %> - - - - - - <% end %> - -
<%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_location") %><%= t("admin.polls.show.table_assignment") %>
- - <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment) %> - - - <%= booth_assignment.booth.location %> - - <%= link_to t("admin.polls.show.remove_booth"), - admin_booth_assignment_path(booth_assignment), - method: :delete, - class: "button hollow alert" %> -
-<% end %> diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index 7d1931093..a209cf761 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -1,28 +1,28 @@ -
    -
  • - <%= link_to "#tab-questions" do %> +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/admin/poll/polls/search_officers.js.erb b/app/views/admin/poll/officer_assignments/search_officers.js.erb similarity index 100% rename from app/views/admin/poll/polls/search_officers.js.erb rename to app/views/admin/poll/officer_assignments/search_officers.js.erb diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index a209cf761..39781de37 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -12,7 +12,7 @@ <% end %>
  • - <%= link_to "#tab-officers" do %> + <%= link_to admin_poll_officer_assignments_path(@poll) do %> <%= t("admin.polls.show.officers_tab") %> (<%= @poll.officer_assignments.select(:officer_id).distinct.count %>) <% end %> diff --git a/app/views/admin/poll/polls/_officers.html.erb b/app/views/admin/poll/polls/_officers.html.erb deleted file mode 100644 index 1ef6f32cc..000000000 --- a/app/views/admin/poll/polls/_officers.html.erb +++ /dev/null @@ -1,34 +0,0 @@ -

    <%= t("admin.polls.show.officers_title") %>

    - -<% if @poll.officers.empty? %> -
    - <%= t("admin.polls.show.no_officers") %> -
    -<% else %> - - - - - - - - <% @poll.officers.uniq.each do |officer| %> - - - - - - <% end %> - -
    <%= t("admin.polls.show.table_name") %><%= t("admin.polls.show.table_email") %><%= t("admin.actions.actions") %>
    - - <%= link_to officer.name, admin_officer_assignments_path(officer: officer, poll: @poll) %> - - - <%= officer.email %> - - <%= link_to t("admin.polls.show.edit_officer_assignments"), - admin_officer_assignments_path(officer: officer, poll: @poll), - class: "button hollow" %> -
    -<% end %> \ No newline at end of file diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index 9155cc70a..835dd155b 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -8,11 +8,6 @@ <%= render "questions" %>
  • -
    - <%= render "search_officers" %> - <%= render 'officers' %> -
    -
    <%= render 'recounting' %>
    diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 87eb096e3..fabc18019 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -271,6 +271,13 @@ en: error_destroy: "An error ocurred when removing officer assignment" error_create: "An error ocurred when adding officer assignment" index: + officers_title: "List of officers" + no_officers: "There are no officers assigned to this poll." + table_name: "Name" + table_email: "Email" + add_officer_assignments: "Add shifts as officer" + edit_officer_assignments: "Edit officing shifts" + by_officer: new_assignment: "New shift" date: "Date" booth: "Booth" @@ -331,21 +338,16 @@ en: recounts_tab: Recounting results_tab: Results no_questions: "There are no questions assigned to this poll." - no_officers: "There are no officers assigned to this poll." no_recounts: "There is nothing to be recounted" no_results: "There are no results" - officers_title: "List of officers" questions_title: "List of questions" recounting_title: "Recounts" results_title: "Results" remove_question: "Remove question from poll" add_question: "Include question" - add_officer_assignments: "Add shifts as officer" - edit_officer_assignments: "Edit officing shifts" table_title: "Title" table_assignment: "Assignment" table_name: "Name" - table_email: "Email" table_booth_name: "Booth" table_final_recount: "Final recount (by officer)" table_recounts: "Accumulated daily recounts (by officer)" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 36ccda68b..5650b7ef2 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -271,6 +271,13 @@ es: error_destroy: "Se ha producido un error al eliminar el turno" error_create: "Se ha producido un error al intentar crear el turno" index: + officers_title: "Listado de presidentes de mesa asignados" + no_officers: "No hay presidentes de mesa asignados a esta votación." + table_name: "Nombre" + table_email: "Email" + add_officer_assignments: "Añadir turnos como presidente de mesa" + edit_officer_assignments: "Editar turnos" + by_officer: new_assignment: "Nuevo turno" date: "Fecha" booth: "Urna" @@ -331,21 +338,16 @@ es: recounts_tab: Recuentos results_tab: Resultados no_questions: "No hay preguntas asignadas a esta votación." - no_officers: "No hay presidentes de mesa asignados a esta votación." no_recounts: "No hay nada de lo que hacer recuento" no_results: "No hay resultados" - officers_title: "Listado de presidentes de mesa asignados" questions_title: "Listado de preguntas asignadas" recounting_title: "Recuentos" results_title: "Resultados" remove_question: "Desasignar pregunta" add_question: "Incluir pregunta" - add_officer_assignments: "Añadir turnos como presidente de mesa" - edit_officer_assignments: "Editar turnos" table_title: "Título" table_assignment: "Asignación" table_name: "Nombre" - table_email: "Email" table_booth_name: "Urna" table_final_recount: "Recuento final (presidente de mesa)" table_recounts: "Recuentos diarios acumulados (presidente de mesa)" diff --git a/config/routes.rb b/config/routes.rb index 3f51abeb6..3bcefd29a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -216,6 +216,11 @@ Rails.application.routes.draw do resources :booth_assignments, only: [:index, :show, :create, :destroy] do get :search_booths, on: :collection end + + resources :officer_assignments, only: [:index, :create, :destroy] do + get :search_officers, on: :collection + get :by_officer, on: :collection + end end resources :officers do @@ -223,7 +228,6 @@ Rails.application.routes.draw do end resources :booths - resources :officer_assignments, only: [:index, :create, :destroy] resources :questions end From bedb9f29e776c3ba8b6e2228c1819924df7ba13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 14:07:22 +0100 Subject: [PATCH 3/8] extracts recounting from admin's poll/show --- .../admin/poll/polls_controller.rb | 8 ++-- .../admin/poll/recounts_controller.rb | 13 ++++++ .../poll/booth_assignments/show.html.erb | 2 +- .../admin/poll/polls/_filter_subnav.html.erb | 2 +- .../admin/poll/polls/_recounting.html.erb | 40 ----------------- app/views/admin/poll/polls/show.html.erb | 10 +---- app/views/admin/poll/recounts/index.html.erb | 45 +++++++++++++++++++ config/locales/admin.en.yml | 12 ++--- config/locales/admin.es.yml | 12 ++--- config/routes.rb | 2 + 10 files changed, 81 insertions(+), 65 deletions(-) create mode 100644 app/controllers/admin/poll/recounts_controller.rb delete mode 100644 app/views/admin/poll/polls/_recounting.html.erb create mode 100644 app/views/admin/poll/recounts/index.html.erb diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 9f5319f9d..eda5736b0 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -8,9 +8,7 @@ class Admin::Poll::PollsController < Admin::BaseController end def show - @poll = Poll.includes(:questions, - booth_assignments: [:final_recounts, - :recounts]). + @poll = Poll.includes(:questions). order('poll_questions.title'). find(params[:id]) end @@ -46,7 +44,7 @@ class Admin::Poll::PollsController < Admin::BaseController else notice = t("admin.polls.flash.error_on_question_added") end - redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice + redirect_to admin_poll_path(@poll), notice: notice end def remove_question @@ -58,7 +56,7 @@ class Admin::Poll::PollsController < Admin::BaseController else notice = t("admin.polls.flash.error_on_question_removed") end - redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice + redirect_to admin_poll_path(@poll), notice: notice end def search_questions diff --git a/app/controllers/admin/poll/recounts_controller.rb b/app/controllers/admin/poll/recounts_controller.rb new file mode 100644 index 000000000..6df6e8ed5 --- /dev/null +++ b/app/controllers/admin/poll/recounts_controller.rb @@ -0,0 +1,13 @@ +class Admin::Poll::RecountsController < Admin::BaseController + before_action :load_poll + + def index + @booth_assignments = @poll.booth_assignments.includes(:recounts, :final_recounts) + end + + private + + def load_poll + @poll = ::Poll.find(params[:poll_id]) + end +end \ No newline at end of file diff --git a/app/views/admin/poll/booth_assignments/show.html.erb b/app/views/admin/poll/booth_assignments/show.html.erb index d8ca6eda5..519b36202 100644 --- a/app/views/admin/poll/booth_assignments/show.html.erb +++ b/app/views/admin/poll/booth_assignments/show.html.erb @@ -34,7 +34,7 @@ <% @booth_assignment.officers.uniq.each do |officer| %> - <%= link_to officer.name, admin_officer_assignments_path(officer: officer, poll: @poll) %> + <%= link_to officer.name, by_officer_admin_poll_officer_assignments_path(@poll, officer_id: officer.id) %> <%= officer.email %> <% end %> diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index 39781de37..00c83cc0a 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -18,7 +18,7 @@ <% end %>
  • - <%= link_to "#tab-recounts" do %> + <%= link_to admin_poll_recounts_path(@poll) do %> <%= t("admin.polls.show.recounts_tab") %> <% end %>
  • diff --git a/app/views/admin/poll/polls/_recounting.html.erb b/app/views/admin/poll/polls/_recounting.html.erb deleted file mode 100644 index 8fb7651ce..000000000 --- a/app/views/admin/poll/polls/_recounting.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -

    <%= t("admin.polls.show.recounting_title") %>

    - -<% if @poll.booth_assignments.empty? %> -
    - <%= t("admin.polls.show.no_recounts") %> -
    -<% else %> - - - - - - - - <% @poll.booth_assignments.each do |booth_assignment| %> - - - - - - <% end %> - -
    <%= t("admin.polls.show.table_booth_name") %><%= t("admin.polls.show.table_recounts") %><%= t("admin.polls.show.table_final_recount") %>
    - - <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %> - - - <% if booth_assignment.recounts.any? %> - <%= booth_assignment.recounts.to_a.sum(&:count) %> - <% else %> - - - <% end %> - - <% if booth_assignment.final_recounts.any? %> - <%= booth_assignment.final_recounts.to_a.sum(&:count) %> - <% else %> - - - <% end %> -
    -<% end %> diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index 835dd155b..9f6ef4816 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -3,14 +3,8 @@
    <%= render "filter_subnav" %> -
    - <%= render "search_questions" %> - <%= render "questions" %> -
    - -
    - <%= render 'recounting' %> -
    + <%= render "search_questions" %> + <%= render "questions" %>
    <%= render 'results' %> diff --git a/app/views/admin/poll/recounts/index.html.erb b/app/views/admin/poll/recounts/index.html.erb new file mode 100644 index 000000000..796a3efbf --- /dev/null +++ b/app/views/admin/poll/recounts/index.html.erb @@ -0,0 +1,45 @@ +<%= render "/admin/poll/polls/poll_header" %> +
    + <%= render "/admin/poll/polls/filter_subnav" %> + +

    <%= t("admin.recounts.index.title") %>

    + + <% if @booth_assignments.empty? %> +
    + <%= t("admin.recounts.index.no_recounts") %> +
    + <% else %> + + + + + + + + <% @booth_assignments.each do |booth_assignment| %> + + + + + + <% end %> + +
    <%= t("admin.recounts.index.table_booth_name") %><%= t("admin.recounts.index.table_recounts") %><%= t("admin.recounts.index.table_final_recount") %>
    + + <%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %> + + + <% if booth_assignment.recounts.any? %> + <%= booth_assignment.recounts.to_a.sum(&:count) %> + <% else %> + - + <% end %> + + <% if booth_assignment.final_recounts.any? %> + <%= booth_assignment.final_recounts.to_a.sum(&:count) %> + <% else %> + - + <% end %> +
    + <% end %> +
    \ No newline at end of file diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index fabc18019..bf51a0fe7 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -338,19 +338,14 @@ en: recounts_tab: Recounting results_tab: Results no_questions: "There are no questions assigned to this poll." - no_recounts: "There is nothing to be recounted" no_results: "There are no results" questions_title: "List of questions" - recounting_title: "Recounts" results_title: "Results" remove_question: "Remove question from poll" add_question: "Include question" table_title: "Title" table_assignment: "Assignment" table_name: "Name" - table_booth_name: "Booth" - table_final_recount: "Final recount (by officer)" - table_recounts: "Accumulated daily recounts (by officer)" table_whites: "Blank ballots" table_nulls: "Invalid ballots" table_answer: Answer @@ -385,6 +380,13 @@ en: valid_answers: Valid answers description: Description preview: View on website + recounts: + index: + title: "Recounts" + no_recounts: "There is nothing to be recounted" + table_booth_name: "Booth" + table_recounts: "Accumulated daily recounts (by officer)" + table_final_recount: "Final recount (by officer)" booths: index: title: "List of booths" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 5650b7ef2..f85d7cec8 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -338,19 +338,14 @@ es: recounts_tab: Recuentos results_tab: Resultados no_questions: "No hay preguntas asignadas a esta votación." - no_recounts: "No hay nada de lo que hacer recuento" no_results: "No hay resultados" questions_title: "Listado de preguntas asignadas" - recounting_title: "Recuentos" results_title: "Resultados" remove_question: "Desasignar pregunta" add_question: "Incluir pregunta" table_title: "Título" table_assignment: "Asignación" table_name: "Nombre" - table_booth_name: "Urna" - table_final_recount: "Recuento final (presidente de mesa)" - table_recounts: "Recuentos diarios acumulados (presidente de mesa)" table_whites: Papeletas en blanco table_nulls: Papeletas nulas table_answer: Respuesta @@ -385,6 +380,13 @@ es: valid_answers: Respuestas válidas description: Descripción preview: Ver en la web + recounts: + index: + title: "Recuentos" + no_recounts: "No hay nada de lo que hacer recuento" + table_booth_name: "Urna" + table_recounts: "Recuentos diarios acumulados (presidente de mesa)" + table_final_recount: "Recuento final (presidente de mesa)" booths: index: title: "Lista de urnas" diff --git a/config/routes.rb b/config/routes.rb index 3bcefd29a..210da83e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -221,6 +221,8 @@ Rails.application.routes.draw do get :search_officers, on: :collection get :by_officer, on: :collection end + + resources :recounts, only: :index end resources :officers do From 2fae5c3b73f2053a31f4490b11805d9696e20bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 14:08:19 +0100 Subject: [PATCH 4/8] makes admin menu aware of recounts --- app/helpers/admin_helper.rb | 2 +- app/views/admin/_menu.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index dc0edf7f0..fdf158550 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -25,7 +25,7 @@ module AdminHelper end def menu_polls? - ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments"].include? controller_name + ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts"].include? controller_name end def menu_profiles? diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index a45b69eb3..77d84a3a3 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -61,7 +61,7 @@ <%= t("admin.menu.title_polls") %>
      > -
    • > +
    • > <%= link_to t('admin.menu.polls'), admin_polls_path %>
    • From 0bd87c7e4352ce3664abf355c146a45d979ebccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 14:26:46 +0100 Subject: [PATCH 5/8] extracts results from admin's poll/show --- .../admin/poll/results_controller.rb | 13 +++++ app/helpers/admin_helper.rb | 2 +- app/views/admin/_menu.html.erb | 2 +- .../admin/poll/polls/_filter_subnav.html.erb | 2 +- app/views/admin/poll/polls/_results.html.erb | 45 ----------------- app/views/admin/poll/polls/show.html.erb | 4 -- app/views/admin/poll/results/index.html.erb | 50 +++++++++++++++++++ config/locales/admin.en.yml | 14 +++--- config/locales/admin.es.yml | 14 +++--- config/routes.rb | 1 + .../admin/poll/officer_assignments_spec.rb | 4 +- 11 files changed, 85 insertions(+), 66 deletions(-) create mode 100644 app/controllers/admin/poll/results_controller.rb delete mode 100644 app/views/admin/poll/polls/_results.html.erb create mode 100644 app/views/admin/poll/results/index.html.erb diff --git a/app/controllers/admin/poll/results_controller.rb b/app/controllers/admin/poll/results_controller.rb new file mode 100644 index 000000000..2c5bbba27 --- /dev/null +++ b/app/controllers/admin/poll/results_controller.rb @@ -0,0 +1,13 @@ +class Admin::Poll::ResultsController < Admin::BaseController + before_action :load_poll + + def index + @partial_results = @poll.partial_results + end + + private + + def load_poll + @poll = ::Poll.includes(:questions).find(params[:poll_id]) + end +end \ No newline at end of file diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index fdf158550..3f0d4db4b 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -25,7 +25,7 @@ module AdminHelper end def menu_polls? - ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts"].include? controller_name + ["polls", "questions", "officers", "booths", "officer_assignments", "booth_assignments", "recounts", "results"].include? controller_name end def menu_profiles? diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 77d84a3a3..d30ac954c 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -61,7 +61,7 @@ <%= t("admin.menu.title_polls") %>
        > -
      • > +
      • > <%= link_to t('admin.menu.polls'), admin_polls_path %>
      • diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb index 00c83cc0a..ecc352d5d 100644 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ b/app/views/admin/poll/polls/_filter_subnav.html.erb @@ -23,7 +23,7 @@ <% end %>
      • - <%= link_to "#tab-results" do %> + <%= link_to admin_poll_results_path(@poll) do %> <%= t("admin.polls.show.results_tab") %> <% end %>
      • diff --git a/app/views/admin/poll/polls/_results.html.erb b/app/views/admin/poll/polls/_results.html.erb deleted file mode 100644 index 564ad49e2..000000000 --- a/app/views/admin/poll/polls/_results.html.erb +++ /dev/null @@ -1,45 +0,0 @@ -

        <%= t("admin.polls.show.results_title") %>

        - -<% if @poll.partial_results.empty? %> -
        - <%= t("admin.polls.show.no_results") %> -
        -<% else %> - - - - - - - - - - - - -
        <%= t("admin.polls.show.table_whites") %><%= t("admin.polls.show.table_nulls") %>
        <%= @poll.white_results.sum(:amount) %><%= @poll.null_results.sum(:amount) %>
        - - - <% by_question = @poll.partial_results.group_by(&:question_id) %> - <% @poll.questions.each do |question| %> -

        <%= question.title %>

        - - - - - - - - - <% question.valid_answers.each_with_index do |answer, i| %> - <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %> - - - - - <% end %> - -
        <%= t("admin.polls.show.table_answer") %><%= t("admin.polls.show.table_votes") %>
        <%= answer %><%= by_answer[answer].present? ? by_answer[answer].sum(&:amount) : 0 %>
        - <% end %> - -<% end %> diff --git a/app/views/admin/poll/polls/show.html.erb b/app/views/admin/poll/polls/show.html.erb index 9f6ef4816..2807d73ca 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -5,8 +5,4 @@ <%= render "search_questions" %> <%= render "questions" %> - -
        - <%= render 'results' %> -
    diff --git a/app/views/admin/poll/results/index.html.erb b/app/views/admin/poll/results/index.html.erb new file mode 100644 index 000000000..3e6ca64a5 --- /dev/null +++ b/app/views/admin/poll/results/index.html.erb @@ -0,0 +1,50 @@ +<%= render "/admin/poll/polls/poll_header" %> +
    + <%= render "/admin/poll/polls/filter_subnav" %> + +

    <%= t("admin.results.index.title") %>

    + + <% if @partial_results.empty? %> +
    + <%= t("admin.results.index.no_results") %> +
    + <% else %> + + + + + + + + + + + + +
    <%= t("admin.results.index.table_whites") %><%= t("admin.results.index.table_nulls") %>
    <%= @poll.white_results.sum(:amount) %><%= @poll.null_results.sum(:amount) %>
    + + + <% by_question = @partial_results.group_by(&:question_id) %> + <% @poll.questions.each do |question| %> +

    <%= question.title %>

    + + + + + + + + + <% question.valid_answers.each_with_index do |answer, i| %> + <% by_answer = by_question[question.id].present? ? by_question[question.id].group_by(&:answer) : {} %> + + + + + <% end %> + +
    <%= t("admin.results.index.table_answer") %><%= t("admin.results.index.table_votes") %>
    <%= answer %><%= by_answer[answer].present? ? by_answer[answer].sum(&:amount) : 0 %>
    + <% end %> + + <% end %> +
    \ No newline at end of file diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index bf51a0fe7..8d5e113cd 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -338,18 +338,12 @@ en: recounts_tab: Recounting results_tab: Results no_questions: "There are no questions assigned to this poll." - no_results: "There are no results" questions_title: "List of questions" - results_title: "Results" remove_question: "Remove question from poll" add_question: "Include question" table_title: "Title" table_assignment: "Assignment" table_name: "Name" - table_whites: "Blank ballots" - table_nulls: "Invalid ballots" - table_answer: Answer - table_votes: Votes flash: question_added: "Question added to this poll" error_on_question_added: "Question could not be assigned to this poll" @@ -387,6 +381,14 @@ en: table_booth_name: "Booth" table_recounts: "Accumulated daily recounts (by officer)" table_final_recount: "Final recount (by officer)" + results: + index: + title: "Results" + no_results: "There are no results" + table_whites: "Blank ballots" + table_nulls: "Invalid ballots" + table_answer: Answer + table_votes: Votes booths: index: title: "List of booths" diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index f85d7cec8..2b087f385 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -338,18 +338,12 @@ es: recounts_tab: Recuentos results_tab: Resultados no_questions: "No hay preguntas asignadas a esta votación." - no_results: "No hay resultados" questions_title: "Listado de preguntas asignadas" - results_title: "Resultados" remove_question: "Desasignar pregunta" add_question: "Incluir pregunta" table_title: "Título" table_assignment: "Asignación" table_name: "Nombre" - table_whites: Papeletas en blanco - table_nulls: Papeletas nulas - table_answer: Respuesta - table_votes: Votos flash: question_added: "Pregunta añadida a esta votación" error_on_question_added: "No se pudo asignar la pregunta" @@ -387,6 +381,14 @@ es: table_booth_name: "Urna" table_recounts: "Recuentos diarios acumulados (presidente de mesa)" table_final_recount: "Recuento final (presidente de mesa)" + results: + index: + title: "Resultados" + no_results: "No hay resultados" + table_whites: Papeletas en blanco + table_nulls: Papeletas nulas + table_answer: Respuesta + table_votes: Votos booths: index: title: "Lista de urnas" diff --git a/config/routes.rb b/config/routes.rb index 210da83e9..a36fbac5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,6 +223,7 @@ Rails.application.routes.draw do end resources :recounts, only: :index + resources :results, only: :index end resources :officers do diff --git a/spec/features/admin/poll/officer_assignments_spec.rb b/spec/features/admin/poll/officer_assignments_spec.rb index 1b62fab30..6cbe43d14 100644 --- a/spec/features/admin/poll/officer_assignments_spec.rb +++ b/spec/features/admin/poll/officer_assignments_spec.rb @@ -54,7 +54,7 @@ feature 'Admin officer assignments in poll' do booth = officer_assignment.booth_assignment.booth officer = officer_assignment.officer - visit admin_officer_assignments_path(poll: poll, officer: officer) + visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id) expect(page).to_not have_content 'This user has no officing shifts in this poll' within("#poll_officer_assignment_#{officer_assignment.id}") do @@ -89,7 +89,7 @@ feature 'Admin officer assignments in poll' do date: poll.ends_at, count: 9876) - visit admin_officer_assignments_path(poll: poll, officer: officer) + visit by_officer_admin_poll_officer_assignments_path(poll, officer_id: officer.id) within('#recount_list') { expect(page).to have_content('77') } within('#final_recount_list') { expect(page).to have_content('9876') } From 2d722f1ad46a145ba5c13aada270ac1f59a6bf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 14 Feb 2017 14:57:49 +0100 Subject: [PATCH 6/8] redux admin poll subnav --- .../poll/booth_assignments/index.html.erb | 2 +- .../poll/officer_assignments/index.html.erb | 3 +- .../admin/poll/polls/_filter_subnav.html.erb | 30 --------- app/views/admin/poll/polls/_subnav.html.erb | 63 +++++++++++++++++++ app/views/admin/poll/polls/show.html.erb | 2 +- app/views/admin/poll/recounts/index.html.erb | 2 +- app/views/admin/poll/results/index.html.erb | 2 +- 7 files changed, 69 insertions(+), 35 deletions(-) delete mode 100644 app/views/admin/poll/polls/_filter_subnav.html.erb create mode 100644 app/views/admin/poll/polls/_subnav.html.erb diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb index e17281c98..c96f6ba3d 100644 --- a/app/views/admin/poll/booth_assignments/index.html.erb +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -1,6 +1,6 @@ <%= render "/admin/poll/polls/poll_header" %>
    - <%= render "/admin/poll/polls/filter_subnav" %> + <%= render "/admin/poll/polls/subnav" %> <%= render "search_booths" %>

    <%= t("admin.poll_booth_assignments.index.booths_title") %>

    diff --git a/app/views/admin/poll/officer_assignments/index.html.erb b/app/views/admin/poll/officer_assignments/index.html.erb index db3dfd6db..e4c3e3052 100644 --- a/app/views/admin/poll/officer_assignments/index.html.erb +++ b/app/views/admin/poll/officer_assignments/index.html.erb @@ -1,6 +1,7 @@ <%= render "/admin/poll/polls/poll_header" %>
    - <%= render "/admin/poll/polls/filter_subnav" %> + <%= render "/admin/poll/polls/subnav" %> + <%= render "search_officers" %>

    <%= t("admin.poll_officer_assignments.index.officers_title") %>

    diff --git a/app/views/admin/poll/polls/_filter_subnav.html.erb b/app/views/admin/poll/polls/_filter_subnav.html.erb deleted file mode 100644 index ecc352d5d..000000000 --- a/app/views/admin/poll/polls/_filter_subnav.html.erb +++ /dev/null @@ -1,30 +0,0 @@ - diff --git a/app/views/admin/poll/polls/_subnav.html.erb b/app/views/admin/poll/polls/_subnav.html.erb new file mode 100644 index 000000000..7d79b5ba5 --- /dev/null +++ b/app/views/admin/poll/polls/_subnav.html.erb @@ -0,0 +1,63 @@ +