diff app/controllers/boards_controller.rb @ 1338:25603efa57b5

Merge from live branch
author Chris Cannam
date Thu, 20 Jun 2013 13:14:14 +0100
parents 3e4c3460b6ca
children 622f24f53b42 261b3d9a4903
line wrap: on
line diff
--- a/app/controllers/boards_controller.rb	Wed Jan 23 13:11:25 2013 +0000
+++ b/app/controllers/boards_controller.rb	Thu Jun 20 13:14:14 2013 +0100
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2011  Jean-Philippe Lang
+# Copyright (C) 2006-2012  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
@@ -17,18 +17,15 @@
 
 class BoardsController < ApplicationController
   default_search_scope :messages
-  before_filter :find_project, :find_board_if_available, :authorize
+  before_filter :find_project_by_project_id, :find_board_if_available, :authorize
   accept_rss_auth :index, :show
 
-  helper :messages
-  include MessagesHelper
   helper :sort
   include SortHelper
   helper :watchers
-  include WatchersHelper
 
   def index
-    @boards = @project.boards
+    @boards = @project.boards.includes(:last_message => :author).all
     # show the board if there is only one
     if @boards.size == 1
       @board = @boards.first
@@ -42,15 +39,19 @@
         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"
+                    'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
 
         @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
+        @topics =  @board.topics.
+          reorder("#{Message.table_name}.sticky DESC").
+          includes(:last_reply).
+          limit(@topic_pages.items_per_page).
+          offset(@topic_pages.current.offset).
+          order(sort_clause).
+          preload(:author, {:last_reply => :author}).
+          all
+        @message = Message.new(:board => @board)
         render :action => 'show', :layout => !request.xhr?
       }
       format.atom {
@@ -62,22 +63,31 @@
     end
   end
 
-  verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
+  def new
+    @board = @project.boards.build
+    @board.safe_attributes = params[:board]
+  end
 
-  def new
-    @board = Board.new
+  def create
+    @board = @project.boards.build
     @board.safe_attributes = params[:board]
-    @board.project = @project
-    if request.post? && @board.save
+    if @board.save
       flash[:notice] = l(:notice_successful_create)
       redirect_to_settings_in_projects
+    else
+      render :action => 'new'
     end
   end
 
   def edit
+  end
+
+  def update
     @board.safe_attributes = params[:board]
-    if request.post? && @board.save
+    if @board.save
       redirect_to_settings_in_projects
+    else
+      render :action => 'edit'
     end
   end
 
@@ -91,12 +101,6 @@
     redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
   end
 
-  def find_project
-    @project = Project.find(params[:project_id])
-  rescue ActiveRecord::RecordNotFound
-    render_404
-  end
-
   def find_board_if_available
     @board = @project.boards.find(params[:id]) if params[:id]
   rescue ActiveRecord::RecordNotFound