diff --git a/app/assets/stylesheets/main.css.erb b/app/assets/stylesheets/main.css.erb index 5a5b5e59..15a21a92 100644 --- a/app/assets/stylesheets/main.css.erb +++ b/app/assets/stylesheets/main.css.erb @@ -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; diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 57d82ac0..169765f5 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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: @@ -225,5 +274,4 @@ def can_edit_profile?(person) @current_user && @current_user.id == params[:id] or @auth['superusers'] end - end diff --git a/app/models/person.rb b/app/models/person.rb index b6ec3ec1..8ca7379c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/views/people/_list_results.html.erb b/app/views/people/_list_results.html.erb index ded2ddc6..147a73c6 100644 --- a/app/views/people/_list_results.html.erb +++ b/app/views/people/_list_results.html.erb @@ -32,3 +32,5 @@ <%= will_paginate @people, :class => "ajax-controls ajax" %> + +<%#= ajaxify_links %> diff --git a/app/views/people/_search_results.html.erb b/app/views/people/_search_results.html.erb new file mode 100644 index 00000000..d10c8d31 --- /dev/null +++ b/app/views/people/_search_results.html.erb @@ -0,0 +1,36 @@ +<%# http://wiki.github.com/mislav/will_paginate/ajax-pagination %> +
Image | +Name (<%= sort_link 'First', 'first_name' %> <%= sort_link 'Last', 'last_name' %>) | +<%= sort_link 'Email', 'email' %> | +Phone | + <% if params[:not_approved] %> +Registered | + <% end %> +
---|---|---|---|---|
+ <%= image_tag person.picture unless person.picture.blank? %> + | +
+ <%= link_to person.fullname, profile_path(:login => person.username) %>
+ <%= person.status %>
+ |
+ <%= raw html_obfuscate person.email if !person.private || @auth['csec'] || @auth['vp'] %> | +<%= person.phone_number if !person.private || @auth['csec'] || !( @current_user.groups.collect(&:name) & person.groups.collect(&:name) & Committeeship.Committees).empty? %> | + <% if params[:not_approved] %> +<%= person.created_at %> | + <% end %> +<% end %> + +