##// END OF EJS Templates
Sort messages by ids to avoid the left join....
Jean-Philippe Lang -
r15200:1b10649783e2
parent child
Show More
@@ -1,120 +1,119
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class BoardsController < ApplicationController
18 class BoardsController < ApplicationController
19 default_search_scope :messages
19 default_search_scope :messages
20 before_filter :find_project_by_project_id, :find_board_if_available, :authorize
20 before_filter :find_project_by_project_id, :find_board_if_available, :authorize
21 accept_rss_auth :index, :show
21 accept_rss_auth :index, :show
22
22
23 helper :sort
23 helper :sort
24 include SortHelper
24 include SortHelper
25 helper :watchers
25 helper :watchers
26
26
27 def index
27 def index
28 @boards = @project.boards.preload(:project, :last_message => :author).to_a
28 @boards = @project.boards.preload(:project, :last_message => :author).to_a
29 # show the board if there is only one
29 # show the board if there is only one
30 if @boards.size == 1
30 if @boards.size == 1
31 @board = @boards.first
31 @board = @boards.first
32 show
32 show
33 end
33 end
34 end
34 end
35
35
36 def show
36 def show
37 respond_to do |format|
37 respond_to do |format|
38 format.html {
38 format.html {
39 sort_init 'updated_on', 'desc'
39 sort_init 'updated_on', 'desc'
40 sort_update 'created_on' => "#{Message.table_name}.created_on",
40 sort_update 'created_on' => "#{Message.table_name}.id",
41 'replies' => "#{Message.table_name}.replies_count",
41 'replies' => "#{Message.table_name}.replies_count",
42 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
42 'updated_on' => "COALESCE(#{Message.table_name}.last_reply_id, #{Message.table_name}.id)"
43
43
44 @topic_count = @board.topics.count
44 @topic_count = @board.topics.count
45 @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
45 @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
46 @topics = @board.topics.
46 @topics = @board.topics.
47 reorder("#{Message.table_name}.sticky DESC").
47 reorder(:sticky => :desc).
48 joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id").
49 limit(@topic_pages.per_page).
48 limit(@topic_pages.per_page).
50 offset(@topic_pages.offset).
49 offset(@topic_pages.offset).
51 order(sort_clause).
50 order(sort_clause).
52 preload(:author, {:last_reply => :author}).
51 preload(:author, {:last_reply => :author}).
53 to_a
52 to_a
54 @message = Message.new(:board => @board)
53 @message = Message.new(:board => @board)
55 render :action => 'show', :layout => !request.xhr?
54 render :action => 'show', :layout => !request.xhr?
56 }
55 }
57 format.atom {
56 format.atom {
58 @messages = @board.messages.
57 @messages = @board.messages.
59 reorder('created_on DESC').
58 reorder(:id => :desc).
60 includes(:author, :board).
59 includes(:author, :board).
61 limit(Setting.feeds_limit.to_i).
60 limit(Setting.feeds_limit.to_i).
62 to_a
61 to_a
63 render_feed(@messages, :title => "#{@project}: #{@board}")
62 render_feed(@messages, :title => "#{@project}: #{@board}")
64 }
63 }
65 end
64 end
66 end
65 end
67
66
68 def new
67 def new
69 @board = @project.boards.build
68 @board = @project.boards.build
70 @board.safe_attributes = params[:board]
69 @board.safe_attributes = params[:board]
71 end
70 end
72
71
73 def create
72 def create
74 @board = @project.boards.build
73 @board = @project.boards.build
75 @board.safe_attributes = params[:board]
74 @board.safe_attributes = params[:board]
76 if @board.save
75 if @board.save
77 flash[:notice] = l(:notice_successful_create)
76 flash[:notice] = l(:notice_successful_create)
78 redirect_to_settings_in_projects
77 redirect_to_settings_in_projects
79 else
78 else
80 render :action => 'new'
79 render :action => 'new'
81 end
80 end
82 end
81 end
83
82
84 def edit
83 def edit
85 end
84 end
86
85
87 def update
86 def update
88 @board.safe_attributes = params[:board]
87 @board.safe_attributes = params[:board]
89 if @board.save
88 if @board.save
90 respond_to do |format|
89 respond_to do |format|
91 format.html {
90 format.html {
92 flash[:notice] = l(:notice_successful_update)
91 flash[:notice] = l(:notice_successful_update)
93 redirect_to_settings_in_projects
92 redirect_to_settings_in_projects
94 }
93 }
95 format.js { render :nothing => true }
94 format.js { render :nothing => true }
96 end
95 end
97 else
96 else
98 respond_to do |format|
97 respond_to do |format|
99 format.html { render :action => 'edit' }
98 format.html { render :action => 'edit' }
100 format.js { render :nothing => true, :status => 422 }
99 format.js { render :nothing => true, :status => 422 }
101 end
100 end
102 end
101 end
103 end
102 end
104
103
105 def destroy
104 def destroy
106 @board.destroy
105 @board.destroy
107 redirect_to_settings_in_projects
106 redirect_to_settings_in_projects
108 end
107 end
109
108
110 private
109 private
111 def redirect_to_settings_in_projects
110 def redirect_to_settings_in_projects
112 redirect_to settings_project_path(@project, :tab => 'boards')
111 redirect_to settings_project_path(@project, :tab => 'boards')
113 end
112 end
114
113
115 def find_board_if_available
114 def find_board_if_available
116 @board = @project.boards.find(params[:id]) if params[:id]
115 @board = @project.boards.find(params[:id]) if params[:id]
117 rescue ActiveRecord::RecordNotFound
116 rescue ActiveRecord::RecordNotFound
118 render_404
117 render_404
119 end
118 end
120 end
119 end
General Comments 0
You need to be logged in to leave comments. Login now