Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/assets/stylesheets/main.css.erb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,28 @@ h4{
text-shadow: none;
}

#peoplesearch {
float: right;
display: inline;
width: 100%;
}

#people_form {
overflow: hidden;
width: 100%;
}

#people_sub {
float: left;
height: 26px;
}

#people_q {
width: 100%;
height: 20px;
margin-left: 3px;
}

#main{
width: 65%;
float: left;
Expand Down
50 changes: 49 additions & 1 deletion app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,55 @@ def contact_card
:filename => "hkn-contacts.csv"
end

def search
return if strip_params
query = @query = sanitize_query(params[:q])

order = params[:sort] || "first_name"
sort_direction = case params[:sort_direction]
when "up" then "ASC"
when "down" then "DESC"
else "ASC"
end

@search_opts = {'sort' => "first_name"}.merge params
opts = { :page => params[:page],
:per_page => params[:per_page] || 20,
:order => "people.#{order} #{sort_direction}"
}

@results = {}

if $SUNSPOT_ENABLED
@results = Person.search do
keywords query # this needs to be a local var, not an instance var, b/c of scoping issues
order_by :first_name, :desc
end.results
else
# Solr isn't started, hack together some results
logger.warn "Solr isn't started, falling back to lame search"
str = "%#{@query}%"
@results = Person.find(:all, :conditions => ['first_name LIKE ? OR last_name LIKE ? OR (first_name||\' \'||last_name) LIKE ?', str, str, str])
flash[:notice] = "Solr isn't started, so your results are probably lacking." if Rails.env.development?
end

# if very likely have a single match, just go to it
if @results.length == 1 then
p = @results.first
redirect_to :action => "show", :login => p.username
return
end

@results = @results.paginate opts
# multiple results
respond_to do |format|
format.html
format.js {
render :partial => 'search_results'
}
end
end

private
def can_edit_profile?(person)
# @current_user can view @person if:
Expand All @@ -225,5 +274,4 @@ def can_edit_profile?(person)
@current_user && @current_user.id == params[:id] or @auth['superusers']
end


end
10 changes: 10 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ module Regex
scope :alpha_last, lambda {order('last_name, first_name')}
scope :alpha, lambda {order('first_name, last_name')}

# Sunspot
searchable do
string :first_name
string :last_name
string :full_name do |p|
[p.first_name, p.lastname].join(' ')
end
end
# end sunspot

acts_as_authentic do |c|
# Options go here if you have any
c.merge_validates_length_of_password_field_options :minimum => 8
Expand Down
2 changes: 2 additions & 0 deletions app/views/people/_list_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@
</table>
<%= will_paginate @people, :class => "ajax-controls ajax" %>
</div>

<%#= ajaxify_links %>
36 changes: 36 additions & 0 deletions app/views/people/_search_results.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%# http://wiki.github.com/mislav/will_paginate/ajax-pagination %>
<div id="ajax-wrapper">
<%= spinner %>
<%= will_paginate @results, :class => "ajax-controls ajax" %>

<table class="table">
<tr class="ajax-controls">
<th>Image</th>
<th>Name (<%= sort_link 'First', 'first_name' %> <%= sort_link 'Last', 'last_name' %>)</th>
<th><%= sort_link 'Email', 'email' %></th>
<th>Phone</th>
<% if params[:not_approved] %>
<th>Registered</th>
<% end %>
</tr>
<% @results.each do |person| %>
<tr>
<td>
<%= image_tag person.picture unless person.picture.blank? %>
</td>
<td>
<%= link_to person.fullname, profile_path(:login => person.username) %>
<div class="small"><%= person.status %></div>
</td>
<td><%= raw html_obfuscate person.email if !person.private || @auth['csec'] || @auth['vp'] %></td>
<td><%= person.phone_number if !person.private || @auth['csec'] || !( @current_user.groups.collect(&:name) & person.groups.collect(&:name) & Committeeship.Committees).empty? %></td>
<% if params[:not_approved] %>
<td><%= person.created_at %></td>
<% end %>
<% end %>

</table>
<%= will_paginate @results, :class => "ajax-controls ajax" %>
</div>

<%#= ajaxify_links %>
11 changes: 11 additions & 0 deletions app/views/people/list.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div id="searcharea">
<div id="peoplesearch" class="searchcontrol">
<%= form_tag(people_search_path, :id=> "people_form", :method => :get) do %>
<%= submit_tag "Search", :id=> "people_sub", :name=>nil %>
<span style="display:block;overflow:hidden;padding-right: 10px;" >
<%= text_field_tag :q, params[:controller].eql?('people') ? h(params[:q]) : '', :id => "people_q", :placeholder=>"Search People", :class=>"text autoclear" %>
</span>
<%- end -%>
</div>
</div>

<%= render :partial => 'list_results' %>

<%= ajaxify_links %>
14 changes: 14 additions & 0 deletions app/views/people/search.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="searcharea">
<div id="peoplesearch" class="searchcontrol">
<%= form_tag(people_search_path, :id=> "people_form", :method => :get) do %>
<%= submit_tag "Search", :id=> "people_sub", :name=>nil %>
<span style="display:block;overflow:hidden;padding-right: 10px;" >
<%= text_field_tag :q, params[:controller].eql?('people') ? h(params[:q]) : '', :id => "people_q", :placeholder=>"Search People", :class=>"text autoclear" %>
</span>
<%- end -%>
</div>
</div>

<%= render :partial => 'search_results' %>

<%= ajaxify_links %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@

# People
scope "people" do
match "search(/:q)" => "people#search", :as => :people_search
match "list(/:category)" => "people#list", :as => :people_list
match "contact_card" => "people#contact_card", :as => :contact_card
end
Expand Down