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