To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / boards_controller.rb @ 1535:e2c122809c5c
History | View | Annotate | Download (3.25 KB)
| 1 | 507:0c939c159af4 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1494:e248c7af89ec | Chris | # Copyright (C) 2006-2014 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | 1115:433d4f72a19b | Chris | before_filter :find_project_by_project_id, :find_board_if_available, :authorize |
| 21 | 507:0c939c159af4 | Chris | accept_rss_auth :index, :show |
| 22 | 0:513646585e45 | Chris | |
| 23 | helper :sort
|
||
| 24 | include SortHelper
|
||
| 25 | helper :watchers
|
||
| 26 | 909:cbb26bc654de | Chris | |
| 27 | 0:513646585e45 | Chris | def index |
| 28 | 1464:261b3d9a4903 | Chris | @boards = @project.boards.includes(:project, :last_message => :author).all |
| 29 | 0:513646585e45 | Chris | # 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 | 1464:261b3d9a4903 | Chris | sort_update 'created_on' => "#{Message.table_name}.created_on", |
| 41 | 0:513646585e45 | Chris | 'replies' => "#{Message.table_name}.replies_count", |
| 42 | 1294:3e4c3460b6ca | Chris | 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)" |
| 43 | 909:cbb26bc654de | Chris | |
| 44 | 0:513646585e45 | Chris | @topic_count = @board.topics.count |
| 45 | 1464:261b3d9a4903 | Chris | @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] |
| 46 | 1294:3e4c3460b6ca | Chris | @topics = @board.topics. |
| 47 | reorder("#{Message.table_name}.sticky DESC").
|
||
| 48 | includes(:last_reply).
|
||
| 49 | 1464:261b3d9a4903 | Chris | limit(@topic_pages.per_page).
|
| 50 | offset(@topic_pages.offset).
|
||
| 51 | 1294:3e4c3460b6ca | Chris | order(sort_clause). |
| 52 | preload(:author, {:last_reply => :author}). |
||
| 53 | all |
||
| 54 | 1115:433d4f72a19b | Chris | @message = Message.new(:board => @board) |
| 55 | 0:513646585e45 | Chris | render :action => 'show', :layout => !request.xhr? |
| 56 | } |
||
| 57 | format.atom {
|
||
| 58 | 1464:261b3d9a4903 | Chris | @messages = @board.messages. |
| 59 | reorder('created_on DESC').
|
||
| 60 | includes(:author, :board). |
||
| 61 | limit(Setting.feeds_limit.to_i).
|
||
| 62 | all |
||
| 63 | 0:513646585e45 | Chris | render_feed(@messages, :title => "#{@project}: #{@board}") |
| 64 | } |
||
| 65 | end
|
||
| 66 | end
|
||
| 67 | 909:cbb26bc654de | Chris | |
| 68 | 1115:433d4f72a19b | Chris | def new |
| 69 | @board = @project.boards.build |
||
| 70 | @board.safe_attributes = params[:board] |
||
| 71 | end
|
||
| 72 | 0:513646585e45 | Chris | |
| 73 | 1115:433d4f72a19b | Chris | def create |
| 74 | @board = @project.boards.build |
||
| 75 | 929:5f33065ddc4b | Chris | @board.safe_attributes = params[:board] |
| 76 | 1115:433d4f72a19b | Chris | if @board.save |
| 77 | 0:513646585e45 | Chris | flash[:notice] = l(:notice_successful_create) |
| 78 | redirect_to_settings_in_projects |
||
| 79 | 1115:433d4f72a19b | Chris | else
|
| 80 | render :action => 'new' |
||
| 81 | 0:513646585e45 | Chris | end
|
| 82 | end
|
||
| 83 | |||
| 84 | def edit |
||
| 85 | 1115:433d4f72a19b | Chris | end
|
| 86 | |||
| 87 | def update |
||
| 88 | 929:5f33065ddc4b | Chris | @board.safe_attributes = params[:board] |
| 89 | 1115:433d4f72a19b | Chris | if @board.save |
| 90 | 0:513646585e45 | Chris | redirect_to_settings_in_projects |
| 91 | 1115:433d4f72a19b | Chris | else
|
| 92 | render :action => 'edit' |
||
| 93 | 0:513646585e45 | Chris | end
|
| 94 | end
|
||
| 95 | |||
| 96 | def destroy |
||
| 97 | @board.destroy
|
||
| 98 | redirect_to_settings_in_projects |
||
| 99 | end
|
||
| 100 | 909:cbb26bc654de | Chris | |
| 101 | 0:513646585e45 | Chris | private |
| 102 | def redirect_to_settings_in_projects |
||
| 103 | 1464:261b3d9a4903 | Chris | redirect_to settings_project_path(@project, :tab => 'boards') |
| 104 | 0:513646585e45 | Chris | end
|
| 105 | |||
| 106 | def find_board_if_available |
||
| 107 | @board = @project.boards.find(params[:id]) if params[:id] |
||
| 108 | rescue ActiveRecord::RecordNotFound |
||
| 109 | render_404 |
||
| 110 | end
|
||
| 111 | end |