To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / .svn / text-base / issues_helper.rb.svn-base @ 441:cbce1fd3b1b7
History | View | Annotate | Download (12.4 KB)
| 1 | 245:051f544170fe | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
||
| 3 | 0:513646585e45 | Chris | # |
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | 441:cbce1fd3b1b7 | Chris | # |
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | 441:cbce1fd3b1b7 | Chris | # |
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License |
| 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. |
||
| 17 | |||
| 18 | module IssuesHelper |
||
| 19 | include ApplicationHelper |
||
| 20 | |||
| 21 | def issue_list(issues, &block) |
||
| 22 | ancestors = [] |
||
| 23 | issues.each do |issue| |
||
| 24 | while (ancestors.any? && !issue.is_descendant_of?(ancestors.last)) |
||
| 25 | ancestors.pop |
||
| 26 | end |
||
| 27 | yield issue, ancestors.size |
||
| 28 | ancestors << issue unless issue.leaf? |
||
| 29 | end |
||
| 30 | end |
||
| 31 | 22:40f7cfd4df19 | chris | |
| 32 | # Renders a HTML/CSS tooltip |
||
| 33 | # |
||
| 34 | # To use, a trigger div is needed. This is a div with the class of "tooltip" |
||
| 35 | # that contains this method wrapped in a span with the class of "tip" |
||
| 36 | # |
||
| 37 | # <div class="tooltip"><%= link_to_issue(issue) %> |
||
| 38 | # <span class="tip"><%= render_issue_tooltip(issue) %></span> |
||
| 39 | # </div> |
||
| 40 | # |
||
| 41 | 0:513646585e45 | Chris | def render_issue_tooltip(issue) |
| 42 | 14:1d32c0a0efbf | Chris | @cached_label_status ||= l(:field_status) |
| 43 | 0:513646585e45 | Chris | @cached_label_start_date ||= l(:field_start_date) |
| 44 | @cached_label_due_date ||= l(:field_due_date) |
||
| 45 | @cached_label_assigned_to ||= l(:field_assigned_to) |
||
| 46 | @cached_label_priority ||= l(:field_priority) |
||
| 47 | 22:40f7cfd4df19 | chris | @cached_label_project ||= l(:field_project) |
| 48 | |||
| 49 | 0:513646585e45 | Chris | link_to_issue(issue) + "<br /><br />" + |
| 50 | 22:40f7cfd4df19 | chris | "<strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />" +
|
| 51 | 14:1d32c0a0efbf | Chris | "<strong>#{@cached_label_status}</strong>: #{issue.status.name}<br />" +
|
| 52 | 0:513646585e45 | Chris | "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
|
| 53 | "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
|
||
| 54 | "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
|
||
| 55 | "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
|
||
| 56 | end |
||
| 57 | 441:cbce1fd3b1b7 | Chris | |
| 58 | def issue_heading(issue) |
||
| 59 | h("#{issue.tracker} ##{issue.id}")
|
||
| 60 | end |
||
| 61 | |||
| 62 | 0:513646585e45 | Chris | def render_issue_subject_with_tree(issue) |
| 63 | s = '' |
||
| 64 | 441:cbce1fd3b1b7 | Chris | ancestors = issue.root? ? [] : issue.ancestors.visible.all |
| 65 | ancestors.each do |ancestor| |
||
| 66 | 0:513646585e45 | Chris | s << '<div>' + content_tag('p', link_to_issue(ancestor))
|
| 67 | end |
||
| 68 | 441:cbce1fd3b1b7 | Chris | s << '<div>' |
| 69 | subject = h(issue.subject) |
||
| 70 | if issue.is_private? |
||
| 71 | subject = content_tag('span', l(:field_is_private), :class => 'private') + ' ' + subject
|
||
| 72 | end |
||
| 73 | s << content_tag('h3', subject)
|
||
| 74 | s << '</div>' * (ancestors.size + 1) |
||
| 75 | 0:513646585e45 | Chris | s |
| 76 | end |
||
| 77 | 441:cbce1fd3b1b7 | Chris | |
| 78 | 0:513646585e45 | Chris | def render_descendants_tree(issue) |
| 79 | s = '<form><table class="list issues">' |
||
| 80 | 441:cbce1fd3b1b7 | Chris | issue_list(issue.descendants.visible.sort_by(&:lft)) do |child, level| |
| 81 | 0:513646585e45 | Chris | s << content_tag('tr',
|
| 82 | content_tag('td', check_box_tag("ids[]", child.id, false, :id => nil), :class => 'checkbox') +
|
||
| 83 | content_tag('td', link_to_issue(child, :truncate => 60), :class => 'subject') +
|
||
| 84 | content_tag('td', h(child.status)) +
|
||
| 85 | content_tag('td', link_to_user(child.assigned_to)) +
|
||
| 86 | content_tag('td', progress_bar(child.done_ratio, :width => '80px')),
|
||
| 87 | :class => "issue issue-#{child.id} hascontextmenu #{level > 0 ? "idnt idnt-#{level}" : nil}")
|
||
| 88 | end |
||
| 89 | s << '</form></table>' |
||
| 90 | s |
||
| 91 | end |
||
| 92 | 441:cbce1fd3b1b7 | Chris | |
| 93 | 0:513646585e45 | Chris | def render_custom_fields_rows(issue) |
| 94 | return if issue.custom_field_values.empty? |
||
| 95 | ordered_values = [] |
||
| 96 | half = (issue.custom_field_values.size / 2.0).ceil |
||
| 97 | half.times do |i| |
||
| 98 | ordered_values << issue.custom_field_values[i] |
||
| 99 | ordered_values << issue.custom_field_values[i + half] |
||
| 100 | end |
||
| 101 | s = "<tr>\n" |
||
| 102 | n = 0 |
||
| 103 | ordered_values.compact.each do |value| |
||
| 104 | s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0 |
||
| 105 | s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
|
||
| 106 | n += 1 |
||
| 107 | end |
||
| 108 | s << "</tr>\n" |
||
| 109 | s |
||
| 110 | end |
||
| 111 | 441:cbce1fd3b1b7 | Chris | |
| 112 | def issues_destroy_confirmation_message(issues) |
||
| 113 | issues = [issues] unless issues.is_a?(Array) |
||
| 114 | message = l(:text_issues_destroy_confirmation) |
||
| 115 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2}
|
||
| 116 | if descendant_count > 0 |
||
| 117 | issues.each do |issue| |
||
| 118 | next if issue.root? |
||
| 119 | issues.each do |other_issue| |
||
| 120 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) |
||
| 121 | end |
||
| 122 | end |
||
| 123 | if descendant_count > 0 |
||
| 124 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) |
||
| 125 | end |
||
| 126 | end |
||
| 127 | message |
||
| 128 | end |
||
| 129 | |||
| 130 | 0:513646585e45 | Chris | def sidebar_queries |
| 131 | unless @sidebar_queries |
||
| 132 | # User can see public queries and his own queries |
||
| 133 | visible = ARCondition.new(["is_public = ? OR user_id = ?", true, (User.current.logged? ? User.current.id : 0)]) |
||
| 134 | # Project specific queries and global queries |
||
| 135 | visible << (@project.nil? ? ["project_id IS NULL"] : ["project_id IS NULL OR project_id = ?", @project.id]) |
||
| 136 | 441:cbce1fd3b1b7 | Chris | @sidebar_queries = Query.find(:all, |
| 137 | 245:051f544170fe | Chris | :select => 'id, name, is_public', |
| 138 | 0:513646585e45 | Chris | :order => "name ASC", |
| 139 | :conditions => visible.conditions) |
||
| 140 | end |
||
| 141 | @sidebar_queries |
||
| 142 | end |
||
| 143 | |||
| 144 | 245:051f544170fe | Chris | def query_links(title, queries) |
| 145 | # links to #index on issues/show |
||
| 146 | url_params = controller_name == 'issues' ? {:controller => 'issues', :action => 'index', :project_id => @project} : params
|
||
| 147 | 441:cbce1fd3b1b7 | Chris | |
| 148 | 245:051f544170fe | Chris | content_tag('h3', title) +
|
| 149 | queries.collect {|query|
|
||
| 150 | link_to(h(query.name), url_params.merge(:query_id => query)) |
||
| 151 | }.join('<br />')
|
||
| 152 | end |
||
| 153 | 441:cbce1fd3b1b7 | Chris | |
| 154 | 245:051f544170fe | Chris | def render_sidebar_queries |
| 155 | out = '' |
||
| 156 | queries = sidebar_queries.select {|q| !q.is_public?}
|
||
| 157 | out << query_links(l(:label_my_queries), queries) if queries.any? |
||
| 158 | queries = sidebar_queries.select {|q| q.is_public?}
|
||
| 159 | out << query_links(l(:label_query_plural), queries) if queries.any? |
||
| 160 | out |
||
| 161 | end |
||
| 162 | |||
| 163 | 0:513646585e45 | Chris | def show_detail(detail, no_html=false) |
| 164 | case detail.property |
||
| 165 | when 'attr' |
||
| 166 | field = detail.prop_key.to_s.gsub(/\_id$/, "") |
||
| 167 | label = l(("field_" + field).to_sym)
|
||
| 168 | case |
||
| 169 | when ['due_date', 'start_date'].include?(detail.prop_key) |
||
| 170 | value = format_date(detail.value.to_date) if detail.value |
||
| 171 | old_value = format_date(detail.old_value.to_date) if detail.old_value |
||
| 172 | |||
| 173 | when ['project_id', 'status_id', 'tracker_id', 'assigned_to_id', 'priority_id', 'category_id', 'fixed_version_id'].include?(detail.prop_key) |
||
| 174 | value = find_name_by_reflection(field, detail.value) |
||
| 175 | old_value = find_name_by_reflection(field, detail.old_value) |
||
| 176 | |||
| 177 | when detail.prop_key == 'estimated_hours' |
||
| 178 | value = "%0.02f" % detail.value.to_f unless detail.value.blank? |
||
| 179 | old_value = "%0.02f" % detail.old_value.to_f unless detail.old_value.blank? |
||
| 180 | |||
| 181 | when detail.prop_key == 'parent_id' |
||
| 182 | label = l(:field_parent_issue) |
||
| 183 | value = "##{detail.value}" unless detail.value.blank?
|
||
| 184 | old_value = "##{detail.old_value}" unless detail.old_value.blank?
|
||
| 185 | 441:cbce1fd3b1b7 | Chris | |
| 186 | when detail.prop_key == 'is_private' |
||
| 187 | value = l(detail.value == "0" ? :general_text_No : :general_text_Yes) unless detail.value.blank? |
||
| 188 | old_value = l(detail.old_value == "0" ? :general_text_No : :general_text_Yes) unless detail.old_value.blank? |
||
| 189 | 0:513646585e45 | Chris | end |
| 190 | when 'cf' |
||
| 191 | custom_field = CustomField.find_by_id(detail.prop_key) |
||
| 192 | if custom_field |
||
| 193 | label = custom_field.name |
||
| 194 | value = format_value(detail.value, custom_field.field_format) if detail.value |
||
| 195 | old_value = format_value(detail.old_value, custom_field.field_format) if detail.old_value |
||
| 196 | end |
||
| 197 | when 'attachment' |
||
| 198 | label = l(:label_attachment) |
||
| 199 | end |
||
| 200 | call_hook(:helper_issues_show_detail_after_setting, {:detail => detail, :label => label, :value => value, :old_value => old_value })
|
||
| 201 | |||
| 202 | label ||= detail.prop_key |
||
| 203 | value ||= detail.value |
||
| 204 | old_value ||= detail.old_value |
||
| 205 | 441:cbce1fd3b1b7 | Chris | |
| 206 | 0:513646585e45 | Chris | unless no_html |
| 207 | label = content_tag('strong', label)
|
||
| 208 | old_value = content_tag("i", h(old_value)) if detail.old_value
|
||
| 209 | old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
|
||
| 210 | if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key) |
||
| 211 | # Link to the attachment if it has not been removed |
||
| 212 | value = link_to_attachment(a) |
||
| 213 | else |
||
| 214 | value = content_tag("i", h(value)) if value
|
||
| 215 | end |
||
| 216 | end |
||
| 217 | 441:cbce1fd3b1b7 | Chris | |
| 218 | 245:051f544170fe | Chris | if detail.property == 'attr' && detail.prop_key == 'description' |
| 219 | s = l(:text_journal_changed_no_detail, :label => label) |
||
| 220 | unless no_html |
||
| 221 | 441:cbce1fd3b1b7 | Chris | diff_link = link_to 'diff', |
| 222 | 245:051f544170fe | Chris | {:controller => 'journals', :action => 'diff', :id => detail.journal_id, :detail_id => detail.id},
|
| 223 | :title => l(:label_view_diff) |
||
| 224 | s << " (#{ diff_link })"
|
||
| 225 | end |
||
| 226 | s |
||
| 227 | elsif !detail.value.blank? |
||
| 228 | 0:513646585e45 | Chris | case detail.property |
| 229 | when 'attr', 'cf' |
||
| 230 | if !detail.old_value.blank? |
||
| 231 | l(:text_journal_changed, :label => label, :old => old_value, :new => value) |
||
| 232 | else |
||
| 233 | l(:text_journal_set_to, :label => label, :value => value) |
||
| 234 | end |
||
| 235 | when 'attachment' |
||
| 236 | l(:text_journal_added, :label => label, :value => value) |
||
| 237 | end |
||
| 238 | else |
||
| 239 | l(:text_journal_deleted, :label => label, :old => old_value) |
||
| 240 | end |
||
| 241 | end |
||
| 242 | |||
| 243 | # Find the name of an associated record stored in the field attribute |
||
| 244 | def find_name_by_reflection(field, id) |
||
| 245 | association = Issue.reflect_on_association(field.to_sym) |
||
| 246 | if association |
||
| 247 | record = association.class_name.constantize.find_by_id(id) |
||
| 248 | return record.name if record |
||
| 249 | end |
||
| 250 | end |
||
| 251 | 441:cbce1fd3b1b7 | Chris | |
| 252 | 119:8661b858af72 | Chris | # Renders issue children recursively |
| 253 | def render_api_issue_children(issue, api) |
||
| 254 | return if issue.leaf? |
||
| 255 | api.array :children do |
||
| 256 | issue.children.each do |child| |
||
| 257 | api.issue(:id => child.id) do |
||
| 258 | api.tracker(:id => child.tracker_id, :name => child.tracker.name) unless child.tracker.nil? |
||
| 259 | api.subject child.subject |
||
| 260 | render_api_issue_children(child, api) |
||
| 261 | end |
||
| 262 | end |
||
| 263 | end |
||
| 264 | end |
||
| 265 | 441:cbce1fd3b1b7 | Chris | |
| 266 | 0:513646585e45 | Chris | def issues_to_csv(issues, project = nil) |
| 267 | 441:cbce1fd3b1b7 | Chris | ic = Iconv.new(l(:general_csv_encoding), 'UTF-8') |
| 268 | 0:513646585e45 | Chris | decimal_separator = l(:general_csv_decimal_separator) |
| 269 | export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv| |
||
| 270 | # csv header fields |
||
| 271 | headers = [ "#", |
||
| 272 | 441:cbce1fd3b1b7 | Chris | l(:field_status), |
| 273 | 0:513646585e45 | Chris | l(:field_project), |
| 274 | l(:field_tracker), |
||
| 275 | l(:field_priority), |
||
| 276 | l(:field_subject), |
||
| 277 | l(:field_assigned_to), |
||
| 278 | l(:field_category), |
||
| 279 | l(:field_fixed_version), |
||
| 280 | l(:field_author), |
||
| 281 | l(:field_start_date), |
||
| 282 | l(:field_due_date), |
||
| 283 | l(:field_done_ratio), |
||
| 284 | l(:field_estimated_hours), |
||
| 285 | l(:field_parent_issue), |
||
| 286 | l(:field_created_on), |
||
| 287 | l(:field_updated_on) |
||
| 288 | ] |
||
| 289 | # Export project custom fields if project is given |
||
| 290 | # otherwise export custom fields marked as "For all projects" |
||
| 291 | custom_fields = project.nil? ? IssueCustomField.for_all : project.all_issue_custom_fields |
||
| 292 | custom_fields.each {|f| headers << f.name}
|
||
| 293 | # Description in the last column |
||
| 294 | headers << l(:field_description) |
||
| 295 | csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
| 296 | # csv lines |
||
| 297 | issues.each do |issue| |
||
| 298 | fields = [issue.id, |
||
| 299 | 441:cbce1fd3b1b7 | Chris | issue.status.name, |
| 300 | 0:513646585e45 | Chris | issue.project.name, |
| 301 | 441:cbce1fd3b1b7 | Chris | issue.tracker.name, |
| 302 | 0:513646585e45 | Chris | issue.priority.name, |
| 303 | issue.subject, |
||
| 304 | issue.assigned_to, |
||
| 305 | issue.category, |
||
| 306 | issue.fixed_version, |
||
| 307 | issue.author.name, |
||
| 308 | format_date(issue.start_date), |
||
| 309 | format_date(issue.due_date), |
||
| 310 | issue.done_ratio, |
||
| 311 | issue.estimated_hours.to_s.gsub('.', decimal_separator),
|
||
| 312 | issue.parent_id, |
||
| 313 | 441:cbce1fd3b1b7 | Chris | format_time(issue.created_on), |
| 314 | 0:513646585e45 | Chris | format_time(issue.updated_on) |
| 315 | ] |
||
| 316 | custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
|
||
| 317 | fields << issue.description |
||
| 318 | csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
| 319 | end |
||
| 320 | end |
||
| 321 | export |
||
| 322 | end |
||
| 323 | end |