2019-03-16 09:37:35 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-03-20 21:06:30 +00:00
|
|
|
# Redmine - project management software
|
2023-01-01 06:19:35 +00:00
|
|
|
# Copyright (C) 2006-2023 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-31 16:05:03 +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-31 16:05:03 +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.
|
|
|
|
|
|
2006-06-28 18:11:03 +00:00
|
|
|
module VersionsHelper
|
2023-04-13 04:20:25 +00:00
|
|
|
include Redmine::Export::Text::VersionsTextHelper
|
2007-12-07 10:26:07 +00:00
|
|
|
|
2012-08-13 14:41:53 +00:00
|
|
|
def version_anchor(version)
|
|
|
|
|
if @project == version.project
|
|
|
|
|
anchor version.name
|
|
|
|
|
else
|
|
|
|
|
anchor "#{version.project.try(:identifier)}-#{version.name}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-14 09:41:39 +00:00
|
|
|
def version_filtered_issues_path(version, options = {})
|
|
|
|
|
options = {:fixed_version_id => version, :set_filter => 1}.merge(options)
|
2019-10-14 17:47:28 +00:00
|
|
|
project =
|
|
|
|
|
case version.sharing
|
2020-10-18 02:28:27 +00:00
|
|
|
when 'tree'
|
|
|
|
|
if version.project && version.project.root.visible? && User.current.allowed_to?(:view_issues, version.project.root)
|
2014-09-14 09:41:39 +00:00
|
|
|
version.project.root
|
|
|
|
|
else
|
2020-10-18 02:28:27 +00:00
|
|
|
nil
|
2014-09-14 09:41:39 +00:00
|
|
|
end
|
|
|
|
|
when 'system'
|
|
|
|
|
nil
|
|
|
|
|
else
|
|
|
|
|
version.project
|
2019-10-17 17:02:23 +00:00
|
|
|
end
|
2014-09-14 09:41:39 +00:00
|
|
|
if project
|
|
|
|
|
project_issues_path(project, options)
|
|
|
|
|
else
|
|
|
|
|
issues_path(options)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2012-07-05 12:20:07 +00:00
|
|
|
STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category)
|
2011-08-31 16:05:03 +00:00
|
|
|
|
2007-12-07 10:26:07 +00:00
|
|
|
def render_issue_status_by(version, criteria)
|
2012-07-05 12:20:07 +00:00
|
|
|
criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria)
|
2020-08-07 12:43:07 +00:00
|
|
|
h = Hash.new {|k, v| k[v] = [0, 0]}
|
2007-12-07 10:26:07 +00:00
|
|
|
begin
|
|
|
|
|
# Total issue count
|
2020-08-07 12:43:07 +00:00
|
|
|
version.visible_fixed_issues.group(criteria).count.each {|c, s| h[c][0] = s}
|
2007-12-07 10:26:07 +00:00
|
|
|
# Open issues count
|
2020-08-07 12:43:07 +00:00
|
|
|
version.visible_fixed_issues.open.group(criteria).count.each {|c, s| h[c][1] = s}
|
2007-12-07 10:26:07 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2019-10-17 15:28:57 +00:00
|
|
|
# When grouping by an association, Rails throws this exception if there's no result (bug)
|
2007-12-07 10:26:07 +00:00
|
|
|
end
|
2012-10-30 14:24:33 +00:00
|
|
|
# Sort with nil keys in last position
|
2019-10-17 15:28:57 +00:00
|
|
|
sorted_keys =
|
2020-08-09 15:57:20 +00:00
|
|
|
h.keys.sort do |a, b|
|
2019-10-17 15:28:57 +00:00
|
|
|
if a.nil?
|
|
|
|
|
1
|
|
|
|
|
else
|
|
|
|
|
b.nil? ? -1 : a <=> b
|
|
|
|
|
end
|
2020-08-09 15:57:20 +00:00
|
|
|
end
|
2019-10-17 15:28:57 +00:00
|
|
|
counts =
|
2020-08-09 15:57:20 +00:00
|
|
|
sorted_keys.collect do |k|
|
2020-09-17 15:48:17 +00:00
|
|
|
{:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}
|
2020-08-09 15:57:20 +00:00
|
|
|
end
|
2022-10-28 07:50:11 +00:00
|
|
|
max = counts.pluck(:total).max
|
2007-12-07 10:26:07 +00:00
|
|
|
render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
|
|
|
|
|
end
|
2011-08-31 16:05:03 +00:00
|
|
|
|
2007-12-07 10:26:07 +00:00
|
|
|
def status_by_options_for_select(value)
|
2023-12-20 07:16:35 +00:00
|
|
|
options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l(:"field_#{criteria}"), criteria]}, value)
|
2007-12-07 10:26:07 +00:00
|
|
|
end
|
2019-10-19 10:22:16 +00:00
|
|
|
|
|
|
|
|
def link_to_new_issue(version, project)
|
|
|
|
|
if version.open? && User.current.allowed_to?(:add_issues, project)
|
|
|
|
|
trackers = Issue.allowed_target_trackers(project)
|
|
|
|
|
|
|
|
|
|
unless trackers.empty?
|
|
|
|
|
issue = Issue.new(:project => project)
|
|
|
|
|
new_issue_tracker = trackers.detect do |tracker|
|
|
|
|
|
issue.tracker = tracker
|
|
|
|
|
issue.safe_attribute?('fixed_version_id')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if new_issue_tracker
|
|
|
|
|
attrs = {
|
|
|
|
|
:tracker_id => new_issue_tracker,
|
|
|
|
|
:fixed_version_id => version.id
|
|
|
|
|
}
|
2019-10-19 10:23:06 +00:00
|
|
|
link_to l(:label_issue_new), new_project_issue_path(project, :issue => attrs, :back_url => version_path(version)), :class => 'icon icon-add'
|
2019-10-19 10:22:16 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|