##// END OF EJS Templates
Refactor: Extract similar logic in IssuesHelper#show_detail to a new method....
Eric Davis -
r3439:43e3c43cbdcf
parent child
Show More
@@ -67,32 +67,33 module IssuesHelper
67 def show_detail(detail, no_html=false)
67 def show_detail(detail, no_html=false)
68 case detail.property
68 case detail.property
69 when 'attr'
69 when 'attr'
70 label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
70 field = detail.prop_key.to_s.gsub(/\_id$/, "")
71 label = l(("field_" + field).to_sym)
71 case detail.prop_key
72 case detail.prop_key
72 when 'due_date', 'start_date'
73 when 'due_date', 'start_date'
73 value = format_date(detail.value.to_date) if detail.value
74 value = format_date(detail.value.to_date) if detail.value
74 old_value = format_date(detail.old_value.to_date) if detail.old_value
75 old_value = format_date(detail.old_value.to_date) if detail.old_value
75 when 'project_id'
76 when 'project_id'
76 p = Project.find_by_id(detail.value) and value = p.name if detail.value
77 value = find_name_by_reflection(field, detail.value)
77 p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value
78 old_value = find_name_by_reflection(field, detail.old_value)
78 when 'status_id'
79 when 'status_id'
79 s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
80 value = find_name_by_reflection(field, detail.value)
80 s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
81 old_value = find_name_by_reflection(field, detail.old_value)
81 when 'tracker_id'
82 when 'tracker_id'
82 t = Tracker.find_by_id(detail.value) and value = t.name if detail.value
83 value = find_name_by_reflection(field, detail.value)
83 t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value
84 old_value = find_name_by_reflection(field, detail.old_value)
84 when 'assigned_to_id'
85 when 'assigned_to_id'
85 u = User.find_by_id(detail.value) and value = u.name if detail.value
86 value = find_name_by_reflection(field, detail.value)
86 u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
87 old_value = find_name_by_reflection(field, detail.old_value)
87 when 'priority_id'
88 when 'priority_id'
88 e = IssuePriority.find_by_id(detail.value) and value = e.name if detail.value
89 value = find_name_by_reflection(field, detail.value)
89 e = IssuePriority.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
90 old_value = find_name_by_reflection(field, detail.old_value)
90 when 'category_id'
91 when 'category_id'
91 c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
92 value = find_name_by_reflection(field, detail.value)
92 c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
93 old_value = find_name_by_reflection(field, detail.old_value)
93 when 'fixed_version_id'
94 when 'fixed_version_id'
94 v = Version.find_by_id(detail.value) and value = v.name if detail.value
95 value = find_name_by_reflection(field, detail.value)
95 v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
96 old_value = find_name_by_reflection(field, detail.old_value)
96 when 'estimated_hours'
97 when 'estimated_hours'
97 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
98 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
98 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
99 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
@@ -140,6 +141,15 module IssuesHelper
140 l(:text_journal_deleted, :label => label, :old => old_value)
141 l(:text_journal_deleted, :label => label, :old => old_value)
141 end
142 end
142 end
143 end
144
145 # Find the name of an associated record stored in the field attribute
146 def find_name_by_reflection(field, id)
147 association = Issue.reflect_on_association(field.to_sym)
148 if association
149 record = association.class_name.constantize.find_by_id(id)
150 return record.name if record
151 end
152 end
143
153
144 def issues_to_csv(issues, project = nil)
154 def issues_to_csv(issues, project = nil)
145 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
155 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
General Comments 0
You need to be logged in to leave comments. Login now