mirror of
https://github.com/redmine/redmine.git
synced 2025-11-05 04:45:57 +01:00
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
This commit is contained in:
@@ -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={})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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? %>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 -%>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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| %>
|
||||
|
||||
@@ -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)}) %>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -153,6 +153,8 @@ date_format:
|
||||
default: ''
|
||||
time_format:
|
||||
default: ''
|
||||
timespan_format:
|
||||
default: 'decimal'
|
||||
user_format:
|
||||
default: :firstname_lastname
|
||||
format: symbol
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user