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

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