Skip to content

Commit

Permalink
Public organization index. Unify to search engine in one field ( keyw…
Browse files Browse the repository at this point in the history
…ord and agent)
  • Loading branch information
vicentemendozam committed Dec 15, 2017
1 parent 6ea1916 commit 443ab67
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def search(params)
Organization.search do
with(:entity_type_id, 2)
with(:invalidate, false)
fulltext params[:keyword] if params[:keyword].present?
with(:interest_ids, params[:interests]) if params[:interests].present?
with(:category_id, params[:category]) if params[:category].present?
with(:lobby_activity, true) if params[:lobby_activity].present?
any do
fulltext(params[:agent_name], :fields => [:agent_name]) if params[:agent_name].present?
fulltext(params[:agent_name], :fields => [:agent_first_surname]) if params[:agent_name].present?
fulltext(params[:agent_name], :fields => [:agent_second_surname]) if params[:agent_name].present?
fulltext params[:keyword] if params[:keyword].present?
fulltext(params[:keyword], :fields => [:agent_name]) if params[:keyword].present?
fulltext(params[:keyword], :fields => [:agent_first_surname]) if params[:keyword].present?
fulltext(params[:keyword], :fields => [:agent_second_surname]) if params[:keyword].present?
end
order_by :created_at, :desc
paginate page: params[:format].present? ? 1 : params[:page] || 1, per_page: params[:format].present? ? 1000 : 10
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def event_status_search_options(selected)
options_for_select(rev, selected)
end

def holder_name_by_position_id(position_id)
def holder_name_by_position_id (position_id)
holder_title = Position.find(position_id).full_name if position_id.present?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Organization < ActiveRecord::Base
end
integer :category_id
integer :id
join(:lobby_activity,:target => Event, :type => :boolean, :join => { :from => :organization_id, :to => :id})
join(:lobby_activity, :target => Event, :type => :boolean, :join => { :from => :organization_id, :to => :id })
join(:name, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
join(:first_surname, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
join(:second_surname, :prefix => "agent", :target => Agent, :type => :text, :join => { :from => :organization_id, :to => :id })
Expand Down
1 change: 1 addition & 0 deletions app/models/position.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Position < ActiveRecord::Base
scope :previous, -> { where.not(to: nil) }
scope :area_filtered, ->(area) { where(area_id: Area.find(area).subtree_ids) if area.present? }
scope :full_like, lambda { |search_name| where("holder_id IN (?) OR title ILIKE ?", Holder.by_name(search_name).pluck(:id), "%#{search_name}%") }

def events
(titular_events + participants_events).uniq
end
Expand Down
3 changes: 0 additions & 3 deletions app/views/organizations/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
<%= label_tag(:lobby_activity, t("backend.lobby_activity")) %>
</div>
</div>
<div class="mb20">
<%= text_field_tag :agent_name, params[:agent_name], placeholder: t("main.form.agent") %>
</div>

<div class="mb20">
<%= link_to t("main.form.reset"), organizations_path, class: "button secondary" %>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/public.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ en:
english: "Inglés"
main:
form:
keyword: "Palabra clave"
keyword: "Search by keywork or agent name"
main_area: "Área/Distrito/Organismo autónomo"
child_area: "Dirección general"
holder: "Titular de la agenda"
Expand Down
2 changes: 1 addition & 1 deletion config/locales/public.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ es:
back: "Volver al listado"
form:
title: "Utiliza estos filtros para buscar la información que más te interesa."
keyword: "Palabra clave"
keyword: "Palabra clave o nombre del agente"
main_area: "Área/Distrito/Organismo autónomo"
child_area: "Dirección general"
holder: "Titular de la agenda"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@
expect(page).to have_content(@org1.name)
expect(page).to have_content(@org2.name)

fill_in :agent_name, with: "Maria"
fill_in :keyword, with: "Maria"
click_button(I18n.t('main.form.search'))

expect(page).to have_content(@org1.name)
expect(page).to have_no_content(@org2.name)

fill_in :agent_name, with: "Pedro"
fill_in :keyword, with: "Pedro"
click_button(I18n.t('main.form.search'))

expect(page).to have_content(@org2.name)
Expand Down

0 comments on commit 443ab67

Please sign in to comment.