adds officer search to admin polls

This commit is contained in:
Juanjo Bazán
2016-12-27 12:36:16 +01:00
parent 122fd5f9ff
commit ee8c057a46
9 changed files with 58 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
class Admin::Poll::PollsController < Admin::BaseController class Admin::Poll::PollsController < Admin::BaseController
load_and_authorize_resource 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 def index
end end
@@ -62,8 +62,16 @@ class Admin::Poll::PollsController < Admin::BaseController
end end
end end
def search_questions #cambiar a @poll.id def search_questions
@questions = ::Poll::Question.where("poll_id IS ? OR poll_id != ?", nil, search_params[:poll_id]).search({search: @search}) @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| respond_to do |format|
format.js format.js
end end

View File

@@ -13,6 +13,7 @@ class User < ActiveRecord::Base
has_one :moderator has_one :moderator
has_one :valuator has_one :valuator
has_one :manager has_one :manager
has_one :poll_officer, class_name: "Poll::Officer"
has_one :organization has_one :organization
has_one :lock has_one :lock
has_many :flags has_many :flags

View File

@@ -0,0 +1,14 @@
<%= form_tag(search_officers_admin_poll_path(@poll), method: :get, remote: true) do |f| %>
<div class="row">
<div class="small-12 medium-6 column">
<%= text_field_tag :search,
@search,
placeholder: t("admin.shared.poll_officers_search.placeholder"), id: "search-officers" %>
</div>
<div class="form-inline small-12 medium-3 column end">
<%= submit_tag t("admin.shared.poll_officers_search.button"), class: "button" %>
</div>
</div>
<% end %>
<div id="search-officers-results"></div>

View File

@@ -0,0 +1,22 @@
<table>
<thead>
<tr>
<th colspan="3"><%= @officers.blank? ? t('admin.polls.show.no_search_results') : t('admin.polls.show.search_results') %></th>
</tr>
</thead>
<tbody>
<% @officers.each do |officer| %>
<tr>
<td>
<%= officer.name %>
</td>
<td>
<%= officer.email %>
</td>
<td class="text-right">
</td>
</tr>
<% end %>
</tbody>
</table>

View File

@@ -0,0 +1 @@
$("#search-officers-results").html("<%= j render 'search_officers_results' %>");

View File

@@ -21,6 +21,7 @@
</div> </div>
<div class="tabs-panel" id="tab-officers"> <div class="tabs-panel" id="tab-officers">
<%= render "search_officers" %>
<%= render 'officers' %> <%= render 'officers' %>
</div> </div>
</div> </div>

View File

@@ -315,6 +315,9 @@ en:
booths_search: booths_search:
button: Search button: Search
placeholder: Search booth by name placeholder: Search booth by name
poll_officers_search:
button: Search
placeholder: Search poll officers
poll_questions_search: poll_questions_search:
button: Search button: Search
placeholder: Search poll questions placeholder: Search poll questions

View File

@@ -315,6 +315,9 @@ es:
booths_search: booths_search:
button: Buscar button: Buscar
placeholder: Buscar urna por nombre placeholder: Buscar urna por nombre
poll_officers_search:
button: Buscar
placeholder: Buscar presidentes de mesa
poll_questions_search: poll_questions_search:
button: Buscar button: Buscar
placeholder: Buscar preguntas placeholder: Buscar preguntas

View File

@@ -189,6 +189,7 @@ Rails.application.routes.draw do
end end
resources :polls do resources :polls do
get :search_booths, on: :member get :search_booths, on: :member
get :search_officers, on: :member
get :search_questions, on: :member get :search_questions, on: :member
patch :add_question, on: :member patch :add_question, on: :member
patch :remove_question, on: :member patch :remove_question, on: :member
@@ -196,6 +197,7 @@ Rails.application.routes.draw do
resources :booths resources :booths
resources :booth_assignments, only: [:create, :destroy] resources :booth_assignments, only: [:create, :destroy]
resources :officer_assignments, only: [:new, :create, :destroy]
resources :questions resources :questions
end end