|
|
|
@ -85,17 +85,82 @@ module AttachmentsHelper
|
|
|
|
|
Attachment.tagged_with(tag_name).order('created_on desc')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_attachments_for_new_project(project)
|
|
|
|
|
def render_attachments_for_new_project(project, limit=nil)
|
|
|
|
|
# 查询条件
|
|
|
|
|
filename_condition = "trustie" #params[:q]
|
|
|
|
|
params[:q] ||= ""
|
|
|
|
|
filename_condition = params[:q]
|
|
|
|
|
|
|
|
|
|
attachAll = Attachment.scoped
|
|
|
|
|
# 当前项目所有资源
|
|
|
|
|
# attachments = Attachment.find_all_by_container_type_and_container_id(project.class, project.id)
|
|
|
|
|
attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
|
|
|
|
|
# attachments = Attachment.where("container_type = '#{project.class}' and container_id = #{project.id}")
|
|
|
|
|
|
|
|
|
|
# 除去当前项目的所有资源
|
|
|
|
|
nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}")
|
|
|
|
|
nobelong_attach = Attachment.where("container_type <> '#{project.class}' and container_id <> #{project.id}") unless project.blank?
|
|
|
|
|
|
|
|
|
|
# 搜索域确定
|
|
|
|
|
domain = project.nil? ? attachAll : nobelong_attach
|
|
|
|
|
|
|
|
|
|
# 搜索到的资源
|
|
|
|
|
searched_attach = nobelong_attach.where("filename like '%#{filename_condition}%' ")
|
|
|
|
|
searched_attach = domain.where("filename like '%#{filename_condition}%' ").limit(limit).order('created_on desc')
|
|
|
|
|
searched_attach = private_filter searched_attach
|
|
|
|
|
searched_attach = paginateHelper(searched_attach, 10)
|
|
|
|
|
|
|
|
|
|
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
|
|
|
|
|
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false) {|text, parameters, options|
|
|
|
|
|
link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
|
|
|
|
|
|
|
|
|
|
return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
|
|
|
|
|
|
|
|
|
# ================================================================================================
|
|
|
|
|
|
|
|
|
|
# attach_count = searched_attach.count
|
|
|
|
|
# attach_pages = Redmine::Pagination::Paginator.new attach_count, 10, params['page'] #by young
|
|
|
|
|
# attachs = searched_attach.offset(attach_pages.offset).limit(attach_pages.per_page).all
|
|
|
|
|
|
|
|
|
|
# s = content_tag('div', attachments_check_box_tags('attachment[attach][]', attachs), :id => 'attachments')
|
|
|
|
|
# links = pagination_links_full(attach_pages, attach_count, :per_page_links => false) {|text, parameters, options|
|
|
|
|
|
# link_to text, attachments_autocomplete_path( parameters.merge(:q => params[:q], :format => 'js')), :remote => true }
|
|
|
|
|
|
|
|
|
|
# return s + content_tag('div', content_tag('ul', links), :class => 'pagination')
|
|
|
|
|
# return searched_attach.to_json
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def attachments_check_box_tags(name, attachs)
|
|
|
|
|
s = ''
|
|
|
|
|
attachs.each do |attach|
|
|
|
|
|
s << "<label>#{ check_box_tag name, attach.id, false, :id => nil } #{h attach.filename}</label><br/>"
|
|
|
|
|
end
|
|
|
|
|
s.html_safe
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def private_filter resultSet
|
|
|
|
|
result = resultSet.to_a.dup
|
|
|
|
|
|
|
|
|
|
return searched_attach.to_yaml
|
|
|
|
|
resultSet.map { |res|
|
|
|
|
|
if(res.container.nil? ||
|
|
|
|
|
(res.container.class.to_s=="Project" && res.container.is_public == false) ||
|
|
|
|
|
(res.container.has_attribute?(:project) && res.container.project.is_public == false) ||
|
|
|
|
|
(res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
result.delete(res)
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
result
|
|
|
|
|
end
|
|
|
|
|
include Redmine::Pagination
|
|
|
|
|
def paginateHelper obj, pre_size=10
|
|
|
|
|
@obj_count = obj.count
|
|
|
|
|
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
|
|
|
|
|
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
|
|
|
|
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset)
|
|
|
|
|
elsif obj.kind_of? Array
|
|
|
|
|
obj[@obj_pages.offset, @obj_pages.per_page]
|
|
|
|
|
else
|
|
|
|
|
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
|
|
|
|
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|