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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 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 { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
  57. end
  58. else
  59. respond_to do |format|
  60. format.html { render :action => 'new'}
  61. format.js { render :action => 'new'}
  62. format.api { render_validation_errors(@category) }
  63. end
  64. end
  65. end
  66. def edit
  67. end
  68. def update
  69. @category.safe_attributes = params[:issue_category]
  70. if @category.save
  71. respond_to do |format|
  72. format.html {
  73. flash[:notice] = l(:notice_successful_update)
  74. redirect_to_settings_in_projects
  75. }
  76. format.api { render_api_ok }
  77. end
  78. else
  79. respond_to do |format|
  80. format.html { render :action => 'edit' }
  81. format.api { render_validation_errors(@category) }
  82. end
  83. end
  84. end
  85. def destroy
  86. @issue_count = @category.issues.size
  87. if @issue_count == 0 || params[:todo] || api_request?
  88. reassign_to = nil
  89. if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
  90. reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
  91. end
  92. @category.destroy(reassign_to)
  93. respond_to do |format|
  94. format.html { redirect_to_settings_in_projects }
  95. format.api { render_api_ok }
  96. end
  97. return
  98. end
  99. @categories = @project.issue_categories - [@category]
  100. end
  101. private
  102. def redirect_to_settings_in_projects
  103. redirect_to settings_project_path(@project, :tab => 'categories')
  104. end
  105. # Wrap ApplicationController's find_model_object method to set
  106. # @category instead of just @issue_category
  107. def find_model_object
  108. super
  109. @category = @object
  110. end
  111. end