Merge pull request #3750 from ulferts/fix/localized_values

Fix/localized values
pull/3757/head
Oliver Günther 9 years ago
commit 62cf8e7216
  1. 23
      frontend/app/components/inplace-edit/services/work-package-field.service.js
  2. 4
      lib/plugins/acts_as_journalized/lib/journal_formatter/fraction.rb
  3. 7
      lib/redmine/custom_field_format.rb
  4. 41
      spec/lib/redmine/custom_field_format_spec.rb

@ -365,30 +365,27 @@ function WorkPackageFieldService($q, $http, $filter, I18n, WorkPackagesHelper,
return null;
}
var mappings = {
var fieldMapping = {
dueDate: 'date',
startDate: 'date',
createdAt: 'datetime',
updatedAt: 'datetime'
};
}[field] || schema.props[field].type;
if (schema.props[field] && schema.props[field]) {
if (schema.props[field].type === 'Duration') {
switch(fieldMapping) {
case('Duration'):
var hours = moment.duration(value).asHours();
var formattedHours = $filter('number')(hours, 2);
return I18n.t('js.units.hour', { count: formattedHours });
}
if (schema.props[field].type === 'Boolean') {
case('Boolean'):
return value ? I18n.t('js.general_text_yes') : I18n.t('js.general_text_no');
}
if (workPackage.schema.props[field].type === 'Date') {
case('Date'):
return value;
}
case('Float'):
return $filter('number')(value);
default:
return WorkPackagesHelper.formatValue(value, fieldMapping);
}
return WorkPackagesHelper.formatValue(value, mappings[field]);
}
var WorkPackageFieldService = {

@ -27,11 +27,13 @@
#++
class JournalFormatter::Fraction < JournalFormatter::Attribute
include ActionView::Helpers::NumberHelper
def format_values(values)
values.map do |v|
v.nil? ?
nil :
'%0.02f' % v.to_f
number_with_precision(v.to_f, precision: 2)
end
end
end

@ -30,6 +30,7 @@
module Redmine
class CustomFieldFormat
include Redmine::I18n
include ActionView::Helpers::NumberHelper
cattr_accessor :available
@@available = {}
@ -56,12 +57,16 @@ module Redmine
l(is_true ? :general_text_Yes : :general_text_No)
end
['string', 'text', 'int', 'float', 'list'].each do |name|
['string', 'text', 'int', 'list'].each do |name|
define_method("format_as_#{name}") {|value|
return value.to_s
}
end
def format_as_float(value)
number_with_delimiter(value.to_s)
end
['user', 'version'].each do |name|
define_method("format_as_#{name}") {|value|
return value.blank? ? '' : name.classify.constantize.find_by(id: value.to_i).to_s

@ -0,0 +1,41 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe Redmine::CustomFieldFormat do
let(:instance) { described_class.new 'test', label: 'blubs', order: '1' }
describe '#format_value' do
it 'returns a localized float' do
I18n.with_locale(:de) do
expect(instance.format_as_float('5.67')).to eql '5,67'
end
end
end
end
Loading…
Cancel
Save