Project

General

Profile

Feature #1358 » linkable_custom_fields.diff

Linkable Custom Fields patch - Aron Burrell, 2009-03-04 21:15

View differences:

app/helpers/queries_helper.rb (working copy)
30 30
  def column_content(column, issue)
31 31
    if column.is_a?(QueryCustomFieldColumn)
32 32
      cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
33
      show_value(cv)
33
      show_value_plain(cv)
34 34
    else
35 35
      value = issue.send(column.name)
36 36
      if value.is_a?(Date)
app/helpers/timelog_helper.rb (working copy)
93 93
                  entry.hours.to_s.gsub('.', decimal_separator),
94 94
                  entry.comments
95 95
                  ]
96
        fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) }
96
        fields += custom_fields.collect {|f| show_value_plain(entry.custom_value_for(f)) }
97 97
                  
98 98
        csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
99 99
      end
app/helpers/custom_fields_helper.rb (working copy)
61 61
  def custom_field_tag_with_label(name, custom_value)
62 62
    custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)
63 63
  end
64
  
65
  # Return a clean URL for a given custom field value
66
  def url_format(custom_value)
67
    url = custom_value.custom_field.url.strip
68
    return false unless url.length > 0
64 69

  
65
  # Return a string used to display a custom value
70
    formatted_value = format_value(custom_value.value, custom_value.custom_field.field_format)
71
    while (url.sub!(/__VALUE__/, h(formatted_value.strip)))
72
    end
73
    return url
74
  end
75

  
76
  # Return a formatted string used to display a custom value (including link if URL defined on custom_field)
66 77
  def show_value(custom_value)
67 78
    return "" unless custom_value
68
    format_value(custom_value.value, custom_value.custom_field.field_format)
79
    formatted_value = format_value(custom_value.value, custom_value.custom_field.field_format)
80
    if (value = url_format(custom_value))
81
      return link_to formatted_value, value, :target=>'_blank'
82
    else
83
      return h(format_value(custom_value.value, custom_value.custom_field.field_format))
84
    end
69 85
  end
86

  
87
  # Return an escaped string used to display a custom value
88
  def show_value_plain(custom_value)
89
    return "" unless custom_value
90
    return h(format_value(custom_value.value, custom_value.custom_field.field_format))
91
  end
70 92
  
71 93
  # Return a string used to display a custom value
72 94
  def format_value(value, field_format)
app/views/custom_fields/_form.rhtml (working copy)
8 8
  p_regexp = $("custom_field_regexp");
9 9
  p_values = $("custom_field_possible_values");
10 10
  p_searchable = $("custom_field_searchable");
11
  p_url = $("custom_field_url");
11 12
  p_default = $("custom_field_default_value");
12 13
  
13 14
  p_default.setAttribute('type','text');
......
65 66
																																			 :rows => 15 %>
66 67
<br /><em><%= l(:text_custom_field_possible_values_info) %></em></p>
67 68
<p><%= @custom_field.field_format == 'bool' ? f.check_box(:default_value) : f.text_field(:default_value) %></p>
69
<p><%= f.text_field :url, :size => 60 %>
70
<br /><%= l(:text_custom_field_url_info) %></p>
68 71
</div>
69 72

  
70 73
<div class="box">
app/views/mailer/_issue_text_plain.rhtml (working copy)
7 7
<%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
8 8
<%=l(:field_category)%>: <%= issue.category %>
9 9
<%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
10
<% issue.custom_values.each do |c| %><%= c.custom_field.name %>: <%= show_value(c) %>
10
<% issue.custom_values.each do |c| %><%= c.custom_field.name %>: <%= show_value_plain(c) %>
11 11
<% end %>
12 12

  
13 13
<%= issue.description %>
app/views/projects/show.rhtml (working copy)
10 10
  <% end %>
11 11
	<% @project.custom_values.each do |custom_value| %>
12 12
	<% if !custom_value.value.empty? %>
13
	   <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
13
	   <li><%= custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
14 14
	<% end %>
15 15
	<% end %>
16 16
	</ul>	
app/views/account/show.rhtml (working copy)
11 11
	<% end %>
12 12
	<% for custom_value in @custom_values %>
13 13
	<% if !custom_value.value.empty? %>
14
    <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
14
    <li><%= custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
15 15
	<% end %>
16 16
	<% end %>
17 17
    <li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
app/views/issues/show.rhtml (working copy)
46 46
<tr>
47 47
<% n = 0 -%>
48 48
<% @issue.custom_values.each do |value| -%>
49
    <td valign="top"><b><%=h value.custom_field.name %>:</b></td><td valign="top"><%= simple_format(h(show_value(value))) %></td>
49
    <td valign="top"><b><%=h value.custom_field.name %>:</b></td><td valign="top"><%= simple_format(show_value(value)) %></td>
50 50
<% n = n + 1
51 51
   if (n > 1) 
52 52
        n = 0 %>
config/locales/en.yml (working copy)
755 755
  text_repository_usernames_mapping: "Select or update the Redmine user mapped to each username found in the repository log.\nUsers with the same Redmine and repository username or email are automatically mapped."
756 756
  text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
757 757
  text_custom_field_possible_values_info: 'One line for each value'
758
  text_custom_field_url_info: '(__VALUE__ is a placeholder for each of the field values, eg. http://www.google.com/search?q=__VALUE__)'
758 759
  
759 760
  default_role_manager: Manager
760 761
  default_role_developper: Developer
db/migrate/20090304184821_add_custom_fields_url.rb (revision 0)
1
class AddCustomFieldsUrl < ActiveRecord::Migration
2
  def self.up
3
    add_column :custom_fields, :url, :string, :limit=>255, :default=>"", :null=>false
4
  end
5

  
6
  def self.down
7
    remove_column :custom_fields, :url
8
  end
9
end
(2-2/3)