Project

General

Profile

Feature #23996 » 0001-introduces-a-setting-to-have-durations-displayed-as-.patch

Jens Krämer, 2016-10-05 04:16

View differences:

app/helpers/application_helper.rb
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={})
app/helpers/queries_helper.rb
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
......
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
app/views/issues/_attributes.html.erb
<% 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? %>
app/views/issues/_edit.html.erb
<%= 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>
app/views/my/blocks/_timelog.html.erb
<% end %>
<div class="total-hours">
<p><%= l(:label_total_time) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
<p><%= l(:label_total_time) %>: <%= html_hours(l_hours_short(entries.sum(&:hours))) %></p>
</div>
<% if entries.any? %>
......
<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>
<td></td>
</tr>
<% entries_by_day[day].each do |entry| -%>
......
<td class="activity"><%= entry.activity %></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>
<td class="buttons">
<% if entry.editable_by?(@user) -%>
<%= link_to l(:button_edit), {:controller => 'timelog', :action => 'edit', :id => entry},
app/views/settings/_display.html.erb
<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>
app/views/timelog/_form.html.erb
<% end %>
</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| %>
app/views/timelog/_report_criteria.html.erb
<% 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)}) %>
app/views/timelog/report.html.erb
<% 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>
config/locales/de.yml
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
config/locales/en.yml
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
config/settings.yml
default: ''
time_format:
default: ''
timespan_format:
default: 'decimal'
user_format:
default: :firstname_lastname
format: symbol
lib/redmine/i18n.rb
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)
......
(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
test/unit/helpers/application_helper_test.rb
stubs(:request).returns(stub(:env => {'HTTP_REFERER' => "/path?utf8=\u2713&foo=bar"}))
assert_equal "/path?foo=bar", back_url
end
def test_hours_formatting
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
    (1-1/1)