Feature #5794 » 5794_git_with_option.diff
| app/helpers/custom_fields_helper.rb | ||
|---|---|---|
|
end
|
||
|
# Return a string used to display a custom value
|
||
|
def show_value(custom_value)
|
||
|
def show_value(custom_value, options = {})
|
||
|
return "" unless custom_value
|
||
|
format_value(custom_value.value, custom_value.custom_field.field_format)
|
||
|
|
||
|
options = {:textilize => true, :simple_format => false}.merge(options)
|
||
|
value = custom_value.value
|
||
|
if options[:simple_format]
|
||
|
value = simple_format_without_paragraph(h(value))
|
||
|
elsif options[:textilize] && custom_value.custom_field.textilized?
|
||
|
value = textilizable(value)
|
||
|
else
|
||
|
value = h(value)
|
||
|
end
|
||
|
|
||
|
format_value(value, custom_value.custom_field.field_format)
|
||
|
end
|
||
|
|
||
|
# Return a string used to display a custom value
|
||
| app/helpers/issues_helper.rb | ||
|---|---|---|
|
n = 0
|
||
|
ordered_values.compact.each do |value|
|
||
|
s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
|
||
|
s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
|
||
|
s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ show_value(value) }</td>\n"
|
||
|
n += 1
|
||
|
end
|
||
|
s << "</tr>\n"
|
||
| ... | ... | |
|
format_time(issue.created_on),
|
||
|
format_time(issue.updated_on)
|
||
|
]
|
||
|
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f)) }
|
||
|
custom_fields.each {|f| fields << show_value(issue.custom_value_for(f), :textilize => false) }
|
||
|
fields << issue.description
|
||
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
|
end
|
||
| app/helpers/timelog_helper.rb | ||
|---|---|---|
|
entry.hours.to_s.gsub('.', decimal_separator),
|
||
|
entry.comments
|
||
|
]
|
||
|
fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f)) }
|
||
|
fields += custom_fields.collect {|f| show_value(entry.custom_value_for(f), :textilize => false) }
|
||
|
|
||
|
csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
|
||
|
end
|
||
| app/models/custom_field.rb | ||
|---|---|---|
|
def before_validation
|
||
|
# make sure these fields are not searchable
|
||
|
self.searchable = false if %w(int float date bool).include?(field_format)
|
||
|
# and only text fields are textilized
|
||
|
self.textilized = false unless %w(string text).include?(field_format)
|
||
|
true
|
||
|
end
|
||
|
|
||
| app/views/custom_fields/_form.rhtml | ||
|---|---|---|
|
p_regexp = $("custom_field_regexp");
|
||
|
p_values = $("custom_field_possible_values");
|
||
|
p_searchable = $("custom_field_searchable");
|
||
|
p_textilized = $("custom_field_textilized");
|
||
|
p_default = $("custom_field_default_value");
|
||
|
|
||
|
p_default.setAttribute('type','text');
|
||
| ... | ... | |
|
case "list":
|
||
|
Element.hide(p_length.parentNode);
|
||
|
Element.hide(p_regexp.parentNode);
|
||
|
Element.hide(p_textilized.parentNode);
|
||
|
if (p_searchable) Element.show(p_searchable.parentNode);
|
||
|
Element.show(p_values);
|
||
|
break;
|
||
| ... | ... | |
|
p_default.setAttribute('type','checkbox');
|
||
|
Element.hide(p_length.parentNode);
|
||
|
Element.hide(p_regexp.parentNode);
|
||
|
Element.hide(p_textilized.parentNode);
|
||
|
if (p_searchable) Element.hide(p_searchable.parentNode);
|
||
|
Element.hide(p_values);
|
||
|
break;
|
||
|
case "date":
|
||
|
Element.hide(p_length.parentNode);
|
||
|
Element.hide(p_regexp.parentNode);
|
||
|
Element.hide(p_textilized.parentNode);
|
||
|
if (p_searchable) Element.hide(p_searchable.parentNode);
|
||
|
Element.hide(p_values);
|
||
|
break;
|
||
| ... | ... | |
|
case "int":
|
||
|
Element.show(p_length.parentNode);
|
||
|
Element.show(p_regexp.parentNode);
|
||
|
Element.hide(p_textilized.parentNode);
|
||
|
if (p_searchable) Element.hide(p_searchable.parentNode);
|
||
|
Element.hide(p_values);
|
||
|
break;
|
||
|
default:
|
||
|
Element.show(p_length.parentNode);
|
||
|
Element.show(p_regexp.parentNode);
|
||
|
Element.show(p_textilized.parentNode);
|
||
|
if (p_searchable) Element.show(p_searchable.parentNode);
|
||
|
Element.hide(p_values);
|
||
|
break;
|
||
| ... | ... | |
|
<p><%= f.check_box :is_for_all %></p>
|
||
|
<p><%= f.check_box :is_filter %></p>
|
||
|
<p><%= f.check_box :searchable %></p>
|
||
|
<p><%= f.check_box :textilized %></p>
|
||
|
|
||
|
<% when "UserCustomField" %>
|
||
|
<p><%= f.check_box :is_required %></p>
|
||
|
<p><%= f.check_box :editable %></p>
|
||
|
<p><%= f.check_box :textilized %></p>
|
||
|
<% when "ProjectCustomField" %>
|
||
|
<p><%= f.check_box :is_required %></p>
|
||
|
<p><%= f.check_box :searchable %></p>
|
||
|
<p><%= f.check_box :textilized %></p>
|
||
|
<% when "TimeEntryCustomField" %>
|
||
|
<p><%= f.check_box :is_required %></p>
|
||
| app/views/mailer/_issue_text_html.rhtml | ||
|---|---|---|
|
<li><%=l(:field_category)%>: <%=h issue.category %></li>
|
||
|
<li><%=l(:field_fixed_version)%>: <%=h issue.fixed_version %></li>
|
||
|
<% issue.custom_values.each do |c| %>
|
||
|
<li><%=h c.custom_field.name %>: <%=h show_value(c) %></li>
|
||
|
<li><%=h c.custom_field.name %>: <%= show_value(c) %></li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
| app/views/mailer/_issue_text_plain.rhtml | ||
|---|---|---|
|
<%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
|
||
|
<%=l(:field_category)%>: <%= issue.category %>
|
||
|
<%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
|
||
|
<% issue.custom_values.each do |c| %><%= c.custom_field.name %>: <%= show_value(c) %>
|
||
|
<% issue.custom_values.each do |c| %><%= c.custom_field.name %>: <%= show_value(c, :textilize => false) %>
|
||
|
<% end %>
|
||
|
<%= issue.description %>
|
||
| app/views/projects/show.rhtml | ||
|---|---|---|
|
<% end %>
|
||
|
<% @project.custom_values.each do |custom_value| %>
|
||
|
<% if !custom_value.value.blank? %>
|
||
|
<li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
|
||
|
<li><%= custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</ul>
|
||
| app/views/users/show.rhtml | ||
|---|---|---|
|
<% end %>
|
||
|
<% for custom_value in @custom_values %>
|
||
|
<% if !custom_value.value.blank? %>
|
||
|
<li><%=h custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
|
||
|
<li><%=h custom_value.custom_field.name%>: <%= show_value(custom_value) %></li>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<li><%=l(:label_registered_on)%>: <%= format_date(@user.created_on) %></li>
|
||
| app/views/versions/_overview.rhtml | ||
|---|---|---|
|
<ul>
|
||
|
<% version.custom_values.each do |custom_value| %>
|
||
|
<% if !custom_value.value.blank? %>
|
||
|
<li><%=h custom_value.custom_field.name %>: <%=h show_value(custom_value) %></li>
|
||
|
<li><%=h custom_value.custom_field.name %>: <%= show_value(custom_value) %></li>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</ul>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
field_group_by: Group results by
|
||
|
field_sharing: Sharing
|
||
|
field_parent_issue: Parent task
|
||
|
field_textilized: Textilized
|
||
|
|
||
|
setting_app_title: Application title
|
||
|
setting_app_subtitle: Application subtitle
|
||
| db/migrate/109_add_custom_fields_textilized.rb | ||
|---|---|---|
|
class AddCustomFieldsTextilized < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
add_column :custom_fields, :textilized, :boolean, :default => false
|
||
|
end
|
||
|
def self.down
|
||
|
remove_column :custom_fields, :textilized
|
||
|
end
|
||
|
end
|
||
| test/fixtures/custom_fields.yml | ||
|---|---|---|
|
field_format: date
|
||
|
default_value: ""
|
||
|
editable: true
|
||
|
custom_fields_010:
|
||
|
name: Textilizable cf
|
||
|
min_length: 0
|
||
|
regexp: ""
|
||
|
is_for_all: true
|
||
|
is_filter: true
|
||
|
type: IssueCustomField
|
||
|
max_length: 0
|
||
|
possible_values: ""
|
||
|
id: 10
|
||
|
is_required: false
|
||
|
field_format: string
|
||
|
textilized: true
|
||
| test/fixtures/custom_fields_trackers.yml | ||
|---|---|---|
|
custom_fields_trackers_006:
|
||
|
custom_field_id: 6
|
||
|
tracker_id: 3
|
||
|
custom_fields_trackers_007:
|
||
|
custom_field_id: 10
|
||
|
tracker_id: 1
|
||
| test/fixtures/custom_values.yml | ||
|---|---|---|
|
customized_id: 1
|
||
|
id: 17
|
||
|
value: '2009-12-01'
|
||
|
custom_values_018:
|
||
|
customized_type: Issue
|
||
|
custom_field_id: 10
|
||
|
customized_id: 1
|
||
|
id: 18
|
||
|
value: "*Issue* test: #1\n(powered by http://www.redmine.org/)"
|
||
| test/unit/helpers/custom_fields_helper_test.rb | ||
|---|---|---|
|
require File.dirname(__FILE__) + '/../../test_helper'
|
||
|
class CustomFieldsHelperTest < HelperTestCase
|
||
|
include ApplicationHelper
|
||
|
include ActionView::Helpers::TextHelper
|
||
|
include CustomFieldsHelper
|
||
|
include Redmine::I18n
|
||
|
|
||
| ... | ... | |
|
assert_equal 'Yes', format_value('1', 'bool')
|
||
|
assert_equal 'No', format_value('0', 'bool')
|
||
|
end
|
||
|
def test_show_value
|
||
|
cv = CustomValue.find(18)
|
||
|
str = cv.value
|
||
|
assert_equal str, show_value(cv, :textilize => false)
|
||
|
assert_equal str.gsub("\n","\n<br />"), show_value(cv, :simple_format => true)
|
||
|
assert_equal textilizable(str), show_value(cv)
|
||
|
end
|
||
|
end
|
||