2013-08-01 10:33:49 +08:00
|
|
|
# Redmine - project management software
|
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
class BoardsController < ApplicationController
|
2013-08-03 22:18:30 +08:00
|
|
|
layout 'base_projects'#by young
|
2013-08-01 10:33:49 +08:00
|
|
|
default_search_scope :messages
|
2013-08-21 22:14:02 +08:00
|
|
|
before_filter :find_project_by_project_id, :find_board_if_available
|
2013-09-13 16:36:36 +08:00
|
|
|
before_filter :authorize, :except => [:new, :show, :create, :index]
|
2013-08-01 10:33:49 +08:00
|
|
|
accept_rss_auth :index, :show
|
2013-09-13 16:36:36 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
|
|
|
helper :watchers
|
|
|
|
|
|
|
|
def index
|
|
|
|
@boards = @project.boards.includes(:last_message => :author).all
|
|
|
|
# show the board if there is only one
|
2013-11-14 19:29:42 +08:00
|
|
|
unless @project.project_type == 1
|
2013-11-16 11:09:10 +08:00
|
|
|
if @boards.size == 1
|
|
|
|
@board = @boards.first
|
|
|
|
show
|
|
|
|
end
|
2013-11-14 19:29:42 +08:00
|
|
|
end
|
2013-09-23 13:35:29 +08:00
|
|
|
if @project.project_type == 1
|
2013-11-14 19:29:42 +08:00
|
|
|
render :layout => 'base_courses'
|
|
|
|
else
|
2013-09-23 13:35:29 +08:00
|
|
|
render :layout => false if request.xhr?
|
2013-08-30 09:34:21 +08:00
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
2013-10-07 22:23:42 +08:00
|
|
|
def show
|
2013-08-01 10:33:49 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
sort_init 'updated_on', 'desc'
|
|
|
|
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
|
|
|
'replies' => "#{Message.table_name}.replies_count",
|
|
|
|
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
|
|
|
|
|
|
|
@topic_count = @board.topics.count
|
|
|
|
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
|
|
|
@topics = @board.topics.
|
|
|
|
reorder("#{Message.table_name}.sticky DESC").
|
|
|
|
includes(:last_reply).
|
|
|
|
limit(@topic_pages.per_page).
|
|
|
|
offset(@topic_pages.offset).
|
|
|
|
order(sort_clause).
|
|
|
|
preload(:author, {:last_reply => :author}).
|
|
|
|
all
|
|
|
|
@message = Message.new(:board => @board)
|
2013-10-07 22:23:42 +08:00
|
|
|
if @project.project_type ==1
|
2013-08-30 09:34:21 +08:00
|
|
|
render :action => 'show', :layout => 'base_courses'
|
|
|
|
else
|
|
|
|
render :action => 'show', :layout => !request.xhr?
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
}
|
|
|
|
format.atom {
|
|
|
|
@messages = @board.messages.
|
|
|
|
reorder('created_on DESC').
|
|
|
|
includes(:author, :board).
|
|
|
|
limit(Setting.feeds_limit.to_i).
|
|
|
|
all
|
|
|
|
render_feed(@messages, :title => "#{@project}: #{@board}")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@board = @project.boards.build
|
|
|
|
@board.safe_attributes = params[:board]
|
2013-09-29 20:04:03 +08:00
|
|
|
if @project.project_type == 1
|
2013-08-30 09:34:21 +08:00
|
|
|
render :layout => 'base_courses'
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
|
|
|
|
2013-11-14 19:29:42 +08:00
|
|
|
def create
|
2013-08-01 10:33:49 +08:00
|
|
|
@board = @project.boards.build
|
|
|
|
@board.safe_attributes = params[:board]
|
2013-11-14 19:29:42 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
if @board.save
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2013-08-21 16:43:47 +08:00
|
|
|
#Modified by young
|
|
|
|
#redirect_to_settings_in_projects
|
|
|
|
redirect_to project_board_path(@project, @board)
|
|
|
|
#Ended by young
|
2013-08-01 10:33:49 +08:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-09-29 20:04:03 +08:00
|
|
|
if @project.project_type ==1
|
2013-08-30 09:34:21 +08:00
|
|
|
render :layout => 'base_courses'
|
|
|
|
end
|
2013-08-01 10:33:49 +08:00
|
|
|
@board.safe_attributes = params[:board]
|
|
|
|
if @board.save
|
|
|
|
redirect_to_settings_in_projects
|
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@board.destroy
|
|
|
|
redirect_to_settings_in_projects
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def redirect_to_settings_in_projects
|
|
|
|
redirect_to settings_project_path(@project, :tab => 'boards')
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_board_if_available
|
|
|
|
@board = @project.boards.find(params[:id]) if params[:id]
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|