2019-03-17 00:29:58 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-02-27 13:34: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-05-18 02:45:59 +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-05-18 02:45:59 +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.
|
|
|
|
|
|
|
|
|
|
module IssuesHelper
|
2007-12-01 21:34:16 +00:00
|
|
|
include ApplicationHelper
|
2015-01-25 09:04:52 +00:00
|
|
|
include Redmine::Export::PDF::IssuesPdfHelper
|
2020-04-23 10:13:10 +00:00
|
|
|
include IssueStatusesHelper
|
2025-04-02 10:14:41 +00:00
|
|
|
include QueriesHelper
|
2007-03-12 17:59:02 +00:00
|
|
|
|
2024-08-21 00:46:15 +00:00
|
|
|
def issue_list(issues, &)
|
2010-03-27 16:55:20 +00:00
|
|
|
ancestors = []
|
|
|
|
|
issues.each do |issue|
|
2019-09-24 05:21:09 +00:00
|
|
|
while ancestors.any? &&
|
|
|
|
|
!issue.is_descendant_of?(ancestors.last)
|
2010-03-27 16:55:20 +00:00
|
|
|
ancestors.pop
|
|
|
|
|
end
|
|
|
|
|
yield issue, ancestors.size
|
2010-03-28 12:57:39 +00:00
|
|
|
ancestors << issue unless issue.leaf?
|
2010-03-27 16:55:20 +00:00
|
|
|
end
|
|
|
|
|
end
|
2010-09-20 18:50:14 +00:00
|
|
|
|
2024-08-21 00:46:15 +00:00
|
|
|
def grouped_issue_list(issues, query, &)
|
2016-07-13 19:02:48 +00:00
|
|
|
ancestors = []
|
2017-03-09 20:01:01 +00:00
|
|
|
grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals|
|
2019-09-24 05:21:09 +00:00
|
|
|
while ancestors.any? &&
|
|
|
|
|
!issue.is_descendant_of?(ancestors.last)
|
2016-07-13 19:02:48 +00:00
|
|
|
ancestors.pop
|
2015-02-07 09:39:39 +00:00
|
|
|
end
|
2016-07-13 19:02:48 +00:00
|
|
|
yield issue, ancestors.size, group_name, group_count, group_totals
|
|
|
|
|
ancestors << issue unless issue.leaf?
|
2015-02-07 09:39:39 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-09-20 18:50:14 +00:00
|
|
|
# Renders a HTML/CSS tooltip
|
|
|
|
|
#
|
|
|
|
|
# To use, a trigger div is needed. This is a div with the class of "tooltip"
|
|
|
|
|
# that contains this method wrapped in a span with the class of "tip"
|
|
|
|
|
#
|
|
|
|
|
# <div class="tooltip"><%= link_to_issue(issue) %>
|
|
|
|
|
# <span class="tip"><%= render_issue_tooltip(issue) %></span>
|
|
|
|
|
# </div>
|
|
|
|
|
#
|
2007-10-03 17:20:04 +00:00
|
|
|
def render_issue_tooltip(issue)
|
2010-08-19 03:43:33 +00:00
|
|
|
@cached_label_status ||= l(:field_status)
|
2007-10-03 17:20:04 +00:00
|
|
|
@cached_label_start_date ||= l(:field_start_date)
|
|
|
|
|
@cached_label_due_date ||= l(:field_due_date)
|
|
|
|
|
@cached_label_assigned_to ||= l(:field_assigned_to)
|
|
|
|
|
@cached_label_priority ||= l(:field_priority)
|
2010-09-10 03:09:02 +00:00
|
|
|
@cached_label_project ||= l(:field_project)
|
|
|
|
|
|
2012-01-01 11:45:18 +00:00
|
|
|
link_to_issue(issue) + "<br /><br />".html_safe +
|
|
|
|
|
"<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
|
2019-08-01 08:10:37 +00:00
|
|
|
"<strong>#{@cached_label_status}</strong>: #{h(issue.status.name) + (" (#{format_date(issue.closed_on)})" if issue.closed?)}<br />".html_safe +
|
2012-01-01 11:45:18 +00:00
|
|
|
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
|
|
|
|
|
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
|
2019-09-19 12:59:24 +00:00
|
|
|
"<strong>#{@cached_label_assigned_to}</strong>: #{avatar(issue.assigned_to, :size => '13', :title => l(:field_assigned_to)) if issue.assigned_to} #{h(issue.assigned_to)}<br />".html_safe +
|
2012-01-01 11:45:18 +00:00
|
|
|
"<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
|
2007-10-03 17:20:04 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2011-04-12 19:53:14 +00:00
|
|
|
def issue_heading(issue)
|
|
|
|
|
h("#{issue.tracker} ##{issue.id}")
|
|
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2010-03-13 14:56:49 +00:00
|
|
|
def render_issue_subject_with_tree(issue)
|
2019-03-17 00:29:58 +00:00
|
|
|
s = +''
|
2014-10-22 17:37:16 +00:00
|
|
|
ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
|
2011-03-28 20:32:35 +00:00
|
|
|
ancestors.each do |ancestor|
|
2012-10-10 17:38:17 +00:00
|
|
|
s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
|
2010-03-13 14:56:49 +00:00
|
|
|
end
|
2011-04-15 13:23:13 +00:00
|
|
|
s << '<div>'
|
|
|
|
|
subject = h(issue.subject)
|
|
|
|
|
s << content_tag('h3', subject)
|
2011-03-28 20:32:35 +00:00
|
|
|
s << '</div>' * (ancestors.size + 1)
|
2011-08-20 23:11:56 +00:00
|
|
|
s.html_safe
|
2010-03-13 14:56:49 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2025-04-02 10:14:41 +00:00
|
|
|
def get_related_issues_columns_for_project(issue)
|
|
|
|
|
query = IssueQuery.new project: issue.project
|
|
|
|
|
available_columns = query.available_inline_columns
|
|
|
|
|
column_names = Setting.related_issues_default_columns
|
|
|
|
|
|
|
|
|
|
(column_names - %w[tracker subject]).filter_map do |name|
|
|
|
|
|
available_columns.find { |f| f.name.to_s == name }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2010-03-13 14:56:49 +00:00
|
|
|
def render_descendants_tree(issue)
|
2025-04-02 10:14:41 +00:00
|
|
|
columns_list = get_related_issues_columns_for_project(issue)
|
|
|
|
|
|
2018-12-16 07:38:03 +00:00
|
|
|
manage_relations = User.current.allowed_to?(:manage_subtasks, issue.project)
|
2019-03-17 00:29:58 +00:00
|
|
|
s = +'<table class="list issues odd-even">'
|
2025-04-02 10:14:41 +00:00
|
|
|
|
|
|
|
|
if Setting.display_related_issues_table_headers?
|
|
|
|
|
headers = [l(:field_subject)]
|
|
|
|
|
headers += columns_list.map(&:caption)
|
|
|
|
|
s << content_tag(:thead, content_tag(:tr, safe_join(headers.map{|h| content_tag :th, h})), class: "related-issues")
|
|
|
|
|
end
|
|
|
|
|
|
2019-11-09 14:09:50 +00:00
|
|
|
issue_list(
|
|
|
|
|
issue.descendants.visible.
|
|
|
|
|
preload(:status, :priority, :tracker,
|
|
|
|
|
:assigned_to).sort_by(&:lft)) do |child, level|
|
2024-09-01 00:38:01 +00:00
|
|
|
css = "issue issue-#{child.id} hascontextmenu #{child.css_classes}"
|
2012-10-17 16:54:26 +00:00
|
|
|
css << " idnt idnt-#{level}" if level > 0
|
2019-09-21 06:39:24 +00:00
|
|
|
buttons =
|
|
|
|
|
if manage_relations
|
2020-11-29 12:47:46 +00:00
|
|
|
link_to(
|
2024-10-19 10:06:26 +00:00
|
|
|
sprite_icon('link-break', l(:label_delete_link_to_subtask)),
|
2020-11-29 12:47:46 +00:00
|
|
|
issue_path(
|
|
|
|
|
{:id => child.id, :issue => {:parent_issue_id => ''},
|
|
|
|
|
:back_url => issue_path(issue.id), :no_flash => '1'}
|
|
|
|
|
),
|
|
|
|
|
:method => :put,
|
|
|
|
|
:data => {:confirm => l(:text_are_you_sure)},
|
|
|
|
|
:title => l(:label_delete_link_to_subtask),
|
|
|
|
|
:class => 'icon-only icon-link-break'
|
|
|
|
|
)
|
2019-09-21 06:39:24 +00:00
|
|
|
else
|
|
|
|
|
"".html_safe
|
|
|
|
|
end
|
2018-12-16 07:38:03 +00:00
|
|
|
buttons << link_to_context_menu
|
2025-04-02 10:14:41 +00:00
|
|
|
|
|
|
|
|
row_content =
|
|
|
|
|
content_tag('td', check_box_tag('ids[]', child.id, false, id: nil), class: 'checkbox') +
|
|
|
|
|
content_tag('td', link_to_issue(child, project: (issue.project_id != child.project_id)), class: 'subject')
|
|
|
|
|
|
|
|
|
|
columns_list.each do |column|
|
|
|
|
|
row_content << content_tag('td', column_content(column, child), class: column.css_classes.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
row_content << content_tag('td', buttons, class: 'buttons')
|
|
|
|
|
s << content_tag('tr', row_content, class: css, id: "issue-#{child.id}").html_safe
|
2010-03-13 14:56:49 +00:00
|
|
|
end
|
2016-10-29 14:06:15 +00:00
|
|
|
s << '</table>'
|
2011-08-20 23:12:20 +00:00
|
|
|
s.html_safe
|
2010-03-13 14:56:49 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2021-01-18 07:11:47 +00:00
|
|
|
# Renders descendants stats (total descendants (open - closed)) with query links
|
|
|
|
|
def render_descendants_stats(issue)
|
|
|
|
|
# Get issue descendants grouped by status type (open/closed) using a single query
|
|
|
|
|
subtasks_grouped = issue.descendants.visible.joins(:status).select(:is_closed, :id).group(:is_closed).reorder(:is_closed).count(:id)
|
|
|
|
|
# Cast keys to boolean in order to have consistent results between database types
|
|
|
|
|
subtasks_grouped.transform_keys! {|k| ActiveModel::Type::Boolean.new.cast(k)}
|
|
|
|
|
|
|
|
|
|
open_subtasks = subtasks_grouped[false].to_i
|
|
|
|
|
closed_subtasks = subtasks_grouped[true].to_i
|
2021-08-23 12:59:48 +00:00
|
|
|
render_issues_stats(open_subtasks, closed_subtasks, {:parent_id => "~#{issue.id}"})
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Renders relations stats (total relations (open - closed)) with query links
|
|
|
|
|
def render_relations_stats(issue, relations)
|
2022-07-16 09:14:38 +00:00
|
|
|
open_relations = relations.count{|r| r.other_issue(issue).closed? == false}
|
2021-08-23 12:59:48 +00:00
|
|
|
closed_relations = relations.count{|r| r.other_issue(issue).closed?}
|
|
|
|
|
render_issues_stats(open_relations, closed_relations, {:issue_id => relations.map{|r| r.other_issue(issue).id}.join(',')})
|
|
|
|
|
end
|
2021-01-18 07:11:47 +00:00
|
|
|
|
2021-08-23 12:59:48 +00:00
|
|
|
# Renders issues stats (total relations (open - closed)) with query links
|
|
|
|
|
def render_issues_stats(open_issues=0, closed_issues=0, issues_path_attr={})
|
|
|
|
|
total_issues = open_issues + closed_issues
|
|
|
|
|
return if total_issues == 0
|
2021-01-18 07:11:47 +00:00
|
|
|
|
|
|
|
|
all_block = content_tag(
|
|
|
|
|
'span',
|
2021-08-23 12:59:48 +00:00
|
|
|
link_to(total_issues, issues_path(issues_path_attr.merge({:set_filter => true, :status_id => '*'}))),
|
2021-01-18 07:11:47 +00:00
|
|
|
class: 'badge badge-issues-count'
|
|
|
|
|
)
|
|
|
|
|
closed_block = content_tag(
|
|
|
|
|
'span',
|
|
|
|
|
link_to_if(
|
2021-08-23 12:59:48 +00:00
|
|
|
closed_issues > 0,
|
|
|
|
|
l(:label_x_closed_issues_abbr, count: closed_issues),
|
|
|
|
|
issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'c'}))
|
2021-01-18 07:11:47 +00:00
|
|
|
),
|
|
|
|
|
class: 'closed'
|
|
|
|
|
)
|
|
|
|
|
open_block = content_tag(
|
|
|
|
|
'span',
|
|
|
|
|
link_to_if(
|
2021-08-23 12:59:48 +00:00
|
|
|
open_issues > 0,
|
|
|
|
|
l(:label_x_open_issues_abbr, :count => open_issues),
|
|
|
|
|
issues_path(issues_path_attr.merge({:set_filter => true, :status_id => 'o'}))
|
2021-01-18 07:11:47 +00:00
|
|
|
),
|
|
|
|
|
class: 'open'
|
|
|
|
|
)
|
|
|
|
|
content_tag(
|
|
|
|
|
'span',
|
|
|
|
|
"#{all_block} (#{open_block} — #{closed_block})".html_safe,
|
|
|
|
|
:class => 'issues-stat'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-19 10:03:27 +00:00
|
|
|
# Renders the list of related issues on the issue details view
|
|
|
|
|
def render_issue_relations(issue, relations)
|
2025-04-02 10:14:41 +00:00
|
|
|
columns_list = get_related_issues_columns_for_project(issue)
|
|
|
|
|
|
2016-11-19 10:03:27 +00:00
|
|
|
manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
|
|
|
|
|
s = ''.html_safe
|
2025-04-02 10:14:41 +00:00
|
|
|
|
|
|
|
|
if Setting.display_related_issues_table_headers?
|
|
|
|
|
headers = [l(:field_subject)]
|
|
|
|
|
headers += columns_list.map(&:caption)
|
|
|
|
|
s = content_tag :thead, content_tag(:tr, safe_join(headers.map{|h| content_tag :th, h})), class: "related-issues"
|
|
|
|
|
end
|
|
|
|
|
|
2016-11-19 10:03:27 +00:00
|
|
|
relations.each do |relation|
|
|
|
|
|
other_issue = relation.other_issue(issue)
|
2022-08-05 00:20:56 +00:00
|
|
|
css = "issue hascontextmenu #{other_issue.css_classes} #{relation.css_classes_for(other_issue)}"
|
2019-09-21 06:39:24 +00:00
|
|
|
buttons =
|
|
|
|
|
if manage_relations
|
2019-11-09 16:04:54 +00:00
|
|
|
link_to(
|
2024-10-19 10:06:26 +00:00
|
|
|
sprite_icon('link-break', l(:label_relation_delete)),
|
2023-10-29 07:31:01 +00:00
|
|
|
relation_path(relation, issue_id: issue.id),
|
2019-11-09 16:04:54 +00:00
|
|
|
:remote => true,
|
|
|
|
|
:method => :delete,
|
|
|
|
|
:data => {:confirm => l(:text_are_you_sure)},
|
|
|
|
|
:title => l(:label_relation_delete),
|
|
|
|
|
:class => 'icon-only icon-link-break'
|
|
|
|
|
)
|
2019-09-21 06:39:24 +00:00
|
|
|
else
|
|
|
|
|
"".html_safe
|
|
|
|
|
end
|
2018-04-21 12:00:22 +00:00
|
|
|
buttons << link_to_context_menu
|
2025-04-02 10:14:41 +00:00
|
|
|
|
|
|
|
|
subject_content = relation.to_s(@issue) { |other| link_to_issue other, project: Setting.cross_project_issue_relations? }.html_safe
|
|
|
|
|
|
|
|
|
|
row_content =
|
|
|
|
|
content_tag('td', check_box_tag('ids[]', other_issue.id, false, id: nil), class: 'checkbox') +
|
|
|
|
|
content_tag('td', subject_content, class: 'subject')
|
|
|
|
|
|
|
|
|
|
columns_list.each do |column|
|
|
|
|
|
row_content << content_tag('td', column_content(column, other_issue), class: column.css_classes.to_s)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
row_content << content_tag('td', buttons, class: 'buttons')
|
|
|
|
|
s << content_tag('tr', row_content, id: "relation-#{relation.id}", class: css)
|
2016-11-19 10:03:27 +00:00
|
|
|
end
|
2017-01-25 16:11:29 +00:00
|
|
|
content_tag('table', s, :class => 'list issues odd-even')
|
2016-11-19 10:03:27 +00:00
|
|
|
end
|
|
|
|
|
|
2015-05-25 11:37:12 +00:00
|
|
|
def issue_estimated_hours_details(issue)
|
2015-05-25 12:06:38 +00:00
|
|
|
if issue.total_estimated_hours.present?
|
|
|
|
|
if issue.total_estimated_hours == issue.estimated_hours
|
|
|
|
|
l_hours_short(issue.estimated_hours)
|
|
|
|
|
else
|
|
|
|
|
s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
|
2019-03-17 00:29:58 +00:00
|
|
|
s += " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
|
2015-05-25 12:06:38 +00:00
|
|
|
s.html_safe
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def issue_spent_hours_details(issue)
|
|
|
|
|
if issue.total_spent_hours > 0
|
2016-07-12 19:28:49 +00:00
|
|
|
path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
|
|
|
|
|
|
2015-05-25 12:06:38 +00:00
|
|
|
if issue.total_spent_hours == issue.spent_hours
|
2016-07-12 19:28:49 +00:00
|
|
|
link_to(l_hours_short(issue.spent_hours), path)
|
2015-05-25 12:06:38 +00:00
|
|
|
else
|
2021-07-26 20:55:09 +00:00
|
|
|
# link to global time entries if cross-project subtasks are allowed
|
|
|
|
|
# in order to show time entries from not descendents projects
|
|
|
|
|
if %w(system tree hierarchy).include?(Setting.cross_project_subtasks)
|
|
|
|
|
path = time_entries_path(:issue_id => "~#{issue.id}")
|
|
|
|
|
end
|
2015-05-25 12:06:38 +00:00
|
|
|
s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
|
2019-03-17 00:29:58 +00:00
|
|
|
s += " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
|
2015-05-25 12:06:38 +00:00
|
|
|
s.html_safe
|
|
|
|
|
end
|
2015-05-25 11:37:12 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-06-07 09:40:12 +00:00
|
|
|
def issue_due_date_details(issue)
|
|
|
|
|
return if issue&.due_date.nil?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2019-06-07 09:40:12 +00:00
|
|
|
s = format_date(issue.due_date)
|
|
|
|
|
s += " (#{due_date_distance_in_words(issue.due_date)})" unless issue.closed?
|
|
|
|
|
s
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-17 16:58:44 +00:00
|
|
|
# Returns a link for adding a new subtask to the given issue
|
|
|
|
|
def link_to_new_subtask(issue)
|
2020-12-10 15:18:49 +00:00
|
|
|
link_to(l(:button_add), url_for_new_subtask(issue))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def url_for_new_subtask(issue)
|
2012-10-17 17:00:24 +00:00
|
|
|
attrs = {
|
|
|
|
|
:parent_issue_id => issue
|
|
|
|
|
}
|
2016-04-24 15:22:18 +00:00
|
|
|
attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
|
2020-12-10 15:18:49 +00:00
|
|
|
params = {:issue => attrs}
|
|
|
|
|
params[:back_url] = issue_path(issue) if controller_name == 'issues' && action_name == 'show'
|
|
|
|
|
new_project_issue_path(issue.project, params)
|
2012-10-17 16:58:44 +00:00
|
|
|
end
|
|
|
|
|
|
2016-05-30 18:20:13 +00:00
|
|
|
def trackers_options_for_select(issue)
|
2019-03-15 10:38:56 +00:00
|
|
|
trackers = trackers_for_select(issue)
|
|
|
|
|
trackers.collect {|t| [t.name, t.id]}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def trackers_for_select(issue)
|
2016-05-30 18:20:13 +00:00
|
|
|
trackers = issue.allowed_target_trackers
|
|
|
|
|
if issue.new_record? && issue.parent_issue_id.present?
|
|
|
|
|
trackers = trackers.reject do |tracker|
|
|
|
|
|
issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-03-15 10:38:56 +00:00
|
|
|
trackers
|
2016-05-30 18:20:13 +00:00
|
|
|
end
|
|
|
|
|
|
2012-07-05 12:20:07 +00:00
|
|
|
class IssueFieldsRows
|
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
|
@left = []
|
|
|
|
|
@right = []
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def left(*args)
|
|
|
|
|
args.any? ? @left << cells(*args) : @left
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def right(*args)
|
|
|
|
|
args.any? ? @right << cells(*args) : @right
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def size
|
2023-01-02 06:10:53 +00:00
|
|
|
[@left.size, @right.size].max
|
2012-07-05 12:20:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def to_html
|
2023-01-11 13:36:36 +00:00
|
|
|
# rubocop:disable Performance/Sum
|
2015-11-08 11:50:36 +00:00
|
|
|
content =
|
|
|
|
|
content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
|
|
|
|
|
content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
|
2023-01-11 13:36:36 +00:00
|
|
|
# rubocop:enable Performance/Sum
|
2015-11-08 11:50:36 +00:00
|
|
|
|
|
|
|
|
content_tag('div', content, :class => 'splitcontent')
|
2012-07-05 12:20:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cells(label, text, options={})
|
2015-11-08 11:50:36 +00:00
|
|
|
options[:class] = [options[:class] || "", 'attribute'].join(' ')
|
2019-11-09 16:04:43 +00:00
|
|
|
content_tag(
|
|
|
|
|
'div',
|
|
|
|
|
content_tag('div', label + ":", :class => 'label') +
|
|
|
|
|
content_tag('div', text, :class => 'value'),
|
|
|
|
|
options)
|
2012-07-05 12:20:07 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def issue_fields_rows
|
|
|
|
|
r = IssueFieldsRows.new
|
|
|
|
|
yield r
|
|
|
|
|
r.to_html
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-25 14:55:36 +00:00
|
|
|
def render_half_width_custom_fields_rows(issue)
|
|
|
|
|
values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
|
2013-07-13 09:20:11 +00:00
|
|
|
return if values.empty?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2013-07-13 09:20:11 +00:00
|
|
|
half = (values.size / 2.0).ceil
|
2015-11-08 10:35:52 +00:00
|
|
|
issue_fields_rows do |rows|
|
|
|
|
|
values.each_with_index do |value, i|
|
|
|
|
|
m = (i < half ? :left : :right)
|
2019-03-09 15:38:24 +00:00
|
|
|
rows.send m, custom_field_name_tag(value.custom_field), custom_field_value_tag(value), :class => value.custom_field.css_classes
|
2015-11-08 10:35:52 +00:00
|
|
|
end
|
|
|
|
|
end
|
2009-07-29 19:04:27 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2017-01-25 14:55:36 +00:00
|
|
|
def render_full_width_custom_fields_rows(issue)
|
|
|
|
|
values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
|
|
|
|
|
return if values.empty?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2017-01-25 16:04:51 +00:00
|
|
|
s = ''.html_safe
|
2017-01-25 14:55:36 +00:00
|
|
|
values.each_with_index do |value, i|
|
2019-02-12 11:52:20 +00:00
|
|
|
attr_value_tag = custom_field_value_tag(value)
|
|
|
|
|
next if attr_value_tag.blank?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2017-01-25 14:55:36 +00:00
|
|
|
content =
|
2019-09-19 06:11:15 +00:00
|
|
|
content_tag('hr') +
|
2024-08-12 08:45:54 +00:00
|
|
|
content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field))) +
|
2019-09-19 06:11:15 +00:00
|
|
|
content_tag('div', attr_value_tag, class: 'value')
|
2019-03-09 15:38:24 +00:00
|
|
|
s << content_tag('div', content, class: "#{value.custom_field.css_classes} attribute")
|
2017-01-25 14:55:36 +00:00
|
|
|
end
|
2017-01-25 16:04:51 +00:00
|
|
|
s
|
2017-01-25 14:55:36 +00:00
|
|
|
end
|
|
|
|
|
|
2015-02-13 20:00:22 +00:00
|
|
|
# Returns the path for updating the issue form
|
|
|
|
|
# with project as the current project
|
|
|
|
|
def update_issue_form_path(project, issue)
|
2015-02-14 08:03:51 +00:00
|
|
|
options = {:format => 'js'}
|
2015-02-13 20:00:22 +00:00
|
|
|
if issue.new_record?
|
2015-02-14 08:03:51 +00:00
|
|
|
if project
|
|
|
|
|
new_project_issue_path(project, options)
|
|
|
|
|
else
|
|
|
|
|
new_issue_path(options)
|
|
|
|
|
end
|
2015-02-13 20:00:22 +00:00
|
|
|
else
|
2015-02-14 08:03:51 +00:00
|
|
|
edit_issue_path(issue, options)
|
2015-02-13 20:00:22 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-12-30 11:24:00 +00:00
|
|
|
# Returns the number of descendants for an array of issues
|
|
|
|
|
def issues_descendant_count(issues)
|
|
|
|
|
ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
|
|
|
|
|
ids -= issues.map(&:id)
|
|
|
|
|
ids.size
|
|
|
|
|
end
|
|
|
|
|
|
2011-04-17 15:17:18 +00:00
|
|
|
def issues_destroy_confirmation_message(issues)
|
|
|
|
|
issues = [issues] unless issues.is_a?(Array)
|
|
|
|
|
message = l(:text_issues_destroy_confirmation)
|
2014-12-30 11:24:00 +00:00
|
|
|
|
2015-06-21 16:38:29 +00:00
|
|
|
descendant_count = issues_descendant_count(issues)
|
2011-04-17 15:17:18 +00:00
|
|
|
if descendant_count > 0
|
2014-12-30 11:24:00 +00:00
|
|
|
message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
|
2011-04-17 15:17:18 +00:00
|
|
|
end
|
|
|
|
|
message
|
|
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2015-02-13 17:32:26 +00:00
|
|
|
# Returns an array of users that are proposed as watchers
|
|
|
|
|
# on the new issue form
|
|
|
|
|
def users_for_new_issue_watchers(issue)
|
2018-05-19 00:44:10 +00:00
|
|
|
users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
|
2020-04-25 08:01:59 +00:00
|
|
|
assignable_watchers = issue.project.principals.assignable_watchers.limit(21)
|
|
|
|
|
if assignable_watchers.size <= 20
|
|
|
|
|
users += assignable_watchers.sort
|
2015-02-13 17:32:26 +00:00
|
|
|
end
|
2020-04-25 07:57:46 +00:00
|
|
|
users.uniq
|
2015-02-13 17:32:26 +00:00
|
|
|
end
|
|
|
|
|
|
2016-12-16 08:53:52 +00:00
|
|
|
def email_issue_attributes(issue, user, html)
|
2013-08-05 17:08:26 +00:00
|
|
|
items = []
|
2023-03-01 03:46:53 +00:00
|
|
|
%w(author status priority assigned_to category fixed_version start_date due_date parent_issue).each do |attribute|
|
2019-01-25 08:06:23 +00:00
|
|
|
if issue.disabled_core_fields.grep(/^#{attribute}(_id)?$/).empty?
|
2019-06-20 11:57:24 +00:00
|
|
|
attr_value = (issue.send attribute).to_s
|
2019-06-20 07:36:21 +00:00
|
|
|
next if attr_value.blank?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2016-12-16 08:53:52 +00:00
|
|
|
if html
|
2019-06-20 07:36:21 +00:00
|
|
|
items << content_tag('strong', "#{l("field_#{attribute}")}: ") + attr_value
|
2016-12-16 08:53:52 +00:00
|
|
|
else
|
2019-06-20 07:36:21 +00:00
|
|
|
items << "#{l("field_#{attribute}")}: #{attr_value}"
|
2016-12-16 08:53:52 +00:00
|
|
|
end
|
2013-08-05 17:08:26 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
issue.visible_custom_field_values(user).each do |value|
|
2019-06-20 07:36:21 +00:00
|
|
|
cf_value = show_value(value, false)
|
|
|
|
|
next if cf_value.blank?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2016-12-16 08:53:52 +00:00
|
|
|
if html
|
2019-06-20 07:36:21 +00:00
|
|
|
items << content_tag('strong', "#{value.custom_field.name}: ") + cf_value
|
2016-12-16 08:53:52 +00:00
|
|
|
else
|
2019-06-20 07:36:21 +00:00
|
|
|
items << "#{value.custom_field.name}: #{cf_value}"
|
2016-12-16 08:53:52 +00:00
|
|
|
end
|
2013-08-05 17:08:26 +00:00
|
|
|
end
|
|
|
|
|
items
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def render_email_issue_attributes(issue, user, html=false)
|
2016-12-16 08:53:52 +00:00
|
|
|
items = email_issue_attributes(issue, user, html)
|
2013-08-05 17:08:26 +00:00
|
|
|
if html
|
2016-12-16 08:53:52 +00:00
|
|
|
content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")
|
2013-08-05 17:08:26 +00:00
|
|
|
else
|
|
|
|
|
items.map{|s| "* #{s}"}.join("\n")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-25 19:24:20 +00:00
|
|
|
MultipleValuesDetail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
|
|
|
|
|
|
2012-01-29 20:51:48 +00:00
|
|
|
# Returns the textual representation of a journal details
|
|
|
|
|
# as an array of strings
|
2012-02-27 20:43:25 +00:00
|
|
|
def details_to_strings(details, no_html=false, options={})
|
2019-09-21 14:14:28 +00:00
|
|
|
options[:only_path] = !(options[:only_path] == false)
|
2012-01-29 20:51:48 +00:00
|
|
|
strings = []
|
|
|
|
|
values_by_field = {}
|
|
|
|
|
details.each do |detail|
|
|
|
|
|
if detail.property == 'cf'
|
2013-10-13 10:04:59 +00:00
|
|
|
field = detail.custom_field
|
2012-01-29 20:51:48 +00:00
|
|
|
if field && field.multiple?
|
2013-10-13 10:04:59 +00:00
|
|
|
values_by_field[field] ||= {:added => [], :deleted => []}
|
2012-01-29 20:51:48 +00:00
|
|
|
if detail.old_value
|
2013-10-13 10:04:59 +00:00
|
|
|
values_by_field[field][:deleted] << detail.old_value
|
2012-01-29 20:51:48 +00:00
|
|
|
end
|
|
|
|
|
if detail.value
|
2013-10-13 10:04:59 +00:00
|
|
|
values_by_field[field][:added] << detail.value
|
2012-01-29 20:51:48 +00:00
|
|
|
end
|
|
|
|
|
next
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-02-27 20:43:25 +00:00
|
|
|
strings << show_detail(detail, no_html, options)
|
2012-01-29 20:51:48 +00:00
|
|
|
end
|
2015-03-08 09:07:20 +00:00
|
|
|
if values_by_field.present?
|
|
|
|
|
values_by_field.each do |field, changes|
|
|
|
|
|
if changes[:added].any?
|
2017-06-25 19:24:20 +00:00
|
|
|
detail = MultipleValuesDetail.new('cf', field.id.to_s, field)
|
2015-03-08 09:07:20 +00:00
|
|
|
detail.value = changes[:added]
|
|
|
|
|
strings << show_detail(detail, no_html, options)
|
|
|
|
|
end
|
|
|
|
|
if changes[:deleted].any?
|
2017-06-25 19:24:20 +00:00
|
|
|
detail = MultipleValuesDetail.new('cf', field.id.to_s, field)
|
2015-03-08 09:07:20 +00:00
|
|
|
detail.old_value = changes[:deleted]
|
|
|
|
|
strings << show_detail(detail, no_html, options)
|
|
|
|
|
end
|
2012-01-29 20:51:48 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
strings
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Returns the textual representation of a single journal detail
|
2012-02-27 20:43:25 +00:00
|
|
|
def show_detail(detail, no_html=false, options={})
|
2012-01-29 20:51:48 +00:00
|
|
|
multiple = false
|
2015-01-31 10:42:41 +00:00
|
|
|
show_diff = false
|
2016-10-23 09:16:14 +00:00
|
|
|
no_details = false
|
2015-01-31 10:42:41 +00:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
case detail.property
|
|
|
|
|
when 'attr'
|
2024-01-08 01:04:37 +00:00
|
|
|
field = detail.prop_key.to_s.delete_suffix('_id')
|
|
|
|
|
label = l(("field_#{field}").to_sym)
|
2012-01-29 21:12:10 +00:00
|
|
|
case detail.prop_key
|
|
|
|
|
when 'due_date', 'start_date'
|
2007-03-12 17:59:02 +00:00
|
|
|
value = format_date(detail.value.to_date) if detail.value
|
|
|
|
|
old_value = format_date(detail.old_value.to_date) if detail.old_value
|
2010-03-08 16:47:57 +00:00
|
|
|
|
2012-01-29 21:12:10 +00:00
|
|
|
when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
|
2022-11-18 08:17:50 +00:00
|
|
|
'priority_id', 'category_id', 'fixed_version_id'
|
2010-03-08 16:47:52 +00:00
|
|
|
value = find_name_by_reflection(field, detail.value)
|
|
|
|
|
old_value = find_name_by_reflection(field, detail.old_value)
|
2010-03-08 16:47:57 +00:00
|
|
|
|
2012-01-29 21:12:10 +00:00
|
|
|
when 'estimated_hours'
|
2016-01-31 11:20:56 +00:00
|
|
|
value = l_hours_short(detail.value.to_f) unless detail.value.blank?
|
|
|
|
|
old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
|
2010-03-16 20:37:29 +00:00
|
|
|
|
2012-01-29 21:12:10 +00:00
|
|
|
when 'parent_id'
|
2010-03-16 20:37:29 +00:00
|
|
|
label = l(:field_parent_issue)
|
|
|
|
|
value = "##{detail.value}" unless detail.value.blank?
|
|
|
|
|
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2021-11-08 14:22:06 +00:00
|
|
|
when 'child_id'
|
|
|
|
|
label = l(:label_subtask)
|
|
|
|
|
value = "##{detail.value}" unless detail.value.blank?
|
|
|
|
|
old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
|
|
|
|
multiple = true
|
|
|
|
|
|
2012-01-29 21:12:10 +00:00
|
|
|
when 'is_private'
|
2011-04-15 13:23:13 +00:00
|
|
|
value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
|
|
|
|
|
old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
|
2015-01-31 10:42:41 +00:00
|
|
|
|
|
|
|
|
when 'description'
|
|
|
|
|
show_diff = true
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
|
|
|
|
when 'cf'
|
2013-10-13 10:04:59 +00:00
|
|
|
custom_field = detail.custom_field
|
2007-03-12 17:59:02 +00:00
|
|
|
if custom_field
|
|
|
|
|
label = custom_field.name
|
2016-10-23 09:16:14 +00:00
|
|
|
if custom_field.format.class.change_no_details
|
|
|
|
|
no_details = true
|
|
|
|
|
elsif custom_field.format.class.change_as_diff
|
2015-01-31 10:42:41 +00:00
|
|
|
show_diff = true
|
|
|
|
|
else
|
|
|
|
|
multiple = custom_field.multiple?
|
|
|
|
|
value = format_value(detail.value, custom_field) if detail.value
|
|
|
|
|
old_value = format_value(detail.old_value, custom_field) if detail.old_value
|
|
|
|
|
end
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2007-04-05 17:20:04 +00:00
|
|
|
when 'attachment'
|
|
|
|
|
label = l(:label_attachment)
|
2013-05-19 02:09:39 +00:00
|
|
|
when 'relation'
|
|
|
|
|
if detail.value && !detail.old_value
|
2013-06-06 16:19:53 +00:00
|
|
|
rel_issue = Issue.visible.find_by_id(detail.value)
|
2019-09-21 06:39:24 +00:00
|
|
|
value =
|
|
|
|
|
if rel_issue.nil?
|
|
|
|
|
"#{l(:label_issue)} ##{detail.value}"
|
|
|
|
|
else
|
|
|
|
|
(no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
|
|
|
|
|
end
|
2013-05-19 02:09:39 +00:00
|
|
|
elsif detail.old_value && !detail.value
|
2013-06-06 16:19:53 +00:00
|
|
|
rel_issue = Issue.visible.find_by_id(detail.old_value)
|
2019-09-21 06:39:24 +00:00
|
|
|
old_value =
|
|
|
|
|
if rel_issue.nil?
|
|
|
|
|
"#{l(:label_issue)} ##{detail.old_value}"
|
|
|
|
|
else
|
|
|
|
|
(no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
|
|
|
|
|
end
|
2013-05-19 02:09:39 +00:00
|
|
|
end
|
2013-12-15 11:02:24 +00:00
|
|
|
relation_type = IssueRelation::TYPES[detail.prop_key]
|
|
|
|
|
label = l(relation_type[:name]) if relation_type
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-12-02 11:36:40 +00:00
|
|
|
call_hook(:helper_issues_show_detail_after_setting,
|
2020-08-07 12:42:42 +00:00
|
|
|
{:detail => detail, :label => label, :value => value, :old_value => old_value})
|
2008-09-05 10:31:06 +00:00
|
|
|
|
2007-03-12 17:59:02 +00:00
|
|
|
label ||= detail.prop_key
|
|
|
|
|
value ||= detail.value
|
|
|
|
|
old_value ||= detail.old_value
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2012-04-08 19:29:26 +00:00
|
|
|
unless no_html
|
2007-03-12 17:59:02 +00:00
|
|
|
label = content_tag('strong', label)
|
|
|
|
|
old_value = content_tag("i", h(old_value)) if detail.old_value
|
2013-05-19 02:09:49 +00:00
|
|
|
if detail.old_value && detail.value.blank? && detail.property != 'relation'
|
|
|
|
|
old_value = content_tag("del", old_value)
|
|
|
|
|
end
|
2015-01-24 10:25:05 +00:00
|
|
|
if detail.property == 'attachment' && value.present? &&
|
|
|
|
|
atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
|
2007-09-14 19:55:51 +00:00
|
|
|
# Link to the attachment if it has not been removed
|
2017-06-10 10:30:59 +00:00
|
|
|
value = link_to_attachment(atta, only_path: options[:only_path])
|
|
|
|
|
if options[:only_path] != false
|
2016-06-18 07:42:51 +00:00
|
|
|
value += ' '
|
2024-11-29 03:31:55 +00:00
|
|
|
value += link_to_attachment atta, class: 'icon-only icon-download', title: l(:button_download), download: true, icon: 'download'
|
2012-04-06 05:44:48 +00:00
|
|
|
end
|
2007-09-14 19:55:51 +00:00
|
|
|
else
|
|
|
|
|
value = content_tag("i", h(value)) if value
|
|
|
|
|
end
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2016-10-23 09:16:14 +00:00
|
|
|
if no_details
|
|
|
|
|
s = l(:text_journal_changed_no_detail, :label => label).html_safe
|
|
|
|
|
elsif show_diff
|
2011-02-27 13:34:41 +00:00
|
|
|
s = l(:text_journal_changed_no_detail, :label => label)
|
|
|
|
|
unless no_html
|
2019-11-09 16:04:32 +00:00
|
|
|
diff_link =
|
|
|
|
|
link_to(
|
2020-05-16 01:02:45 +00:00
|
|
|
l(:label_diff),
|
2019-11-09 16:04:32 +00:00
|
|
|
diff_journal_url(detail.journal_id, :detail_id => detail.id,
|
|
|
|
|
:only_path => options[:only_path]),
|
|
|
|
|
:title => l(:label_view_diff))
|
2019-09-24 05:54:42 +00:00
|
|
|
s << " (#{diff_link})"
|
2011-02-27 13:34:41 +00:00
|
|
|
end
|
2011-12-02 11:35:54 +00:00
|
|
|
s.html_safe
|
2012-01-29 21:12:10 +00:00
|
|
|
elsif detail.value.present?
|
2007-04-05 17:20:04 +00:00
|
|
|
case detail.property
|
|
|
|
|
when 'attr', 'cf'
|
2012-01-29 21:12:10 +00:00
|
|
|
if detail.old_value.present?
|
2011-12-02 11:35:54 +00:00
|
|
|
l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
|
2012-01-29 20:51:48 +00:00
|
|
|
elsif multiple
|
|
|
|
|
l(:text_journal_added, :label => label, :value => value).html_safe
|
2007-04-05 17:20:04 +00:00
|
|
|
else
|
2011-12-02 11:35:54 +00:00
|
|
|
l(:text_journal_set_to, :label => label, :value => value).html_safe
|
2007-04-05 17:20:04 +00:00
|
|
|
end
|
2013-05-19 02:09:39 +00:00
|
|
|
when 'attachment', 'relation'
|
2011-12-02 11:35:54 +00:00
|
|
|
l(:text_journal_added, :label => label, :value => value).html_safe
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
|
|
|
|
else
|
2011-12-02 11:35:54 +00:00
|
|
|
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
|
2007-03-12 17:59:02 +00:00
|
|
|
end
|
2006-11-27 22:31:14 +00:00
|
|
|
end
|
2010-03-08 16:47:52 +00:00
|
|
|
|
|
|
|
|
# Find the name of an associated record stored in the field attribute
|
2021-03-18 07:44:42 +00:00
|
|
|
# For project, return the associated record only if is visible for the current User
|
2010-03-08 16:47:52 +00:00
|
|
|
def find_name_by_reflection(field, id)
|
2019-09-21 06:39:36 +00:00
|
|
|
return nil if id.blank?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2015-01-24 10:45:45 +00:00
|
|
|
@detail_value_name_by_reflection ||= Hash.new do |hash, key|
|
|
|
|
|
association = Issue.reflect_on_association(key.first.to_sym)
|
2015-02-14 08:57:22 +00:00
|
|
|
name = nil
|
2015-01-24 10:45:45 +00:00
|
|
|
if association
|
2015-01-24 10:47:21 +00:00
|
|
|
record = association.klass.find_by_id(key.last)
|
2021-03-18 07:44:42 +00:00
|
|
|
if (record && !record.is_a?(Project)) || (record.is_a?(Project) && record.visible?)
|
2015-02-14 08:57:22 +00:00
|
|
|
name = record.name.force_encoding('UTF-8')
|
2015-01-24 10:45:45 +00:00
|
|
|
end
|
2013-03-16 07:02:43 +00:00
|
|
|
end
|
2015-02-14 08:57:22 +00:00
|
|
|
hash[key] = name
|
2010-03-08 16:47:52 +00:00
|
|
|
end
|
2015-01-24 10:45:45 +00:00
|
|
|
@detail_value_name_by_reflection[[field, id]]
|
2010-03-08 16:47:52 +00:00
|
|
|
end
|
2011-05-18 02:45:59 +00:00
|
|
|
|
2010-12-04 13:02:14 +00:00
|
|
|
# Renders issue children recursively
|
|
|
|
|
def render_api_issue_children(issue, api)
|
|
|
|
|
return if issue.leaf?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2010-12-04 13:02:14 +00:00
|
|
|
api.array :children do
|
|
|
|
|
issue.children.each do |child|
|
|
|
|
|
api.issue(:id => child.id) do
|
|
|
|
|
api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
|
|
|
|
|
api.subject child.subject
|
|
|
|
|
render_api_issue_children(child, api)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-06-20 07:07:22 +00:00
|
|
|
|
|
|
|
|
# Issue history tabs
|
2019-06-20 12:15:28 +00:00
|
|
|
def issue_history_tabs
|
2019-06-20 07:07:22 +00:00
|
|
|
tabs = []
|
|
|
|
|
if @journals.present?
|
2023-02-01 07:11:25 +00:00
|
|
|
has_details = @journals.any? {|value| value.details.present?}
|
|
|
|
|
has_notes = @journals.any? {|value| value.notes.present?}
|
2020-11-30 15:48:44 +00:00
|
|
|
tabs <<
|
|
|
|
|
{
|
|
|
|
|
:name => 'history',
|
|
|
|
|
:label => :label_history,
|
|
|
|
|
:onclick => 'showIssueHistory("history", this.href)',
|
|
|
|
|
:partial => 'issues/tabs/history',
|
|
|
|
|
:locals => {:issue => @issue, :journals => @journals}
|
|
|
|
|
}
|
2023-02-01 07:11:25 +00:00
|
|
|
if has_notes
|
2020-11-30 15:48:44 +00:00
|
|
|
tabs <<
|
|
|
|
|
{
|
|
|
|
|
:name => 'notes',
|
|
|
|
|
:label => :label_issue_history_notes,
|
|
|
|
|
:onclick => 'showIssueHistory("notes", this.href)'
|
|
|
|
|
}
|
|
|
|
|
end
|
2023-02-01 07:11:25 +00:00
|
|
|
if has_details
|
2020-11-30 15:48:44 +00:00
|
|
|
tabs <<
|
|
|
|
|
{
|
|
|
|
|
:name => 'properties',
|
|
|
|
|
:label => :label_issue_history_properties,
|
|
|
|
|
:onclick => 'showIssueHistory("properties", this.href)'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if User.current.allowed_to?(:view_time_entries, @project) && @issue.spent_hours > 0
|
|
|
|
|
tabs <<
|
|
|
|
|
{
|
|
|
|
|
:name => 'time_entries',
|
|
|
|
|
:label => :label_time_entry_plural,
|
|
|
|
|
:remote => true,
|
|
|
|
|
:onclick =>
|
|
|
|
|
"getRemoteTab('time_entries', " \
|
|
|
|
|
"'#{tab_issue_path(@issue, :name => 'time_entries')}', " \
|
|
|
|
|
"'#{issue_path(@issue, :tab => 'time_entries')}')"
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
if @has_changesets
|
|
|
|
|
tabs <<
|
|
|
|
|
{
|
|
|
|
|
:name => 'changesets',
|
|
|
|
|
:label => :label_associated_revisions,
|
|
|
|
|
:remote => true,
|
|
|
|
|
:onclick =>
|
|
|
|
|
"getRemoteTab('changesets', " \
|
|
|
|
|
"'#{tab_issue_path(@issue, :name => 'changesets')}', " \
|
|
|
|
|
"'#{issue_path(@issue, :tab => 'changesets')}')"
|
|
|
|
|
}
|
2019-06-20 07:07:22 +00:00
|
|
|
end
|
|
|
|
|
tabs
|
|
|
|
|
end
|
2019-06-20 07:12:30 +00:00
|
|
|
|
2019-06-20 07:13:54 +00:00
|
|
|
def issue_history_default_tab
|
|
|
|
|
# tab params overrides user default tab preference
|
|
|
|
|
return params[:tab] if params[:tab].present?
|
2020-07-19 14:06:01 +00:00
|
|
|
|
2019-06-20 07:13:54 +00:00
|
|
|
user_default_tab = User.current.pref.history_default_tab
|
|
|
|
|
|
|
|
|
|
case user_default_tab
|
|
|
|
|
when 'last_tab_visited'
|
2019-06-20 12:23:04 +00:00
|
|
|
cookies['history_last_tab'].presence || 'notes'
|
2019-06-20 07:13:54 +00:00
|
|
|
when ''
|
|
|
|
|
'notes'
|
|
|
|
|
else
|
|
|
|
|
user_default_tab
|
|
|
|
|
end
|
|
|
|
|
end
|
2021-01-01 00:59:07 +00:00
|
|
|
|
|
|
|
|
def projects_for_select(issue)
|
2022-10-31 09:04:46 +00:00
|
|
|
projects =
|
|
|
|
|
if issue.parent_issue_id.present?
|
|
|
|
|
issue.allowed_target_projects_for_subtask(User.current)
|
|
|
|
|
elsif @project && issue.new_record? && !issue.copy?
|
|
|
|
|
issue.allowed_target_projects(User.current, 'tree')
|
|
|
|
|
else
|
|
|
|
|
issue.allowed_target_projects(User.current)
|
|
|
|
|
end
|
|
|
|
|
if issue.read_only_attribute_names(User.current).include?('project_id')
|
|
|
|
|
params['project_id'].present? ? Project.where(identifier: params['project_id']) : projects
|
2021-01-01 00:59:07 +00:00
|
|
|
else
|
2022-10-31 09:04:46 +00:00
|
|
|
projects
|
2021-01-01 00:59:07 +00:00
|
|
|
end
|
|
|
|
|
end
|
2006-06-28 18:11:03 +00:00
|
|
|
end
|