2011-07-09 12:56:07 +04:00
|
|
|
# Redmine - project management software
|
2014-02-08 11:58:49 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2007-05-13 21:09:56 +04:00
|
|
|
#
|
|
|
|
# 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.
|
2011-08-30 17:05:09 +04:00
|
|
|
#
|
2007-05-13 21:09:56 +04:00
|
|
|
# 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.
|
2011-08-30 17:05:09 +04:00
|
|
|
#
|
2007-05-13 21:09:56 +04:00
|
|
|
# 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
|
2009-10-21 21:07:18 +04:00
|
|
|
default_search_scope :messages
|
2011-12-02 01:16:44 +04:00
|
|
|
before_filter :find_project_by_project_id, :find_board_if_available, :authorize
|
2011-07-09 12:56:07 +04:00
|
|
|
accept_rss_auth :index, :show
|
2007-05-13 21:09:56 +04:00
|
|
|
|
|
|
|
helper :sort
|
|
|
|
include SortHelper
|
2007-05-13 23:43:35 +04:00
|
|
|
helper :watchers
|
2011-08-30 17:05:09 +04:00
|
|
|
|
2007-05-13 21:09:56 +04:00
|
|
|
def index
|
2013-06-12 23:34:23 +04:00
|
|
|
@boards = @project.boards.includes(:project, :last_message => :author).all
|
2007-05-13 21:09:56 +04:00
|
|
|
# show the board if there is only one
|
|
|
|
if @boards.size == 1
|
|
|
|
@board = @boards.first
|
|
|
|
show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2009-04-24 20:51:07 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
sort_init 'updated_on', 'desc'
|
2013-02-17 14:17:33 +04:00
|
|
|
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
2009-04-24 20:51:07 +04:00
|
|
|
'replies' => "#{Message.table_name}.replies_count",
|
2013-02-17 15:10:17 +04:00
|
|
|
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
2011-08-30 17:05:09 +04:00
|
|
|
|
2009-04-24 20:51:07 +04:00
|
|
|
@topic_count = @board.topics.count
|
2013-01-09 00:18:12 +04:00
|
|
|
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
2012-12-04 01:30:10 +04:00
|
|
|
@topics = @board.topics.
|
|
|
|
reorder("#{Message.table_name}.sticky DESC").
|
2013-02-17 15:10:17 +04:00
|
|
|
includes(:last_reply).
|
2013-02-17 15:35:42 +04:00
|
|
|
limit(@topic_pages.per_page).
|
2013-01-09 00:18:12 +04:00
|
|
|
offset(@topic_pages.offset).
|
2012-12-04 01:30:10 +04:00
|
|
|
order(sort_clause).
|
2013-02-17 15:10:17 +04:00
|
|
|
preload(:author, {:last_reply => :author}).
|
2012-12-04 01:30:10 +04:00
|
|
|
all
|
2012-04-06 17:51:16 +04:00
|
|
|
@message = Message.new(:board => @board)
|
2009-04-24 20:51:07 +04:00
|
|
|
render :action => 'show', :layout => !request.xhr?
|
|
|
|
}
|
|
|
|
format.atom {
|
2012-12-04 01:30:10 +04:00
|
|
|
@messages = @board.messages.
|
|
|
|
reorder('created_on DESC').
|
|
|
|
includes(:author, :board).
|
|
|
|
limit(Setting.feeds_limit.to_i).
|
|
|
|
all
|
2009-04-24 20:51:07 +04:00
|
|
|
render_feed(@messages, :title => "#{@project}: #{@board}")
|
|
|
|
}
|
|
|
|
end
|
2007-05-13 21:09:56 +04:00
|
|
|
end
|
2011-08-30 17:05:09 +04:00
|
|
|
|
2007-05-13 21:09:56 +04:00
|
|
|
def new
|
2012-03-07 01:36:28 +04:00
|
|
|
@board = @project.boards.build
|
|
|
|
@board.safe_attributes = params[:board]
|
2011-12-02 01:14:09 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-03-07 01:36:28 +04:00
|
|
|
@board = @project.boards.build
|
|
|
|
@board.safe_attributes = params[:board]
|
2011-12-02 01:14:09 +04:00
|
|
|
if @board.save
|
2007-05-13 21:09:56 +04:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2010-03-04 08:33:35 +03:00
|
|
|
redirect_to_settings_in_projects
|
2011-12-02 01:14:09 +04:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
2007-05-13 21:09:56 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2011-12-02 01:14:09 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-03-07 01:36:28 +04:00
|
|
|
@board.safe_attributes = params[:board]
|
|
|
|
if @board.save
|
2010-03-04 08:33:35 +03:00
|
|
|
redirect_to_settings_in_projects
|
2011-12-02 01:14:09 +04:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
2007-05-13 21:09:56 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@board.destroy
|
2010-03-04 08:33:35 +03:00
|
|
|
redirect_to_settings_in_projects
|
2007-05-13 21:09:56 +04:00
|
|
|
end
|
2011-08-30 17:05:09 +04:00
|
|
|
|
2007-05-13 21:09:56 +04:00
|
|
|
private
|
2010-03-04 08:33:35 +03:00
|
|
|
def redirect_to_settings_in_projects
|
2012-12-11 21:51:30 +04:00
|
|
|
redirect_to settings_project_path(@project, :tab => 'boards')
|
2010-03-04 08:33:35 +03:00
|
|
|
end
|
|
|
|
|
2010-03-04 08:33:40 +03:00
|
|
|
def find_board_if_available
|
2007-05-13 21:09:56 +04:00
|
|
|
@board = @project.boards.find(params[:id]) if params[:id]
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|