To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / boards_controller.rb @ 1349:4ff3f8b81ab3

History | View | Annotate | Download (3.36 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
class BoardsController < ApplicationController
19
  default_search_scope :messages
20
  before_filter :find_project_by_project_id, :find_board_if_available, :authorize
21
  accept_rss_auth :index, :show
22

    
23
  helper :sort
24
  include SortHelper
25
  helper :watchers
26

    
27
  def index
28
    @boards = @project.boards.includes(:last_message => :author).all
29
    # show the board if there is only one
30
    if @boards.size == 1
31
      @board = @boards.first
32
      show
33
    end
34
  end
35

    
36
  def show
37
    respond_to do |format|
38
      format.html {
39
        sort_init 'updated_on', 'desc'
40
        sort_update        'created_on' => "#{Message.table_name}.created_on",
41
                    'replies' => "#{Message.table_name}.replies_count",
42
                    'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
43

    
44
        @topic_count = @board.topics.count
45
        @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
46
        @topics =  @board.topics.
47
          reorder("#{Message.table_name}.sticky DESC").
48
          includes(:last_reply).
49
          limit(@topic_pages.items_per_page).
50
          offset(@topic_pages.current.offset).
51
          order(sort_clause).
52
          preload(:author, {:last_reply => :author}).
53
          all
54
        @message = Message.new(:board => @board)
55
        render :action => 'show', :layout => !request.xhr?
56
      }
57
      format.atom {
58
        @messages = @board.messages.find :all, :order => 'created_on DESC',
59
                                               :include => [:author, :board],
60
                                               :limit => Setting.feeds_limit.to_i
61
        render_feed(@messages, :title => "#{@project}: #{@board}")
62
      }
63
    end
64
  end
65

    
66
  def new
67
    @board = @project.boards.build
68
    @board.safe_attributes = params[:board]
69
  end
70

    
71
  def create
72
    @board = @project.boards.build
73
    @board.safe_attributes = params[:board]
74
    if @board.save
75
      flash[:notice] = l(:notice_successful_create)
76
      redirect_to_settings_in_projects
77
    else
78
      render :action => 'new'
79
    end
80
  end
81

    
82
  def edit
83
  end
84

    
85
  def update
86
    @board.safe_attributes = params[:board]
87
    if @board.save
88
      redirect_to_settings_in_projects
89
    else
90
      render :action => 'edit'
91
    end
92
  end
93

    
94
  def destroy
95
    @board.destroy
96
    redirect_to_settings_in_projects
97
  end
98

    
99
private
100
  def redirect_to_settings_in_projects
101
    redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
102
  end
103

    
104
  def find_board_if_available
105
    @board = @project.boards.find(params[:id]) if params[:id]
106
  rescue ActiveRecord::RecordNotFound
107
    render_404
108
  end
109
end