From 0540430bfddf70c30db08937c50e4643c6e43912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 12:37:47 +0100 Subject: [PATCH 01/10] adds date and booth/officer trace fields to poll partial results --- ...20170201113206_adds_fields_to_poll_partial_results.rb | 9 +++++++++ db/schema.rb | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170201113206_adds_fields_to_poll_partial_results.rb diff --git a/db/migrate/20170201113206_adds_fields_to_poll_partial_results.rb b/db/migrate/20170201113206_adds_fields_to_poll_partial_results.rb new file mode 100644 index 000000000..3755dc700 --- /dev/null +++ b/db/migrate/20170201113206_adds_fields_to_poll_partial_results.rb @@ -0,0 +1,9 @@ +class AddsFieldsToPollPartialResults < ActiveRecord::Migration + def change + add_column :poll_partial_results, :date, :date + add_column :poll_partial_results, :booth_assignment_id, :integer + add_column :poll_partial_results, :officer_assignment_id, :integer + + add_index :poll_partial_results, [:booth_assignment_id, :date] + end +end diff --git a/db/schema.rb b/db/schema.rb index 544d2a6ff..13ad1dce7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170130171322) do +ActiveRecord::Schema.define(version: 20170201113206) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -430,10 +430,14 @@ ActiveRecord::Schema.define(version: 20170130171322) do t.string "answer" t.integer "amount" t.string "origin" + t.date "date" + t.integer "booth_assignment_id" + t.integer "officer_assignment_id" end add_index "poll_partial_results", ["answer"], name: "index_poll_partial_results_on_answer", using: :btree add_index "poll_partial_results", ["author_id"], name: "index_poll_partial_results_on_author_id", using: :btree + add_index "poll_partial_results", ["booth_assignment_id", "date"], name: "index_poll_partial_results_on_booth_assignment_id_and_date", using: :btree add_index "poll_partial_results", ["origin"], name: "index_poll_partial_results_on_origin", using: :btree add_index "poll_partial_results", ["question_id"], name: "index_poll_partial_results_on_question_id", using: :btree From 5531b5e4697d7e34a6d9c76a46ca48f644aec655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 12:47:58 +0100 Subject: [PATCH 02/10] adds selected option via params for helper methods --- app/helpers/officing_helper.rb | 2 +- app/helpers/polls_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb index 842eaee63..43916fc24 100644 --- a/app/helpers/officing_helper.rb +++ b/app/helpers/officing_helper.rb @@ -13,7 +13,7 @@ module OfficingHelper officer_assignments.each do |oa| options << ["#{oa.booth_assignment.booth.name}", oa.id] end - options_for_select(options) + options_for_select(options, params[:oa]) end def recount_to_compare_with_final_recount(final_recount) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 214234762..5425a6b52 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -25,7 +25,7 @@ module PollsHelper (poll.starts_at.to_date..poll.ends_at.to_date).each do |date| options << [l(date, format: :long), l(date)] end - options_for_select(options) + options_for_select(options, params[:d]) end def poll_final_recount_option(poll) From a9a93ed441c7d4d3dc571271446727d28fe08f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 13:25:39 +0100 Subject: [PATCH 03/10] adds basic new view for officing results --- .../officing/results_controller.rb | 41 ++++++++++++ app/views/officing/results/new.html.erb | 65 +++++++++++++++++++ config/locales/officing.en.yml | 15 +++++ config/locales/officing.es.yml | 15 +++++ config/routes.rb | 1 + 5 files changed, 137 insertions(+) create mode 100644 app/controllers/officing/results_controller.rb create mode 100644 app/views/officing/results/new.html.erb diff --git a/app/controllers/officing/results_controller.rb b/app/controllers/officing/results_controller.rb new file mode 100644 index 000000000..be6f312bf --- /dev/null +++ b/app/controllers/officing/results_controller.rb @@ -0,0 +1,41 @@ +class Officing::ResultsController < Officing::BaseController + before_action :load_poll + before_action :load_officer_assignment, only: :create + + def new + @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). + order(date: :asc) + end + + def create + if false + notice = t("officing.results.flash.create") + else + notice = t("officing.results.flash.error_create") + end + redirect_to new_officing_poll_result_path(@poll), notice: notice + end + + private + def load_poll + @poll = Poll.expired.includes(:questions).find(params[:poll_id]) + end + + def load_officer_assignment + @officer_assignment = current_user.poll_officer. + officer_assignments.final.find_by(id: final_recount_params[:officer_assignment_id]) + if @officer_assignment.blank? + redirect_to new_officing_poll_result_path(@poll), notice: t("officing.results.flash.error_create") + end + end + + def final_recount_params + params.permit(:officer_assignment_id, :count, :date) + end + +end \ No newline at end of file diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb new file mode 100644 index 000000000..0e57f640d --- /dev/null +++ b/app/views/officing/results/new.html.erb @@ -0,0 +1,65 @@ +<% if @officer_assignments.any? %> +

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

+ + <%= form_tag(officing_poll_results_path(@poll), {id: "officer_assignment_form"}) do %> +
+
+ + <%= select_tag :officer_assignment_id, + booths_for_officer_select_options(@officer_assignments), + { prompt: t("officing.results.new.select_booth"), + label: false } %> +
+
+ +
+
+ + <%= select_tag :date, + poll_dates_select_options(@poll), + { prompt: t("officing.results.new.select_date"), + label: false } %> +
+
+ + <% @poll.questions.each do |question| %> +
+

<%= question.title %>

+ <% question.valid_answers.each do |answer| %> +
+ + <%= text_field_tag :count, nil, placeholder: "0" %> +
+ <% end %> +
+
+ <% end %> + +
+

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

+
+ <%= text_field_tag :count, nil, placeholder: "0" %> +
+
+
+

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

+
+ <%= text_field_tag :count, nil, placeholder: "0" %> +
+
+ + +
+
+ <%= submit_tag t("officing.results.new.submit"), class: "button expanded" %> +
+
+ <% end %> + +<% else %> +

<%= @poll.name %>

+
+ <%= t("officing.results.new.not_allowed") %> +
+<% end %> + diff --git a/config/locales/officing.en.yml b/config/locales/officing.en.yml index c591f7b03..084ceb4ba 100644 --- a/config/locales/officing.en.yml +++ b/config/locales/officing.en.yml @@ -20,6 +20,7 @@ en: no_polls: You are not officing final recounts in any active poll select_poll: Select poll add_recount: Add final recount + add_results: Add results recounts: flash: create: "Data added" @@ -51,6 +52,20 @@ en: submit: Save final_recount_list: "Your final recounts" system_count: "System recount" + results: + flash: + create: "Results saved" + error_create: "Results NOT saved. Error in data." + new: + title: "%{poll} - Add results" + not_allowed: "You are allowed to add results for this poll" + booth: "Booth" + date: "Date" + select_booth: "Select booth" + select_date: "Select date" + ballots_blank: "Blank ballots" + ballots_null: "Invalid ballots" + submit: "Save" residence: flash: create: "Document verified with Census" diff --git a/config/locales/officing.es.yml b/config/locales/officing.es.yml index 9de110454..56d6f745f 100644 --- a/config/locales/officing.es.yml +++ b/config/locales/officing.es.yml @@ -20,6 +20,7 @@ es: no_polls: "No tienes permiso para recuento final en ninguna votación reciente" select_poll: "Selecciona votación" add_recount: "Añadir recuentos finales" + add_results: "Añadir resultados" recounts: flash: create: "Datos añadidos" @@ -51,6 +52,20 @@ es: submit: "Guardar" final_recount_list: "Tus recuentos finales" system_count: "Recuento del sistema" + results: + flash: + create: "Datos guardados" + error_create: "Resultados NO añadidos. Error en los datos" + new: + title: "%{poll} - Añadir resultados" + not_allowed: "No tienes permiso para introducir resultados" + booth: "Urna" + date: "Día" + select_booth: "Elige urna" + select_date: "Elige día" + ballots_blank: "Papeletas en blanco" + ballots_null: "Papeletas nulas" + submit: "Guardar" residence: flash: create: "Documento verificado con el Padrón" diff --git a/config/routes.rb b/config/routes.rb index 8be55feb5..2295453b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -336,6 +336,7 @@ Rails.application.routes.draw do resources :recounts, only: [:new, :create] resources :final_recounts, only: [:new, :create] + resources :results, only: [:new, :create] end resource :residence, controller: "residence", only: [:new, :create] resources :voters, only: [:new, :create] From 64c07a5d56ca519e7e6627b16e7a0bfce732e04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 13:26:02 +0100 Subject: [PATCH 04/10] adds link to add results for officers --- app/views/officing/polls/final.html.erb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/views/officing/polls/final.html.erb b/app/views/officing/polls/final.html.erb index 7159a3769..6bdeed269 100644 --- a/app/views/officing/polls/final.html.erb +++ b/app/views/officing/polls/final.html.erb @@ -5,13 +5,14 @@ <%= t("officing.polls.final.select_poll") %>   +   <% @polls.each do |poll| %> - <%= link_to poll.name, new_officing_poll_final_recount_path(poll) %> + <%= poll.name %> @@ -19,6 +20,11 @@ new_officing_poll_final_recount_path(poll), class: "button hollow" %> + + <%= link_to t("officing.polls.final.add_results"), + new_officing_poll_result_path(poll), + class: "button hollow" %> + <% end %> From f6b03460ea74eeb21860951fbdad95eceec87fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 13:26:33 +0100 Subject: [PATCH 05/10] changes poll questions in dev_seeds to have different answers --- db/dev_seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index d9b09f70a..09278aa56 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -521,7 +521,7 @@ print "Creating Poll Questions" question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), description: description, - valid_answers: Faker::Lorem.words(3).join(', '), + valid_answers: Faker::Lorem.words((2..7).to_a.sample).join(', '), poll: poll) end From 2eaab52b12e052648501a848449a04fc16d26a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 13:58:50 +0100 Subject: [PATCH 06/10] fixes spec --- spec/features/officing/final_recount_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/features/officing/final_recount_spec.rb b/spec/features/officing/final_recount_spec.rb index e712f13f7..c9ed2a5c5 100644 --- a/spec/features/officing/final_recount_spec.rb +++ b/spec/features/officing/final_recount_spec.rb @@ -43,7 +43,10 @@ feature 'Officing Final Recount' do click_link 'Final recounts' end - click_link @poll.name + within("#poll_#{@poll.id}") do + expect(page).to have_content(@poll.name) + click_link 'Add final recount' + end expect(page).to_not have_content('Your recounts') From 5fbc9fb9a6da94191294e3ef240cd58848541c05 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 1 Feb 2017 14:00:38 +0100 Subject: [PATCH 07/10] improves styles on officing results new form --- app/views/officing/results/new.html.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb index 0e57f640d..ed9c702d2 100644 --- a/app/views/officing/results/new.html.erb +++ b/app/views/officing/results/new.html.erb @@ -24,9 +24,11 @@ <% @poll.questions.each do |question| %>
-

<%= question.title %>

+
+

<%= question.title %>

+
<% question.valid_answers.each do |answer| %> -
+
<%= text_field_tag :count, nil, placeholder: "0" %>
From ee993a6aa550e85f36b4397a9f42387b8ced5c44 Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 1 Feb 2017 14:10:59 +0100 Subject: [PATCH 08/10] adds styles to ballots blank and ballots null inputs --- app/views/officing/results/new.html.erb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/views/officing/results/new.html.erb b/app/views/officing/results/new.html.erb index ed9c702d2..7d55537f6 100644 --- a/app/views/officing/results/new.html.erb +++ b/app/views/officing/results/new.html.erb @@ -38,21 +38,20 @@ <% end %>
-

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

-
+
+

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

+ <%= text_field_tag :count, nil, placeholder: "0" %> +
+ +
+

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

<%= text_field_tag :count, nil, placeholder: "0" %>
-
-

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

-
- <%= text_field_tag :count, nil, placeholder: "0" %> -
-
- +
-
+
<%= submit_tag t("officing.results.new.submit"), class: "button expanded" %>
From 6584b3c44592c0f4f8695e913a558e6c608e05ee Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Wed, 1 Feb 2017 14:15:49 +0100 Subject: [PATCH 09/10] fixes html table on officing polls final --- app/views/officing/polls/final.html.erb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/views/officing/polls/final.html.erb b/app/views/officing/polls/final.html.erb index 6bdeed269..b46ab0b13 100644 --- a/app/views/officing/polls/final.html.erb +++ b/app/views/officing/polls/final.html.erb @@ -3,9 +3,7 @@ <% if @polls.any? %> - - - + <% @polls.each do |poll| %> @@ -19,8 +17,6 @@ <%= link_to t("officing.polls.final.add_recount"), new_officing_poll_final_recount_path(poll), class: "button hollow" %> - - + <% @final_recounts.each do |final_recount| %> @@ -69,6 +70,9 @@ + <% end %> diff --git a/config/locales/officing.en.yml b/config/locales/officing.en.yml index 084ceb4ba..fd1987833 100644 --- a/config/locales/officing.en.yml +++ b/config/locales/officing.en.yml @@ -52,6 +52,7 @@ en: submit: Save final_recount_list: "Your final recounts" system_count: "System recount" + add_results: "Add results" results: flash: create: "Results saved" diff --git a/config/locales/officing.es.yml b/config/locales/officing.es.yml index 56d6f745f..79e8b4f98 100644 --- a/config/locales/officing.es.yml +++ b/config/locales/officing.es.yml @@ -52,6 +52,7 @@ es: submit: "Guardar" final_recount_list: "Tus recuentos finales" system_count: "Recuento del sistema" + add_results: "Añadir resultados" results: flash: create: "Datos guardados" diff --git a/spec/features/officing/final_recount_spec.rb b/spec/features/officing/final_recount_spec.rb index c9ed2a5c5..75ecbf7ec 100644 --- a/spec/features/officing/final_recount_spec.rb +++ b/spec/features/officing/final_recount_spec.rb @@ -122,6 +122,26 @@ feature 'Officing Final Recount' do expect(page).to have_content('100') expect(page).to have_content('33') end - end + + scenario "Show link to add results for same booth/date" do + final_officer_assignment = create(:poll_officer_assignment, :final, officer: @poll_officer) + poll = final_officer_assignment.booth_assignment.poll + poll.update(ends_at: 1.day.ago) + final_recount = create(:poll_final_recount, + officer_assignment: final_officer_assignment, + booth_assignment: final_officer_assignment.booth_assignment, + date: 7.days.ago, + count: 100) + visit new_officing_poll_final_recount_path(poll) + within("#poll_final_recount_#{final_recount.id}") do + click_link "Add results" + end + + expected_path = new_officing_poll_result_path(poll, oa: final_recount.officer_assignment.id, d: I18n.l(final_recount.date.to_date)) + expect(page).to have_current_path(expected_path) + expect(page).to have_select('officer_assignment_id', selected: final_recount.booth_assignment.booth.name) + expect(page).to have_select('date', selected: I18n.l(final_recount.date.to_date, format: :long)) + end + end \ No newline at end of file
<%= t("officing.polls.final.select_poll") %>  <%= t("officing.polls.final.select_poll") %>
<%= link_to t("officing.polls.final.add_results"), new_officing_poll_result_path(poll), class: "button hollow" %> From 3ebe96241cdb5f98d4ffe6e14e4268aaa22a2411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Wed, 1 Feb 2017 16:22:04 +0100 Subject: [PATCH 10/10] adds link to results for each final recount in officing --- .../officing/final_recounts/new.html.erb | 4 ++++ config/locales/officing.en.yml | 1 + config/locales/officing.es.yml | 1 + spec/features/officing/final_recount_spec.rb | 22 ++++++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/views/officing/final_recounts/new.html.erb b/app/views/officing/final_recounts/new.html.erb index ee09a1d38..647bd31b4 100644 --- a/app/views/officing/final_recounts/new.html.erb +++ b/app/views/officing/final_recounts/new.html.erb @@ -53,6 +53,7 @@ <%= t("officing.final_recounts.new.booth") %> <%= t("officing.final_recounts.new.count") %> <%= t("officing.final_recounts.new.system_count") %> 
<%= system_recount_to_compare_with_final_recount final_recount %> + <%= link_to t("officing.final_recounts.new.add_results"), new_officing_poll_result_path(@poll, oa: final_recount.officer_assignment.id, d: l(final_recount.date.to_date) )%> +