2014-01-14 09:29:28 +08:00
|
|
|
module StoresHelper
|
|
|
|
def attachFromUrl attachment
|
|
|
|
container = attachment.container
|
2014-01-14 09:43:53 +08:00
|
|
|
case container.class.to_s
|
2014-01-14 09:29:28 +08:00
|
|
|
when 'Message'
|
|
|
|
board_message_path(container.board, container)
|
|
|
|
when 'Issue'
|
|
|
|
issue_path(container)
|
|
|
|
when 'Document'
|
|
|
|
document_path container
|
|
|
|
when 'HomeworkAttach'
|
|
|
|
bid_path(container.bid)
|
|
|
|
when 'Memo'
|
|
|
|
forum_memo_path(container.forum, container)
|
|
|
|
when 'News'
|
|
|
|
news_path(container)
|
|
|
|
when 'Project'
|
|
|
|
project_files_path(container)
|
2014-07-17 16:06:10 +08:00
|
|
|
when 'Course'
|
|
|
|
course_files_path(container)
|
2014-01-14 09:29:28 +08:00
|
|
|
when 'Version'
|
|
|
|
# version_path(container)
|
|
|
|
project_files_path(container.project)
|
|
|
|
when 'WikiPage'
|
|
|
|
project_wiki_path(container.project)
|
|
|
|
when 'Bid'
|
|
|
|
bid_path(container)
|
|
|
|
else
|
2014-01-15 14:28:36 +08:00
|
|
|
Rails.logger.error "ERROR: StoresHelper#attachUrl unkown type ==> #{container}"
|
|
|
|
'#'
|
2014-01-14 09:29:28 +08:00
|
|
|
end
|
|
|
|
end
|
2014-01-14 20:48:43 +08:00
|
|
|
|
2014-01-15 10:40:37 +08:00
|
|
|
def result_come_from attachment
|
|
|
|
come_from_local(attachment).join(" > ").html_safe
|
|
|
|
end
|
|
|
|
|
2014-01-15 14:28:36 +08:00
|
|
|
private
|
|
|
|
|
2014-01-15 10:40:37 +08:00
|
|
|
WORD_LIMIT = 100
|
|
|
|
def come_from_local attachment
|
2014-01-14 20:48:43 +08:00
|
|
|
container = attachment.container
|
|
|
|
case container.class.to_s
|
|
|
|
when 'Message'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > zzz > 论坛 > 帖子xxx'
|
|
|
|
# topic_str = container.project.project_type == 0 ? l(:label_board) : l(:label_new_course)
|
2014-07-07 16:52:39 +08:00
|
|
|
|
|
|
|
course = container.course
|
|
|
|
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
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'Issue'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > 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)
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'Document'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > 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)
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'News'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '课程 > zzz > 新闻 > 新闻xxx'
|
2014-07-07 16:52:39 +08:00
|
|
|
course = container.course
|
|
|
|
project = container.project
|
|
|
|
if course.nil? # container is belongs to Project
|
|
|
|
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
|
|
|
|
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'Project'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > 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)
|
2014-07-07 16:52:39 +08:00
|
|
|
when 'Course'
|
|
|
|
files_list = link_to l(:label_course_file), course_files_path(container)
|
|
|
|
project_link(container).push(files_list)
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'Version'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > 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)
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'WikiPage'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '项目 > 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]
|
2014-01-14 20:48:43 +08:00
|
|
|
when 'Bid'
|
2014-01-15 10:40:37 +08:00
|
|
|
# '竞赛 > xxx '
|
|
|
|
bid_link(container)
|
2014-01-14 20:48:43 +08:00
|
|
|
else
|
2014-07-07 16:52:39 +08:00
|
|
|
Rails.logger.error "ERROR: attachment type unkown. file:#{__FILE__}, line:#{__LINE__}"
|
|
|
|
Rails.logger.error "#{container.class.to_s}"
|
2014-01-15 10:40:37 +08:00
|
|
|
[link_to('unkown', '')]
|
|
|
|
end
|
2014-01-18 08:51:20 +08:00
|
|
|
rescue ActionController::RoutingError => e
|
|
|
|
Rails.logger.error "ERROR: RoutingError #{e}"
|
|
|
|
[link_to('unkown', '')]
|
2014-01-15 10:40:37 +08:00
|
|
|
end
|
|
|
|
|
2014-01-14 20:48:43 +08:00
|
|
|
|
2014-01-15 10:40:37 +08:00
|
|
|
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"
|
2014-01-15 14:28:36 +08:00
|
|
|
return [link_to('unkown', '#')]
|
2014-01-15 10:40:37 +08:00
|
|
|
end
|
2014-07-07 16:52:39 +08:00
|
|
|
bid_list = link_to l(:label_homework), homework_course_path(bid.courses.first)
|
2014-01-15 10:40:37 +08:00
|
|
|
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]
|
2014-01-14 20:48:43 +08:00
|
|
|
end
|
2014-07-07 16:52:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2014-01-14 09:29:28 +08:00
|
|
|
end
|