##// END OF EJS Templates
Only retrieve query name for display....
Jean-Philippe Lang -
r2511:eb7903c0ec04
parent child
Show More
@@ -1,198 +1,199
1 1 # redMine - project management software
2 2 # Copyright (C) 2006 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'csv'
19 19
20 20 module IssuesHelper
21 21 include ApplicationHelper
22 22
23 23 def render_issue_tooltip(issue)
24 24 @cached_label_start_date ||= l(:field_start_date)
25 25 @cached_label_due_date ||= l(:field_due_date)
26 26 @cached_label_assigned_to ||= l(:field_assigned_to)
27 27 @cached_label_priority ||= l(:field_priority)
28 28
29 29 link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" +
30 30 "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
31 31 "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
32 32 "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
33 33 "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
34 34 end
35 35
36 36 # Returns a string of css classes that apply to the given issue
37 37 def css_issue_classes(issue)
38 38 s = "issue status-#{issue.status.position} priority-#{issue.priority.position}"
39 39 s << ' closed' if issue.closed?
40 40 s << ' overdue' if issue.overdue?
41 41 s << ' created-by-me' if User.current.logged? && issue.author_id == User.current.id
42 42 s << ' assigned-to-me' if User.current.logged? && issue.assigned_to_id == User.current.id
43 43 s
44 44 end
45 45
46 46 def sidebar_queries
47 47 unless @sidebar_queries
48 48 # User can see public queries and his own queries
49 49 visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)])
50 50 # Project specific queries and global queries
51 51 visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id])
52 52 @sidebar_queries = Query.find(:all,
53 :select => 'id, name',
53 54 :order => "name ASC",
54 55 :conditions => visible.conditions)
55 56 end
56 57 @sidebar_queries
57 58 end
58 59
59 60 def show_detail(detail, no_html=false)
60 61 case detail.property
61 62 when 'attr'
62 63 label = l(("field_" + detail.prop_key.to_s.gsub(/\_id$/, "")).to_sym)
63 64 case detail.prop_key
64 65 when 'due_date', 'start_date'
65 66 value = format_date(detail.value.to_date) if detail.value
66 67 old_value = format_date(detail.old_value.to_date) if detail.old_value
67 68 when 'project_id'
68 69 p = Project.find_by_id(detail.value) and value = p.name if detail.value
69 70 p = Project.find_by_id(detail.old_value) and old_value = p.name if detail.old_value
70 71 when 'status_id'
71 72 s = IssueStatus.find_by_id(detail.value) and value = s.name if detail.value
72 73 s = IssueStatus.find_by_id(detail.old_value) and old_value = s.name if detail.old_value
73 74 when 'tracker_id'
74 75 t = Tracker.find_by_id(detail.value) and value = t.name if detail.value
75 76 t = Tracker.find_by_id(detail.old_value) and old_value = t.name if detail.old_value
76 77 when 'assigned_to_id'
77 78 u = User.find_by_id(detail.value) and value = u.name if detail.value
78 79 u = User.find_by_id(detail.old_value) and old_value = u.name if detail.old_value
79 80 when 'priority_id'
80 81 e = Enumeration.find_by_id(detail.value) and value = e.name if detail.value
81 82 e = Enumeration.find_by_id(detail.old_value) and old_value = e.name if detail.old_value
82 83 when 'category_id'
83 84 c = IssueCategory.find_by_id(detail.value) and value = c.name if detail.value
84 85 c = IssueCategory.find_by_id(detail.old_value) and old_value = c.name if detail.old_value
85 86 when 'fixed_version_id'
86 87 v = Version.find_by_id(detail.value) and value = v.name if detail.value
87 88 v = Version.find_by_id(detail.old_value) and old_value = v.name if detail.old_value
88 89 when 'estimated_hours'
89 90 value = "%0.02f" % detail.value.to_f unless detail.value.blank?
90 91 old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank?
91 92 end
92 93 when 'cf'
93 94 custom_field = CustomField.find_by_id(detail.prop_key)
94 95 if custom_field
95 96 label = custom_field.name
96 97 value = format_value(detail.value, custom_field.field_format) if detail.value
97 98 old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value
98 99 end
99 100 when 'attachment'
100 101 label = l(:label_attachment)
101 102 end
102 103 call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
103 104
104 105 label ||= detail.prop_key
105 106 value ||= detail.value
106 107 old_value ||= detail.old_value
107 108
108 109 unless no_html
109 110 label = content_tag('strong', label)
110 111 old_value = content_tag("i", h(old_value)) if detail.old_value
111 112 old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
112 113 if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
113 114 # Link to the attachment if it has not been removed
114 115 value = link_to_attachment(a)
115 116 else
116 117 value = content_tag("i", h(value)) if value
117 118 end
118 119 end
119 120
120 121 if !detail.value.blank?
121 122 case detail.property
122 123 when 'attr', 'cf'
123 124 if !detail.old_value.blank?
124 125 label + " " + l(:text_journal_changed, :old => old_value, :new => value)
125 126 else
126 127 label + " " + l(:text_journal_set_to, value)
127 128 end
128 129 when 'attachment'
129 130 "#{label} #{value} #{l(:label_added)}"
130 131 end
131 132 else
132 133 case detail.property
133 134 when 'attr', 'cf'
134 135 label + " " + l(:text_journal_deleted) + " (#{old_value})"
135 136 when 'attachment'
136 137 "#{label} #{old_value} #{l(:label_deleted)}"
137 138 end
138 139 end
139 140 end
140 141
141 142 def issues_to_csv(issues, project = nil)
142 143 ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
143 144 decimal_separator = l(:general_csv_decimal_separator)
144 145 export = StringIO.new
145 146 CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
146 147 # csv header fields
147 148 headers = [ "#",
148 149 l(:field_status),
149 150 l(:field_project),
150 151 l(:field_tracker),
151 152 l(:field_priority),
152 153 l(:field_subject),
153 154 l(:field_assigned_to),
154 155 l(:field_category),
155 156 l(:field_fixed_version),
156 157 l(:field_author),
157 158 l(:field_start_date),
158 159 l(:field_due_date),
159 160 l(:field_done_ratio),
160 161 l(:field_estimated_hours),
161 162 l(:field_created_on),
162 163 l(:field_updated_on)
163 164 ]
164 165 # Export project custom fields if project is given
165 166 # otherwise export custom fields marked as "For all projects"
166 167 custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields
167 168 custom_fields.each {|f| headers << f.name}
168 169 # Description in the last column
169 170 headers << l(:field_description)
170 171 csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
171 172 # csv lines
172 173 issues.each do |issue|
173 174 fields = [issue.id,
174 175 issue.status.name,
175 176 issue.project.name,
176 177 issue.tracker.name,
177 178 issue.priority.name,
178 179 issue.subject,
179 180 issue.assigned_to,
180 181 issue.category,
181 182 issue.fixed_version,
182 183 issue.author.name,
183 184 format_date(issue.start_date),
184 185 format_date(issue.due_date),
185 186 issue.done_ratio,
186 187 issue.estimated_hours.to_s.gsub('.', decimal_separator),
187 188 format_time(issue.created_on),
188 189 format_time(issue.updated_on)
189 190 ]
190 191 custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
191 192 fields << issue.description
192 193 csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
193 194 end
194 195 end
195 196 export.rewind
196 197 export
197 198 end
198 199 end
General Comments 0
You need to be logged in to leave comments. Login now