1.修改课程讨论区control index、show方法及路由

2.BoardsHelper添加课程相关方法
This commit is contained in:
nwb 2014-06-12 09:44:22 +08:00
parent 814233d245
commit 70901832a8
4 changed files with 49 additions and 17 deletions

View File

@ -28,17 +28,25 @@ class BoardsController < ApplicationController
helper :watchers helper :watchers
def index def index
@boards = @project.boards.includes(:last_message => :author).all #modify by nwb
@boards = [] << @boards[0] if @boards.any? if @project
if @boards.size == 1 @boards = @project.boards.includes(:last_message => :author).all
@board = @boards.first @boards = [] << @boards[0] if @boards.any?
show and return if @boards.size == 1
end @board = @boards.first
if @project.project_type == 1 show and return
render :layout => 'base_courses' end
else render :layout => false if request.xhr?
render :layout => false if request.xhr? elsif @course
@boards = @course.boards.includes(:last_message => :author).all
@boards = [] << @boards[0] if @boards.any?
if @boards.size == 1
@board = @boards.first
show and return
end
render :layout => 'base_courses'
end end
end end
def show def show
@ -60,10 +68,11 @@ class BoardsController < ApplicationController
preload(:author, {:last_reply => :author}). preload(:author, {:last_reply => :author}).
all all
@message = Message.new(:board => @board) @message = Message.new(:board => @board)
if @project.project_type ==1 #modify by nwb
render :action => 'show', :layout => 'base_courses' if @project
else
render :action => 'show', :layout => !request.xhr? render :action => 'show', :layout => !request.xhr?
elsif @course
render :action => 'show', :layout => 'base_courses'
end end
} }
format.atom { format.atom {
@ -72,7 +81,12 @@ class BoardsController < ApplicationController
includes(:author, :board). includes(:author, :board).
limit(Setting.feeds_limit.to_i). limit(Setting.feeds_limit.to_i).
all all
render_feed(@messages, :title => "#{@project}: #{@board}") if @project
render_feed(@messages, :title => "#{@project}: #{@board}")
elsif @course
render_feed(@messages, :title => "#{@course}: #{@board}")
end
} }
end end
end end

View File

@ -88,8 +88,12 @@ class NewsController < ApplicationController
def show def show
@comments = @news.comments @comments = @news.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order? @comments.reverse! if User.current.wants_comments_in_reverse_order?
if @project.project_type == 1 #modify by nwb
render :layout => 'base_courses' if @news.course_id
@course = Course.find(@news.course_id)
if @course
render :layout => 'base_courses'
end
end end
end end

View File

@ -29,6 +29,19 @@ module BoardsHelper
breadcrumb links breadcrumb links
end end
# add by nwb
def course_board_breadcrumb(item)
board = item.is_a?(Message) ? item.board : item
links = [link_to(l(:label_board_plural), course_boards_path(item.course))]
boards = board.ancestors.reverse
if item.is_a?(Message)
boards << board
end
links += boards.map {|ancestor| link_to(h(ancestor.name), course_board_path(ancestor.course, ancestor))}
breadcrumb links
end
def boards_options_for_select(boards) def boards_options_for_select(boards)
options = [] options = []
Board.board_tree(boards) do |board, level| Board.board_tree(boards) do |board, level|

View File

@ -567,6 +567,7 @@ RedmineApp::Application.routes.draw do
end end
end end
resources :news, :except => [:show, :edit, :update, :destroy] resources :news, :except => [:show, :edit, :update, :destroy]
resources :boards
end # end of resources :courses end # end of resources :courses
match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback' match 'courses/:id/feedback', :to => 'courses#feedback', :via => :get, :as => 'course_feedback'
match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post]