Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

boards_controller.rb 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # redMine - project management software
  2. # Copyright (C) 2006-2007 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. before_filter :find_project, :authorize
  19. helper :messages
  20. include MessagesHelper
  21. helper :sort
  22. include SortHelper
  23. helper :watchers
  24. include WatchersHelper
  25. def index
  26. @boards = @project.boards
  27. # show the board if there is only one
  28. if @boards.size == 1
  29. @board = @boards.first
  30. show
  31. end
  32. end
  33. def show
  34. sort_init 'updated_on', 'desc'
  35. sort_update 'created_on' => "#{Message.table_name}.created_on",
  36. 'replies' => "#{Message.table_name}.replies_count",
  37. 'updated_on' => "#{Message.table_name}.updated_on"
  38. @topic_count = @board.topics.count
  39. @topic_pages = Paginator.new self, @topic_count, per_page_option, params['page']
  40. @topics = @board.topics.find :all, :order => ["#{Message.table_name}.sticky DESC", sort_clause].compact.join(', '),
  41. :include => [:author, {:last_reply => :author}],
  42. :limit => @topic_pages.items_per_page,
  43. :offset => @topic_pages.current.offset
  44. @message = Message.new
  45. render :action => 'show', :layout => !request.xhr?
  46. end
  47. verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index }
  48. def new
  49. @board = Board.new(params[:board])
  50. @board.project = @project
  51. if request.post? && @board.save
  52. flash[:notice] = l(:notice_successful_create)
  53. redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
  54. end
  55. end
  56. def edit
  57. if request.post? && @board.update_attributes(params[:board])
  58. redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
  59. end
  60. end
  61. def destroy
  62. @board.destroy
  63. redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards'
  64. end
  65. private
  66. def find_project
  67. @project = Project.find(params[:project_id])
  68. @board = @project.boards.find(params[:id]) if params[:id]
  69. rescue ActiveRecord::RecordNotFound
  70. render_404
  71. end
  72. end