Merge branch 'polls' into polls-design
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]
|
||||
before_action :load_search, only: [:search_booths, :search_questions]
|
||||
|
||||
def index
|
||||
end
|
||||
@@ -31,6 +31,30 @@ class Admin::Poll::PollsController < Admin::BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def add_question
|
||||
question = ::Poll::Question.find(params[:question_id])
|
||||
|
||||
if question.present?
|
||||
@poll.questions << question
|
||||
notice = t("admin.polls.flash.question_added")
|
||||
else
|
||||
notice = t("admin.polls.flash.error_on_question_added")
|
||||
end
|
||||
redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice
|
||||
end
|
||||
|
||||
def remove_question
|
||||
question = ::Poll::Question.find(params[:question_id])
|
||||
|
||||
if @poll.questions.include? question
|
||||
@poll.questions.delete(question)
|
||||
notice = t("admin.polls.flash.question_removed")
|
||||
else
|
||||
notice = t("admin.polls.flash.error_on_question_removed")
|
||||
end
|
||||
redirect_to admin_poll_path(@poll, anchor: 'tab-questions'), notice: notice
|
||||
end
|
||||
|
||||
def search_booths
|
||||
@booths = ::Poll::Booth.search(@search)
|
||||
respond_to do |format|
|
||||
@@ -38,6 +62,13 @@ 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})
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def poll_params
|
||||
|
||||
@@ -21,6 +21,7 @@ class Poll::Question < ActiveRecord::Base
|
||||
validates :title, length: { in: 4..Poll::Question.title_max_length }
|
||||
validates :description, length: { maximum: Poll::Question.description_max_length }
|
||||
|
||||
scope :no_poll, -> { where(poll_id: nil) }
|
||||
scope :by_poll_id, -> (poll_id) { where(poll_id: poll_id) }
|
||||
scope :by_geozone_id, -> (geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) }
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
include Verification
|
||||
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable,
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable,
|
||||
:trackable, :validatable, :omniauthable, :async, :password_expirable, :secure_validatable
|
||||
|
||||
acts_as_voter
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
<td><%= link_to question.title, admin_question_path(question) %></td>
|
||||
<td class="text-right">
|
||||
<%= link_to t('admin.polls.show.remove_question'),
|
||||
admin_question_path(question),
|
||||
remove_question_admin_poll_path(poll_id: @poll.id, question_id: question.id),
|
||||
class: "button hollow alert",
|
||||
method: :delete %>
|
||||
method: :patch %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
14
app/views/admin/poll/polls/_search_questions.html.erb
Normal file
14
app/views/admin/poll/polls/_search_questions.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<%= form_tag(search_questions_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_questions_search.placeholder"), id: "search-questions" %>
|
||||
</div>
|
||||
<div class="form-inline small-12 medium-3 column end">
|
||||
<%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div id="search-questions-results"></div>
|
||||
@@ -0,0 +1,25 @@
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3"><%= @questions.blank? ? t('admin.polls.show.no_search_results') : t('admin.polls.show.search_results') %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @questions.each do |question| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= question.title %>
|
||||
</td>
|
||||
<td>
|
||||
<%= question.summary %>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<%= link_to t("admin.polls.show.add_question"),
|
||||
add_question_admin_poll_path(poll_id: @poll.id, question_id: question.id),
|
||||
method: :patch,
|
||||
class: "button hollow" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
1
app/views/admin/poll/polls/search_questions.js.erb
Normal file
1
app/views/admin/poll/polls/search_questions.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#search-questions-results").html("<%= j render 'search_questions_results' %>");
|
||||
@@ -11,6 +11,7 @@
|
||||
<%= render "filter_subnav" %>
|
||||
|
||||
<div class="tabs-panel is-active" id="tab-questions">
|
||||
<%= render "search_questions" %>
|
||||
<%= render "questions" %>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<div class="input-group">
|
||||
<%= text_field_tag :search,
|
||||
@search,
|
||||
placeholder: t("admin.shared.spending_proposal_search.placeholder") %>
|
||||
placeholder: t("admin.shared.poll_questions_search.placeholder") %>
|
||||
<div class="input-group-button">
|
||||
<%= submit_tag t("admin.shared.spending_proposal_search.button"), class: "button" %>
|
||||
<%= submit_tag t("admin.shared.poll_questions_search.button"), class: "button" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user