优化用户搜索

This commit is contained in:
nieguanghui 2013-11-08 11:01:28 +08:00
parent 8f216a6723
commit dd6563cf8c
3 changed files with 34 additions and 49 deletions

View File

@ -67,9 +67,6 @@ class Project < ActiveRecord::Base
#ADDED BY NIE #ADDED BY NIE
has_many :project_infos, :dependent => :destroy has_many :project_infos, :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy
#end #end

View File

@ -152,6 +152,15 @@ class User < Principal
} }
scope :sorted, lambda { order(*User.fields_for_order_statement)} scope :sorted, lambda { order(*User.fields_for_order_statement)}
scope :like, lambda {|arg|
if arg.blank?
where(nil)
else
pattern = "%#{arg.to_s.strip.downcase}%"
where(" LOWER(concat(lastname, firstname)) LIKE :p ", :p => pattern)
end
}
###添加留言 fq ###添加留言 fq
def add_jour(user, notes, reference_user_id = 0) def add_jour(user, notes, reference_user_id = 0)

View File

@ -20,7 +20,7 @@
<label for='name'><%= l(:label_user) %>:</label> <label for='name'><%= l(:label_user) %>:</label>
<%= text_field_tag 'name', params[:name], :size => 30 %> <%= text_field_tag 'name', params[:name], :size => 30 %>
<%= submit_tag l(:label_search), :class => "small", :name => nil %><!--Modified by young--> <%= submit_tag l(:label_search), :class => "small", :name => nil %>
</fieldset> </fieldset>
<% end %> <% end %>
&nbsp; &nbsp;
@ -66,75 +66,54 @@
<% html_title(l(:label_user_plural)) -%> <% html_title(l(:label_user_plural)) -%>
<% else %> <% else %>
<!-- <div class="contextual">
<%= link_to l(:label_user_new), new_user_path, :class => 'icon icon-add' %>
</div> -->
<div class="project-search-block"> <div class="project-search-block">
<span><%= l(:label_user_plural)%></span> <span><%= l(:label_user_plural)%></span>
<%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %> <%= form_tag(:controller => 'users', :action => 'search', :method => :get) do %>
<!-- <fieldset>
<legend>
<%= l(:label_filter_plural) %>
</legend> -->
<div class="project-search"> <div class="project-search">
<%= text_field_tag 'name', params[:name], :size => 30 %> <%= text_field_tag 'name', params[:name], :size => 30 %>
<%= submit_tag l(:label_search), :class => "small", :name => nil %><!--Modified by young--> <%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
<!-- </fieldset> -->
<% end %> <% end %>
</div> </div>
</div> </div>
<!-- <div class="pagination" style="border-bottom: 1px solid rgb(223,223,223); width: 95%; margin-left: 2%; margin-top: 0px">
<ul style="margin-right:0px">
<li>
<%= link_to l(:label_sort_by_time), users_path(:user_sort_type => '0') %>
</li>
<li>
<%= link_to l(:label_sort_by_active), users_path(:user_sort_type => '1') %>
</li>
<li>
<%= link_to l(:label_sort_by_influence), users_path(:user_sort_type => '2') %>
</li>
</ul>
</div> -->
<div class="autoscroll"> <div class="autoscroll">
<% for user in @users -%> <% if @users.size > 0 %>
<% unless user.id == 1%> <% @users.each do |user| -%>
<div class="well"> <% unless user.id == 1%>
<div class="well">
<%= content_tag "p", "#{format_date(user.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %> <%= content_tag "p", "#{format_date(user.created_on)}#{l(:label_member_since)}", :class => "float_right member_since" %>
<%= image_tag "/images/time_member.png", :class => "img_member_time"%> <%= image_tag "/images/time_member.png", :class => "img_member_time"%>
<!-- <%= get_avatar?(user) ? (link_to image_tag(avatar_image(user), :class => 'avatar'), user_path(user), :class => "avatar") : (link_to image_tag("/images/12_50.png", :class => 'avatar'), user_path(user), :class => "avatar") %> --> <div>
<div> <%= image_tag(url_to_avatar(user), :class => 'avatar') %>
<%= image_tag(url_to_avatar(user), :class => 'avatar') %> <%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %>
<%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %> </div>
</div> <div style="margin-top: 20px;margin-left:66px">
<div style="margin-top: 20px;margin-left:66px"> <%= l(:label_has_fans,:count=>user.watcher_users.count)%>
<%= l(:label_has_fans,:count=>user.watcher_users.count)%> <%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %>
<%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %> </div>
</div>
<div class="user-bottom"> <div class="user-bottom">
<% unless user.memberships.empty? %> <% unless user.memberships.empty? %>
<%= l(:label_contribute_to, :project_count => "#{user.memberships.count}") %> <%= l(:label_contribute_to, :project_count => "#{user.memberships.count}") %>
<% for member in user.memberships %> <% for member in user.memberships %>
<%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : '' %> <%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : '' %>
<% end %> <% end %>
<% end %> <% end %>
<%= user.changesets.count == 0 ? '' : ",#{l(:label_total_commit, :total_commit => user.changesets.count)}" %> <%= user.changesets.count == 0 ? '' : ",#{l(:label_total_commit, :total_commit => user.changesets.count)}" %>
</div> </div>
</div> </div>
<% end -%> <% end -%>
<% end -%> <% end -%>
<% else %>
<div style="width: 400px; height: 60px; margin-left: 22px;color:#6c5524; background-color: #FFD9BF; vertical-align: center;">如果没有搜到希望的结果,请清除用户姓和名之间的空格,或者重新输入搜索关键词!</div>
<% end %>
</div> </div>
<div class="pagination"> <div class="pagination">
<ul> <ul>
<%= pagination_links_full @user_pages, @user_count %> <%= pagination_links_full @user_pages, @user_count %>
<ul> <ul>
</div> </div>
<% html_title(l(:label_user_plural)) -%> <% html_title(l(:label_user_plural)) -%>
<% end -%> <% end -%>