Mercurial > hg > soundsoftware-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
1209:1b1138f6f55e | 1338:25603efa57b5 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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, :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 :messages | |
24 include MessagesHelper | |
25 helper :sort | 23 helper :sort |
26 include SortHelper | 24 include SortHelper |
27 helper :watchers | 25 helper :watchers |
28 include WatchersHelper | |
29 | 26 |
30 def index | 27 def index |
31 @boards = @project.boards | 28 @boards = @project.boards.includes(:last_message => :author).all |
32 # show the board if there is only one | 29 # show the board if there is only one |
33 if @boards.size == 1 | 30 if @boards.size == 1 |
34 @board = @boards.first | 31 @board = @boards.first |
35 show | 32 show |
36 end | 33 end |
40 respond_to do |format| | 37 respond_to do |format| |
41 format.html { | 38 format.html { |
42 sort_init 'updated_on', 'desc' | 39 sort_init 'updated_on', 'desc' |
43 sort_update 'created_on' => "#{Message.table_name}.created_on", | 40 sort_update 'created_on' => "#{Message.table_name}.created_on", |
44 'replies' => "#{Message.table_name}.replies_count", | 41 'replies' => "#{Message.table_name}.replies_count", |
45 'updated_on' => "#{Message.table_name}.updated_on" | 42 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" |
46 | 43 |
47 @topic_count = @board.topics.count | 44 @topic_count = @board.topics.count |
48 @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page'] | 45 @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page'] |
49 @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '), | 46 @topics = @board.topics. |
50 :include => [:author, {:last_reply => :author}], | 47 reorder("#{Message.table_name}.sticky DESC"). |
51 :limit => @topic_pages.items_per_page, | 48 includes(:last_reply). |
52 :offset => @topic_pages.current.offset | 49 limit(@topic_pages.items_per_page). |
53 @message = Message.new | 50 offset(@topic_pages.current.offset). |
51 order(sort_clause). | |
52 preload(:author, {:last_reply => :author}). | |
53 all | |
54 @message = Message.new(:board => @board) | |
54 render :action => 'show', :layout => !request.xhr? | 55 render :action => 'show', :layout => !request.xhr? |
55 } | 56 } |
56 format.atom { | 57 format.atom { |
57 @messages = @board.messages.find :all, :order => 'created_on DESC', | 58 @messages = @board.messages.find :all, :order => 'created_on DESC', |
58 :include => [:author, :board], | 59 :include => [:author, :board], |
60 render_feed(@messages, :title => "#{@project}: #{@board}") | 61 render_feed(@messages, :title => "#{@project}: #{@board}") |
61 } | 62 } |
62 end | 63 end |
63 end | 64 end |
64 | 65 |
65 verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index } | 66 def new |
67 @board = @project.boards.build | |
68 @board.safe_attributes = params[:board] | |
69 end | |
66 | 70 |
67 def new | 71 def create |
68 @board = Board.new | 72 @board = @project.boards.build |
69 @board.safe_attributes = params[:board] | 73 @board.safe_attributes = params[:board] |
70 @board.project = @project | 74 if @board.save |
71 if request.post? && @board.save | |
72 flash[:notice] = l(:notice_successful_create) | 75 flash[:notice] = l(:notice_successful_create) |
73 redirect_to_settings_in_projects | 76 redirect_to_settings_in_projects |
77 else | |
78 render :action => 'new' | |
74 end | 79 end |
75 end | 80 end |
76 | 81 |
77 def edit | 82 def edit |
83 end | |
84 | |
85 def update | |
78 @board.safe_attributes = params[:board] | 86 @board.safe_attributes = params[:board] |
79 if request.post? && @board.save | 87 if @board.save |
80 redirect_to_settings_in_projects | 88 redirect_to_settings_in_projects |
89 else | |
90 render :action => 'edit' | |
81 end | 91 end |
82 end | 92 end |
83 | 93 |
84 def destroy | 94 def destroy |
85 @board.destroy | 95 @board.destroy |
89 private | 99 private |
90 def redirect_to_settings_in_projects | 100 def redirect_to_settings_in_projects |
91 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' | 101 redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
92 end | 102 end |
93 | 103 |
94 def find_project | |
95 @project = Project.find(params[:project_id]) | |
96 rescue ActiveRecord::RecordNotFound | |
97 render_404 | |
98 end | |
99 | |
100 def find_board_if_available | 104 def find_board_if_available |
101 @board = @project.boards.find(params[:id]) if params[:id] | 105 @board = @project.boards.find(params[:id]) if params[:id] |
102 rescue ActiveRecord::RecordNotFound | 106 rescue ActiveRecord::RecordNotFound |
103 render_404 | 107 render_404 |
104 end | 108 end |