附件按tag查询时,只查选定项目中的附件

This commit is contained in:
alan 2014-04-12 19:01:48 +08:00
parent 272be122e5
commit 7781203474
2 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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] ||= ""