2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2009-02-26 09:21:41 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2007-03-12 17:59:02 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-08-30 14:10:37 +00:00
|
|
|
#
|
2007-03-12 17:59:02 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2011-08-30 14:10:37 +00:00
|
|
|
#
|
2007-03-12 17:59:02 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
class TrackersController < ApplicationController
|
2009-12-17 18:21:02 +00:00
|
|
|
layout 'admin'
|
2016-11-19 10:30:02 +00:00
|
|
|
self.main_menu = false
|
2011-08-30 14:10:37 +00:00
|
|
|
|
2016-07-14 07:27:31 +00:00
|
|
|
before_action :require_admin, :except => :index
|
|
|
|
|
before_action :require_admin_or_api_request, :only => :index
|
2011-11-20 14:17:43 +00:00
|
|
|
accept_api_auth :index
|
2006-06-28 18:11:03 +00:00
|
|
|
|
2010-02-15 16:41:27 +00:00
|
|
|
def index
|
2023-04-22 01:12:28 +00:00
|
|
|
@trackers = Tracker.sorted.preload(:default_status).to_a
|
2011-11-20 14:17:43 +00:00
|
|
|
respond_to do |format|
|
2020-11-19 13:30:46 +00:00
|
|
|
format.html {render :layout => false if request.xhr?}
|
2016-03-20 09:57:24 +00:00
|
|
|
format.api
|
2011-11-20 14:17:43 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
2019-06-20 13:34:48 +00:00
|
|
|
@tracker ||= Tracker.new(:default_status => IssueStatus.sorted.first)
|
2016-07-16 09:34:45 +00:00
|
|
|
@tracker.safe_attributes = params[:tracker]
|
2020-11-25 07:51:58 +00:00
|
|
|
if params[:copy].present? && @copy_from = Tracker.find_by_id(params[:copy])
|
|
|
|
|
@tracker.copy_from(@copy_from)
|
|
|
|
|
end
|
2014-10-22 17:37:16 +00:00
|
|
|
@trackers = Tracker.sorted.to_a
|
2012-12-02 19:09:42 +00:00
|
|
|
@projects = Project.all
|
2011-11-22 21:32:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
2016-07-16 09:34:45 +00:00
|
|
|
@tracker = Tracker.new
|
|
|
|
|
@tracker.safe_attributes = params[:tracker]
|
2012-12-08 11:31:29 +00:00
|
|
|
if @tracker.save
|
2007-04-02 17:45:21 +00:00
|
|
|
# workflow copy
|
2023-03-25 01:32:23 +00:00
|
|
|
if params[:copy_workflow_from].present? && (copy_from = Tracker.find_by_id(params[:copy_workflow_from]))
|
2017-06-03 08:04:13 +00:00
|
|
|
@tracker.copy_workflow_rules(copy_from)
|
2007-04-02 17:45:21 +00:00
|
|
|
end
|
2006-07-30 10:47:02 +00:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2012-12-11 19:39:47 +00:00
|
|
|
redirect_to trackers_path
|
2009-01-29 14:22:56 +00:00
|
|
|
return
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
2011-11-22 21:32:45 +00:00
|
|
|
new
|
|
|
|
|
render :action => 'new'
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit
|
2011-11-22 21:32:45 +00:00
|
|
|
@tracker ||= Tracker.find(params[:id])
|
2012-12-02 19:09:42 +00:00
|
|
|
@projects = Project.all
|
2011-11-22 21:32:45 +00:00
|
|
|
end
|
2012-11-18 23:15:45 +00:00
|
|
|
|
2011-11-22 21:32:45 +00:00
|
|
|
def update
|
2006-06-28 18:11:03 +00:00
|
|
|
@tracker = Tracker.find(params[:id])
|
2016-07-16 09:34:45 +00:00
|
|
|
@tracker.safe_attributes = params[:tracker]
|
|
|
|
|
if @tracker.save
|
2016-04-17 07:40:39 +00:00
|
|
|
respond_to do |format|
|
2020-11-08 13:02:42 +00:00
|
|
|
format.html do
|
2016-04-17 07:40:39 +00:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
|
|
|
|
redirect_to trackers_path(:page => params[:page])
|
2020-11-08 13:02:42 +00:00
|
|
|
end
|
2024-05-18 05:56:55 +00:00
|
|
|
format.js {head :ok}
|
2016-04-17 07:40:39 +00:00
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
respond_to do |format|
|
2020-11-08 13:02:42 +00:00
|
|
|
format.html do
|
2016-04-17 07:40:39 +00:00
|
|
|
edit
|
|
|
|
|
render :action => 'edit'
|
2020-11-08 13:02:42 +00:00
|
|
|
end
|
2024-06-12 16:09:37 +00:00
|
|
|
format.js {head :unprocessable_content}
|
2016-04-17 07:40:39 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-30 14:10:37 +00:00
|
|
|
|
2006-06-28 18:11:03 +00:00
|
|
|
def destroy
|
2007-03-12 17:59:02 +00:00
|
|
|
@tracker = Tracker.find(params[:id])
|
2025-09-05 06:45:30 +00:00
|
|
|
if @tracker.issues.empty?
|
|
|
|
|
@tracker.destroy
|
|
|
|
|
redirect_to trackers_path
|
|
|
|
|
else
|
2024-11-03 07:11:07 +00:00
|
|
|
projects = Project.joins(:issues).where(issues: {tracker_id: @tracker.id}).sorted.distinct
|
|
|
|
|
links = projects.map do |p|
|
2024-11-04 04:50:25 +00:00
|
|
|
view_context.link_to(p, project_issues_path(p, set_filter: 1, tracker_id: @tracker.id, status_id: '*'))
|
2024-11-03 07:11:07 +00:00
|
|
|
end.join(', ')
|
2025-09-05 06:45:30 +00:00
|
|
|
flash.now[:error] = l(:error_can_not_delete_tracker_html, projects: links.html_safe)
|
|
|
|
|
@trackers = Tracker.sorted.preload(:default_status).to_a
|
|
|
|
|
render :index
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|
2011-08-30 14:10:37 +00:00
|
|
|
end
|
2012-09-02 16:55:16 +00:00
|
|
|
|
|
|
|
|
def fields
|
|
|
|
|
if request.post? && params[:trackers]
|
|
|
|
|
params[:trackers].each do |tracker_id, tracker_params|
|
|
|
|
|
tracker = Tracker.find_by_id(tracker_id)
|
|
|
|
|
if tracker
|
|
|
|
|
tracker.core_fields = tracker_params[:core_fields]
|
|
|
|
|
tracker.custom_field_ids = tracker_params[:custom_field_ids]
|
|
|
|
|
tracker.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2012-12-11 19:39:47 +00:00
|
|
|
redirect_to fields_trackers_path
|
2012-09-02 16:55:16 +00:00
|
|
|
return
|
|
|
|
|
end
|
2014-10-22 17:37:16 +00:00
|
|
|
@trackers = Tracker.sorted.to_a
|
2018-03-25 09:49:52 +00:00
|
|
|
@custom_fields = IssueCustomField.sorted
|
2012-09-02 16:55:16 +00:00
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|