|
|
|
@ -39,23 +39,40 @@ class TagsController < ApplicationController
|
|
|
|
|
@obj_flag = params[:object_flag]
|
|
|
|
|
|
|
|
|
|
@selected_tags = Array.new
|
|
|
|
|
@selected_tag_ids = Array.new
|
|
|
|
|
@selected_tag_objs = Array.new
|
|
|
|
|
@related_tags = nil
|
|
|
|
|
|
|
|
|
|
@related_tag_ids = Array.new
|
|
|
|
|
@related_tag_objs = Array.new
|
|
|
|
|
if params[:q]
|
|
|
|
|
@selected_tags << params[:q]
|
|
|
|
|
@tag = ActsAsTaggableOn::Tag.find(params[:q])
|
|
|
|
|
@selected_tags << @tag.name
|
|
|
|
|
@selected_tag_ids << @tag.id.to_s
|
|
|
|
|
@selected_tag_objs << @tag
|
|
|
|
|
else
|
|
|
|
|
@do_what = params[:do_what]
|
|
|
|
|
@tag = params[:tag]
|
|
|
|
|
@selected_tags = params[:current_selected_tags]
|
|
|
|
|
@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
|
|
|
|
|
@tag = ActsAsTaggableOn::Tag.find(params[:tag])
|
|
|
|
|
#@selected_tags = params[:current_selected_tags]
|
|
|
|
|
@selected_tag_ids = params[:current_selected_tags]
|
|
|
|
|
@selected_tag_ids = @selected_tag_ids.nil? ? Array.new : @selected_tag_ids
|
|
|
|
|
@selected_tag_ids.each do |t|
|
|
|
|
|
ta = ActsAsTaggableOn::Tag.find(t)
|
|
|
|
|
@selected_tags << ta.name
|
|
|
|
|
@selected_tag_objs << ta
|
|
|
|
|
end
|
|
|
|
|
#@selected_tags = @selected_tags.nil? ? Array.new : @selected_tags
|
|
|
|
|
|
|
|
|
|
case @do_what
|
|
|
|
|
when '0' then
|
|
|
|
|
@selected_tags.delete @tag #数组中删除有多方式 可以改用shift,pop
|
|
|
|
|
@selected_tags.delete @tag.name #数组中删除有多方式 可以改用shift,pop
|
|
|
|
|
@selected_tag_ids.delete @tag.id.to_s
|
|
|
|
|
@selected_tag_objs.delete @tag
|
|
|
|
|
when '1' then
|
|
|
|
|
# 判断是否已存在该tag 主要用来处理分页的情况
|
|
|
|
|
unless @selected_tags.include? @tag
|
|
|
|
|
@selected_tags << @tag
|
|
|
|
|
unless @selected_tags.include? @tag.name
|
|
|
|
|
@selected_tags << @tag.name
|
|
|
|
|
@selected_tag_ids << @tag.id.to_s
|
|
|
|
|
@selected_tag_objs << @tag
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
@ -75,7 +92,7 @@ class TagsController < ApplicationController
|
|
|
|
|
@attachments_results,
|
|
|
|
|
@contests_results,
|
|
|
|
|
@courses_results,
|
|
|
|
|
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags)
|
|
|
|
|
@open_source_projects_results= refresh_results(@obj_id,@obj_flag,@selected_tags,@selected_tag_ids)
|
|
|
|
|
|
|
|
|
|
# 这里是做tag推荐用的, 用来生产推荐的tags
|
|
|
|
|
unless @obj.nil?
|
|
|
|
@ -85,6 +102,13 @@ class TagsController < ApplicationController
|
|
|
|
|
# @tags.delete(i)
|
|
|
|
|
# end
|
|
|
|
|
@related_tags = @tags
|
|
|
|
|
@tag_objs = @obj.tags
|
|
|
|
|
@tag_objs.each do |t|
|
|
|
|
|
unless @selected_tags.include?(t.name)
|
|
|
|
|
@related_tag_ids << t.id.to_s
|
|
|
|
|
@related_tag_objs << t
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
@ -162,8 +186,8 @@ class TagsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
if request.get?
|
|
|
|
|
# 获取传过来的tag_id taggable_id 和 taggable_type,通过2者确定要删除tag的对象
|
|
|
|
|
@tag_name = params[:tag_name]
|
|
|
|
|
@tag_id = (ActsAsTaggableOn::Tag.find_by_name(@tag_name)).id
|
|
|
|
|
@tag_id = params[:tag_name]
|
|
|
|
|
@tag_name = (ActsAsTaggableOn::Tag.find(@tag_id)).name
|
|
|
|
|
@taggable_id = params[:taggable_id] # 当做参数传时对象会变成字符串
|
|
|
|
|
@taggable_type = numbers_to_object_type(params[:taggable_type])
|
|
|
|
|
|
|
|
|
@ -192,7 +216,7 @@ class TagsController < ApplicationController
|
|
|
|
|
private
|
|
|
|
|
# 这里用来刷新搜索结果的区域
|
|
|
|
|
# 函数的返回值 前2字段用来处理获取其他tag和分页 ,另外4个返回值为过滤结果
|
|
|
|
|
def refresh_results(obj_id,obj_flag,selected_tags)
|
|
|
|
|
def refresh_results(obj_id,obj_flag,selected_tags,selected_tag_ids = nil)
|
|
|
|
|
@users_results = nil
|
|
|
|
|
@projects_results = nil
|
|
|
|
|
@issues_results = nil
|
|
|
|
@ -210,36 +234,36 @@ class TagsController < ApplicationController
|
|
|
|
|
case obj_flag
|
|
|
|
|
when '1' then
|
|
|
|
|
@obj = User.find_by_id(obj_id)
|
|
|
|
|
@obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@users_results,@results_count = for_pagination(get_users_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '2' then
|
|
|
|
|
@obj = Project.find_by_id(obj_id)
|
|
|
|
|
@obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@projects_results,@results_count = for_pagination(get_projects_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '3' then
|
|
|
|
|
@obj = Issue.find_by_id(obj_id)
|
|
|
|
|
@obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@issues_results,@results_count = for_pagination(get_issues_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '4' then
|
|
|
|
|
@obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@bids_results,@results_count = for_pagination(get_bids_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
@obj = Bid.find_by_id(obj_id)
|
|
|
|
|
when '5'
|
|
|
|
|
@obj = Forum.find_by_id(obj_id)
|
|
|
|
|
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '6'
|
|
|
|
|
@obj = Attachment.find_by_id(obj_id)
|
|
|
|
|
|
|
|
|
|
# modifed by Long Jun
|
|
|
|
|
# this is used to find the attachments that came from the same project and tagged with the same tag.
|
|
|
|
|
#@result = get_attachments_by_project_tag(selected_tags, @obj)
|
|
|
|
|
@result = get_attachments_by_tag(selected_tags)
|
|
|
|
|
@result = get_attachments_by_tag(selected_tags,selected_tag_ids)
|
|
|
|
|
@obj_pages, @attachments_results, @results_count = for_pagination(@result)
|
|
|
|
|
when '7'
|
|
|
|
|
@obj = Contest.find_by_id(obj_id)
|
|
|
|
|
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags))
|
|
|
|
|
@obj_pages,@contests_results,@results_count = for_pagination(get_contests_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '8'
|
|
|
|
|
@obj = OpenSourceProject.find_by_id(obj_id)
|
|
|
|
|
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags))
|
|
|
|
|
@obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
when '9' then
|
|
|
|
|
@obj = Course.find_by_id(obj_id)
|
|
|
|
|
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags))
|
|
|
|
|
@obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags,selected_tag_ids))
|
|
|
|
|
else
|
|
|
|
|
@obj = nil
|
|
|
|
|
end
|
|
|
|
|