From: Tomas Sedovic tomas@sedovic.cz
https://bugzilla.redhat.com/show_bug.cgi?id=767100
The uptime output was too long when the value exceeded 1 day. Moreover, it was not using i18n which made it untranslatable.
Now it uses standard I18n values for displaying time difference, which incidentally makes the output long enough to fit into the pretty view deployment boxes.
The boxes are a bit wider, too. That will hopefully make the translators' jobs a bit easier. --- src/app/helpers/application_helper.rb | 33 +++++++++++++++++++-------------- src/app/stylesheets/layout.scss | 4 ++-- src/config/locales/en.yml | 5 +++++ 3 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/app/helpers/application_helper.rb b/src/app/helpers/application_helper.rb index 654013c..9e24112 100644 --- a/src/app/helpers/application_helper.rb +++ b/src/app/helpers/application_helper.rb @@ -112,21 +112,26 @@ module ApplicationHelper title.split(' ').join('_').downcase end
- def count_uptime(time) - if time - result_string = [] - - seconds = time % 60 - time = (time - seconds) / 60 - minutes = time % 60 - time = (time - minutes) / 60 - hours = time % 24 - time = (time - hours) / 24 - days = time % 7 - - result_string<< "#{days.to_i} #{(days.to_i > 1 ? 'days' : 'day')}" if days != 0 - result_string<<"#{"%02d"%hours.to_i}:#{"%02d"%minutes.to_i}:#{"%02d"%seconds.to_i}" - result_string.join(", ") + def count_uptime(delta_seconds) + if delta_seconds + seconds = delta_seconds.to_i + minutes = seconds / 60 + hours = minutes / 60 + days = hours / 24 + months = days / 31 + + case + when months > 0 + I18n.t('datetime.distance_in_words.x_months', :count => months) + when days > 0 + I18n.t('datetime.distance_in_words.x_days', :count => days) + when hours > 0 + I18n.t('datetime.distance_in_words.x_hours', :count => hours) + when minutes > 0 + I18n.t('datetime.distance_in_words.x_minutes', :count => minutes) + else + I18n.t('datetime.distance_in_words.x_seconds', :count => seconds) + end else "N/A" end diff --git a/src/app/stylesheets/layout.scss b/src/app/stylesheets/layout.scss index 18a7c53..5417d36 100644 --- a/src/app/stylesheets/layout.scss +++ b/src/app/stylesheets/layout.scss @@ -2176,7 +2176,7 @@ $font-family-primary: Helvetica, Arial, "Lucida Grande", sans-serif; /* todo: move this elsewhere */
$deployment-large-height: 154px; -$deployment-large-width: 154px; +$deployment-large-width: 166px; $deployment-large-padding: 8px;
ul.deployment-array.large{ @@ -2240,7 +2240,7 @@ ul.deployment-array.large{ }
li.deployment + li.deployment{ - margin-left: 38px; + margin-left: 23px; }
li.deployment.pending, li.deployment.alert, li.deployment.failure{ diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index 94e9873..a996011 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -1,5 +1,10 @@ en: dashboard: Dashboard + datetime: + distance_in_words: + x_hours: + one: 1 hour + other: %{count} hours users: users_groups: "Users & Groups" return_to: "Return to:"