adds officer search to admin polls
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
14
app/views/admin/poll/polls/_search_officers.html.erb
Normal file
14
app/views/admin/poll/polls/_search_officers.html.erb
Normal 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>
|
||||
22
app/views/admin/poll/polls/_search_officers_results.html.erb
Normal file
22
app/views/admin/poll/polls/_search_officers_results.html.erb
Normal 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>
|
||||
1
app/views/admin/poll/polls/search_officers.js.erb
Normal file
1
app/views/admin/poll/polls/search_officers.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-officers-results").html("<%= j render 'search_officers_results' %>");
|
||||
@@ -21,6 +21,7 @@
|
||||
</div>
|
||||
|
||||
<div class="tabs-panel" id="tab-officers">
|
||||
<%= render "search_officers" %>
|
||||
<%= render 'officers' %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user