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

View File

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

View File

@ -29,6 +29,19 @@ module BoardsHelper
breadcrumb links
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)
options = []
Board.board_tree(boards) do |board, level|

View File

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