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