Feature #22024 » 22024-v3.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
when Integer
|
||
|
object.to_s
|
||
|
when Float
|
||
|
sprintf "%.2f", object
|
||
|
number_with_delimiter(sprintf('%.2f', object), delimiter: nil)
|
||
|
when User, Group
|
||
|
html ? link_to_principal(object) : object.to_s
|
||
|
when Project
|
||
| ... | ... | |
|
def html_hours(text)
|
||
|
text.gsub(
|
||
|
%r{(\d+)([\.:])(\d+)},
|
||
|
%r{(\d+)([\.,:])(\d+)},
|
||
|
'<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>'
|
||
|
).html_safe
|
||
|
end
|
||
| lib/redmine/export/pdf/issues_pdf_helper.rb | ||
|---|---|---|
|
module Export
|
||
|
module PDF
|
||
|
module IssuesPdfHelper
|
||
|
include ActionView::Helpers::NumberHelper
|
||
|
# Returns a PDF string of a single issue
|
||
|
def issue_to_pdf(issue, assoc={})
|
||
|
pdf = ITCPDF.new(current_language)
|
||
| ... | ... | |
|
elsif value.is_a?(Time)
|
||
|
format_time(value)
|
||
|
elsif value.is_a?(Float)
|
||
|
sprintf "%.2f", value
|
||
|
number_with_delimiter(sprintf('%.2f', value), delimiter: nil)
|
||
|
else
|
||
|
value
|
||
|
end
|
||
| lib/redmine/field_format.rb | ||
|---|---|---|
|
end
|
||
|
def validate_single_value(custom_field, value, customized=nil)
|
||
|
value = normalize_float(value)
|
||
|
errs = super
|
||
|
errs << ::I18n.t('activerecord.errors.messages.invalid') unless (Kernel.Float(value) rescue nil)
|
||
|
errs << ::I18n.t('activerecord.errors.messages.invalid') unless Kernel.Float(value, exception: false)
|
||
|
errs
|
||
|
end
|
||
| lib/redmine/i18n.rb | ||
|---|---|---|
|
module Redmine
|
||
|
module I18n
|
||
|
include ActionView::Helpers::NumberHelper
|
||
|
def self.included(base)
|
||
|
base.extend Redmine::I18n
|
||
|
end
|
||
| ... | ... | |
|
m = ((hours - h) * 60).round
|
||
|
"%d:%02d" % [h, m]
|
||
|
else
|
||
|
"%.2f" % hours.to_f
|
||
|
number_with_delimiter(sprintf('%.2f', hours.to_f), delimiter: nil)
|
||
|
end
|
||
|
end
|
||
|
# Will consider language specific separator in user input
|
||
|
# and normalize them to a unified format to be accepted by Kernel.Float().
|
||
|
#
|
||
|
# @param value [String] A string represenation of a float value.
|
||
|
#
|
||
|
# @note The delimiter cannot be used here if it is a decimal point since it
|
||
|
# will clash with the dot separator.
|
||
|
def normalize_float(value)
|
||
|
separator = ::I18n.t('number.format.separator')
|
||
|
value.gsub(/[#{separator}]/, separator => '.')
|
||
|
end
|
||
|
def day_name(day)
|
||
|
::I18n.t('date.day_names')[day % 7]
|
||
|
end
|
||
| test/helpers/application_helper_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def test_format_hours_should_use_locale_decimal_separator
|
||
|
to_test = {'en' => '0.75', 'de' => '0,75'}
|
||
|
with_settings :timespan_format => 'decimal' do
|
||
|
to_test.each do |locale, expected|
|
||
|
with_locale locale do
|
||
|
assert_equal expected, format_hours(0.75)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_html_hours
|
||
|
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>',
|
||
|
html_hours('0:45')
|
||
| test/unit/lib/redmine/export/pdf/issues_pdf_test.rb | ||
|---|---|---|
|
time_entry = TimeEntry.create!(:spent_on => Date.today, :hours => 4.3432, :user => user, :author => user,
|
||
|
:project_id => 1, :issue => issue, :activity => TimeEntryActivity.first)
|
||
|
results = fetch_row_values(issue, query, 0)
|
||
|
assert_equal ["2", "Add ingredients categories", "4.34"], results
|
||
|
to_test = {'en' => '4.34', 'de' => '4,34'}
|
||
|
to_test.each do |locale, expected|
|
||
|
with_locale locale do
|
||
|
results = fetch_row_values(issue, query, 0)
|
||
|
assert_equal ['2', 'Add ingredients categories', expected], results
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_fetch_row_values_should_be_able_to_handle_parent_issue_subject
|
||
| test/unit/lib/redmine/field_format/numeric_format_test.rb | ||
|---|---|---|
|
class Redmine::NumericFieldFormatTest < ActionView::TestCase
|
||
|
include ApplicationHelper
|
||
|
fixtures :projects, :users, :issue_statuses, :enumerations,
|
||
|
:trackers, :projects_trackers, :roles, :member_roles,
|
||
|
:members, :enabled_modules
|
||
|
def setup
|
||
|
User.current = nil
|
||
|
end
|
||
| ... | ... | |
|
assert_equal 3, field.format.formatted_custom_value(self, custom_value, false)
|
||
|
assert_equal '<a href="http://foo/3" class="external">3</a>', field.format.formatted_custom_value(self, custom_value, true)
|
||
|
end
|
||
|
def test_float_field_value_should_validate_when_given_with_various_separator
|
||
|
field = IssueCustomField.generate!(field_format: 'float')
|
||
|
issue = Issue.generate!(tracker: Tracker.find(1), status: IssueStatus.find(1), priority: IssuePriority.find(6))
|
||
|
to_test = {'en' => '3.33', 'de' => '3,33'}
|
||
|
to_test.each do |locale, expected|
|
||
|
with_locale locale do
|
||
|
assert field.format.validate_single_value(field, expected, issue)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_float_field_should_format_with_various_locale_separator
|
||
|
field = IssueCustomField.generate!(field_format: 'float')
|
||
|
issue = Issue.generate!(tracker: Tracker.find(1), status: IssueStatus.find(1), priority: IssuePriority.find(6))
|
||
|
issue.custom_field_values = { field.id => '1234.56' }
|
||
|
issue.save!
|
||
|
to_test = {'en' => '1234.56', 'de' => '1234,56'}
|
||
|
to_test.each do |locale, expected|
|
||
|
with_locale locale do
|
||
|
assert_equal expected, format_object(issue.reload.custom_field_values.last, false)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »