From aca63146e9ef2b2a3653d3a632ee8a97592d358c Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 7 Jul 2014 16:52:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=BD=92=E5=B1=9E=EF=BC=8C=E8=AF=BE=E7=A8=8B=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8A=8A=E8=BF=87=E6=BB=A4=E5=8E=BB=E6=8E=89=E4=BA=86=E3=80=82?= =?UTF-8?q?=E6=9A=82=E6=97=B6=E6=B2=A1=E6=83=B3=E6=9C=89=E4=BB=80=E4=B9=88?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E7=9A=84=E5=A5=BD=E5=8A=9E=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/stores_controller.rb | 28 +++++---- app/helpers/attachments_helper.rb | 4 +- app/helpers/stores_helper.rb | 79 +++++++++++++++++-------- app/views/layouts/_base_footer.html.erb | 22 +++---- 4 files changed, 84 insertions(+), 49 deletions(-) diff --git a/app/controllers/stores_controller.rb b/app/controllers/stores_controller.rb index 0ed12d76d..fd0d3cf53 100644 --- a/app/controllers/stores_controller.rb +++ b/app/controllers/stores_controller.rb @@ -20,25 +20,27 @@ class StoresController < ApplicationController resultSet = Attachment.where("attachments.container_type IS NOT NULL AND filename LIKE :like ", like: "%#{keywords}%"). reorder("created_on DESC") - result = resultSet.to_a.dup + # result = resultSet.to_a.dup - resultSet.to_a.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 + # resultSet.to_a.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 LIMIT = 12 unless const_defined?(:LIMIT) def index @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). # reorder("#{Attachment.table_name}.downloads DESC"). # limit(LIMIT) diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 3e61b2a44..14105bf88 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -110,7 +110,7 @@ module AttachmentsHelper # 搜索到的资源 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) 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 = private_filter searched_attach + #searched_attach = private_filter searched_attach searched_attach = paginateHelper(searched_attach, 10) #testattach = Attachment.public_attachments diff --git a/app/helpers/stores_helper.rb b/app/helpers/stores_helper.rb index c01fae55e..0c7fdac43 100644 --- a/app/helpers/stores_helper.rb +++ b/app/helpers/stores_helper.rb @@ -37,15 +37,24 @@ module StoresHelper WORD_LIMIT = 100 def come_from_local attachment - container = attachment.container case container.class.to_s when 'Message' + # binding.pry # '项目 > 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) + + 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 when 'Issue' # '项目 > zzz > 缺陷 > 问题xxx' 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) when 'News' # '课程 > 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) + 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 + when 'Project' # '项目 > 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 'Course' + files_list = link_to l(:label_course_file), course_files_path(container) + project_link(container).push(files_list) when 'Version' # '项目 > zzz > 里程碑 > xxx' ver_list = link_to l(:label_roadmap), project_roadmap_path(container.project) @@ -91,7 +111,8 @@ module StoresHelper # '竞赛 > xxx ' bid_link(container) 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', '')] end rescue ActionController::RoutingError => e @@ -99,20 +120,6 @@ module StoresHelper [link_to('unkown', '')] 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 bid_list = nil @@ -129,7 +136,7 @@ module StoresHelper Rails.logger.error "ERROR: attachment type unkown #bid_link/when 3" return [link_to('unkown', '#')] 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) return project_link(bid.courses.first).push(bid_list, bid_item) else @@ -137,4 +144,28 @@ module StoresHelper end [bid_list, bid_item] 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 diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 2fc383440..37f5cf0e2 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -29,21 +29,23 @@ -