diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 71c9b0e7e..3a7e0f635 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -178,7 +178,8 @@ private attachments_results = nil @obj_pages = nil @obj = nil - + @result = nil + # 这里为了提高系统的响应速度 把搜索结果放到case中去了 case obj_flag when '1' then @@ -198,7 +199,11 @@ private @obj_pages,@forums_results,@results_count = for_pagination(get_forums_by_tag(selected_tags)) when '6' @obj = Attachment.find_by_id(obj_id) - @obj_pages, attachments_results, @results_count = for_pagination(get_attachments_by_tag(selected_tags)) + + # 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) + @obj_pages, attachments_results, @results_count = for_pagination(@result) else @obj = nil end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 7d5db3012..4d51a84ce 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -85,6 +85,22 @@ module AttachmentsHelper Attachment.tagged_with(tag_name).order('created_on desc') end + # this method is used to get all attachments that from one project and tagged one tag + # added by Long Jun + def get_attachments_by_project_tag(tag_name, obj) + @project_id =nil + if obj.container_type == 'Version' + @project_id = Version.find(obj.container_id).project_id + + elsif obj.container_type == 'Project' + @project_id = obj.container_id + + end + Attachment.tagged_with(tag_name).order('created_on desc').where("(container_id = :project_id and container_type = 'Project') or + (container_id in (select id from versions where project_id =:project_id) and container_type = 'Version')", {:project_id => @project_id}) + end + + def render_attachments_for_new_project(project, limit=nil) # 查询条件 params[:q] ||= ""