From 61380a5e1a5e25d18f268438398c79921469c9d9 Mon Sep 17 00:00:00 2001 From: yanxd Date: Wed, 15 Jan 2014 10:40:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/stores_controller.rb | 6 +- app/helpers/stores_helper.rb | 106 +++++++++++++++++++++++---- app/views/stores/search.html.erb | 2 +- 3 files changed, 97 insertions(+), 17 deletions(-) diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index a0624b1cd..ea4812809 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -10,7 +10,11 @@ class StoresController < ApplicationController def search name = params[:name] ||= '' # 按文件名搜索 - result = Attachment.includes(:project).where("projects.is_public = ? AND filename LIKE '%" << name << "%' ", 1) + #result = Attachment.includes(:project).where("projects.is_public = 1 AND filename LIKE '%" << name << "%' ") + result = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE '%" + name + "%' "). + reorder("created_on DESC") + result = result.to_a + result.map { |res| result.delete(res) if res.container.nil?} @searched_attach = result return @searched_attach end diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index 76ff1fd76..3ab574e86 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -28,33 +28,109 @@ module StoresHelper end end - def come_from_local attachment # TODO: title_html look at. + def result_come_from attachment + come_from_local(attachment).join(" > ").html_safe + end + + WORD_LIMIT = 100 + def come_from_local attachment + container = attachment.container case container.class.to_s when 'Message' - board_message_path(container.board, container) + # '项目 > zzz > 论坛 > 帖子xxx' + # 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 + project_link(container.project).push(topic_list, topic_item) when 'Issue' - issue_path(container) + # '项目 > zzz > 缺陷 > 问题xxx' + issue_list = link_to l(:label_project_issues), project_issues_path(container.project) + issue_item = link_to container.subject.truncate(WORD_LIMIT, omission: '...'), issue_path(container), title: container.subject + project_link(container.project).push(issue_list, issue_item) when 'Document' - document_path container - when 'HomeworkAttach' - bid_path(container.bid) - when 'Memo' - forum_memo_path(container.forum, container) + # '项目 > zzz > 文档 > 文档xxx' + doc_list = link_to l(:label_document), project_documents_path(container.project) + doc_item = link_to container.title.truncate(WORD_LIMIT, omission: '...'), document_path(container), title: container.title + project_link(container.project).push(doc_list, doc_item) when 'News' - news_path(container) + # '课程 > zzz > 新闻 > 新闻xxx' + news_str = container.project.project_type == 0 ? l(:label_news) : l(:label_course_news) + news_list = link_to news_str, 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) when 'Project' - project_files_path(container) + # '项目 > zzz ' + 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) + project_link(container).push(files_list) when 'Version' - # version_path(container) - project_files_path(container.project) + # '项目 > zzz > 里程碑 > xxx' + ver_list = link_to l(:label_roadmap), project_roadmap_path(container.project) + files_list = link_to l(:label_course_file), project_files_path(container.project) + ver_item = link_to container.name.truncate(WORD_LIMIT, omission: '...'), version_path(container), title: container.name + project_link(container.project).push(ver_list, files_list, ver_item) when 'WikiPage' - project_wiki_path(container.project) + # '项目 > zzz > 维基 > xxx' 有点问题 + wiki_list = link_to l(:label_wiki), project_wiki_path(container.project) + project_link(container.project).push(wiki_list) + when 'HomeworkAttach' + # '课程 > zzz > 作业 > 作业xxx' + bid_link(container.bid) + when 'Memo' + # '贴吧 > 讨论区 > 帖子 xxx' + return [link_to(attachment.id, '#')] if container.forum.nil? + forums_list = link_to l(:label_forum), forums_path + memo_list = link_to container.forum.name, forum_path(container.forum) + memo_item = link_to container.subject, forum_memo_path(container.forum, container) + [forums_list, memo_list, memo_item] when 'Bid' - bid_path(container) + # '竞赛 > xxx ' + bid_link(container) else - '#'#logger.error "StoresHelper#attachUrl unkown type ==> #{container}" + Rails.logger.error "ERROR: attachment type unkown" + [link_to('unkown', '')] end + end + private + + 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 + bid_list = nil + bid_item = nil + case bid.reward_type + when 1 # 众包 + bid_list = link_to l(:label_requirement_enterprise_list), calls_path + bid_item = link_to bid.name, respond_path(bid) + when 2 # 竞赛 + bid_list = link_to l(:label_contest_list), contest_path + bid_item = link_to bid.name, respond_path(bid) + when 3 # 作业 + if bid.courses.first.nil? + Rails.logger.error "ERROR: attachment type unkown #bid_link/when 3" + return [link_to(bid.id, '#')] + end + bid_list = link_to l(:label_homework), project_homework_path(bid.courses.first) + bid_item = link_to bid.name, respond_path(bid) + return project_link(bid.courses.first).push(bid_list, bid_item) + else + xxx + end + [bid_list, bid_item] end end diff --git a/app/views/stores/search.html.erb b/app/views/stores/search.html.erb index 84f5a0780..03bbf9b13 100644 --- a/app/views/stores/search.html.erb +++ b/app/views/stores/search.html.erb @@ -18,7 +18,7 @@ class=f16 href="http://ishare.iask.sina.com.cn/f/23680389.html" target=_blank><%= result.filename %> <%= result.description %> -
所属分类:所属分类:<%=result_come_from result%>=====================IT资料 > 常用软件 >