summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-11-18 12:42:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-11-18 12:42:20 +0000
commit5495e6f3424f44faa16b4d03dfe1e76a30e50469 (patch)
treef37543a819979725a0a916af660e49095ff303e3
parent9c3e3a4276612f60552379518ab8c9a11319e73b (diff)
downloadredmine-5495e6f3424f44faa16b4d03dfe1e76a30e50469.tar.gz
redmine-5495e6f3424f44faa16b4d03dfe1e76a30e50469.zip
Introduce a setting to change the display format of timespans to h:mm (#23996).
Patch by Jens Kraemer. git-svn-id: http://svn.redmine.org/redmine/trunk@15965 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/helpers/application_helper.rb2
-rw-r--r--app/helpers/queries_helper.rb9
-rw-r--r--app/views/issues/_attributes.html.erb2
-rw-r--r--app/views/issues/_edit.html.erb2
-rw-r--r--app/views/my/blocks/_timelog.html.erb4
-rw-r--r--app/views/settings/_display.html.erb2
-rw-r--r--app/views/timelog/_form.html.erb2
-rw-r--r--app/views/timelog/_report_criteria.html.erb4
-rw-r--r--app/views/timelog/report.html.erb4
-rw-r--r--config/locales/de.yml1
-rw-r--r--config/locales/en.yml1
-rw-r--r--config/locales/fr.yml1
-rw-r--r--config/settings.yml2
-rw-r--r--lib/redmine/i18n.rb16
-rw-r--r--test/unit/helpers/application_helper_test.rb20
15 files changed, 59 insertions, 13 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e1505f824..61b29e740 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -426,7 +426,7 @@ module ApplicationHelper
end
def html_hours(text)
- text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>').html_safe
+ text.gsub(%r{(\d+)([\.:])(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">\2\3</span>').html_safe
end
def authoring(created, author, options={})
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index 57a45312e..ea551ecf0 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -149,7 +149,12 @@ module QueriesHelper
def total_tag(column, value)
label = content_tag('span', "#{column.caption}:")
- value = content_tag('span', format_object(value), :class => 'value')
+ value = if [:hours, :spent_hours, :total_spent_hours, :estimated_hours].include? column.name
+ format_hours(value)
+ else
+ format_object(value)
+ end
+ value = content_tag('span', value, :class => 'value')
content_tag('span', label + " " + value, :class => "total-for-#{column.name.to_s.dasherize}")
end
@@ -184,6 +189,8 @@ module QueriesHelper
content_tag('span',
value.to_s(issue) {|other| link_to_issue(other, :subject => false, :tracker => false)}.html_safe,
:class => value.css_classes_for(issue))
+ when :hours, :spent_hours, :total_spent_hours, :estimated_hours
+ format_hours(value)
else
format_object(value)
end
diff --git a/app/views/issues/_attributes.html.erb b/app/views/issues/_attributes.html.erb
index 960256e44..f8acef58b 100644
--- a/app/views/issues/_attributes.html.erb
+++ b/app/views/issues/_attributes.html.erb
@@ -65,7 +65,7 @@
<% end %>
<% if @issue.safe_attribute? 'estimated_hours' %>
-<p><%= f.text_field :estimated_hours, :size => 3, :required => @issue.required_attribute?('estimated_hours') %> <%= l(:field_hours) %></p>
+<p><%= f.text_field :estimated_hours, :size => 3, :required => @issue.required_attribute?('estimated_hours'), :value => format_hours(@issue.estimated_hours) %> <%= l(:field_hours) %></p>
<% end %>
<% if @issue.safe_attribute?('done_ratio') && Issue.use_field_for_done_ratio? %>
diff --git a/app/views/issues/_edit.html.erb b/app/views/issues/_edit.html.erb
index 3291ba737..0a642f22c 100644
--- a/app/views/issues/_edit.html.erb
+++ b/app/views/issues/_edit.html.erb
@@ -14,7 +14,7 @@
<%= labelled_fields_for :time_entry, @time_entry do |time_entry| %>
<div class="splitcontent">
<div class="splitcontentleft">
- <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
+ <p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time, :value => format_hours(@time_entry.hours) %> <%= l(:field_hours) %></p>
</div>
<div class="splitcontentright">
<p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p>
diff --git a/app/views/my/blocks/_timelog.html.erb b/app/views/my/blocks/_timelog.html.erb
index 566831132..5b8820c19 100644
--- a/app/views/my/blocks/_timelog.html.erb
+++ b/app/views/my/blocks/_timelog.html.erb
@@ -46,7 +46,7 @@ entries_by_day = entries.group_by(&:spent_on)
<tr class="odd">
<td><strong><%= day == User.current.today ? l(:label_today).titleize : format_date(day) %></strong></td>
<td colspan="2"></td>
- <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
+ <td class="hours"><em><%= html_hours(l_hours_short(entries_by_day[day].sum(&:hours))) %></em></td>
</tr>
<% entries_by_day[day].each do |entry| -%>
<tr class="time-entry hascontextmenu">
@@ -56,7 +56,7 @@ entries_by_day = entries.group_by(&:spent_on)
</td>
<td class="subject"><%= entry.project %> <%= h(' - ') + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
<td class="comments"><%= entry.comments %></td>
- <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
+ <td class="hours"><%= html_hours(l_hours_short(entry.hours)) %></td>
</tr>
<% end -%>
<% end -%>
diff --git a/app/views/settings/_display.html.erb b/app/views/settings/_display.html.erb
index be3e70e34..93eaa6ef4 100644
--- a/app/views/settings/_display.html.erb
+++ b/app/views/settings/_display.html.erb
@@ -15,6 +15,8 @@
<p><%= setting_select :time_format, Setting::TIME_FORMATS.collect {|f| [::I18n.l(Time.now, :locale => locale, :format => f), f]}, :blank => :label_language_based %></p>
+<p><%= setting_select :timespan_format, [["%.2f" % 0.75, 'decimal'], ['0:45 h', 'minutes']], :blank => false %></p>
+
<p><%= setting_select :user_format, @options[:user_format] %></p>
<p><%= setting_check_box :gravatar_enabled %></p>
diff --git a/app/views/timelog/_form.html.erb b/app/views/timelog/_form.html.erb
index 5b0ec6aac..59198d0fb 100644
--- a/app/views/timelog/_form.html.erb
+++ b/app/views/timelog/_form.html.erb
@@ -18,7 +18,7 @@
</span>
</p>
<p><%= f.date_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
- <p><%= f.text_field :hours, :size => 6, :required => true %></p>
+ <p><%= f.text_field :hours, :size => 6, :required => true, :value => format_hours(@time_entry.hours) %></p>
<p><%= f.text_field :comments, :size => 100, :maxlength => 1024 %></p>
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
<% @time_entry.custom_field_values.each do |value| %>
diff --git a/app/views/timelog/_report_criteria.html.erb b/app/views/timelog/_report_criteria.html.erb
index c86b219d1..a74cdbfec 100644
--- a/app/views/timelog/_report_criteria.html.erb
+++ b/app/views/timelog/_report_criteria.html.erb
@@ -8,9 +8,9 @@
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(hours_for_value, @report.columns, period.to_s)); total += sum -%>
- <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
+ <td class="hours"><%= html_hours(l_hours_short(sum)) if sum > 0 %></td>
<% end -%>
- <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
+ <td class="hours"><%= html_hours(l_hours_short(total)) if total > 0 %></td>
</tr>
<% if criterias.length > level+1 -%>
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
diff --git a/app/views/timelog/report.html.erb b/app/views/timelog/report.html.erb
index 05ad08b93..ecab7dea4 100644
--- a/app/views/timelog/report.html.erb
+++ b/app/views/timelog/report.html.erb
@@ -52,9 +52,9 @@
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(@report.hours, @report.columns, period.to_s)); total += sum -%>
- <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
+ <td class="hours"><%= html_hours(l_hours_short(sum)) if sum > 0 %></td>
<% end -%>
- <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
+ <td class="hours"><%= html_hours(l_hours_short(total)) if total > 0 %></td>
</tr>
</tbody>
</table>
diff --git a/config/locales/de.yml b/config/locales/de.yml
index 5bdb484a7..60db8a608 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -1047,6 +1047,7 @@ de:
setting_thumbnails_enabled: Vorschaubilder von Dateianhängen anzeigen
setting_thumbnails_size: Größe der Vorschaubilder (in Pixel)
setting_time_format: Zeitformat
+ setting_timespan_format: Format für Zeitspannen
setting_unsubscribe: Erlaubt Benutzern das eigene Benutzerkonto zu löschen
setting_user_format: Benutzer-Anzeigeformat
setting_welcome_text: Willkommenstext
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 56a06c7d5..eae146951 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -389,6 +389,7 @@ en:
setting_autologin: Autologin
setting_date_format: Date format
setting_time_format: Time format
+ setting_timespan_format: Time span format
setting_cross_project_issue_relations: Allow cross-project issue relations
setting_cross_project_subtasks: Allow cross-project subtasks
setting_issue_list_default_columns: Default columns displayed on the issue list
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index d0ef34c46..95c5bf9dc 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -401,6 +401,7 @@ fr:
setting_autologin: Durée maximale de connexion automatique
setting_date_format: Format de date
setting_time_format: Format d'heure
+ setting_timespan_format: Format des temps en heures
setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets
setting_cross_project_subtasks: Autoriser les sous-tâches dans des projets différents
setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes
diff --git a/config/settings.yml b/config/settings.yml
index 807f9b7a7..b9a82583f 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -153,6 +153,8 @@ date_format:
default: ''
time_format:
default: ''
+timespan_format:
+ default: 'decimal'
user_format:
default: :firstname_lastname
format: symbol
diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb
index 7b4495e0e..dfeaf474e 100644
--- a/lib/redmine/i18n.rb
+++ b/lib/redmine/i18n.rb
@@ -45,11 +45,11 @@ module Redmine
def l_hours(hours)
hours = hours.to_f
- l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
+ l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => format_hours(hours))
end
def l_hours_short(hours)
- l(:label_f_hour_short, :value => ("%.2f" % hours.to_f))
+ l(:label_f_hour_short, :value => format_hours(hours.to_f))
end
def ll(lang, str, arg=nil)
@@ -82,6 +82,18 @@ module Redmine
(include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
end
+ def format_hours(hours)
+ return "" if hours.blank?
+
+ if Setting.timespan_format == 'minutes'
+ h = hours.floor
+ m = ((hours - h) * 60).round
+ "%d:%02d" % [ h, m ]
+ else
+ "%.2f" % hours.to_f
+ end
+ end
+
def day_name(day)
::I18n.t('date.day_names')[day % 7]
end
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index bc3063d52..064d4141c 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -1544,4 +1544,24 @@ RAW
stubs(:request).returns(stub(:env => {'HTTP_REFERER' => "/path?utf8=\u2713&foo=bar"}))
assert_equal "/path?foo=bar", back_url
end
+
+ def test_hours_formatting
+ set_language_if_valid 'en'
+
+ with_settings :timespan_format => 'minutes' do
+ assert_equal '0:45', format_hours(0.75)
+ assert_equal '0:45 h', l_hours_short(0.75)
+ assert_equal '0:45 hour', l_hours(0.75)
+ end
+ with_settings :timespan_format => 'decimal' do
+ assert_equal '0.75', format_hours(0.75)
+ assert_equal '0.75 h', l_hours_short(0.75)
+ assert_equal '0.75 hour', l_hours(0.75)
+ 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')
+ assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">.75</span>', html_hours('0.75')
+ end
end