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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2021 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class BoardsController < ApplicationController
  19. default_search_scope :messages
  20. before_action :find_project_by_project_id, :find_board_if_available, :authorize
  21. accept_rss_auth :index, :show
  22. helper :sort
  23. include SortHelper
  24. helper :watchers
  25. def index
  26. @boards = @project.boards.preload(:last_message => :author).to_a
  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. respond_to do |format|
  35. format.html do
  36. sort_init 'updated_on', 'desc'
  37. sort_update 'created_on' => "#{Message.table_name}.id",
  38. 'replies' => "#{Message.table_name}.replies_count",
  39. 'updated_on' => "COALESCE(#{Message.table_name}.last_reply_id, #{Message.table_name}.id)"
  40. @topic_count = @board.topics.count
  41. @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
  42. @topics = @board.topics.
  43. reorder(:sticky => :desc).
  44. limit(@topic_pages.per_page).
  45. offset(@topic_pages.offset).
  46. order(sort_clause).
  47. preload(:author, {:last_reply => :author}).
  48. to_a
  49. @message = Message.new(:board => @board)
  50. render :action => 'show', :layout => !request.xhr?
  51. end
  52. format.atom do
  53. @messages = @board.messages.
  54. reorder(:id => :desc).
  55. includes(:author, :board).
  56. limit(Setting.feeds_limit.to_i).
  57. to_a
  58. render_feed(@messages, :title => "#{@project}: #{@board}")
  59. end
  60. end
  61. end
  62. def new
  63. @board = @project.boards.build
  64. @board.safe_attributes = params[:board]
  65. end
  66. def create
  67. @board = @project.boards.build
  68. @board.safe_attributes = params[:board]
  69. if @board.save
  70. flash[:notice] = l(:notice_successful_create)
  71. redirect_to_settings_in_projects
  72. else
  73. render :action => 'new'
  74. end
  75. end
  76. def edit
  77. end
  78. def update
  79. @board.safe_attributes = params[:board]
  80. if @board.save
  81. respond_to do |format|
  82. format.html do
  83. flash[:notice] = l(:notice_successful_update)
  84. redirect_to_settings_in_projects
  85. end
  86. format.js {head 200}
  87. end
  88. else
  89. respond_to do |format|
  90. format.html {render :action => 'edit'}
  91. format.js {head 422}
  92. end
  93. end
  94. end
  95. def destroy
  96. if @board.destroy
  97. flash[:notice] = l(:notice_successful_delete)
  98. end
  99. redirect_to_settings_in_projects
  100. end
  101. private
  102. def redirect_to_settings_in_projects
  103. redirect_to settings_project_path(@project, :tab => 'boards')
  104. end
  105. def find_board_if_available
  106. @board = @project.boards.find(params[:id]) if params[:id]
  107. rescue ActiveRecord::RecordNotFound
  108. render_404
  109. end
  110. end