Project

General

Profile

Feature #5794 » 5794_git_with_option.diff

Jean-Baptiste Barth, 2010-07-08 06:32

View differences:

app/helpers/custom_fields_helper.rb
90 90
  end
91 91

  
92 92
  # Return a string used to display a custom value
93
  def show_value(custom_value)
93
  def show_value(custom_value, options = {})
94 94
    return "" unless custom_value
95
    format_value(custom_value.value, custom_value.custom_field.field_format)
95
    
96
    options = {:textilize => true, :simple_format => false}.merge(options)
97
    value = custom_value.value
98
    if options[:simple_format]
99
      value = simple_format_without_paragraph(h(value))
100
    elsif options[:textilize] && custom_value.custom_field.textilized?
101
      value = textilizable(value)
102
    else
103
      value = h(value)
104
    end
105
    
106
    format_value(value, custom_value.custom_field.field_format)
96 107
  end
97 108
  
98 109
  # Return a string used to display a custom value
app/helpers/issues_helper.rb
79 79
    n = 0
80 80
    ordered_values.compact.each do |value|
81 81
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
82
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
82
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ show_value(value) }</td>\n"
83 83
      n += 1
84 84
    end
85 85
    s << "</tr>\n"
......
226 226
                  format_time(issue.created_on),  
227 227
                  format_time(issue.updated_on)
228 228
                  ]
229
        custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
229
        custom_fields.each {|f| fields << show_value(issue.custom_value_for(f), :textilize => false) }
230 230
        fields << issue.description
231 231
        csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
232 232
      end
app/helpers/timelog_helper.rb
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(entry.custom_value_for(f), :textilize => false) }
119 119
                  
120 120
        csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
121 121
      end
app/models/custom_field.rb
34 34
  def before_validation
35 35
    # make sure these fields are not searchable
36 36
    self.searchable = false if %w(int float date bool).include?(field_format)
37
    # and only text fields are textilized
38
    self.textilized = false unless %w(string text).include?(field_format)
37 39
    true
38 40
  end
39 41
  
app/views/custom_fields/_form.rhtml
8 8
  p_regexp = $("custom_field_regexp");
9 9
  p_values = $("custom_field_possible_values");
10 10
  p_searchable = $("custom_field_searchable");
11
  p_textilized = $("custom_field_textilized");
11 12
  p_default = $("custom_field_default_value");
12 13
  
13 14
  p_default.setAttribute('type','text');
......
17 18
    case "list":
18 19
      Element.hide(p_length.parentNode);
19 20
      Element.hide(p_regexp.parentNode);
21
      Element.hide(p_textilized.parentNode);
20 22
      if (p_searchable) Element.show(p_searchable.parentNode);
21 23
      Element.show(p_values);
22 24
      break;
......
24 26
      p_default.setAttribute('type','checkbox');
25 27
      Element.hide(p_length.parentNode);
26 28
      Element.hide(p_regexp.parentNode);
29
      Element.hide(p_textilized.parentNode);
27 30
      if (p_searchable) Element.hide(p_searchable.parentNode);
28 31
      Element.hide(p_values);
29 32
      break;
30 33
    case "date":
31 34
      Element.hide(p_length.parentNode);
32 35
      Element.hide(p_regexp.parentNode);
36
      Element.hide(p_textilized.parentNode);
33 37
      if (p_searchable) Element.hide(p_searchable.parentNode);
34 38
      Element.hide(p_values);
35 39
      break;
......
37 41
    case "int":
38 42
      Element.show(p_length.parentNode);
39 43
      Element.show(p_regexp.parentNode);
44
      Element.hide(p_textilized.parentNode);
40 45
      if (p_searchable) Element.hide(p_searchable.parentNode);
41 46
      Element.hide(p_values);
42 47
      break;
43 48
    default:
44 49
      Element.show(p_length.parentNode);
45 50
      Element.show(p_regexp.parentNode);
51
      Element.show(p_textilized.parentNode);
46 52
      if (p_searchable) Element.show(p_searchable.parentNode);
47 53
      Element.hide(p_values);
48 54
      break;
......
83 89
    <p><%= f.check_box :is_for_all %></p>
84 90
    <p><%= f.check_box :is_filter %></p>
85 91
    <p><%= f.check_box :searchable %></p>
92
    <p><%= f.check_box :textilized %></p>
86 93
    
87 94
<% when "UserCustomField" %>
88 95
    <p><%= f.check_box :is_required %></p>
89 96
    <p><%= f.check_box :editable %></p>
97
    <p><%= f.check_box :textilized %></p>
90 98

  
91 99
<% when "ProjectCustomField" %>
92 100
    <p><%= f.check_box :is_required %></p>
93 101
    <p><%= f.check_box :searchable %></p>
102
    <p><%= f.check_box :textilized %></p>
94 103

  
95 104
<% when "TimeEntryCustomField" %>
96 105
    <p><%= f.check_box :is_required %></p>
app/views/mailer/_issue_text_html.rhtml
8 8
<li><%=l(:field_category)%>: <%=h issue.category %></li>
9 9
<li><%=l(:field_fixed_version)%>: <%=h issue.fixed_version %></li>
10 10
<% issue.custom_values.each do |c| %>
11
  <li><%=h c.custom_field.name %>: <%=h show_value(c) %></li>
11
  <li><%=h c.custom_field.name %>: <%= show_value(c) %></li>
12 12
<% end %>
13 13
</ul>
14 14

  
app/views/mailer/_issue_text_plain.rhtml
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(c, :textilize => false) %>
11 11
<% end %>
12 12

  
13 13
<%= issue.description %>
app/views/projects/show.rhtml
18 18
  <% end %>
19 19
	<% @project.custom_values.each do |custom_value| %>
20 20
	<% if !custom_value.value.blank? %>
21
	   <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
21
	   <li><%= custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
22 22
	<% end %>
23 23
	<% end %>
24 24
	</ul>	
app/views/users/show.rhtml
11 11
	<% end %>
12 12
	<% for custom_value in @custom_values %>
13 13
	<% if !custom_value.value.blank? %>
14
    <li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
14
    <li><%=h 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/versions/_overview.rhtml
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>
config/locales/en.yml
285 285
  field_group_by: Group results by
286 286
  field_sharing: Sharing
287 287
  field_parent_issue: Parent task
288
  field_textilized: Textilized
288 289
  
289 290
  setting_app_title: Application title
290 291
  setting_app_subtitle: Application subtitle
db/migrate/109_add_custom_fields_textilized.rb
1
class AddCustomFieldsTextilized < ActiveRecord::Migration
2
  def self.up
3
    add_column :custom_fields, :textilized, :boolean, :default => false
4
  end
5

  
6
  def self.down
7
    remove_column :custom_fields, :textilized
8
  end
9
end
test/fixtures/custom_fields.yml
129 129
  field_format: date
130 130
  default_value: ""
131 131
  editable: true
132
custom_fields_010: 
133
  name: Textilizable cf
134
  min_length: 0
135
  regexp: ""
136
  is_for_all: true
137
  is_filter: true
138
  type: IssueCustomField
139
  max_length: 0
140
  possible_values: ""
141
  id: 10
142
  is_required: false
143
  field_format: string
144
  textilized: true
test/fixtures/custom_fields_trackers.yml
17 17
custom_fields_trackers_006: 
18 18
  custom_field_id: 6
19 19
  tracker_id: 3
20
custom_fields_trackers_007:
21
  custom_field_id: 10
22
  tracker_id: 1
test/fixtures/custom_values.yml
101 101
  customized_id: 1
102 102
  id: 17
103 103
  value: '2009-12-01'
104
custom_values_018: 
105
  customized_type: Issue
106
  custom_field_id: 10
107
  customized_id: 1
108
  id: 18
109
  value: "*Issue* test: #1\n(powered by http://www.redmine.org/)"
test/unit/helpers/custom_fields_helper_test.rb
18 18
require File.dirname(__FILE__) + '/../../test_helper'
19 19

  
20 20
class CustomFieldsHelperTest < HelperTestCase
21
  include ApplicationHelper
22
  include ActionView::Helpers::TextHelper
21 23
  include CustomFieldsHelper
22 24
  include Redmine::I18n
23 25
  
......
26 28
    assert_equal 'Yes', format_value('1', 'bool')
27 29
    assert_equal 'No', format_value('0', 'bool')
28 30
  end
31

  
32
  def test_show_value
33
    cv = CustomValue.find(18)
34
    str = cv.value
35
    assert_equal str, show_value(cv, :textilize => false)
36
    assert_equal str.gsub("\n","\n<br />"), show_value(cv, :simple_format => true)
37
    assert_equal textilizable(str), show_value(cv)
38
  end
29 39
end
(1-1/2)