From 45d91a7e502eaeb99062b088dba5213b2a24babb Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 19:27:26 +0200 Subject: [PATCH 01/29] Add Poll booth_assignments and :Poll::BoothAssignment manage routes, actions and views --- .../poll/booth_assignments_controller.rb | 4 +++ .../admin/poll/polls_controller.rb | 4 +++ app/models/abilities/administrator.rb | 4 +-- app/views/admin/_menu.html.erb | 7 +++++- .../poll/booth_assignments/manage.html.erb | 25 +++++++++++++++++++ .../poll/polls/booth_assignments.html.erb | 18 +++++++++++++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + config/routes.rb | 4 ++- 9 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/poll/booth_assignments/manage.html.erb create mode 100644 app/views/admin/poll/polls/booth_assignments.html.erb diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 7998f29a2..221a623ef 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -45,6 +45,10 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice end + def manage + @booths = ::Poll::Booth.all + end + private def load_booth_assignment diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 5103275fb..8ba6e934e 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -47,6 +47,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController redirect_to admin_poll_path(@poll), notice: notice end + def booth_assignments + @polls = Poll.current_or_incoming + end + private def load_geozones diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 1bc8d5e0c..704f9be24 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -56,10 +56,10 @@ module Abilities can [:index, :create, :edit, :update, :destroy], Geozone - can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers], Poll + can [:read, :create, :update, :destroy, :add_question, :search_booths, :search_officers, :booth_assignments], Poll can [:read, :create, :update, :destroy, :available], Poll::Booth can [:search, :create, :index, :destroy], ::Poll::Officer - can [:create, :destroy], ::Poll::BoothAssignment + can [:create, :destroy, :manage], ::Poll::BoothAssignment can [:create, :destroy], ::Poll::OfficerAssignment can [:read, :create, :update], Poll::Question can :destroy, Poll::Question # , comments_count: 0, votes_up: 0 diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index f2af2c116..0518aa0e3 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -60,7 +60,8 @@ <%= t("admin.menu.title_polls") %> <% end %> diff --git a/app/views/admin/poll/booth_assignments/manage.html.erb b/app/views/admin/poll/booth_assignments/manage.html.erb new file mode 100644 index 000000000..65cec228a --- /dev/null +++ b/app/views/admin/poll/booth_assignments/manage.html.erb @@ -0,0 +1,25 @@ +

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

+ +<% if controller_name == "booths" && action_name != "available" %> + <%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button success float-right" %> +<% end %> + +<% if @booths.empty? %> +
+ <%= t("admin.booths.index.no_booths") %> +
+<% end %> + +<% if @booths.any? %> + + + + + + + <% @booths.each do |booth| %> + <% end %> + +
<%= t("admin.booths.index.name") %><%= t("admin.actions.actions") %>
+ +<% end %> diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb new file mode 100644 index 000000000..0d9bf98ce --- /dev/null +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -0,0 +1,18 @@ +

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

+ +<% if @polls.any? %> + + + + + + + + <%= render @polls %> + +
<%= t("admin.polls.index.name") %><%= t("admin.polls.index.dates") %><%= t("admin.actions.actions") %>
+<% else %> +
+ <%= t("admin.polls.index.no_polls") %> +
+<% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 38abe6f56..a2657a2b3 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -409,6 +409,7 @@ en: poll_officers: Poll officers polls: Polls poll_booths: Booths location + poll_booth_assignments: Booths Assignments poll_shifts: Manage shifts officials: Officials organizations: Organisations diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3336cdc5b..4c56e131c 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -420,6 +420,7 @@ es: poll_officers: Presidentes de mesa polls: Votaciones poll_booths: Ubicación de urnas + poll_booth_assignments: Asignación de urnas poll_shifts: Asignar turnos officials: Cargos públicos organizations: Organizaciones diff --git a/config/routes.rb b/config/routes.rb index ae4f7280c..6f94594a3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,7 +111,7 @@ Rails.application.routes.draw do resources :annotations do get :search, on: :collection end - + resources :polls, only: [:show, :index] do resources :questions, controller: 'polls/questions', shallow: true do post :answer, on: :member @@ -273,10 +273,12 @@ Rails.application.routes.draw do scope module: :poll do resources :polls do + get :booth_assignments, on: :collection patch :add_question, on: :member resources :booth_assignments, only: [:index, :show, :create, :destroy] do get :search_booths, on: :collection + get :manage, on: :collection end resources :officer_assignments, only: [:index, :create, :destroy] do From c52c0a5452f8e1170401dc871834b7c531870dd7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 19:42:00 +0200 Subject: [PATCH 02/29] Complete Poll list with booth assigment management links --- .../admin/poll/polls/booth_assignments.html.erb | 16 +++++++++++++++- config/locales/en/admin.yml | 2 ++ config/locales/es/admin.yml | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb index 0d9bf98ce..819474852 100644 --- a/app/views/admin/poll/polls/booth_assignments.html.erb +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -8,7 +8,21 @@ <%= t("admin.actions.actions") %> - <%= render @polls %> + <% @polls.each do |poll| %> + + + <%= poll.name %> + + + <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> + + + <%= link_to t("admin.booth_assignments.manage_assignments"), + manage_admin_poll_booth_assignments_path(poll), + class: "button hollow" %> + + + <% end %> <% else %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index a2657a2b3..863ae8688 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -525,6 +525,8 @@ en: date_missing: "A date must be selected" vote_collection: Collect Votes recount_scrutiny: Recount & Scrutiny + booth_assignments: + manage_assignments: Manage assignments poll_booth_assignments: flash: destroy: "Booth not assigned anymore" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 4c56e131c..a7d4d2c81 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -525,6 +525,8 @@ es: date_missing: "Debe seleccionarse una fecha" vote_collection: Recoger Votos recount_scrutiny: Recuento & Escrutinio + booth_assignments: + manage_assignments: Gestionar asignaciones poll_booth_assignments: flash: destroy: "Urna desasignada" From f8839434f77d37a2243f3af77ba1f8239248148d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 20:10:51 +0200 Subject: [PATCH 03/29] Complete booth assignment view list without actions yet --- .../admin/poll/booth_assignments_controller.rb | 1 + .../_booth_assignment.html.erb | 17 +++++++++++++++++ .../poll/booth_assignments/manage.html.erb | 16 ++++++++-------- config/locales/en/admin.yml | 9 +++++++++ config/locales/es/admin.yml | 9 +++++++++ 5 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/poll/booth_assignments/_booth_assignment.html.erb diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index 221a623ef..ab3f52d11 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -47,6 +47,7 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController def manage @booths = ::Poll::Booth.all + @poll = Poll.find(params[:poll_id]) end private diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb new file mode 100644 index 000000000..06188df9c --- /dev/null +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -0,0 +1,17 @@ + + + <%= link_to booth.name, admin_booth_path(booth) %> + + + <%= t("admin.booth_assignments.status.assigned") %> + <%= t("admin.booth_assignments.status.unassigned") %> + + + <%= link_to t("admin.booth_assignments.manage.assign"), + new_admin_booth_shift_path(booth), + class: "button" %> + <%= link_to t("admin.booth_assignments.manage.unassign"), + new_admin_booth_shift_path(booth), + class: "button hollow" %> + + diff --git a/app/views/admin/poll/booth_assignments/manage.html.erb b/app/views/admin/poll/booth_assignments/manage.html.erb index 65cec228a..c76485cc9 100644 --- a/app/views/admin/poll/booth_assignments/manage.html.erb +++ b/app/views/admin/poll/booth_assignments/manage.html.erb @@ -1,25 +1,25 @@ -

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

- -<% if controller_name == "booths" && action_name != "available" %> - <%= link_to t("admin.booths.index.add_booth"), new_admin_booth_path, class: "button success float-right" %> +<%= link_to booth_assignments_admin_polls_path do %> + <%= t("shared.back") %> <% end %> +
+ +

<%= t("admin.booth_assignments.manage.assignments_list", poll: @poll.name) %>

<% if @booths.empty? %>
<%= t("admin.booths.index.no_booths") %>
-<% end %> - -<% if @booths.any? %> +<% else %> + <% @booths.each do |booth| %> + <%= render partial: "booth_assignment", locals: { booth: booth } %> <% end %>
<%= t("admin.booths.index.name") %><%= t("admin.booth_assignments.status.assign_status") %> <%= t("admin.actions.actions") %>
- <% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 863ae8688..398744720 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -527,6 +527,15 @@ en: recount_scrutiny: Recount & Scrutiny booth_assignments: manage_assignments: Manage assignments + manage: + assignments_list: "Assignments for poll '%{poll}'" + status: + assign_status: Assignment + assigned: Assigned + unassigned: Unassigned + actions: + assign: Assign booth + unassign: Unassign booth poll_booth_assignments: flash: destroy: "Booth not assigned anymore" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index a7d4d2c81..7169d6017 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -527,6 +527,15 @@ es: recount_scrutiny: Recuento & Escrutinio booth_assignments: manage_assignments: Gestionar asignaciones + manage: + assignments_list: "Asignaciones para la votación '%{poll}'" + status: + assign_status: Asignación + assigned: Asignada + unassigned: No asignada + actions: + assign: Assign booth + unassign: Unassign booth poll_booth_assignments: flash: destroy: "Urna desasignada" From e6efd8ad7d7c385ea5f97a7252dd8a283ac5d0f7 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 20:54:42 +0200 Subject: [PATCH 04/29] Remove assign/unassign booth to poll from poll booth assigments list --- .../booth_assignments/_search_booths_results.html.erb | 9 --------- app/views/admin/poll/booth_assignments/index.html.erb | 7 ------- config/locales/en/admin.yml | 2 -- config/locales/es/admin.yml | 2 -- 4 files changed, 20 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb index 3fa7fc080..cebde154c 100644 --- a/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb +++ b/app/views/admin/poll/booth_assignments/_search_booths_results.html.erb @@ -12,7 +12,6 @@ <%= t("admin.poll_booth_assignments.index.table_name") %> <%= t("admin.poll_booth_assignments.index.table_location") %> - <%= t("admin.poll_booth_assignments.index.table_assignment") %> @@ -24,14 +23,6 @@ <%= booth.location %> - - <% unless @poll.booth_ids.include?(booth.id) %> - <%= link_to t("admin.poll_booth_assignments.index.add_booth"), - admin_poll_booth_assignments_path(@poll, booth_id: booth.id), - method: :post, - class: "button hollow" %> - <% end %> - <% end %> diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb index f14e59ef1..fcedaec79 100644 --- a/app/views/admin/poll/booth_assignments/index.html.erb +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -14,7 +14,6 @@ <%= t("admin.poll_booth_assignments.index.table_name") %> <%= t("admin.poll_booth_assignments.index.table_location") %> - <%= t("admin.poll_booth_assignments.index.table_assignment") %> <% @booth_assignments.each do |booth_assignment| %> @@ -27,12 +26,6 @@ <%= 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/config/locales/en/admin.yml b/config/locales/en/admin.yml index 398744720..d991ad85f 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -559,8 +559,6 @@ en: no_booths: "There are no booths assigned to this poll." table_name: "Name" table_location: "Location" - table_assignment: "Assignment" - remove_booth: "Remove booth from poll" add_booth: "Assign booth" polls: index: diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 7169d6017..1ac21c633 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -559,8 +559,6 @@ es: no_booths: "No hay urnas asignadas a esta votación." table_name: "Nombre" table_location: "Ubicación" - table_assignment: "Asignación" - remove_booth: "Desasignar urna" add_booth: "Asignar urna" polls: index: From 7507f43ea813a63ac56cd71936ff4097fbeb1d2c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 21:30:31 +0200 Subject: [PATCH 05/29] Add helper method on Booth model to get booth assigment for a given poll --- app/models/poll/booth.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/poll/booth.rb b/app/models/poll/booth.rb index 04f9d3dea..07e7d2456 100644 --- a/app/models/poll/booth.rb +++ b/app/models/poll/booth.rb @@ -15,5 +15,8 @@ class Poll where(polls: { id: Poll.current_or_incoming }).includes(:polls) end + def assignment_on_poll(poll) + booth_assignments.where(poll: poll).first + end end -end \ No newline at end of file +end From ca9e807cd4134aa4677848fa16c8d08b2d5d4288 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 21:30:57 +0200 Subject: [PATCH 06/29] Add link to booth assignment management at poll booth assigments list --- app/views/admin/poll/booth_assignments/index.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb index fcedaec79..39435254b 100644 --- a/app/views/admin/poll/booth_assignments/index.html.erb +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -1,10 +1,16 @@ <%= render "/admin/poll/polls/poll_header" %> + +
<%= render "/admin/poll/polls/subnav" %> <%= render "search_booths" %>

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

+ <%= link_to t("admin.booth_assignments.manage_assignments"), + manage_admin_poll_booth_assignments_path(@poll), + class: "button hollow float-right" %> + <% if @booth_assignments.empty? %>
<%= t("admin.poll_booth_assignments.index.no_booths") %> From 68b7528bab4f7a44967c01a1bae988d684050482 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 21:31:36 +0200 Subject: [PATCH 07/29] Complete booth assigment partial with assign/unassign buttons and status --- .../_booth_assignment.html.erb | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb index 06188df9c..5956b5342 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -1,17 +1,28 @@ - + + <%= link_to booth.name, admin_booth_path(booth) %> + +<% if booth_assignment.present? %> - <%= link_to booth.name, admin_booth_path(booth) %> - - - <%= t("admin.booth_assignments.status.assigned") %> - <%= t("admin.booth_assignments.status.unassigned") %> + <%= t("admin.booth_assignments.status.assigned") %> - <%= link_to t("admin.booth_assignments.manage.assign"), - new_admin_booth_shift_path(booth), - class: "button" %> - <%= link_to t("admin.booth_assignments.manage.unassign"), - new_admin_booth_shift_path(booth), - class: "button hollow" %> + <%= link_to t("admin.booth_assignments.manage.actions.unassign"), + admin_poll_booth_assignment_path(@poll, booth_assignment, booth_id: booth.id), + method: :delete, + remote: true, + title: t("admin.booth_assignments.manage.actions.unassign"), + class: "button hollow alert" %> - +<% else %> + + <%= t("admin.booth_assignments.status.unassigned") %> + + + <%= link_to t("admin.booth_assignments.manage.actions.assign"), + admin_poll_booth_assignments_path(@poll, booth_id: booth.id), + method: :post, + remote: true, + title: t("admin.booth_assignments.manage.actions.assign"), + class: "button" %> + +<% end %> From ce25780f70f122bd52796b6ce12c5c4decea5b36 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 21:32:09 +0200 Subject: [PATCH 08/29] Use booth assigment partial correctly --- app/views/admin/poll/booth_assignments/manage.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/admin/poll/booth_assignments/manage.html.erb b/app/views/admin/poll/booth_assignments/manage.html.erb index c76485cc9..fab5b8487 100644 --- a/app/views/admin/poll/booth_assignments/manage.html.erb +++ b/app/views/admin/poll/booth_assignments/manage.html.erb @@ -18,7 +18,9 @@ <% @booths.each do |booth| %> - <%= render partial: "booth_assignment", locals: { booth: booth } %> + + <%= render partial: "booth_assignment", locals: { booth: booth, booth_assignment: booth.assignment_on_poll(@poll) } %> + <% end %> From 085e6ecba4c6d19856c2168067cb746cd6dc9718 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 21:32:37 +0200 Subject: [PATCH 09/29] Complete booth assigment create/destroy methods to work with ajax --- .../admin/poll/booth_assignments_controller.rb | 16 ++++++++++++---- .../admin/poll/booth_assignments/create.js.erb | 1 + .../admin/poll/booth_assignments/destroy.js.erb | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 app/views/admin/poll/booth_assignments/create.js.erb create mode 100644 app/views/admin/poll/booth_assignments/destroy.js.erb diff --git a/app/controllers/admin/poll/booth_assignments_controller.rb b/app/controllers/admin/poll/booth_assignments_controller.rb index ab3f52d11..5b9ea9d7b 100644 --- a/app/controllers/admin/poll/booth_assignments_controller.rb +++ b/app/controllers/admin/poll/booth_assignments_controller.rb @@ -23,18 +23,24 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController end def create - @booth_assignment = ::Poll::BoothAssignment.new(poll_id: booth_assignment_params[:poll_id], - booth_id: booth_assignment_params[:booth_id]) + @poll = Poll.find(booth_assignment_params[:poll_id]) + @booth = Poll::Booth.find(booth_assignment_params[:booth_id]) + @booth_assignment = ::Poll::BoothAssignment.new(poll: @poll, + booth: @booth) if @booth_assignment.save notice = t("admin.poll_booth_assignments.flash.create") else notice = t("admin.poll_booth_assignments.flash.error_create") end - redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice + respond_to do |format| + format.js { render layout: false } + end end def destroy + @poll = Poll.find(booth_assignment_params[:poll_id]) + @booth = Poll::Booth.find(booth_assignment_params[:booth_id]) @booth_assignment = ::Poll::BoothAssignment.find(params[:id]) if @booth_assignment.destroy @@ -42,7 +48,9 @@ class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController else notice = t("admin.poll_booth_assignments.flash.error_destroy") end - redirect_to admin_poll_booth_assignments_path(@booth_assignment.poll_id), notice: notice + respond_to do |format| + format.js { render layout: false } + end end def manage diff --git a/app/views/admin/poll/booth_assignments/create.js.erb b/app/views/admin/poll/booth_assignments/create.js.erb new file mode 100644 index 000000000..8b278f7b3 --- /dev/null +++ b/app/views/admin/poll/booth_assignments/create.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@booth) %>").html('<%= j render("booth_assignment", booth: @booth, booth_assignment: @booth.assignment_on_poll(@poll)) %>'); diff --git a/app/views/admin/poll/booth_assignments/destroy.js.erb b/app/views/admin/poll/booth_assignments/destroy.js.erb new file mode 100644 index 000000000..8b278f7b3 --- /dev/null +++ b/app/views/admin/poll/booth_assignments/destroy.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@booth) %>").html('<%= j render("booth_assignment", booth: @booth, booth_assignment: @booth.assignment_on_poll(@poll)) %>'); From 9b70b90e6a0d5dd295429c480ae6aa12b1367a26 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 22:05:02 +0200 Subject: [PATCH 10/29] Fix texts for booth assignment management --- .../admin/poll/booth_assignments/_booth_assignment.html.erb | 4 ++-- app/views/admin/poll/booth_assignments/manage.html.erb | 2 +- config/locales/en/admin.yml | 1 - config/locales/es/admin.yml | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb index 5956b5342..7865b201e 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -3,7 +3,7 @@ <% if booth_assignment.present? %> - <%= t("admin.booth_assignments.status.assigned") %> + <%= t("admin.booth_assignments.manage.status.assigned") %> <%= link_to t("admin.booth_assignments.manage.actions.unassign"), @@ -15,7 +15,7 @@ <% else %> - <%= t("admin.booth_assignments.status.unassigned") %> + <%= t("admin.booth_assignments.manage.status.unassigned") %> <%= link_to t("admin.booth_assignments.manage.actions.assign"), diff --git a/app/views/admin/poll/booth_assignments/manage.html.erb b/app/views/admin/poll/booth_assignments/manage.html.erb index fab5b8487..f55e85c74 100644 --- a/app/views/admin/poll/booth_assignments/manage.html.erb +++ b/app/views/admin/poll/booth_assignments/manage.html.erb @@ -13,7 +13,7 @@ - + diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index d991ad85f..3826e9764 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -559,7 +559,6 @@ en: no_booths: "There are no booths assigned to this poll." table_name: "Name" table_location: "Location" - add_booth: "Assign booth" polls: index: title: "List of polls" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 1ac21c633..9bc97c35f 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -559,7 +559,6 @@ es: no_booths: "No hay urnas asignadas a esta votación." table_name: "Nombre" table_location: "Ubicación" - add_booth: "Asignar urna" polls: index: title: "Listado de votaciones" From 17e6a66b80a9e8573c5e82dc031d0d3b8ab7bffe Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 22:33:00 +0200 Subject: [PATCH 11/29] Refactor booth assigment management feature specs to test new assign/unassign feature --- .../admin/poll/booth_assigments_spec.rb | 139 ++++++++++++------ 1 file changed, 91 insertions(+), 48 deletions(-) diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 5813e2dac..cceec1a3e 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -7,66 +7,109 @@ feature 'Admin booths assignments' do login_as(admin.user) end - scenario 'Assign booth to poll', :js do - poll = create(:poll) - booth = create(:poll_booth) + feature 'Admin Booth Assignment management' do - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (0)' + let!(:poll) { create(:poll) } + let!(:booth) { create(:poll_booth) } + + scenario 'List Polls and Booths to manage', :js do + second_poll = create(:poll) + second_booth = create(:poll_booth) + + visit booth_assignments_admin_polls_path + + expect(page).to have_content(poll.name) + expect(page).to have_content(second_poll.name) + + within("#poll_#{second_poll.id}") do + click_link 'Manage assignments' + end + + expect(page).to have_content "Assignments for poll '#{second_poll.name}'" + + expect(page).to have_content(booth.name) + expect(page).to have_content(second_booth.name) end - expect(page).to have_content 'There are no booths assigned to this poll.' + scenario 'Assign booth to poll', :js do + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (0)' + end - fill_in 'search-booths', with: booth.name - click_button 'Search' - expect(page).to have_content(booth.name) + expect(page).to have_content 'There are no booths assigned to this poll.' + expect(page).to_not have_content booth.name - within('#search-booths-results') do - click_link 'Assign booth' + fill_in 'search-booths', with: booth.name + click_button 'Search' + expect(page).to have_content(booth.name) + + visit manage_admin_poll_booth_assignments_path(poll) + + expect(page).to have_content "Assignments for poll '#{poll.name}'" + + within("#poll_booth_#{booth.id}") do + expect(page).to have_content(booth.name) + expect(page).to have_content "Unassigned" + + click_link 'Assign booth' + + expect(page).not_to have_content "Unassigned" + expect(page).to have_content "Assigned" + expect(page).to have_link "Unassign booth" + end + + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (1)' + end + + expect(page).to_not have_content 'There are no booths assigned to this poll.' + expect(page).to have_content booth.name end - expect(page).to have_content 'Booth assigned' + scenario 'Unassign booth from poll', :js do + assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (1)' + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (1)' + end + + expect(page).not_to have_content 'There are no booths assigned to this poll.' + expect(page).to have_content booth.name + + fill_in 'search-booths', with: booth.name + click_button 'Search' + expect(page).to have_content(booth.name) + + visit manage_admin_poll_booth_assignments_path(poll) + + expect(page).to have_content "Assignments for poll '#{poll.name}'" + + within("#poll_booth_#{booth.id}") do + expect(page).to have_content(booth.name) + expect(page).to have_content "Assigned" + + click_link 'Unassign booth' + + expect(page).to have_content "Unassigned" + expect(page).not_to have_content "Assigned" + expect(page).to have_link "Assign booth" + end + + visit admin_poll_path(poll) + within('#poll-resources') do + click_link 'Booths (0)' + end + + expect(page).to have_content 'There are no booths assigned to this poll.' + expect(page).not_to have_content booth.name end - - expect(page).to_not have_content 'There are no booths assigned to this poll.' - expect(page).to have_content booth.name - end - - scenario 'Remove booth from poll', :js do - poll = create(:poll) - booth = create(:poll_booth) - assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (1)' - end - - expect(page).to_not have_content 'There are no booths assigned to this poll.' - expect(page).to have_content booth.name - - within("#poll_booth_assignment_#{assignment.id}") do - click_link 'Remove booth from poll' - end - - expect(page).to have_content 'Booth not assigned anymore' - - visit admin_poll_path(poll) - within('#poll-resources') do - click_link 'Booths (0)' - end - - expect(page).to have_content 'There are no booths assigned to this poll.' - expect(page).to_not have_content booth.name end feature 'Show' do - scenario 'Lists all assigned poll oficers' do + scenario 'Lists all assigned poll officers' do poll = create(:poll) booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) From 9fc35e9087d957fd205d958854bc9f97fac2dfc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 20 Oct 2017 18:44:56 +0200 Subject: [PATCH 12/29] Added `results_enabled` and `stats_enabled` to Poll --- ...20163240_add_results_and_stats_to_polls.rb | 6 ++ db/schema.rb | 56 ++++++++++++++++--- 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20171020163240_add_results_and_stats_to_polls.rb diff --git a/db/migrate/20171020163240_add_results_and_stats_to_polls.rb b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb new file mode 100644 index 000000000..af6f82aaa --- /dev/null +++ b/db/migrate/20171020163240_add_results_and_stats_to_polls.rb @@ -0,0 +1,6 @@ +class AddResultsAndStatsToPolls < ActiveRecord::Migration + def change + add_column :polls, :results_enabled, :boolean, default: false + add_column :polls, :stats_enabled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index c3ccbeac7..f8dd19c13 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: 20171017221546) do +ActiveRecord::Schema.define(version: 20171020163240) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -486,6 +486,10 @@ ActiveRecord::Schema.define(version: 20171017221546) do t.boolean "draft_publication_enabled", default: false t.boolean "result_publication_enabled", default: false t.boolean "published", default: true + t.date "proposals_phase_start_date" + t.date "proposals_phase_end_date" + t.boolean "proposals_phase_enabled" + t.text "proposals_description" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree @@ -498,6 +502,36 @@ ActiveRecord::Schema.define(version: 20171017221546) do add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree + create_table "legislation_proposals", force: :cascade do |t| + t.integer "legislation_process_id" + t.string "title", limit: 80 + t.text "description" + t.string "question" + t.string "external_url" + t.integer "author_id" + t.datetime "hidden_at" + t.integer "flags_count", default: 0 + t.datetime "ignored_flag_at" + t.integer "cached_votes_up", default: 0 + t.integer "comments_count", default: 0 + t.datetime "confirmed_hide_at" + t.integer "hot_score", limit: 8, default: 0 + t.integer "confidence_score", default: 0 + t.string "responsible_name", limit: 60 + t.text "summary" + t.string "video_url" + t.tsvector "tsv" + t.integer "geozone_id" + t.datetime "retired_at" + t.string "retired_reason" + t.text "retired_explanation" + t.integer "community_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree + create_table "legislation_question_options", force: :cascade do |t| t.integer "legislation_question_id" t.string "value" @@ -666,6 +700,7 @@ ActiveRecord::Schema.define(version: 20171017221546) do t.text "description" t.integer "question_id" t.integer "given_order", default: 1 + t.boolean "most_voted", default: false end add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree @@ -759,6 +794,8 @@ ActiveRecord::Schema.define(version: 20171017221546) do t.integer "comments_count", default: 0 t.integer "author_id" t.datetime "hidden_at" + t.boolean "results_enabled", default: false + t.boolean "stats_enabled", default: false end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree @@ -918,16 +955,20 @@ ActiveRecord::Schema.define(version: 20171017221546) do add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| - t.string "name", limit: 40 - t.integer "taggings_count", default: 0 - t.integer "debates_count", default: 0 - t.integer "proposals_count", default: 0 - t.integer "spending_proposals_count", default: 0 + t.string "name", limit: 40 + t.integer "taggings_count", default: 0 + t.integer "debates_count", default: 0 + t.integer "proposals_count", default: 0 + t.integer "spending_proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 + t.integer "budget/investments_count", default: 0 + t.integer "legislation/proposals_count", default: 0 + t.integer "legislation/processes_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree + add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree + add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree @@ -1105,6 +1146,7 @@ ActiveRecord::Schema.define(version: 20171017221546) do add_foreign_key "identities", "users" add_foreign_key "images", "users" add_foreign_key "legislation_draft_versions", "legislation_processes" + add_foreign_key "legislation_proposals", "legislation_processes" add_foreign_key "locks", "users" add_foreign_key "managers", "users" add_foreign_key "moderators", "users" From 62b1998ec6ccbb4e9e5571ae044d1bc4deb4883d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 20 Oct 2017 18:45:34 +0200 Subject: [PATCH 13/29] Added `results_enabled` and `stats_enabled` to Poll admin form --- app/controllers/admin/poll/polls_controller.rb | 7 ++++--- app/models/poll.rb | 8 ++++++++ app/views/admin/poll/polls/_form.html.erb | 9 +++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 5103275fb..b146f66cc 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -54,9 +54,10 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, - geozone_ids: [], - image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, + :summary, :description, :results_enabled,:stats_enabled, + geozone_ids: [], + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def search_params diff --git a/app/models/poll.rb b/app/models/poll.rb index 27125d8a1..e1a1c2754 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -90,4 +90,12 @@ class Poll < ActiveRecord::Base end end + def results_enabled? + results_enabled + end + + def stats_enabled? + stats_enabled + end + end diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index aff19d9d7..21f1a97f3 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -53,6 +53,15 @@ +
+
+ <%= t('admin.polls.new.show_results_and_stats') %> + <%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %> + <%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %> +

<%= t('admin.polls.new.results_and_stats_reminder') %> +

+
+
<%= f.submit t("admin.polls.#{admin_submit_action(@poll)}.submit_button"), From b64ef9f68972fef5518b08a321fd25813f6f2203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 20 Oct 2017 18:45:43 +0200 Subject: [PATCH 14/29] New translations --- config/locales/en/admin.yml | 4 ++++ config/locales/es/admin.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 38abe6f56..084a0443c 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -560,6 +560,10 @@ en: geozone_restricted: "Restricted to districts" new: title: "New poll" + show_results_and_stats: "Show results and stats" + show_results: "Show results" + show_stats: "Show stats" + results_and_stats_reminder: "Marking these checkboxes the results and/or stats of this poll will be publicly available and every user will see them." submit_button: "Create poll" edit: title: "Edit poll" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3336cdc5b..c13292f89 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -560,6 +560,10 @@ es: geozone_restricted: "Restringida a los distritos" new: title: "Nueva votación" + show_results_and_stats: "Mostrar resultados y estadísticas" + show_results: "Mostrar resultados" + show_stats: "Mostrar estadísticas" + results_and_stats_reminder: "Si marcas estas casillas los resultados y/o estadísticas de esta votación serán públicos y podrán verlos todos los usuarios." submit_button: "Crear votación" edit: title: "Editar votación" From 8ee35df35f5743b958f7d45ea3658b3dd88df672 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 20 Oct 2017 20:56:01 +0200 Subject: [PATCH 15/29] changes poll title link if results or stats are enabled --- app/views/polls/_poll_group.html.erb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 529e9a99e..9d83d5233 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -19,11 +19,27 @@
<% if poll.questions.count == 1 %> <% poll.questions.each do |question| %> -

<%= link_to question.title, poll %>

+

+ <% if poll.results_enabled? %> + <%= link_to question.title, poll_results_path(poll) %> + <% elsif poll.stats_enabled? %> + <%= link_to question.title, poll_stats_path(poll) %> + <% else %> + <%= link_to question.title, poll %> + <% end %> +

<%= poll_dates(poll) %> <% end %> <% else %> -

<%= link_to poll.name, poll %>

+

+ <% if poll.results_enabled? %> + <%= link_to poll.name, poll_results_path(poll) %> + <% elsif poll.stats_enabled? %> + <%= link_to poll.name, poll_stats_path(poll) %> + <% else %> + <%= link_to poll.name, poll %> + <% end %> +

<%= poll_dates(poll) %>
    <% poll.questions.each do |question| %> From d21f0aa8a1427e25a7299f8984e89c27bdff8509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Fri, 20 Oct 2017 21:11:54 +0200 Subject: [PATCH 16/29] Hide results and stats from poll create form --- app/views/admin/poll/polls/_form.html.erb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 21f1a97f3..4926e28ac 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -53,14 +53,16 @@
-
-
- <%= t('admin.polls.new.show_results_and_stats') %> - <%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %> - <%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %> -

<%= t('admin.polls.new.results_and_stats_reminder') %> -

-
+ <% if controller_name == "polls" && action_name == "edit" %> +
+
+ <%= t('admin.polls.new.show_results_and_stats') %> + <%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %> + <%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %> +

<%= t('admin.polls.new.results_and_stats_reminder') %> +

+
+ <% end %>
From 995289304e24530533dbc8b4f2eaa4402b9559f8 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 19 Oct 2017 22:41:54 +0200 Subject: [PATCH 17/29] Add booth location on booth assigment management list, plus poll links on list --- .../admin/poll/booth_assignments/_booth_assignment.html.erb | 3 +++ app/views/admin/poll/booth_assignments/index.html.erb | 3 +-- app/views/admin/poll/booth_assignments/manage.html.erb | 1 + app/views/admin/poll/polls/booth_assignments.html.erb | 2 +- config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb index 7865b201e..d78f7be8b 100644 --- a/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb +++ b/app/views/admin/poll/booth_assignments/_booth_assignment.html.erb @@ -1,6 +1,9 @@
+ <% if booth_assignment.present? %> <% end %> diff --git a/app/views/admin/poll/booth_assignments/manage.html.erb b/app/views/admin/poll/booth_assignments/manage.html.erb index f55e85c74..a24fac478 100644 --- a/app/views/admin/poll/booth_assignments/manage.html.erb +++ b/app/views/admin/poll/booth_assignments/manage.html.erb @@ -13,6 +13,7 @@
<%= t("admin.booths.index.name") %><%= t("admin.booth_assignments.status.assign_status") %><%= t("admin.booth_assignments.manage.status.assign_status") %> <%= t("admin.actions.actions") %>
<%= link_to booth.name, admin_booth_path(booth) %> + <%= booth.location || t("admin.booths.index.no_location") %> + <%= t("admin.booth_assignments.manage.status.assigned") %> diff --git a/app/views/admin/poll/booth_assignments/index.html.erb b/app/views/admin/poll/booth_assignments/index.html.erb index 39435254b..75cbe889f 100644 --- a/app/views/admin/poll/booth_assignments/index.html.erb +++ b/app/views/admin/poll/booth_assignments/index.html.erb @@ -1,6 +1,5 @@ <%= render "/admin/poll/polls/poll_header" %> -
<%= render "/admin/poll/polls/subnav" %> <%= render "search_booths" %> @@ -30,7 +29,7 @@
- <%= booth_assignment.booth.location %> + <%= booth_assignment.booth.location || t("admin.booths.index.no_location") %>
+ diff --git a/app/views/admin/poll/polls/booth_assignments.html.erb b/app/views/admin/poll/polls/booth_assignments.html.erb index 819474852..ad5dc6211 100644 --- a/app/views/admin/poll/polls/booth_assignments.html.erb +++ b/app/views/admin/poll/polls/booth_assignments.html.erb @@ -11,7 +11,7 @@ <% @polls.each do |poll| %>
<%= t("admin.booths.index.name") %><%= t("admin.booths.index.location") %> <%= t("admin.booth_assignments.manage.status.assign_status") %> <%= t("admin.actions.actions") %>
- <%= poll.name %> + <%= link_to poll.name, admin_poll_path(poll) %> <%= l poll.starts_at.to_date %> - <%= l poll.ends_at.to_date %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 3826e9764..aa0fc0f8a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -675,6 +675,7 @@ en: add_booth: "Add booth" name: "Name" location: "Location" + no_location: "No Location" new: title: "New booth" name: "Name" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 9bc97c35f..2ff4449ec 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -677,6 +677,7 @@ es: add_booth: "Añadir urna" name: "Nombre" location: "Ubicación" + no_location: "Sin Ubicación" new: title: "Nueva urna" name: "Nombre" From 5b40696f4f71f3fdebde55fc6be36ea249cf1628 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 17:34:45 +0200 Subject: [PATCH 18/29] shows admin shortcuts menu only to admin users --- .../admin/shared/_admin_shortcuts.html.erb | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/views/admin/shared/_admin_shortcuts.html.erb b/app/views/admin/shared/_admin_shortcuts.html.erb index 7ead6d419..8a292d6bb 100644 --- a/app/views/admin/shared/_admin_shortcuts.html.erb +++ b/app/views/admin/shared/_admin_shortcuts.html.erb @@ -1,10 +1,12 @@ -
  • - <%= link_to admin_stats_path, title: t("admin.menu.stats") do %> - - <% end %> -
  • -
  • - <%= link_to admin_settings_path, title: t("admin.menu.settings") do %> - - <% end %> -
  • +<% if current_user.administrator? %> +
  • + <%= link_to admin_stats_path, title: t("admin.menu.stats") do %> + + <% end %> +
  • +
  • + <%= link_to admin_settings_path, title: t("admin.menu.settings") do %> + + <% end %> +
  • +<% end %> \ No newline at end of file From 668745f3e1d56559152abd264affe9fde0ba2e87 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 17:36:44 +0200 Subject: [PATCH 19/29] moves officing menu outside of admin dropdown --- app/helpers/users_helper.rb | 6 +----- app/views/shared/_admin_login_items.html.erb | 11 +++++------ 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 111a80267..da340bb46 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -52,12 +52,8 @@ module UsersHelper current_user && current_user.manager? end - def current_poll_officer? - current_user && current_user.poll_officer? - end - def show_admin_menu? - current_administrator? || current_moderator? || current_valuator? || current_manager? || current_poll_officer? + current_administrator? || current_moderator? || current_valuator? || current_manager? end def interests_title_text(user) diff --git a/app/views/shared/_admin_login_items.html.erb b/app/views/shared/_admin_login_items.html.erb index 9634874f9..a9e6fa4b9 100644 --- a/app/views/shared/_admin_login_items.html.erb +++ b/app/views/shared/_admin_login_items.html.erb @@ -26,12 +26,11 @@ <%= link_to t("layouts.header.management"), management_sign_in_path %> <% end %> - - <% if current_user.administrator? || current_user.poll_officer? %> -
  • - <%= link_to t("layouts.header.officing"), officing_root_path %> -
  • - <% end %> <% end %> +<% if current_user && current_user.poll_officer? %> +
  • + <%= link_to t("layouts.header.officing"), officing_root_path %> +
  • +<% end %> From 573961a3218a6c81c78b7f4370af9213f7b69bf0 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 17:37:14 +0200 Subject: [PATCH 20/29] avoids admin access to officing panel --- app/controllers/officing/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/officing/base_controller.rb b/app/controllers/officing/base_controller.rb index 97ef23d30..07cf4cfa5 100644 --- a/app/controllers/officing/base_controller.rb +++ b/app/controllers/officing/base_controller.rb @@ -7,6 +7,6 @@ class Officing::BaseController < ApplicationController skip_authorization_check def verify_officer - raise CanCan::AccessDenied unless current_user.try(:poll_officer?) || current_user.try(:administrator?) + raise CanCan::AccessDenied unless current_user.try(:poll_officer?) end end \ No newline at end of file From 47d626619fcab1a6372b1ac516bbf39962364dd6 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 17:37:37 +0200 Subject: [PATCH 21/29] adds specs for admin access to officing --- spec/features/officing_spec.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/features/officing_spec.rb b/spec/features/officing_spec.rb index 338b416ea..b208b735c 100644 --- a/spec/features/officing_spec.rb +++ b/spec/features/officing_spec.rb @@ -55,7 +55,22 @@ feature 'Poll Officing' do expect(page).to have_content "You do not have permission to access this page" end - scenario 'Access as an poll officer is authorized' do + scenario 'Access as an administrator is not authorized' do + create(:administrator, user: user) + create(:poll) + login_as(user) + visit root_path + + expect(page).to_not have_link("Polling officers") + visit officing_root_path + + expect(current_path).not_to eq(officing_root_path) + expect(current_path).to eq(root_path) + expect(page).to have_content "You do not have permission to access this page" + end + + scenario 'Access as an administrator with poll officer role is authorized' do + create(:administrator, user: user) create(:poll_officer, user: user) create(:poll) login_as(user) @@ -68,8 +83,8 @@ feature 'Poll Officing' do expect(page).to_not have_content "You do not have permission to access this page" end - scenario 'Access as an administrator is authorized' do - create(:administrator, user: user) + scenario 'Access as an poll officer is authorized' do + create(:poll_officer, user: user) create(:poll) login_as(user) visit root_path From 3b2f3ae40bf57e6f7ea35bc3f0186855bd3c3945 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 18:20:09 +0200 Subject: [PATCH 22/29] changes admin menu order --- app/views/admin/_menu.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 0518aa0e3..2cc44711f 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -80,15 +80,15 @@ <%= link_to t('admin.menu.poll_booths'), admin_booths_path %> +
  • > + <%= link_to t('admin.menu.poll_booth_assignments'), booth_assignments_admin_polls_path %> +
  • +
  • > <%= link_to t('admin.menu.poll_shifts'), available_admin_booths_path %>
  • - -
  • > - <%= link_to t('admin.menu.poll_booth_assignments'), booth_assignments_admin_polls_path %> -
  • <% end %> From e0a1a73e0b2b8c95ab2d0089866a56c1d8645831 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 18:20:26 +0200 Subject: [PATCH 23/29] fixes active class on polls admin menu --- app/views/admin/_menu.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 2cc44711f..f3abf04aa 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -60,8 +60,8 @@ <%= t("admin.menu.title_polls") %>
      > -
    • > +
    • > <%= link_to t('admin.menu.polls'), admin_polls_path %>
    • From 70713e08c3469965bb2930404743486b88a78d5b Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 18:25:30 +0200 Subject: [PATCH 24/29] adds missing space --- app/controllers/admin/poll/polls_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index b146f66cc..0860e8518 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -55,7 +55,7 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController def poll_params params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, - :summary, :description, :results_enabled,:stats_enabled, + :summary, :description, :results_enabled, :stats_enabled, geozone_ids: [], image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end From f8e5f791b34154767c3d93cccd1d5d6e18e65e4b Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 21 Oct 2017 18:25:58 +0200 Subject: [PATCH 25/29] adds missing p close tag --- app/views/admin/poll/polls/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 4926e28ac..c0439af7b 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -59,7 +59,7 @@ <%= t('admin.polls.new.show_results_and_stats') %> <%= f.check_box :results_enabled, checked: @poll.results_enabled?, label: t('admin.polls.new.show_results') %> <%= f.check_box :stats_enabled, checked: @poll.stats_enabled?, label: t('admin.polls.new.show_stats') %> -

      <%= t('admin.polls.new.results_and_stats_reminder') %> +

      <%= t('admin.polls.new.results_and_stats_reminder') %>

      <% end %> From 6b5c29f23ec2429119fe7dc63e5d4922460bd896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 23 Oct 2017 12:25:51 +0200 Subject: [PATCH 26/29] Added tests --- spec/features/admin/poll/polls_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 2a2d26ea5..8180a89f2 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -60,6 +60,10 @@ feature 'Admin polls' do fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." fill_in 'poll_description', with: "Upcomming poll's description. This poll..." + + expect(page).to_not have_css("#poll_results_enabled") + expect(page).to_not have_css("#poll_stats_enabled") + click_button "Create poll" expect(page).to have_content "Poll created successfully" @@ -79,6 +83,9 @@ feature 'Admin polls' do expect(page).to have_css("img[alt='#{poll.image.title}']") + expect(page).to have_css("#poll_results_enabled") + expect(page).to have_css("#poll_stats_enabled") + fill_in "poll_name", with: "Next Poll" fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") From fad5841d8ff501279d4193c81ae3e5876339ae96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 23 Oct 2017 12:57:41 +0200 Subject: [PATCH 27/29] Improvements --- app/models/poll.rb | 8 ------- db/schema.rb | 52 ++++++---------------------------------------- 2 files changed, 6 insertions(+), 54 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index e1a1c2754..27125d8a1 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -90,12 +90,4 @@ class Poll < ActiveRecord::Base end end - def results_enabled? - results_enabled - end - - def stats_enabled? - stats_enabled - end - end diff --git a/db/schema.rb b/db/schema.rb index f8dd19c13..506153b6a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -486,10 +486,6 @@ ActiveRecord::Schema.define(version: 20171020163240) do t.boolean "draft_publication_enabled", default: false t.boolean "result_publication_enabled", default: false t.boolean "published", default: true - t.date "proposals_phase_start_date" - t.date "proposals_phase_end_date" - t.boolean "proposals_phase_enabled" - t.text "proposals_description" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree @@ -502,36 +498,6 @@ ActiveRecord::Schema.define(version: 20171020163240) do add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree - create_table "legislation_proposals", force: :cascade do |t| - t.integer "legislation_process_id" - t.string "title", limit: 80 - t.text "description" - t.string "question" - t.string "external_url" - t.integer "author_id" - t.datetime "hidden_at" - t.integer "flags_count", default: 0 - t.datetime "ignored_flag_at" - t.integer "cached_votes_up", default: 0 - t.integer "comments_count", default: 0 - t.datetime "confirmed_hide_at" - t.integer "hot_score", limit: 8, default: 0 - t.integer "confidence_score", default: 0 - t.string "responsible_name", limit: 60 - t.text "summary" - t.string "video_url" - t.tsvector "tsv" - t.integer "geozone_id" - t.datetime "retired_at" - t.string "retired_reason" - t.text "retired_explanation" - t.integer "community_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - end - - add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree - create_table "legislation_question_options", force: :cascade do |t| t.integer "legislation_question_id" t.string "value" @@ -700,7 +666,6 @@ ActiveRecord::Schema.define(version: 20171020163240) do t.text "description" t.integer "question_id" t.integer "given_order", default: 1 - t.boolean "most_voted", default: false end add_index "poll_question_answers", ["question_id"], name: "index_poll_question_answers_on_question_id", using: :btree @@ -955,20 +920,16 @@ ActiveRecord::Schema.define(version: 20171020163240) do add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree create_table "tags", force: :cascade do |t| - t.string "name", limit: 40 - t.integer "taggings_count", default: 0 - t.integer "debates_count", default: 0 - t.integer "proposals_count", default: 0 - t.integer "spending_proposals_count", default: 0 + t.string "name", limit: 40 + t.integer "taggings_count", default: 0 + t.integer "debates_count", default: 0 + t.integer "proposals_count", default: 0 + t.integer "spending_proposals_count", default: 0 t.string "kind" - t.integer "budget/investments_count", default: 0 - t.integer "legislation/proposals_count", default: 0 - t.integer "legislation/processes_count", default: 0 + t.integer "budget/investments_count", default: 0 end add_index "tags", ["debates_count"], name: "index_tags_on_debates_count", using: :btree - add_index "tags", ["legislation/processes_count"], name: "index_tags_on_legislation/processes_count", using: :btree - add_index "tags", ["legislation/proposals_count"], name: "index_tags_on_legislation/proposals_count", using: :btree add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree add_index "tags", ["proposals_count"], name: "index_tags_on_proposals_count", using: :btree add_index "tags", ["spending_proposals_count"], name: "index_tags_on_spending_proposals_count", using: :btree @@ -1146,7 +1107,6 @@ ActiveRecord::Schema.define(version: 20171020163240) do add_foreign_key "identities", "users" add_foreign_key "images", "users" add_foreign_key "legislation_draft_versions", "legislation_processes" - add_foreign_key "legislation_proposals", "legislation_processes" add_foreign_key "locks", "users" add_foreign_key "managers", "users" add_foreign_key "moderators", "users" From b1e91cdc03acf3072d6d5b27c8d14965d2d0cb53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 23 Oct 2017 12:57:52 +0200 Subject: [PATCH 28/29] Tests improvements --- spec/features/admin/poll/polls_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index 8180a89f2..210b2ff6a 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -88,12 +88,20 @@ feature 'Admin polls' do fill_in "poll_name", with: "Next Poll" fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + check 'poll_results_enabled' + check 'poll_stats_enabled' click_button "Update poll" expect(page).to have_content "Poll updated successfully" expect(page).to have_content "Next Poll" expect(page).to have_content I18n.l(end_date.to_date) + + click_link "Edit poll" + + expect(page).to have_field('poll_results_enabled', checked: true) + expect(page).to have_field('poll_stats_enabled', checked: true) + end scenario 'Edit from index' do From f38f333fe55288919254f0c6412de2a90b632757 Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 23 Oct 2017 13:02:37 +0200 Subject: [PATCH 29/29] undo changes on poll title links --- app/views/polls/_poll_group.html.erb | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/app/views/polls/_poll_group.html.erb b/app/views/polls/_poll_group.html.erb index 9d83d5233..529e9a99e 100644 --- a/app/views/polls/_poll_group.html.erb +++ b/app/views/polls/_poll_group.html.erb @@ -19,27 +19,11 @@
      <% if poll.questions.count == 1 %> <% poll.questions.each do |question| %> -

      - <% if poll.results_enabled? %> - <%= link_to question.title, poll_results_path(poll) %> - <% elsif poll.stats_enabled? %> - <%= link_to question.title, poll_stats_path(poll) %> - <% else %> - <%= link_to question.title, poll %> - <% end %> -

      +

      <%= link_to question.title, poll %>

      <%= poll_dates(poll) %> <% end %> <% else %> -

      - <% if poll.results_enabled? %> - <%= link_to poll.name, poll_results_path(poll) %> - <% elsif poll.stats_enabled? %> - <%= link_to poll.name, poll_stats_path(poll) %> - <% else %> - <%= link_to poll.name, poll %> - <% end %> -

      +

      <%= link_to poll.name, poll %>

      <%= poll_dates(poll) %>
        <% poll.questions.each do |question| %>