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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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.includes(:last_message => :author).all
  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 @topic_count, per_page_option, params['page']
  41. @topics = @board.topics.
  42. reorder("#{Message.table_name}.sticky DESC").
  43. includes(:author, {:last_reply => :author}).
  44. limit(@topic_pages.items_per_page).
  45. offset(@topic_pages.offset).
  46. order(sort_clause).
  47. all
  48. @message = Message.new(:board => @board)
  49. render :action => 'show', :layout => !request.xhr?
  50. }
  51. format.atom {
  52. @messages = @board.messages.
  53. reorder('created_on DESC').
  54. includes(:author, :board).
  55. limit(Setting.feeds_limit.to_i).
  56. all
  57. render_feed(@messages, :title => "#{@project}: #{@board}")
  58. }
  59. end
  60. end
  61. def new
  62. @board = @project.boards.build
  63. @board.safe_attributes = params[:board]
  64. end
  65. def create
  66. @board = @project.boards.build
  67. @board.safe_attributes = params[:board]
  68. if @board.save
  69. flash[:notice] = l(:notice_successful_create)
  70. redirect_to_settings_in_projects
  71. else
  72. render :action => 'new'
  73. end
  74. end
  75. def edit
  76. end
  77. def update
  78. @board.safe_attributes = params[:board]
  79. if @board.save
  80. redirect_to_settings_in_projects
  81. else
  82. render :action => 'edit'
  83. end
  84. end
  85. def destroy
  86. @board.destroy
  87. redirect_to_settings_in_projects
  88. end
  89. private
  90. def redirect_to_settings_in_projects
  91. redirect_to settings_project_path(@project, :tab => 'boards')
  92. end
  93. def find_board_if_available
  94. @board = @project.boards.find(params[:id]) if params[:id]
  95. rescue ActiveRecord::RecordNotFound
  96. render_404
  97. end
  98. end