|
|
|
@ -14,71 +14,28 @@ class TagsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
$selected_tags = Array.new
|
|
|
|
|
$related_tags = Array.new
|
|
|
|
|
@@numbers = Setting.tags_show_search_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
$selected_tags = []
|
|
|
|
|
$related_tags = []
|
|
|
|
|
$selected_tags << params[:q]
|
|
|
|
|
|
|
|
|
|
@issues_tags_num = Issue.tag_counts.size
|
|
|
|
|
@projects_tags_num = Project.tag_counts.size
|
|
|
|
|
@users_tags_num = User.tag_counts.size
|
|
|
|
|
@bids_tags_num = Bid.tag_counts.size
|
|
|
|
|
|
|
|
|
|
# 这里为了提高系统的响应速度 把搜索结果放到case中去了
|
|
|
|
|
@users_results = nil
|
|
|
|
|
@projects_results = nil
|
|
|
|
|
@issues_results = nil
|
|
|
|
|
@bids_results = nil
|
|
|
|
|
@obj_pages = nil
|
|
|
|
|
|
|
|
|
|
@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]
|
|
|
|
|
@numbers = Setting.tags_show_search_results
|
|
|
|
|
|
|
|
|
|
case @obj_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'
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取搜索结果
|
|
|
|
|
@obj,@obj_pages,@users_results,
|
|
|
|
|
@projects_results,
|
|
|
|
|
@issues_results,
|
|
|
|
|
@bids_results,
|
|
|
|
|
@obj_pages = refresh_results(@obj_id,@obj_flag)
|
|
|
|
|
|
|
|
|
|
# 这里是做tag推荐用的, 用来生产推荐的tag
|
|
|
|
|
unless @obj.nil?
|
|
|
|
|
@tags = @obj.tag_list
|
|
|
|
|
$selected_tags.each do |i|
|
|
|
|
@ -91,35 +48,44 @@ class TagsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 增加已选的tag
|
|
|
|
|
def add_tag
|
|
|
|
|
@tag = params[:tag]
|
|
|
|
|
@show_flag = params[:show_flag]
|
|
|
|
|
|
|
|
|
|
$selected_tags << @tag
|
|
|
|
|
$related_tags.delete(@tag)
|
|
|
|
|
|
|
|
|
|
@obj_pages = nil
|
|
|
|
|
@numbers = Setting.tags_show_search_results
|
|
|
|
|
# # 获取搜索结果
|
|
|
|
|
# @obj,@obj_pages,@users_results,
|
|
|
|
|
# @projects_results,
|
|
|
|
|
# @issues_results,
|
|
|
|
|
# @bids_results,
|
|
|
|
|
# @obj_pages = refresh_results(@obj_id,@show_flag)
|
|
|
|
|
|
|
|
|
|
# @issues_results = get_issues_by_tag($selected_tags)
|
|
|
|
|
# @projects_results = get_projects_by_tag($selected_tags)
|
|
|
|
|
# @users_results = get_users_by_tag($selected_tags)
|
|
|
|
|
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})
|
|
|
|
|
@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})
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
@ -127,44 +93,49 @@ class TagsController < ApplicationController
|
|
|
|
|
@issues_results = get_issues_by_tag($selected_tags)
|
|
|
|
|
@obj = Issue.find_by_id(@obj_id)
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => @numbers})
|
|
|
|
|
@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'
|
|
|
|
|
|
|
|
|
|
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})
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
|
@bids_results = @bids_results.offset(@offset).limit(@limit)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
@obj = nil
|
|
|
|
|
@obj = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 删除已选tag
|
|
|
|
|
def delete_tag
|
|
|
|
|
@tag = params[:tag]
|
|
|
|
|
@show_flag = params[:show_flag]
|
|
|
|
|
|
|
|
|
|
$related_tags << @tag
|
|
|
|
|
$selected_tags.delete(@tag)
|
|
|
|
|
|
|
|
|
|
@obj_pages = nil
|
|
|
|
|
@numbers = Setting.tags_show_search_results
|
|
|
|
|
|
|
|
|
|
# @issues_results = get_issues_by_tag($selected_tags)
|
|
|
|
|
# @projects_results = get_projects_by_tag($selected_tags)
|
|
|
|
|
# @users_results = get_users_by_tag($selected_tags)
|
|
|
|
|
|
|
|
|
|
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})
|
|
|
|
|
@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
|
|
|
|
@ -173,7 +144,7 @@ class TagsController < ApplicationController
|
|
|
|
|
@projects_results = get_projects_by_tag($selected_tags)
|
|
|
|
|
@obj = Project.find_by_id(@obj_id)
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => @numbers})
|
|
|
|
|
@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
|
|
|
|
@ -183,20 +154,26 @@ class TagsController < ApplicationController
|
|
|
|
|
@issues_results = get_issues_by_tag($selected_tags)
|
|
|
|
|
@obj = Issue.find_by_id(@obj_id)
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => @numbers})
|
|
|
|
|
@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'
|
|
|
|
|
@bids_results = get_bids_by_tag($selected_tags)
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
@ -209,22 +186,13 @@ class TagsController < ApplicationController
|
|
|
|
|
def show_all
|
|
|
|
|
@tags = ActsAsTaggableOn::Tag.find(:all)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def for_pagination(results)
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 2})
|
|
|
|
|
@project_count = results.count
|
|
|
|
|
@obj_pages = Paginator.new @project_count, @limit, params['page']
|
|
|
|
|
@offset ||= @obj_pages.offset
|
|
|
|
|
results = results.offset(@offset).limit(@limit).order('lft').all
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#完全从数据库删除tag
|
|
|
|
|
def delete
|
|
|
|
|
if params[:q]
|
|
|
|
|
@tag = ActsAsTaggableOn::Tag.find_by_id(params[:q])
|
|
|
|
|
@tag.delete
|
|
|
|
|
|
|
|
|
|
@tag.delete
|
|
|
|
|
@taggings = ActsAsTaggableOn::Tagging.find_all_by_tag_id(@tag.id)
|
|
|
|
|
|
|
|
|
|
@taggings.each do |tagging|
|
|
|
|
|
tagging.delete
|
|
|
|
|
end
|
|
|
|
@ -238,4 +206,51 @@ private
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 这里用来刷新搜索结果的区域
|
|
|
|
|
# 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果
|
|
|
|
|
def refresh_results(obj_id,obj_flag)
|
|
|
|
|
@users_results = nil
|
|
|
|
|
@projects_results = nil
|
|
|
|
|
@issues_results = nil
|
|
|
|
|
@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))
|
|
|
|
|
when '2' then
|
|
|
|
|
@obj = Project.find_by_id(obj_id)
|
|
|
|
|
@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))
|
|
|
|
|
when '4' then
|
|
|
|
|
@obj_pages,@bids_results = for_pagination(get_bids_by_tag($selected_tags))
|
|
|
|
|
@obj = Bid.find_by_id(obj_id)
|
|
|
|
|
else
|
|
|
|
|
@obj = nil
|
|
|
|
|
end
|
|
|
|
|
return @obj,@obj_pages,@users_results,@projects_results,@issues_results,@bids_results
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
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']
|
|
|
|
|
@offset ||= @obj_pages.offset
|
|
|
|
|
results = results.offset(@offset).limit(@limit).all # 这里默认设置为按时间排序
|
|
|
|
|
return @obj_pages,results
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#获取有某类对象的tag总数
|
|
|
|
|
def get_tags_size
|
|
|
|
|
@issues_tags_num = Issue.tag_counts.size
|
|
|
|
|
@projects_tags_num = Project.tag_counts.size
|
|
|
|
|
@users_tags_num = User.tag_counts.size
|
|
|
|
|
@bids_tags_num = Bid.tag_counts.size
|
|
|
|
|
return @users_tags_num,@projects_tags_num,@issues_tags_num,@bids_tags_num
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|