修改标签的搜索显示

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]
$selected_tags = Array.new
$related_tags = Array.new
@@numbers = Setting.tags_show_search_results
# $selected_tags = Array.new
# $related_tags = Array.new
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
if params[:q]
@selected_tags = Array.new
@related_tags = Array.new
@selected_tags.push params[:q]
@obj_id = params[:obj_id]
@obj_flag = params[:object_flag]
else
@selected_tags = params[:selected_tags]
end
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
@obj_id = params[:obj_id]
@obj_flag = params[:object_flag]
# 获取搜索结果
@obj,@obj_pages,@users_results,
@projects_results,
@issues_results,
@bids_results,
@obj_pages = refresh_results(@obj_id,@obj_flag)
@bids_results = refresh_results(@obj_id,@obj_flag)
# 这里是做tag推荐用的 用来生产推荐的tag
# 这里是做tag推荐用的 用来生产推荐的tags
unless @obj.nil?
@tags = @obj.tag_list
$selected_tags.each do |i|
@selected_tags.each do |i|
@tags.delete(i)
end
$related_tags = @tags
end
@related_tags = @tags
else
return
return
end
end
# 增加已选的tag
def add_tag
@tag = params[:tag]
@ -57,67 +64,11 @@ class TagsController < ApplicationController
$selected_tags << @tag
$related_tags.delete(@tag)
# # 获取搜索结果
# @obj,@obj_pages,@users_results,
# @projects_results,
# @issues_results,
# @bids_results,
# @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
# 获取搜索结果
@obj,@obj_pages,@users_results,
@projects_results,
@issues_results,
@bids_results = refresh_results(@obj_id,@show_flag)
end
# 删除已选tag
@ -128,59 +79,12 @@ class TagsController < ApplicationController
$related_tags << @tag
$selected_tags.delete(@tag)
@obj_pages = nil
case @show_flag
when '1' then
@users_results = get_users_by_tag($selected_tags)
@obj = User.find_by_id(@obj_id)
# 获取搜索结果
@obj,@obj_pages,@users_results,
@projects_results,
@issues_results,
@bids_results = refresh_results(@obj_id,@show_flag)
@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
def show_all
@ -215,19 +119,20 @@ private
@bids_results = nil
@obj_pages = nil
@obj = nil
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
case obj_flag
when '1' then
@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
@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
@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
@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)
else
@obj = nil
@ -238,7 +143,7 @@ private
def for_pagination(results)
@offset, @limit = api_offset_and_limit({:limit => 3}) # 设置每页显示的个数
@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
results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序
return @obj_pages,results

View File

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

View File

@ -2,10 +2,12 @@
<ul style="list-style-type: none">
<% for rt in related_tags %>
<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">
<%= rt %>
</span>
<!-- 这里用例计数某类对象的所有该tag总数 -->
<%= render :partial => 'sidebar_tags',:locals => {:show_flag => show_flag,:sg => rt }%>
</li>
<% end %>

View File

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

View File

@ -3,7 +3,8 @@
<hr />
<% bids_results.each do |bid| %>
<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 />
<strong><%= l(:label_tags_bid_description) %>:</strong><%= bid.description %>
<%= bid.updated_on %>

View File

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

View File

@ -2,12 +2,14 @@
<div>
<h3><strong><%= l(:label_tags_selected) %></strong></h3>
<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>
<h3><strong><%= l(:label_tags_related) %></strong></h3>
<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>
<% end %>
@ -28,6 +30,6 @@
</div>
</div>
<%= render :partial => "pagination",:locals => {:obj_pages => @obj_pages}%>
<% end %>