修改标签的搜索显示

This commit is contained in:
william 2013-08-28 10:57:06 +08:00
parent fa27d3bf32
commit 7fbe7f4de6
7 changed files with 67 additions and 159 deletions

View File

@ -12,43 +12,50 @@ class TagsController < ApplicationController
before_filter :require_admin,:only => [:delete,:show_all] before_filter :require_admin,:only => [:delete,:show_all]
$selected_tags = Array.new # $selected_tags = Array.new
$related_tags = Array.new # $related_tags = Array.new
@@numbers = Setting.tags_show_search_results NUMBERS = Setting.tags_show_search_results
attr_reader :obj_id,:obj_flag,:selected_tags,:related_tags
# 接收参数解释:
# params[:q]这是在其他页面点击tag跳转到该页面后的结果显示
# params[:selected_tags]这是在过滤页面增删tag进行过滤传过来的参数
# 最后是2个过滤何种数据显示结果的控制参数params[:obj_id],params[:object_falg]
def index def index
$selected_tags = []
$related_tags = []
$selected_tags << params[:q]
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num = get_tags_size if params[:q]
@selected_tags = Array.new
@related_tags = Array.new
@selected_tags.push params[:q]
@obj_id = params[:obj_id] @obj_id = params[:obj_id]
@obj_flag = params[:object_flag] @obj_flag = params[:object_flag]
else
@selected_tags = params[:selected_tags]
end
@users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num = get_tags_size
# 获取搜索结果 # 获取搜索结果
@obj,@obj_pages,@users_results, @obj,@obj_pages,@users_results,
@projects_results, @projects_results,
@issues_results, @issues_results,
@bids_results, @bids_results = refresh_results(@obj_id,@obj_flag)
@obj_pages = refresh_results(@obj_id,@obj_flag)
# 这里是做tag推荐用的 用来生产推荐的tag # 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil? unless @obj.nil?
@tags = @obj.tag_list @tags = @obj.tag_list
$selected_tags.each do |i| @selected_tags.each do |i|
@tags.delete(i) @tags.delete(i)
end end
$related_tags = @tags @related_tags = @tags
else else
return return
end end
end end
# 增加已选的tag # 增加已选的tag
def add_tag def add_tag
@tag = params[:tag] @tag = params[:tag]
@ -57,67 +64,11 @@ class TagsController < ApplicationController
$selected_tags << @tag $selected_tags << @tag
$related_tags.delete(@tag) $related_tags.delete(@tag)
# # 获取搜索结果 # 获取搜索结果
# @obj,@obj_pages,@users_results, @obj,@obj_pages,@users_results,
# @projects_results, @projects_results,
# @issues_results, @issues_results,
# @bids_results, @bids_results = refresh_results(@obj_id,@show_flag)
# @obj_pages = refresh_results(@obj_id,@show_flag)
case @show_flag
when '1' then
@users_results = get_users_by_tag($selected_tags)
@obj = User.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @users_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@users_results = @users_results.offset(@offset).limit(@limit).all
when '2' then
@projects_results = get_projects_by_tag($selected_tags)
@obj = Project.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @projects_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@projects_results = @projects_results.offset(@offset).limit(@limit).order('lft').all
when '3' then
@issues_results = get_issues_by_tag($selected_tags)
@obj = Issue.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @issues_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@issues_results = @issues_results.offset(@offset).limit(@limit).all
when '4' then
@bids_results = get_bids_by_tag($selected_tags)
@obj = Bid.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @bids_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@bids_results = @bids_results.offset(@offset).limit(@limit)
else
@obj = nil
end
end end
# 删除已选tag # 删除已选tag
@ -128,59 +79,12 @@ class TagsController < ApplicationController
$related_tags << @tag $related_tags << @tag
$selected_tags.delete(@tag) $selected_tags.delete(@tag)
@obj_pages = nil # 获取搜索结果
@obj,@obj_pages,@users_results,
@projects_results,
@issues_results,
@bids_results = refresh_results(@obj_id,@show_flag)
case @show_flag
when '1' then
@users_results = get_users_by_tag($selected_tags)
@obj = User.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @users_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@users_results = @users_results.offset(@offset).limit(@limit).all
when '2' then
@projects_results = get_projects_by_tag($selected_tags)
@obj = Project.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @projects_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@projects_results = @projects_results.offset(@offset).limit(@limit).order('lft').all
when '3' then
@issues_results = get_issues_by_tag($selected_tags)
@obj = Issue.find_by_id(@obj_id)
@offset, @limit = api_offset_and_limit({:limit => @@numbers})
@project_count = @issues_results.count
@obj_pages = Paginator.new @project_count, @limit, params['page']
@offset ||= @obj_pages.offset
@issues_results = @issues_results.offset(@offset).limit(@limit).all
when '4'
@obj_pages,@bids_results = for_pagination(get_bids_by_tag($selected_tags))
# @bids_results = get_bids_by_tag($selected_tags)
@obj = Bid.find_by_id(@obj_id)
#
# @offset, @limit = api_offset_and_limit({:limit => @@numbers})
# @project_count = @bids_results.count
# @obj_pages = Paginator.new @project_count, @limit, params['page']
# @offset ||= @obj_pages.offset
# @bids_results = @bids_results.offset(@offset).limit(@limit).all
else
@obj = nil
end
end
def count(name)
end end
def show_all def show_all
@ -215,19 +119,20 @@ private
@bids_results = nil @bids_results = nil
@obj_pages = nil @obj_pages = nil
@obj = nil @obj = nil
# 这里为了提高系统的响应速度 把搜索结果放到case中去了 # 这里为了提高系统的响应速度 把搜索结果放到case中去了
case obj_flag case obj_flag
when '1' then when '1' then
@obj = User.find_by_id(obj_id) @obj = User.find_by_id(obj_id)
@obj_pages,@users_results = for_pagination(get_users_by_tag($selected_tags)) @obj_pages,@users_results = for_pagination(get_users_by_tag(@selected_tags))
when '2' then when '2' then
@obj = Project.find_by_id(obj_id) @obj = Project.find_by_id(obj_id)
@obj_pages,@projects_results = for_pagination(get_projects_by_tag($selected_tags)) @obj_pages,@projects_results = for_pagination(get_projects_by_tag(@selected_tags))
when '3' then when '3' then
@obj = Issue.find_by_id(obj_id) @obj = Issue.find_by_id(obj_id)
@obj_pages,@issues_results = for_pagination(get_issues_by_tag($selected_tags)) @obj_pages,@issues_results = for_pagination(get_issues_by_tag(@selected_tags))
when '4' then when '4' then
@obj_pages,@bids_results = for_pagination(get_bids_by_tag($selected_tags)) @obj_pages,@bids_results = for_pagination(get_bids_by_tag(@selected_tags))
@obj = Bid.find_by_id(obj_id) @obj = Bid.find_by_id(obj_id)
else else
@obj = nil @obj = nil
@ -238,7 +143,7 @@ private
def for_pagination(results) def for_pagination(results)
@offset, @limit = api_offset_and_limit({:limit => 3}) # 设置每页显示的个数 @offset, @limit = api_offset_and_limit({:limit => 3}) # 设置每页显示的个数
@results_count = results.count @results_count = results.count
@obj_pages = Paginator.new @results_count, @limit, params['page'] @obj_pages = Paginator.new @results_count, @limit, params['page'] # 3个参数分别是总数每页显示数目第几页
@offset ||= @obj_pages.offset @offset ||= @obj_pages.offset
results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序 results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序
return @obj_pages,results return @obj_pages,results

View File

@ -100,22 +100,22 @@ class WatchersController < ApplicationController
watchable.set_watcher(user, watching) watchable.set_watcher(user, watching)
# @user = watchable # added by william # @user = watchable # added by william
if watching if watching
# 修改 user和project的状态 # 修改 user和project的状态
if watchable.instance_of?(User) if watchable.instance_of?(User)
#写user_statuses表 #写user_statuses表
watchable.user_status.update_watchers_count(1) UserStatus.find_by_user_id(watchable.id).update_watchers_count(1)
elsif watchable.instance_of?(Project) elsif watchable.instance_of?(Project)
#写project_statuese表 #写project_statuese表
watchable.project_status.update_watchers_count(1) ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(1)
end end
else else
# 修改 user和project的状态 # 修改 user和project的状态
if watchable.instance_of?(User) if watchable.instance_of?(User)
#写user_statuses表 #写user_statuses表
watchable.user_status.update_watchers_count(-1) UserStatus.find_by_user_id(watchable.id).update_watchers_count(-1)
elsif watchable.instance_of?(Project) elsif watchable.instance_of?(Project)
#写project_statuese表 :project_status #写project_statuese表 :project_status
watchable.project_status.update_watchers_count(-1) ProjectStatus.find_by_project_id(watchable.id).update_watchers_count(-1)
end end
end end

View File

@ -2,10 +2,12 @@
<ul style="list-style-type: none"> <ul style="list-style-type: none">
<% for rt in related_tags %> <% for rt in related_tags %>
<li> <li>
<%= link_to image_tag("/images/sidebar/add.png"),:action => "add_tag",:remote => true,:tag => rt,:show_flag => show_flag %> <%= link_to image_tag("/images/sidebar/add.png"),:action => "index",
:selected_tags => selected_tags %>
<span id="tag"> <span id="tag">
<%= rt %> <%= rt %>
</span> </span>
<!-- 这里用例计数某类对象的所有该tag总数 -->
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%> <%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%>
</li> </li>
<% end %> <% end %>

View File

@ -2,8 +2,8 @@
<ul style="list-style-type: none"> <ul style="list-style-type: none">
<% for sg in selected_tags %> <% for sg in selected_tags %>
<li> <li>
<%= link_to image_tag("/images/sidebar/minus.png"),:action => "delete_tag", <%= link_to image_tag("/images/sidebar/minus.png"),:action => "index",
:remote=>true,:tag => sg,:show_flag => show_flag %> :selected_tags => selected_tags %>
<span id="tag"><%= sg %> </span> <span id="tag"><%= sg %> </span>
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => sg }%> <%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => sg }%>
</li> </li>

View File

@ -3,7 +3,8 @@
<hr /> <hr />
<% bids_results.each do |bid| %> <% bids_results.each do |bid| %>
<p class="font_description2"> <p class="font_description2">
<strong><%= l(:label_tags_bid) %>:<%= link_to "#{bid.name}",:controller => "bids",:action => "show",:id => bid.id %></strong> <strong><%= l(:label_tags_bid) %>:<%= link_to "#{bid.name}",
:controller => "bids",:action => "show",:id => bid.id %></strong>
<br /> <br />
<strong><%= l(:label_tags_bid_description) %>:</strong><%= bid.description %> <strong><%= l(:label_tags_bid_description) %>:</strong><%= bid.description %>
<%= bid.updated_on %> <%= bid.updated_on %>

View File

@ -27,8 +27,6 @@
<% end %> <% end %>
<% else %> <% else %>
<!-- 用来显示三大对象的主页中的tag 故是全部显示 --> <!-- 用来显示三大对象的主页中的tag 故是全部显示 -->
<% if @tags.size > 0 %> <% if @tags.size > 0 %>
<% @tags.each do |tag| %> <% @tags.each do |tag| %>

View File

@ -2,12 +2,14 @@
<div> <div>
<h3><strong><%= l(:label_tags_selected) %></strong></h3> <h3><strong><%= l(:label_tags_selected) %></strong></h3>
<div id="selected_tags"> <div id="selected_tags">
<%= render :partial => "selected_tags",:locals => {:selected_tags => $selected_tags,:show_flag => @obj_flag}%> <%= render :partial => "selected_tags",:locals => {
:selected_tags => @selected_tags,:show_flag => @obj_flag}%>
</div> </div>
<h3><strong><%= l(:label_tags_related) %></strong></h3> <h3><strong><%= l(:label_tags_related) %></strong></h3>
<div id="related_tags"> <div id="related_tags">
<%= render :partial => "related_tags",:locals => {:related_tags => $related_tags,:show_flag => @obj_flag }%> <%= render :partial => "related_tags",:locals => {:related_tags => @related_tags,
:selected_tags => @selected_tags,:show_flag => @obj_flag }%>
</div> </div>
</div> </div>
<% end %> <% end %>
@ -28,6 +30,6 @@
</div> </div>
</div> </div>
<%= render :partial => "pagination",:locals => {:obj_pages => @obj_pages}%>
<% end %> <% end %>