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