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.

issue_categories_controller.rb 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 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 IssueCategoriesController < ApplicationController
  19. menu_item :settings
  20. model_object IssueCategory
  21. before_action :find_model_object, :except => [:index, :new, :create]
  22. before_action :find_project_from_association, :except => [:index, :new, :create]
  23. before_action :find_project_by_project_id, :only => [:index, :new, :create]
  24. before_action :authorize
  25. accept_api_auth :index, :show, :create, :update, :destroy
  26. def index
  27. respond_to do |format|
  28. format.html {redirect_to_settings_in_projects}
  29. format.api {@categories = @project.issue_categories.to_a}
  30. end
  31. end
  32. def show
  33. respond_to do |format|
  34. format.html {redirect_to_settings_in_projects}
  35. format.api
  36. end
  37. end
  38. def new
  39. @category = @project.issue_categories.build
  40. @category.safe_attributes = params[:issue_category]
  41. respond_to do |format|
  42. format.html
  43. format.js
  44. end
  45. end
  46. def create
  47. @category = @project.issue_categories.build
  48. @category.safe_attributes = params[:issue_category]
  49. if @category.save
  50. respond_to do |format|
  51. format.html do
  52. flash[:notice] = l(:notice_successful_create)
  53. redirect_to_settings_in_projects
  54. end
  55. format.js
  56. format.api do
  57. render(:action => 'show', :status => :created,
  58. :location => issue_category_path(@category))
  59. end
  60. end
  61. else
  62. respond_to do |format|
  63. format.html {render :action => 'new'}
  64. format.js {render :action => 'new'}
  65. format.api {render_validation_errors(@category)}
  66. end
  67. end
  68. end
  69. def edit
  70. end
  71. def update
  72. @category.safe_attributes = params[:issue_category]
  73. if @category.save
  74. respond_to do |format|
  75. format.html do
  76. flash[:notice] = l(:notice_successful_update)
  77. redirect_to_settings_in_projects
  78. end
  79. format.api {render_api_ok}
  80. end
  81. else
  82. respond_to do |format|
  83. format.html {render :action => 'edit'}
  84. format.api {render_validation_errors(@category)}
  85. end
  86. end
  87. end
  88. def destroy
  89. @issue_count = @category.issues.size
  90. if @issue_count == 0 || params[:todo] || api_request?
  91. reassign_to = nil
  92. if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
  93. reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
  94. end
  95. @category.destroy(reassign_to)
  96. respond_to do |format|
  97. format.html {redirect_to_settings_in_projects}
  98. format.api {render_api_ok}
  99. end
  100. return
  101. end
  102. @categories = @project.issue_categories - [@category]
  103. end
  104. private
  105. def redirect_to_settings_in_projects
  106. redirect_to settings_project_path(@project, :tab => 'categories')
  107. end
  108. # Wrap ApplicationController's find_model_object method to set
  109. # @category instead of just @issue_category
  110. def find_model_object
  111. super
  112. @category = @object
  113. end
  114. end