搜索文件归属,课程相关逻辑修改,查询把过滤去掉了。暂时没想有什么过滤的好办法

GitlabVersion
yanxd 11 years ago
parent 5c93442c79
commit aca63146e9

@ -20,25 +20,27 @@ class StoresController < ApplicationController
resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%").
reorder("created_on DESC") reorder("created_on DESC")
result = resultSet.to_a.dup # result = resultSet.to_a.dup
resultSet.to_a.map { |res| # resultSet.to_a.map { |res|
if(res.container.nil? || # if(res.container.nil? ||
(res.container.class.to_s=="Project" && res.container.is_public == false) || # (res.container.class.to_s=="Project" && res.container.is_public == false) ||
(res.container.has_attribute?(:project) && res.container.project.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) || # (res.container.class.to_s=="HomeworkAttach" && res.container.bid.reward_type == 3) ||
false # false
) # )
result.delete(res) # result.delete(res)
end # end
} # }
result # result
end end
LIMIT = 12 unless const_defined?(:LIMIT) LIMIT = 12 unless const_defined?(:LIMIT)
def index def index
@projects_attach = project_classification(0).take(LIMIT) @projects_attach = project_classification(0).take(LIMIT)
@courses_attach = project_classification(1).take(LIMIT) @courses_attach = Attachment.includes(:course).where("courses.is_public = ?", 1).
where(container_type: 'Course').
limit(LIMIT)
# @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1). # @projects_attach = Attachment.includes(:project).where("projects.project_type=? AND projects.is_public = ?", 0, 1).
# reorder("#{Attachment.table_name}.downloads DESC"). # reorder("#{Attachment.table_name}.downloads DESC").
# limit(LIMIT) # limit(LIMIT)

@ -110,7 +110,7 @@ module AttachmentsHelper
# 搜索到的资源 # 搜索到的资源
searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc') searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc')
searched_attach = private_filter searched_attach #searched_attach = private_filter searched_attach
searched_attach = paginateHelper(searched_attach, 10) searched_attach = paginateHelper(searched_attach, 10)
s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments') s = content_tag('div', attachments_check_box_tags('attachment[attach][]', searched_attach), :id => 'attachments')
@ -149,7 +149,7 @@ module AttachmentsHelper
# 搜索到的资源 # 搜索到的资源
searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc') searched_attach = domain.where("filename LIKE :like ", like:"%#{filename_condition}%").limit(limit).order('created_on desc')
searched_attach = private_filter searched_attach #searched_attach = private_filter searched_attach
searched_attach = paginateHelper(searched_attach, 10) searched_attach = paginateHelper(searched_attach, 10)
#testattach = Attachment.public_attachments #testattach = Attachment.public_attachments

@ -37,15 +37,24 @@ module StoresHelper
WORD_LIMIT = 100 WORD_LIMIT = 100
def come_from_local attachment def come_from_local attachment
container = attachment.container container = attachment.container
case container.class.to_s case container.class.to_s
when 'Message' when 'Message'
# binding.pry
# '项目 > zzz > 论坛 > 帖子xxx' # '项目 > zzz > 论坛 > 帖子xxx'
# topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course) # topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course)
topic_list = link_to l(:label_board), project_boards_path(container.project)
topic_item = link_to container.subject.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject course = container.course
project_link(container.project).push(topic_list, topic_item) project = container.project
if course.nil? # container is belongs to Project
topic_list = link_to l(:label_board), project_boards_path(container.project)
topic_item = link_to container.subject.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject
project_link(container.project).push(topic_list, topic_item)
else # container is belongs to Course
topic_list = link_to l(:label_course_news), course_boards_path(course)
topic_item = link_to container.try(:subject).to_s.truncate(WORD_LIMIT, omission: '...'), board_message_path(container.board, container), title: container.subject
project_link(course).push(topic_list, topic_item)
end
when 'Issue' when 'Issue'
# '项目 > zzz > 缺陷 > 问题xxx' # '项目 > zzz > 缺陷 > 问题xxx'
issue_list = link_to l(:label_project_issues), project_issues_path(container.project) issue_list = link_to l(:label_project_issues), project_issues_path(container.project)
@ -58,15 +67,26 @@ module StoresHelper
project_link(container.project).push(doc_list, doc_item) project_link(container.project).push(doc_list, doc_item)
when 'News' when 'News'
# '课程 > zzz > 新闻 > 新闻xxx' # '课程 > zzz > 新闻 > 新闻xxx'
news_str = container.project.project_type == 0 ? l(:label_news) : l(:label_course_news) course = container.course
news_list = link_to news_str, project_news_index_path(container.project) project = container.project
news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title if course.nil? # container is belongs to Project
project_link(container.project).push(news_list, news_item) news_list = link_to l(:label_news), project_news_index_path(container.project)
news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title
project_link(container.project).push(news_list, news_item)
else # container is belongs to Course
news_list = link_to l(:label_course_news), course_news_index_path(course)
news_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), news_path(container), title: container.title
project_link(course).push(news_list, news_item)
end
when 'Project' when 'Project'
# '项目 > zzz ' # '项目 > zzz '
file_str = container.project.project_type == 0 ? l(:project_module_files) : l(:label_course_file) file_str = container.project.project_type == 0 ? l(:project_module_files) : l(:label_course_file)
files_list = link_to file_str, project_files_path(container.project) files_list = link_to file_str, project_files_path(container.project)
project_link(container).push(files_list) project_link(container).push(files_list)
when 'Course'
files_list = link_to l(:label_course_file), course_files_path(container)
project_link(container).push(files_list)
when 'Version' when 'Version'
# '项目 > zzz > 里程碑 > xxx' # '项目 > zzz > 里程碑 > xxx'
ver_list = link_to l(:label_roadmap), project_roadmap_path(container.project) ver_list = link_to l(:label_roadmap), project_roadmap_path(container.project)
@ -91,7 +111,8 @@ module StoresHelper
# '竞赛 > xxx ' # '竞赛 > xxx '
bid_link(container) bid_link(container)
else else
Rails.logger.error "ERROR: attachment type unkown" Rails.logger.error "ERROR: attachment type unkown. file:#{__FILE__}, line:#{__LINE__}"
Rails.logger.error "#{container.class.to_s}"
[link_to('unkown', '')] [link_to('unkown', '')]
end end
rescue ActionController::RoutingError => e rescue ActionController::RoutingError => e
@ -99,20 +120,6 @@ module StoresHelper
[link_to('unkown', '')] [link_to('unkown', '')]
end end
def project_link project
if project.nil?
Rails.logger.error "ERROR: attachment type unkown #project_link project.nil?"
return [link_to('unkown', '')]
end
project_list = nil
if project.project_type == 0
project_list = link_to l(:label_project_plural), projects_path
else
project_list = link_to l(:label_new_course), course_path
end
project_item = link_to project.to_s, project_path(project)
[project_list, project_item]
end
def bid_link bid def bid_link bid
bid_list = nil bid_list = nil
@ -129,7 +136,7 @@ module StoresHelper
Rails.logger.error "ERROR: attachment type unkown #bid_link/when 3" Rails.logger.error "ERROR: attachment type unkown #bid_link/when 3"
return [link_to('unkown', '#')] return [link_to('unkown', '#')]
end end
bid_list = link_to l(:label_homework), project_homework_path(bid.courses.first) bid_list = link_to l(:label_homework), homework_course_path(bid.courses.first)
bid_item = link_to bid.name, respond_path(bid) bid_item = link_to bid.name, respond_path(bid)
return project_link(bid.courses.first).push(bid_list, bid_item) return project_link(bid.courses.first).push(bid_list, bid_item)
else else
@ -137,4 +144,28 @@ module StoresHelper
end end
[bid_list, bid_item] [bid_list, bid_item]
end end
def project_link project
if project.nil?
Rails.logger.error "ERROR: attachment type unkown #project_link project.nil? file: #{__FILE__}, line: #{__LINE__}"
return [link_to('unkown', '')]
end
project_list = nil
klass = project.class.to_s
case klass
when "Project"
project_list = link_to l(:label_project_plural), projects_path
project_item = link_to project.to_s, project_path(project)
[project_list, project_item]
when "Course"
course_list = link_to l(:label_new_course), courses_path
course_item = link_to project.name, course_path(project)
[course_list, course_item]
else
Rails.logger.error "[StoresHelper]: #{klass} ======================================="
[]
end
end
end end

@ -29,21 +29,23 @@
</div> </div>
</div> </div>
</div> </div>
<div class="debug hidden"> <div class="debug">
<%= debug(params) if Rails.env.development? %> <%= debug(params) if Rails.env.development? %>
<div class="hidden">
<script src="http://s4.cnzz.com/z_stat.php?id=1000482288&web_id=1000482288" language="JavaScript"></script> <script src="http://s4.cnzz.com/z_stat.php?id=1000482288&web_id=1000482288" language="JavaScript"></script>
<script> <script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46523987-1', 'trustie.net'); ga('create', 'UA-46523987-1', 'trustie.net');
ga('send', 'pageview'); ga('send', 'pageview');
</script> </script>
</div>
</div> </div>
<% end %> <% end %>

Loading…
Cancel
Save