##// END OF EJS Templates
Extracts the rendering of related issues to an helper (#3425)....
Jean-Philippe Lang -
r15599:17233e868110
parent child
Show More
@@ -1,90 +1,92
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class IssueRelationsController < ApplicationController
18 class IssueRelationsController < ApplicationController
19 helper :issues
20
19 before_action :find_issue, :authorize, :only => [:index, :create]
21 before_action :find_issue, :authorize, :only => [:index, :create]
20 before_action :find_relation, :only => [:show, :destroy]
22 before_action :find_relation, :only => [:show, :destroy]
21
23
22 accept_api_auth :index, :show, :create, :destroy
24 accept_api_auth :index, :show, :create, :destroy
23
25
24 def index
26 def index
25 @relations = @issue.relations
27 @relations = @issue.relations
26
28
27 respond_to do |format|
29 respond_to do |format|
28 format.html { head 200 }
30 format.html { head 200 }
29 format.api
31 format.api
30 end
32 end
31 end
33 end
32
34
33 def show
35 def show
34 raise Unauthorized unless @relation.visible?
36 raise Unauthorized unless @relation.visible?
35
37
36 respond_to do |format|
38 respond_to do |format|
37 format.html { head 200 }
39 format.html { head 200 }
38 format.api
40 format.api
39 end
41 end
40 end
42 end
41
43
42 def create
44 def create
43 @relation = IssueRelation.new
45 @relation = IssueRelation.new
44 @relation.issue_from = @issue
46 @relation.issue_from = @issue
45 @relation.safe_attributes = params[:relation]
47 @relation.safe_attributes = params[:relation]
46 @relation.init_journals(User.current)
48 @relation.init_journals(User.current)
47 saved = @relation.save
49 saved = @relation.save
48
50
49 respond_to do |format|
51 respond_to do |format|
50 format.html { redirect_to issue_path(@issue) }
52 format.html { redirect_to issue_path(@issue) }
51 format.js {
53 format.js {
52 @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
54 @relations = @issue.reload.relations.select {|r| r.other_issue(@issue) && r.other_issue(@issue).visible? }
53 }
55 }
54 format.api {
56 format.api {
55 if saved
57 if saved
56 render :action => 'show', :status => :created, :location => relation_url(@relation)
58 render :action => 'show', :status => :created, :location => relation_url(@relation)
57 else
59 else
58 render_validation_errors(@relation)
60 render_validation_errors(@relation)
59 end
61 end
60 }
62 }
61 end
63 end
62 end
64 end
63
65
64 def destroy
66 def destroy
65 raise Unauthorized unless @relation.deletable?
67 raise Unauthorized unless @relation.deletable?
66 @relation.init_journals(User.current)
68 @relation.init_journals(User.current)
67 @relation.destroy
69 @relation.destroy
68
70
69 respond_to do |format|
71 respond_to do |format|
70 format.html { redirect_to issue_path(@relation.issue_from) }
72 format.html { redirect_to issue_path(@relation.issue_from) }
71 format.js
73 format.js
72 format.api { render_api_ok }
74 format.api { render_api_ok }
73 end
75 end
74 end
76 end
75
77
76 private
78 private
77
79
78 def find_issue
80 def find_issue
79 @issue = Issue.find(params[:issue_id])
81 @issue = Issue.find(params[:issue_id])
80 @project = @issue.project
82 @project = @issue.project
81 rescue ActiveRecord::RecordNotFound
83 rescue ActiveRecord::RecordNotFound
82 render_404
84 render_404
83 end
85 end
84
86
85 def find_relation
87 def find_relation
86 @relation = IssueRelation.find(params[:id])
88 @relation = IssueRelation.find(params[:id])
87 rescue ActiveRecord::RecordNotFound
89 rescue ActiveRecord::RecordNotFound
88 render_404
90 render_404
89 end
91 end
90 end
92 end
@@ -1,484 +1,515
1 # encoding: utf-8
1 # encoding: utf-8
2 #
2 #
3 # Redmine - project management software
3 # Redmine - project management software
4 # Copyright (C) 2006-2016 Jean-Philippe Lang
4 # Copyright (C) 2006-2016 Jean-Philippe Lang
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
9 # of the License, or (at your option) any later version.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
19
20 module IssuesHelper
20 module IssuesHelper
21 include ApplicationHelper
21 include ApplicationHelper
22 include Redmine::Export::PDF::IssuesPdfHelper
22 include Redmine::Export::PDF::IssuesPdfHelper
23
23
24 def issue_list(issues, &block)
24 def issue_list(issues, &block)
25 ancestors = []
25 ancestors = []
26 issues.each do |issue|
26 issues.each do |issue|
27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
27 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
28 ancestors.pop
28 ancestors.pop
29 end
29 end
30 yield issue, ancestors.size
30 yield issue, ancestors.size
31 ancestors << issue unless issue.leaf?
31 ancestors << issue unless issue.leaf?
32 end
32 end
33 end
33 end
34
34
35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
35 def grouped_issue_list(issues, query, issue_count_by_group, &block)
36 ancestors = []
36 ancestors = []
37 grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals|
37 grouped_query_results(issues, query, issue_count_by_group) do |issue, group_name, group_count, group_totals|
38 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
38 while (ancestors.any? && !issue.is_descendant_of?(ancestors.last))
39 ancestors.pop
39 ancestors.pop
40 end
40 end
41 yield issue, ancestors.size, group_name, group_count, group_totals
41 yield issue, ancestors.size, group_name, group_count, group_totals
42 ancestors << issue unless issue.leaf?
42 ancestors << issue unless issue.leaf?
43 end
43 end
44 end
44 end
45
45
46 # Renders a HTML/CSS tooltip
46 # Renders a HTML/CSS tooltip
47 #
47 #
48 # To use, a trigger div is needed. This is a div with the class of "tooltip"
48 # To use, a trigger div is needed. This is a div with the class of "tooltip"
49 # that contains this method wrapped in a span with the class of "tip"
49 # that contains this method wrapped in a span with the class of "tip"
50 #
50 #
51 # <div class="tooltip"><%= link_to_issue(issue) %>
51 # <div class="tooltip"><%= link_to_issue(issue) %>
52 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
52 # <span class="tip"><%= render_issue_tooltip(issue) %></span>
53 # </div>
53 # </div>
54 #
54 #
55 def render_issue_tooltip(issue)
55 def render_issue_tooltip(issue)
56 @cached_label_status ||= l(:field_status)
56 @cached_label_status ||= l(:field_status)
57 @cached_label_start_date ||= l(:field_start_date)
57 @cached_label_start_date ||= l(:field_start_date)
58 @cached_label_due_date ||= l(:field_due_date)
58 @cached_label_due_date ||= l(:field_due_date)
59 @cached_label_assigned_to ||= l(:field_assigned_to)
59 @cached_label_assigned_to ||= l(:field_assigned_to)
60 @cached_label_priority ||= l(:field_priority)
60 @cached_label_priority ||= l(:field_priority)
61 @cached_label_project ||= l(:field_project)
61 @cached_label_project ||= l(:field_project)
62
62
63 link_to_issue(issue) + "<br /><br />".html_safe +
63 link_to_issue(issue) + "<br /><br />".html_safe +
64 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
64 "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />".html_safe +
65 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
65 "<strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />".html_safe +
66 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
66 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />".html_safe +
67 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
67 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />".html_safe +
68 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
68 "<strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />".html_safe +
69 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
69 "<strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe
70 end
70 end
71
71
72 def issue_heading(issue)
72 def issue_heading(issue)
73 h("#{issue.tracker} ##{issue.id}")
73 h("#{issue.tracker} ##{issue.id}")
74 end
74 end
75
75
76 def render_issue_subject_with_tree(issue)
76 def render_issue_subject_with_tree(issue)
77 s = ''
77 s = ''
78 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
78 ancestors = issue.root? ? [] : issue.ancestors.visible.to_a
79 ancestors.each do |ancestor|
79 ancestors.each do |ancestor|
80 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
80 s << '<div>' + content_tag('p', link_to_issue(ancestor, :project => (issue.project_id != ancestor.project_id)))
81 end
81 end
82 s << '<div>'
82 s << '<div>'
83 subject = h(issue.subject)
83 subject = h(issue.subject)
84 if issue.is_private?
84 if issue.is_private?
85 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
85 subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
86 end
86 end
87 s << content_tag('h3', subject)
87 s << content_tag('h3', subject)
88 s << '</div>' * (ancestors.size + 1)
88 s << '</div>' * (ancestors.size + 1)
89 s.html_safe
89 s.html_safe
90 end
90 end
91
91
92 def render_descendants_tree(issue)
92 def render_descendants_tree(issue)
93 s = '<table class="list issues">'
93 s = '<table class="list issues">'
94 issue_list(issue.descendants.visible.preload(:status, :priority, :tracker, :assigned_to).sort_by(&:lft)) do |child, level|
94 issue_list(issue.descendants.visible.preload(:status, :priority, :tracker, :assigned_to).sort_by(&:lft)) do |child, level|
95 css = "issue issue-#{child.id} hascontextmenu #{child.css_classes}"
95 css = "issue issue-#{child.id} hascontextmenu #{child.css_classes}"
96 css << " idnt idnt-#{level}" if level > 0
96 css << " idnt idnt-#{level}" if level > 0
97 s << content_tag('tr',
97 s << content_tag('tr',
98 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
98 content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
99 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
99 content_tag('td', link_to_issue(child, :project => (issue.project_id != child.project_id)), :class => 'subject', :style => 'width: 50%') +
100 content_tag('td', h(child.status), :class => 'status') +
100 content_tag('td', h(child.status), :class => 'status') +
101 content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
101 content_tag('td', link_to_user(child.assigned_to), :class => 'assigned_to') +
102 content_tag('td', child.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(child.done_ratio), :class=> 'done_ratio'),
102 content_tag('td', child.disabled_core_fields.include?('done_ratio') ? '' : progress_bar(child.done_ratio), :class=> 'done_ratio'),
103 :class => css)
103 :class => css)
104 end
104 end
105 s << '</table>'
105 s << '</table>'
106 s.html_safe
106 s.html_safe
107 end
107 end
108
108
109 # Renders the list of related issues on the issue details view
110 def render_issue_relations(issue, relations)
111 manage_relations = User.current.allowed_to?(:manage_issue_relations, issue.project)
112
113 s = ''.html_safe
114 relations.each do |relation|
115 other_issue = relation.other_issue(issue)
116 css = "issue hascontextmenu #{other_issue.css_classes}"
117 link = manage_relations ? link_to(l(:label_relation_delete),
118 relation_path(relation),
119 :remote => true,
120 :method => :delete,
121 :data => {:confirm => l(:text_are_you_sure)},
122 :title => l(:label_relation_delete),
123 :class => 'icon-only icon-link-break'
124 ) : nil
125
126 s << content_tag('tr',
127 content_tag('td', check_box_tag("ids[]", other_issue.id, false, :id => nil), :class => 'checkbox') +
128 content_tag('td', relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe, :class => 'subject', :style => 'width: 50%') +
129 content_tag('td', other_issue.status, :class => 'status') +
130 content_tag('td', other_issue.start_date, :class => 'start_date') +
131 content_tag('td', other_issue.due_date, :class => 'due_date') +
132 content_tag('td', link, :class => 'buttons'),
133 :id => "relation-#{relation.id}",
134 :class => css)
135 end
136
137 content_tag('table', s, :class => 'list issues')
138 end
139
109 def issue_estimated_hours_details(issue)
140 def issue_estimated_hours_details(issue)
110 if issue.total_estimated_hours.present?
141 if issue.total_estimated_hours.present?
111 if issue.total_estimated_hours == issue.estimated_hours
142 if issue.total_estimated_hours == issue.estimated_hours
112 l_hours_short(issue.estimated_hours)
143 l_hours_short(issue.estimated_hours)
113 else
144 else
114 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
145 s = issue.estimated_hours.present? ? l_hours_short(issue.estimated_hours) : ""
115 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
146 s << " (#{l(:label_total)}: #{l_hours_short(issue.total_estimated_hours)})"
116 s.html_safe
147 s.html_safe
117 end
148 end
118 end
149 end
119 end
150 end
120
151
121 def issue_spent_hours_details(issue)
152 def issue_spent_hours_details(issue)
122 if issue.total_spent_hours > 0
153 if issue.total_spent_hours > 0
123 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
154 path = project_time_entries_path(issue.project, :issue_id => "~#{issue.id}")
124
155
125 if issue.total_spent_hours == issue.spent_hours
156 if issue.total_spent_hours == issue.spent_hours
126 link_to(l_hours_short(issue.spent_hours), path)
157 link_to(l_hours_short(issue.spent_hours), path)
127 else
158 else
128 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
159 s = issue.spent_hours > 0 ? l_hours_short(issue.spent_hours) : ""
129 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
160 s << " (#{l(:label_total)}: #{link_to l_hours_short(issue.total_spent_hours), path})"
130 s.html_safe
161 s.html_safe
131 end
162 end
132 end
163 end
133 end
164 end
134
165
135 # Returns an array of error messages for bulk edited issues
166 # Returns an array of error messages for bulk edited issues
136 def bulk_edit_error_messages(issues)
167 def bulk_edit_error_messages(issues)
137 messages = {}
168 messages = {}
138 issues.each do |issue|
169 issues.each do |issue|
139 issue.errors.full_messages.each do |message|
170 issue.errors.full_messages.each do |message|
140 messages[message] ||= []
171 messages[message] ||= []
141 messages[message] << issue
172 messages[message] << issue
142 end
173 end
143 end
174 end
144 messages.map { |message, issues|
175 messages.map { |message, issues|
145 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
176 "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ')
146 }
177 }
147 end
178 end
148
179
149 # Returns a link for adding a new subtask to the given issue
180 # Returns a link for adding a new subtask to the given issue
150 def link_to_new_subtask(issue)
181 def link_to_new_subtask(issue)
151 attrs = {
182 attrs = {
152 :parent_issue_id => issue
183 :parent_issue_id => issue
153 }
184 }
154 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
185 attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
155 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
186 link_to(l(:button_add), new_project_issue_path(issue.project, :issue => attrs))
156 end
187 end
157
188
158 def trackers_options_for_select(issue)
189 def trackers_options_for_select(issue)
159 trackers = issue.allowed_target_trackers
190 trackers = issue.allowed_target_trackers
160 if issue.new_record? && issue.parent_issue_id.present?
191 if issue.new_record? && issue.parent_issue_id.present?
161 trackers = trackers.reject do |tracker|
192 trackers = trackers.reject do |tracker|
162 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
193 issue.tracker_id != tracker.id && tracker.disabled_core_fields.include?('parent_issue_id')
163 end
194 end
164 end
195 end
165 trackers.collect {|t| [t.name, t.id]}
196 trackers.collect {|t| [t.name, t.id]}
166 end
197 end
167
198
168 class IssueFieldsRows
199 class IssueFieldsRows
169 include ActionView::Helpers::TagHelper
200 include ActionView::Helpers::TagHelper
170
201
171 def initialize
202 def initialize
172 @left = []
203 @left = []
173 @right = []
204 @right = []
174 end
205 end
175
206
176 def left(*args)
207 def left(*args)
177 args.any? ? @left << cells(*args) : @left
208 args.any? ? @left << cells(*args) : @left
178 end
209 end
179
210
180 def right(*args)
211 def right(*args)
181 args.any? ? @right << cells(*args) : @right
212 args.any? ? @right << cells(*args) : @right
182 end
213 end
183
214
184 def size
215 def size
185 @left.size > @right.size ? @left.size : @right.size
216 @left.size > @right.size ? @left.size : @right.size
186 end
217 end
187
218
188 def to_html
219 def to_html
189 content =
220 content =
190 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
221 content_tag('div', @left.reduce(&:+), :class => 'splitcontentleft') +
191 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
222 content_tag('div', @right.reduce(&:+), :class => 'splitcontentleft')
192
223
193 content_tag('div', content, :class => 'splitcontent')
224 content_tag('div', content, :class => 'splitcontent')
194 end
225 end
195
226
196 def cells(label, text, options={})
227 def cells(label, text, options={})
197 options[:class] = [options[:class] || "", 'attribute'].join(' ')
228 options[:class] = [options[:class] || "", 'attribute'].join(' ')
198 content_tag 'div',
229 content_tag 'div',
199 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
230 content_tag('div', label + ":", :class => 'label') + content_tag('div', text, :class => 'value'),
200 options
231 options
201 end
232 end
202 end
233 end
203
234
204 def issue_fields_rows
235 def issue_fields_rows
205 r = IssueFieldsRows.new
236 r = IssueFieldsRows.new
206 yield r
237 yield r
207 r.to_html
238 r.to_html
208 end
239 end
209
240
210 def render_custom_fields_rows(issue)
241 def render_custom_fields_rows(issue)
211 values = issue.visible_custom_field_values
242 values = issue.visible_custom_field_values
212 return if values.empty?
243 return if values.empty?
213 half = (values.size / 2.0).ceil
244 half = (values.size / 2.0).ceil
214 issue_fields_rows do |rows|
245 issue_fields_rows do |rows|
215 values.each_with_index do |value, i|
246 values.each_with_index do |value, i|
216 css = "cf_#{value.custom_field.id}"
247 css = "cf_#{value.custom_field.id}"
217 m = (i < half ? :left : :right)
248 m = (i < half ? :left : :right)
218 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
249 rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
219 end
250 end
220 end
251 end
221 end
252 end
222
253
223 # Returns the path for updating the issue form
254 # Returns the path for updating the issue form
224 # with project as the current project
255 # with project as the current project
225 def update_issue_form_path(project, issue)
256 def update_issue_form_path(project, issue)
226 options = {:format => 'js'}
257 options = {:format => 'js'}
227 if issue.new_record?
258 if issue.new_record?
228 if project
259 if project
229 new_project_issue_path(project, options)
260 new_project_issue_path(project, options)
230 else
261 else
231 new_issue_path(options)
262 new_issue_path(options)
232 end
263 end
233 else
264 else
234 edit_issue_path(issue, options)
265 edit_issue_path(issue, options)
235 end
266 end
236 end
267 end
237
268
238 # Returns the number of descendants for an array of issues
269 # Returns the number of descendants for an array of issues
239 def issues_descendant_count(issues)
270 def issues_descendant_count(issues)
240 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
271 ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq
241 ids -= issues.map(&:id)
272 ids -= issues.map(&:id)
242 ids.size
273 ids.size
243 end
274 end
244
275
245 def issues_destroy_confirmation_message(issues)
276 def issues_destroy_confirmation_message(issues)
246 issues = [issues] unless issues.is_a?(Array)
277 issues = [issues] unless issues.is_a?(Array)
247 message = l(:text_issues_destroy_confirmation)
278 message = l(:text_issues_destroy_confirmation)
248
279
249 descendant_count = issues_descendant_count(issues)
280 descendant_count = issues_descendant_count(issues)
250 if descendant_count > 0
281 if descendant_count > 0
251 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
282 message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count)
252 end
283 end
253 message
284 message
254 end
285 end
255
286
256 # Returns an array of users that are proposed as watchers
287 # Returns an array of users that are proposed as watchers
257 # on the new issue form
288 # on the new issue form
258 def users_for_new_issue_watchers(issue)
289 def users_for_new_issue_watchers(issue)
259 users = issue.watcher_users
290 users = issue.watcher_users
260 if issue.project.users.count <= 20
291 if issue.project.users.count <= 20
261 users = (users + issue.project.users.sort).uniq
292 users = (users + issue.project.users.sort).uniq
262 end
293 end
263 users
294 users
264 end
295 end
265
296
266 def email_issue_attributes(issue, user)
297 def email_issue_attributes(issue, user)
267 items = []
298 items = []
268 %w(author status priority assigned_to category fixed_version).each do |attribute|
299 %w(author status priority assigned_to category fixed_version).each do |attribute|
269 unless issue.disabled_core_fields.include?(attribute+"_id")
300 unless issue.disabled_core_fields.include?(attribute+"_id")
270 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
301 items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
271 end
302 end
272 end
303 end
273 issue.visible_custom_field_values(user).each do |value|
304 issue.visible_custom_field_values(user).each do |value|
274 items << "#{value.custom_field.name}: #{show_value(value, false)}"
305 items << "#{value.custom_field.name}: #{show_value(value, false)}"
275 end
306 end
276 items
307 items
277 end
308 end
278
309
279 def render_email_issue_attributes(issue, user, html=false)
310 def render_email_issue_attributes(issue, user, html=false)
280 items = email_issue_attributes(issue, user)
311 items = email_issue_attributes(issue, user)
281 if html
312 if html
282 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
313 content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe)
283 else
314 else
284 items.map{|s| "* #{s}"}.join("\n")
315 items.map{|s| "* #{s}"}.join("\n")
285 end
316 end
286 end
317 end
287
318
288 # Returns the textual representation of a journal details
319 # Returns the textual representation of a journal details
289 # as an array of strings
320 # as an array of strings
290 def details_to_strings(details, no_html=false, options={})
321 def details_to_strings(details, no_html=false, options={})
291 options[:only_path] = (options[:only_path] == false ? false : true)
322 options[:only_path] = (options[:only_path] == false ? false : true)
292 strings = []
323 strings = []
293 values_by_field = {}
324 values_by_field = {}
294 details.each do |detail|
325 details.each do |detail|
295 if detail.property == 'cf'
326 if detail.property == 'cf'
296 field = detail.custom_field
327 field = detail.custom_field
297 if field && field.multiple?
328 if field && field.multiple?
298 values_by_field[field] ||= {:added => [], :deleted => []}
329 values_by_field[field] ||= {:added => [], :deleted => []}
299 if detail.old_value
330 if detail.old_value
300 values_by_field[field][:deleted] << detail.old_value
331 values_by_field[field][:deleted] << detail.old_value
301 end
332 end
302 if detail.value
333 if detail.value
303 values_by_field[field][:added] << detail.value
334 values_by_field[field][:added] << detail.value
304 end
335 end
305 next
336 next
306 end
337 end
307 end
338 end
308 strings << show_detail(detail, no_html, options)
339 strings << show_detail(detail, no_html, options)
309 end
340 end
310 if values_by_field.present?
341 if values_by_field.present?
311 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
342 multiple_values_detail = Struct.new(:property, :prop_key, :custom_field, :old_value, :value)
312 values_by_field.each do |field, changes|
343 values_by_field.each do |field, changes|
313 if changes[:added].any?
344 if changes[:added].any?
314 detail = multiple_values_detail.new('cf', field.id.to_s, field)
345 detail = multiple_values_detail.new('cf', field.id.to_s, field)
315 detail.value = changes[:added]
346 detail.value = changes[:added]
316 strings << show_detail(detail, no_html, options)
347 strings << show_detail(detail, no_html, options)
317 end
348 end
318 if changes[:deleted].any?
349 if changes[:deleted].any?
319 detail = multiple_values_detail.new('cf', field.id.to_s, field)
350 detail = multiple_values_detail.new('cf', field.id.to_s, field)
320 detail.old_value = changes[:deleted]
351 detail.old_value = changes[:deleted]
321 strings << show_detail(detail, no_html, options)
352 strings << show_detail(detail, no_html, options)
322 end
353 end
323 end
354 end
324 end
355 end
325 strings
356 strings
326 end
357 end
327
358
328 # Returns the textual representation of a single journal detail
359 # Returns the textual representation of a single journal detail
329 def show_detail(detail, no_html=false, options={})
360 def show_detail(detail, no_html=false, options={})
330 multiple = false
361 multiple = false
331 show_diff = false
362 show_diff = false
332 no_details = false
363 no_details = false
333
364
334 case detail.property
365 case detail.property
335 when 'attr'
366 when 'attr'
336 field = detail.prop_key.to_s.gsub(/\_id$/, "")
367 field = detail.prop_key.to_s.gsub(/\_id$/, "")
337 label = l(("field_" + field).to_sym)
368 label = l(("field_" + field).to_sym)
338 case detail.prop_key
369 case detail.prop_key
339 when 'due_date', 'start_date'
370 when 'due_date', 'start_date'
340 value = format_date(detail.value.to_date) if detail.value
371 value = format_date(detail.value.to_date) if detail.value
341 old_value = format_date(detail.old_value.to_date) if detail.old_value
372 old_value = format_date(detail.old_value.to_date) if detail.old_value
342
373
343 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
374 when 'project_id', 'status_id', 'tracker_id', 'assigned_to_id',
344 'priority_id', 'category_id', 'fixed_version_id'
375 'priority_id', 'category_id', 'fixed_version_id'
345 value = find_name_by_reflection(field, detail.value)
376 value = find_name_by_reflection(field, detail.value)
346 old_value = find_name_by_reflection(field, detail.old_value)
377 old_value = find_name_by_reflection(field, detail.old_value)
347
378
348 when 'estimated_hours'
379 when 'estimated_hours'
349 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
380 value = l_hours_short(detail.value.to_f) unless detail.value.blank?
350 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
381 old_value = l_hours_short(detail.old_value.to_f) unless detail.old_value.blank?
351
382
352 when 'parent_id'
383 when 'parent_id'
353 label = l(:field_parent_issue)
384 label = l(:field_parent_issue)
354 value = "##{detail.value}" unless detail.value.blank?
385 value = "##{detail.value}" unless detail.value.blank?
355 old_value = "##{detail.old_value}" unless detail.old_value.blank?
386 old_value = "##{detail.old_value}" unless detail.old_value.blank?
356
387
357 when 'is_private'
388 when 'is_private'
358 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
389 value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank?
359 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
390 old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank?
360
391
361 when 'description'
392 when 'description'
362 show_diff = true
393 show_diff = true
363 end
394 end
364 when 'cf'
395 when 'cf'
365 custom_field = detail.custom_field
396 custom_field = detail.custom_field
366 if custom_field
397 if custom_field
367 label = custom_field.name
398 label = custom_field.name
368 if custom_field.format.class.change_no_details
399 if custom_field.format.class.change_no_details
369 no_details = true
400 no_details = true
370 elsif custom_field.format.class.change_as_diff
401 elsif custom_field.format.class.change_as_diff
371 show_diff = true
402 show_diff = true
372 else
403 else
373 multiple = custom_field.multiple?
404 multiple = custom_field.multiple?
374 value = format_value(detail.value, custom_field) if detail.value
405 value = format_value(detail.value, custom_field) if detail.value
375 old_value = format_value(detail.old_value, custom_field) if detail.old_value
406 old_value = format_value(detail.old_value, custom_field) if detail.old_value
376 end
407 end
377 end
408 end
378 when 'attachment'
409 when 'attachment'
379 label = l(:label_attachment)
410 label = l(:label_attachment)
380 when 'relation'
411 when 'relation'
381 if detail.value && !detail.old_value
412 if detail.value && !detail.old_value
382 rel_issue = Issue.visible.find_by_id(detail.value)
413 rel_issue = Issue.visible.find_by_id(detail.value)
383 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
414 value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.value}" :
384 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
415 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
385 elsif detail.old_value && !detail.value
416 elsif detail.old_value && !detail.value
386 rel_issue = Issue.visible.find_by_id(detail.old_value)
417 rel_issue = Issue.visible.find_by_id(detail.old_value)
387 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
418 old_value = rel_issue.nil? ? "#{l(:label_issue)} ##{detail.old_value}" :
388 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
419 (no_html ? rel_issue : link_to_issue(rel_issue, :only_path => options[:only_path]))
389 end
420 end
390 relation_type = IssueRelation::TYPES[detail.prop_key]
421 relation_type = IssueRelation::TYPES[detail.prop_key]
391 label = l(relation_type[:name]) if relation_type
422 label = l(relation_type[:name]) if relation_type
392 end
423 end
393 call_hook(:helper_issues_show_detail_after_setting,
424 call_hook(:helper_issues_show_detail_after_setting,
394 {:detail => detail, :label => label, :value => value, :old_value => old_value })
425 {:detail => detail, :label => label, :value => value, :old_value => old_value })
395
426
396 label ||= detail.prop_key
427 label ||= detail.prop_key
397 value ||= detail.value
428 value ||= detail.value
398 old_value ||= detail.old_value
429 old_value ||= detail.old_value
399
430
400 unless no_html
431 unless no_html
401 label = content_tag('strong', label)
432 label = content_tag('strong', label)
402 old_value = content_tag("i", h(old_value)) if detail.old_value
433 old_value = content_tag("i", h(old_value)) if detail.old_value
403 if detail.old_value && detail.value.blank? && detail.property != 'relation'
434 if detail.old_value && detail.value.blank? && detail.property != 'relation'
404 old_value = content_tag("del", old_value)
435 old_value = content_tag("del", old_value)
405 end
436 end
406 if detail.property == 'attachment' && value.present? &&
437 if detail.property == 'attachment' && value.present? &&
407 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
438 atta = detail.journal.journalized.attachments.detect {|a| a.id == detail.prop_key.to_i}
408 # Link to the attachment if it has not been removed
439 # Link to the attachment if it has not been removed
409 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
440 value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
410 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
441 if options[:only_path] != false && (atta.is_text? || atta.is_image?)
411 value += ' '
442 value += ' '
412 value += link_to(l(:button_view),
443 value += link_to(l(:button_view),
413 { :controller => 'attachments', :action => 'show',
444 { :controller => 'attachments', :action => 'show',
414 :id => atta, :filename => atta.filename },
445 :id => atta, :filename => atta.filename },
415 :class => 'icon-only icon-magnifier',
446 :class => 'icon-only icon-magnifier',
416 :title => l(:button_view))
447 :title => l(:button_view))
417 end
448 end
418 else
449 else
419 value = content_tag("i", h(value)) if value
450 value = content_tag("i", h(value)) if value
420 end
451 end
421 end
452 end
422
453
423 if no_details
454 if no_details
424 s = l(:text_journal_changed_no_detail, :label => label).html_safe
455 s = l(:text_journal_changed_no_detail, :label => label).html_safe
425 elsif show_diff
456 elsif show_diff
426 s = l(:text_journal_changed_no_detail, :label => label)
457 s = l(:text_journal_changed_no_detail, :label => label)
427 unless no_html
458 unless no_html
428 diff_link = link_to 'diff',
459 diff_link = link_to 'diff',
429 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
460 diff_journal_url(detail.journal_id, :detail_id => detail.id, :only_path => options[:only_path]),
430 :title => l(:label_view_diff)
461 :title => l(:label_view_diff)
431 s << " (#{ diff_link })"
462 s << " (#{ diff_link })"
432 end
463 end
433 s.html_safe
464 s.html_safe
434 elsif detail.value.present?
465 elsif detail.value.present?
435 case detail.property
466 case detail.property
436 when 'attr', 'cf'
467 when 'attr', 'cf'
437 if detail.old_value.present?
468 if detail.old_value.present?
438 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
469 l(:text_journal_changed, :label => label, :old => old_value, :new => value).html_safe
439 elsif multiple
470 elsif multiple
440 l(:text_journal_added, :label => label, :value => value).html_safe
471 l(:text_journal_added, :label => label, :value => value).html_safe
441 else
472 else
442 l(:text_journal_set_to, :label => label, :value => value).html_safe
473 l(:text_journal_set_to, :label => label, :value => value).html_safe
443 end
474 end
444 when 'attachment', 'relation'
475 when 'attachment', 'relation'
445 l(:text_journal_added, :label => label, :value => value).html_safe
476 l(:text_journal_added, :label => label, :value => value).html_safe
446 end
477 end
447 else
478 else
448 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
479 l(:text_journal_deleted, :label => label, :old => old_value).html_safe
449 end
480 end
450 end
481 end
451
482
452 # Find the name of an associated record stored in the field attribute
483 # Find the name of an associated record stored in the field attribute
453 def find_name_by_reflection(field, id)
484 def find_name_by_reflection(field, id)
454 unless id.present?
485 unless id.present?
455 return nil
486 return nil
456 end
487 end
457 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
488 @detail_value_name_by_reflection ||= Hash.new do |hash, key|
458 association = Issue.reflect_on_association(key.first.to_sym)
489 association = Issue.reflect_on_association(key.first.to_sym)
459 name = nil
490 name = nil
460 if association
491 if association
461 record = association.klass.find_by_id(key.last)
492 record = association.klass.find_by_id(key.last)
462 if record
493 if record
463 name = record.name.force_encoding('UTF-8')
494 name = record.name.force_encoding('UTF-8')
464 end
495 end
465 end
496 end
466 hash[key] = name
497 hash[key] = name
467 end
498 end
468 @detail_value_name_by_reflection[[field, id]]
499 @detail_value_name_by_reflection[[field, id]]
469 end
500 end
470
501
471 # Renders issue children recursively
502 # Renders issue children recursively
472 def render_api_issue_children(issue, api)
503 def render_api_issue_children(issue, api)
473 return if issue.leaf?
504 return if issue.leaf?
474 api.array :children do
505 api.array :children do
475 issue.children.each do |child|
506 issue.children.each do |child|
476 api.issue(:id => child.id) do
507 api.issue(:id => child.id) do
477 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
508 api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil?
478 api.subject child.subject
509 api.subject child.subject
479 render_api_issue_children(child, api)
510 render_api_issue_children(child, api)
480 end
511 end
481 end
512 end
482 end
513 end
483 end
514 end
484 end
515 end
@@ -1,43 +1,22
1 <div class="contextual">
1 <div class="contextual">
2 <% if User.current.allowed_to?(:manage_issue_relations, @project) %>
2 <% if User.current.allowed_to?(:manage_issue_relations, @project) %>
3 <%= toggle_link l(:button_add), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>
3 <%= toggle_link l(:button_add), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>
4 <% end %>
4 <% end %>
5 </div>
5 </div>
6
6
7 <p><strong><%=l(:label_related_issues)%></strong></p>
7 <p><strong><%=l(:label_related_issues)%></strong></p>
8
8
9 <% if @relations.present? %>
9 <% if @relations.present? %>
10 <%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
10 <%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do %>
11 <table class="list issues">
11 <%= render_issue_relations(@issue, @relations) %>
12 <% @relations.each do |relation| %>
13 <% other_issue = relation.other_issue(@issue) -%>
14 <tr class="issue hascontextmenu <%= other_issue.css_classes %>" id="relation-<%= relation.id %>">
15 <td class="checkbox"><%= check_box_tag("ids[]", other_issue.id, false, :id => nil) %></td>
16 <td class="subject" style="width: 50%">
17 <%= relation.to_s(@issue) {|other| link_to_issue(other, :project => Setting.cross_project_issue_relations?)}.html_safe %>
18 </td>
19 <td class="status"><%= other_issue.status.name %></td>
20 <td class="start_date"><%= format_date(other_issue.start_date) %></td>
21 <td class="due_date"><%= format_date(other_issue.due_date) %></td>
22 <td class="buttons"><%= link_to(l(:label_relation_delete),
23 relation_path(relation),
24 :remote => true,
25 :method => :delete,
26 :data => {:confirm => l(:text_are_you_sure)},
27 :title => l(:label_relation_delete),
28 :class => 'icon-only icon-link-break'
29 ) if User.current.allowed_to?(:manage_issue_relations, @project) %></td>
30 </tr>
31 <% end %>
32 </table>
33 <% end %>
12 <% end %>
34 <% end %>
13 <% end %>
35
14
36 <%= form_for @relation, {
15 <%= form_for @relation, {
37 :as => :relation, :remote => true,
16 :as => :relation, :remote => true,
38 :url => issue_relations_path(@issue),
17 :url => issue_relations_path(@issue),
39 :method => :post,
18 :method => :post,
40 :html => {:id => 'new-relation-form', :style => 'display: none;'}
19 :html => {:id => 'new-relation-form', :style => 'display: none;'}
41 } do |f| %>
20 } do |f| %>
42 <%= render :partial => 'issue_relations/form', :locals => {:f => f}%>
21 <%= render :partial => 'issue_relations/form', :locals => {:f => f}%>
43 <% end %>
22 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now