You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

boards_controller.rb 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. class BoardsController < ApplicationController
  18. default_search_scope :messages
  19. before_filter :find_project_by_project_id, :find_board_if_available, :authorize
  20. accept_rss_auth :index, :show
  21. helper :sort
  22. include SortHelper
  23. helper :watchers
  24. def index
  25. @boards = @project.boards
  26. # show the board if there is only one
  27. if @boards.size == 1
  28. @board = @boards.first
  29. show
  30. end
  31. end
  32. def show
  33. respond_to do |format|
  34. format.html {
  35. sort_init 'updated_on', 'desc'
  36. sort_update 'created_on' => "#{Message.table_name}.created_on",
  37. 'replies' => "#{Message.table_name}.replies_count",
  38. 'updated_on' => "#{Message.table_name}.updated_on"
  39. @topic_count = @board.topics.count
  40. @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
  41. @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
  42. :include => [:author, {:last_reply => :author}],
  43. :limit => @topic_pages.items_per_page,
  44. :offset => @topic_pages.current.offset
  45. @message = Message.new(:board => @board)
  46. render :action => 'show', :layout => !request.xhr?
  47. }
  48. format.atom {
  49. @messages = @board.messages.find :all, :order => 'created_on DESC',
  50. :include => [:author, :board],
  51. :limit => Setting.feeds_limit.to_i
  52. render_feed(@messages, :title => "#{@project}: #{@board}")
  53. }
  54. end
  55. end
  56. def new
  57. @board = @project.boards.build
  58. @board.safe_attributes = params[:board]
  59. end
  60. def create
  61. @board = @project.boards.build
  62. @board.safe_attributes = params[:board]
  63. if @board.save
  64. flash[:notice] = l(:notice_successful_create)
  65. redirect_to_settings_in_projects
  66. else
  67. render :action => 'new'
  68. end
  69. end
  70. def edit
  71. end
  72. def update
  73. @board.safe_attributes = params[:board]
  74. if @board.save
  75. redirect_to_settings_in_projects
  76. else
  77. render :action => 'edit'
  78. end
  79. end
  80. def destroy
  81. @board.destroy
  82. redirect_to_settings_in_projects
  83. end
  84. private
  85. def redirect_to_settings_in_projects
  86. redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
  87. end
  88. def find_board_if_available
  89. @board = @project.boards.find(params[:id]) if params[:id]
  90. rescue ActiveRecord::RecordNotFound
  91. render_404
  92. end
  93. end