From 77812034740e208fa2e88eb3b6ef3b4de72dee44 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Sat, 12 Apr 2014 19:01:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6=E6=8C=89tag=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=97=B6=EF=BC=8C=E5=8F=AA=E6=9F=A5=E9=80=89=E5=AE=9A?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B8=AD=E7=9A=84=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 9 +++++++-- app/helpers/attachments_helper.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) 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] ||= ""