Project

General

Profile

Feature #1358 » linkable_custom_field_redmine_0.9.2_v1.0.patch

Vladimir Kovacik, 2010-03-10 10:38

View differences:

app/helpers/issues_helper.rb (revision 19866)
43 43
    n = 0
44 44
    ordered_values.compact.each do |value|
45 45
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
46
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
46
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(show_value(value)) }</td>\n"
47 47
      n += 1
48 48
    end
49 49
    s << "</tr>\n"
app/helpers/queries_helper.rb (revision 19866)
28 28
  end
29 29
  
30 30
  def column_content(column, issue, query = nil)
31
    value = column.value(issue)
32
    
33
    case value.class.name
34
    when 'String'
35
      if column.name == :subject
36
        subject_in_tree( issue, issue.subject, query)
31
    case column.class.name
32
    when 'QueryColumn'
33
      value = column.value(issue)
34
      case value.class.name
35
      when 'String'
36
        if column.name == :subject
37
          subject_in_tree( issue, issue.subject, query)
38
        else
39
          h(value)
40
        end
41
      when 'Time'
42
        format_time(value)
43
      when 'Date'
44
        format_date(value)
45
      when 'Fixnum', 'Float'
46
        case column.name
47
        when :done_ratio
48
            progress_bar(value, :width => '80px')
49
        when :estimated_hours
50
            l_hours(value)
51
        else
52
          value.to_s
53
        end
54
      when 'User'
55
        link_to_user value
56
      when 'Project'
57
        link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
58
      when 'Version'
59
        link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
60
      when 'TrueClass'
61
        l(:general_text_Yes)
62
      when 'FalseClass'
63
        l(:general_text_No)
37 64
      else
38 65
        h(value)
39 66
      end
40
    when 'Time'
41
      format_time(value)
42
    when 'Date'
43
      format_date(value)
44
    when 'Fixnum', 'Float'
45
      case column.name
46
      when :done_ratio
47
          progress_bar(value, :width => '80px')
48
      when :estimated_hours
49
          l_hours(value)
50
      else
51
        value.to_s
52
      end
53
    when 'User'
54
      link_to_user value
55
    when 'Project'
56
      link_to(h(value), :controller => 'projects', :action => 'show', :id => value)
57
    when 'Version'
58
      link_to(h(value), :controller => 'versions', :action => 'show', :id => value)
59
    when 'TrueClass'
60
      l(:general_text_Yes)
61
    when 'FalseClass'
62
      l(:general_text_No)
63
    else
64
      h(value)
67

  
68
    when 'QueryCustomFieldColumn'
69
      cfv = issue.custom_field_values.detect {|v| v.custom_field_id == column.custom_field.id}
70
      show_value(cfv)
65 71
    end
66 72
  end
67 73

  
app/helpers/custom_fields_helper.rb (revision 19866)
89 89

  
90 90
  # Return a string used to display a custom value
91 91
  def show_value(custom_value)
92
    return "" unless custom_value
93
    format_value(custom_value.value, custom_value.custom_field.field_format)
92
    return "" unless custom_value && !custom_value.value.empty?
93
    if custom_value.custom_field.url.empty?
94
      return h(format_value(custom_value.value, custom_value.custom_field.field_format))
95
    else
96
      return url_format(custom_value)
97
    end
94 98
  end
99

  
100
  # Return an escaped string used to display a custom value
101
  def show_value_plain(custom_value)
102
    return "" unless custom_value && !custom_value.value.empty?
103
    return h(format_value(custom_value.value, custom_value.custom_field.field_format))
104
  end
95 105
  
96 106
  # Return a string used to display a custom value
97 107
  def format_value(value, field_format)
......
106 116
    end
107 117
  end
108 118

  
119
  # Return a clean URL for a given custom field value
120
  def url_format(custom_value)
121
    url = custom_value.custom_field.url
122
    return if url.empty?
123
    
124
    formatted_value = format_value(custom_value.value, custom_value.custom_field.field_format)
125
    while (url.sub!(/__VALUE__/, h(custom_value.value)))
126
    end
127
    return link_to formatted_value, url, :target=>'_blank'
128
  end
129

  
109 130
  # Return an array of custom field formats which can be used in select_tag
110 131
  def custom_field_formats_for_select
111 132
    CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
app/helpers/timelog_helper.rb (revision 19866)
115 115
                  entry.hours.to_s.gsub('.', decimal_separator),
116 116
                  entry.comments
117 117
                  ]
118
        fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) }
118
        fields += custom_fields.collect {|f| show_value_plain(entry.custom_value_for(f)) }
119 119
                  
120 120
        csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
121 121
      end
app/controllers/custom_fields_controller.rb (revision 19866)
33 33
    rescue
34 34
    end
35 35
    (redirect_to(:action => 'index'); return) unless @custom_field.is_a?(CustomField)
36
    
36

  
37
    @custom_field.url.strip!
37 38
    if request.post? and @custom_field.save
38 39
      flash[:notice] = l(:notice_successful_create)
39 40
      call_hook(:controller_custom_fields_new_after_save, :params => params, :custom_field => @custom_field)
app/views/custom_fields/_form.rhtml (revision 19866)
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
<%= call_hook(:view_custom_fields_form_upper_box, :custom_field => @custom_field, :form => f) %>
69 72
</div>
70 73

  
app/views/users/show.rhtml (revision 19866)
12 12
	<% end %>
13 13
	<% for custom_value in @custom_values %>
14 14
	<% if !custom_value.value.blank? %>
15
    <li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
15
    <li><%=h custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
16 16
	<% end %>
17 17
	<% end %>
18 18
    <li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
app/views/versions/_overview.rhtml (revision 19866)
8 8
<ul>
9 9
	<% version.custom_values.each do |custom_value| %>
10 10
		<% if !custom_value.value.blank? %>
11
		   <li><%=h custom_value.custom_field.name %>: <%=h show_value(custom_value) %></li>
11
		   <li><%=h custom_value.custom_field.name %>: <%= show_value(custom_value) %></li>
12 12
		<% end %>
13 13
	<% end %>
14 14
</ul>
app/views/mailer/_issue_text_plain.rhtml (revision 19866)
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 (revision 19866)
16 16
  <% end %>
17 17
	<% @project.custom_values.each do |custom_value| %>
18 18
	<% if !custom_value.value.blank? %>
19
	   <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
19
	   <li><%= custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
20 20
	<% end %>
21 21
	<% end %>
22 22
	</ul>	
db/migrate/20100309115805_add_custom_fields_url.rb (revision 19866)
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
config/locales/en.yml (revision 19866)
866 866
  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."
867 867
  text_diff_truncated: '... This diff was truncated because it exceeds the maximum size that can be displayed.'
868 868
  text_custom_field_possible_values_info: 'One line for each value'
869
  text_custom_field_url_info: '(__VALUE__ is a placeholder for each of the field values, eg. http://www.google.com/search?q=__VALUE__)'
869 870
  text_wiki_page_destroy_question: "This page has {{descendants}} child page(s) and descendant(s). What do you want to do?"
870 871
  text_wiki_page_nullify_children: "Keep child pages as root pages"
871 872
  text_wiki_page_destroy_children: "Delete child pages and all their descendants"
config/locales/sk.yml (revision 19866)
789 789
  label_display: Zobrazenie
790 790
  button_create_and_continue: Vytvoriť a pokračovať
791 791
  text_custom_field_possible_values_info: 'Jeden riadok pre každú hodnotu'
792
  text_custom_field_url_info: '(__VALUE__ sa nahradí hodnotou poľa, príklad: http://www.google.com/search?q=__VALUE__)'
792 793
  setting_repository_log_display_limit: Maximálne množstvo revizií zobrazené v logu
793 794
  setting_file_max_size_displayed: Maximálna veľkosť textových súborov zobrazených priamo na stránke
794 795
  field_watcher: Pozorovateľ
(3-3/3)