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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class TrackersController < ApplicationController
  18. layout 'admin'
  19. self.main_menu = false
  20. before_action :require_admin, :except => :index
  21. before_action :require_admin_or_api_request, :only => :index
  22. accept_api_auth :index
  23. def index
  24. @trackers = Tracker.sorted.to_a
  25. respond_to do |format|
  26. format.html { render :layout => false if request.xhr? }
  27. format.api
  28. end
  29. end
  30. def new
  31. @tracker ||= Tracker.new
  32. @tracker.safe_attributes = params[:tracker]
  33. @trackers = Tracker.sorted.to_a
  34. @projects = Project.all
  35. end
  36. def create
  37. @tracker = Tracker.new
  38. @tracker.safe_attributes = params[:tracker]
  39. if @tracker.save
  40. # workflow copy
  41. if !params[:copy_workflow_from].blank? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
  42. @tracker.copy_workflow_rules(copy_from)
  43. end
  44. flash[:notice] = l(:notice_successful_create)
  45. redirect_to trackers_path
  46. return
  47. end
  48. new
  49. render :action => 'new'
  50. end
  51. def edit
  52. @tracker ||= Tracker.find(params[:id])
  53. @projects = Project.all
  54. end
  55. def update
  56. @tracker = Tracker.find(params[:id])
  57. @tracker.safe_attributes = params[:tracker]
  58. if @tracker.save
  59. respond_to do |format|
  60. format.html {
  61. flash[:notice] = l(:notice_successful_update)
  62. redirect_to trackers_path(:page => params[:page])
  63. }
  64. format.js { head 200 }
  65. end
  66. else
  67. respond_to do |format|
  68. format.html {
  69. edit
  70. render :action => 'edit'
  71. }
  72. format.js { head 422 }
  73. end
  74. end
  75. end
  76. def destroy
  77. @tracker = Tracker.find(params[:id])
  78. unless @tracker.issues.empty?
  79. flash[:error] = l(:error_can_not_delete_tracker)
  80. else
  81. @tracker.destroy
  82. end
  83. redirect_to trackers_path
  84. end
  85. def fields
  86. if request.post? && params[:trackers]
  87. params[:trackers].each do |tracker_id, tracker_params|
  88. tracker = Tracker.find_by_id(tracker_id)
  89. if tracker
  90. tracker.core_fields = tracker_params[:core_fields]
  91. tracker.custom_field_ids = tracker_params[:custom_field_ids]
  92. tracker.save
  93. end
  94. end
  95. flash[:notice] = l(:notice_successful_update)
  96. redirect_to fields_trackers_path
  97. return
  98. end
  99. @trackers = Tracker.sorted.to_a
  100. @custom_fields = IssueCustomField.sorted
  101. end
  102. end