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.

trackers_controller.rb 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 TrackersController < ApplicationController
  19. layout 'admin'
  20. self.main_menu = false
  21. before_action :require_admin, :except => :index
  22. before_action :require_admin_or_api_request, :only => :index
  23. accept_api_auth :index
  24. def index
  25. @trackers = Tracker.sorted.to_a
  26. respond_to do |format|
  27. format.html {render :layout => false if request.xhr?}
  28. format.api
  29. end
  30. end
  31. def new
  32. @tracker ||= Tracker.new(:default_status => IssueStatus.sorted.first)
  33. @tracker.safe_attributes = params[:tracker]
  34. if params[:copy].present? && @copy_from = Tracker.find_by_id(params[:copy])
  35. @tracker.copy_from(@copy_from)
  36. end
  37. @trackers = Tracker.sorted.to_a
  38. @projects = Project.all
  39. end
  40. def create
  41. @tracker = Tracker.new
  42. @tracker.safe_attributes = params[:tracker]
  43. if @tracker.save
  44. # workflow copy
  45. if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
  46. @tracker.copy_workflow_rules(copy_from)
  47. end
  48. flash[:notice] = l(:notice_successful_create)
  49. redirect_to trackers_path
  50. return
  51. end
  52. new
  53. render :action => 'new'
  54. end
  55. def edit
  56. @tracker ||= Tracker.find(params[:id])
  57. @projects = Project.all
  58. end
  59. def update
  60. @tracker = Tracker.find(params[:id])
  61. @tracker.safe_attributes = params[:tracker]
  62. if @tracker.save
  63. respond_to do |format|
  64. format.html do
  65. flash[:notice] = l(:notice_successful_update)
  66. redirect_to trackers_path(:page => params[:page])
  67. end
  68. format.js {head 200}
  69. end
  70. else
  71. respond_to do |format|
  72. format.html do
  73. edit
  74. render :action => 'edit'
  75. end
  76. format.js {head 422}
  77. end
  78. end
  79. end
  80. def destroy
  81. @tracker = Tracker.find(params[:id])
  82. unless @tracker.issues.empty?
  83. flash[:error] = l(:error_can_not_delete_tracker)
  84. else
  85. @tracker.destroy
  86. end
  87. redirect_to trackers_path
  88. end
  89. def fields
  90. if request.post? && params[:trackers]
  91. params[:trackers].each do |tracker_id, tracker_params|
  92. tracker = Tracker.find_by_id(tracker_id)
  93. if tracker
  94. tracker.core_fields = tracker_params[:core_fields]
  95. tracker.custom_field_ids = tracker_params[:custom_field_ids]
  96. tracker.save
  97. end
  98. end
  99. flash[:notice] = l(:notice_successful_update)
  100. redirect_to fields_trackers_path
  101. return
  102. end
  103. @trackers = Tracker.sorted.to_a
  104. @custom_fields = IssueCustomField.sorted
  105. end
  106. end