From ee8c057a464d17dcc86c97400bbce8a543fa857e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Tue, 27 Dec 2016 12:36:16 +0100 Subject: [PATCH] adds officer search to admin polls --- .../admin/poll/polls_controller.rb | 14 +++++++++--- app/models/user.rb | 1 + .../poll/polls/_search_officers.html.erb | 14 ++++++++++++ .../polls/_search_officers_results.html.erb | 22 +++++++++++++++++++ .../admin/poll/polls/search_officers.js.erb | 1 + app/views/admin/poll/polls/show.html.erb | 1 + config/locales/admin.en.yml | 3 +++ config/locales/admin.es.yml | 3 +++ config/routes.rb | 2 ++ 9 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/poll/polls/_search_officers.html.erb create mode 100644 app/views/admin/poll/polls/_search_officers_results.html.erb create mode 100644 app/views/admin/poll/polls/search_officers.js.erb diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index 2b17075ce..22938d83a 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -1,6 +1,6 @@ class Admin::Poll::PollsController < Admin::BaseController load_and_authorize_resource - before_action :load_search, only: [:search_booths, :search_questions] + before_action :load_search, only: [:search_booths, :search_questions, :search_officers] def index end @@ -62,8 +62,16 @@ class Admin::Poll::PollsController < Admin::BaseController end end - def search_questions #cambiar a @poll.id - @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, search_params[:poll_id]).search({search: @search}) + def search_questions + @questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, @poll.id).search({search: @search}) + respond_to do |format| + format.js + end + end + + def search_officers + @officers = User.joins(:poll_officer).search(@search) + respond_to do |format| format.js end diff --git a/app/models/user.rb b/app/models/user.rb index d248e5f48..79c5d1af3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,7 @@ class User < ActiveRecord::Base has_one :moderator has_one :valuator has_one :manager + has_one :poll_officer, class_name: "Poll::Officer" has_one :organization has_one :lock has_many :flags diff --git a/app/views/admin/poll/polls/_search_officers.html.erb b/app/views/admin/poll/polls/_search_officers.html.erb new file mode 100644 index 000000000..45ce9bd8f --- /dev/null +++ b/app/views/admin/poll/polls/_search_officers.html.erb @@ -0,0 +1,14 @@ +<%= form_tag(search_officers_admin_poll_path(@poll), method: :get, remote: true) do |f| %> +
+
+ <%= text_field_tag :search, + @search, + placeholder: t("admin.shared.poll_officers_search.placeholder"), id: "search-officers" %> +
+
+ <%= submit_tag t("admin.shared.poll_officers_search.button"), class: "button" %> +
+
+<% end %> + +
diff --git a/app/views/admin/poll/polls/_search_officers_results.html.erb b/app/views/admin/poll/polls/_search_officers_results.html.erb new file mode 100644 index 000000000..b77c06827 --- /dev/null +++ b/app/views/admin/poll/polls/_search_officers_results.html.erb @@ -0,0 +1,22 @@ + + + + + + + + <% @officers.each do |officer| %> + + + + + + <% end %> + +
<%= @officers.blank? ? t('admin.polls.show.no_search_results') : t('admin.polls.show.search_results') %>
+ <%= officer.name %> + + <%= officer.email %> + + +
\ No newline at end of file diff --git a/app/views/admin/poll/polls/search_officers.js.erb b/app/views/admin/poll/polls/search_officers.js.erb new file mode 100644 index 000000000..ba621d8f7 --- /dev/null +++ b/app/views/admin/poll/polls/search_officers.js.erb @@ -0,0 +1 @@ +$("#search-officers-results").html("<%= j render 'search_officers_results' %>"); \ 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 b948ee9a5..e357bc7f4 100644 --- a/app/views/admin/poll/polls/show.html.erb +++ b/app/views/admin/poll/polls/show.html.erb @@ -21,6 +21,7 @@
+ <%= render "search_officers" %> <%= render 'officers' %>
\ No newline at end of file diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 6e8f4e46e..a3dddb17f 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -315,6 +315,9 @@ en: booths_search: button: Search placeholder: Search booth by name + poll_officers_search: + button: Search + placeholder: Search poll officers poll_questions_search: button: Search placeholder: Search poll questions diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 6158f02de..03ceb208e 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -315,6 +315,9 @@ es: booths_search: button: Buscar placeholder: Buscar urna por nombre + poll_officers_search: + button: Buscar + placeholder: Buscar presidentes de mesa poll_questions_search: button: Buscar placeholder: Buscar preguntas diff --git a/config/routes.rb b/config/routes.rb index 587d1e70e..63b0e9f6e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -189,6 +189,7 @@ Rails.application.routes.draw do end resources :polls do get :search_booths, on: :member + get :search_officers, on: :member get :search_questions, on: :member patch :add_question, on: :member patch :remove_question, on: :member @@ -196,6 +197,7 @@ Rails.application.routes.draw do resources :booths resources :booth_assignments, only: [:create, :destroy] + resources :officer_assignments, only: [:new, :create, :destroy] resources :questions end