Project

General

Profile

Error #268

Wrong labels in roadmap for "Due in" values

Added by Sebastian Mehner over 11 years ago. Updated about 11 years ago.

Status:
Resolved
Priority:
Normal
Category:
Roadmap
Target version:
Start date:
2010-04-28
Due date:
2010-08-23
% Done:

100%

Estimated time:
Source:
Detected on version:
Redmine version:
Milestones:

Description

I have the problem, that all of the "Due in" values in Advanced Roadmap are labeled as hours. I don't quite know how this error evolves since the labels here in your project are correct "hours/days/weeks". I'm running Redmine 0.9.2.

Any suggestions?


Files

RoadmapTotal.JPG (11.8 KB) RoadmapTotal.JPG Screenshot Sebastian Mehner, 2010-04-28 11:38
projects_roadmap.png (5.52 KB) projects_roadmap.png Andrew Rudenko, 2010-08-19 10:29
versions_show.png (4.17 KB) versions_show.png Andrew Rudenko, 2010-08-19 10:29
milestones_show.png (6.19 KB) milestones_show.png Andrew Rudenko, 2010-08-19 10:29
#1

Updated by Andrew Rudenko about 11 years ago

I've resolved this issue by modifying the existing code and extending i18n.rb Redmine's lib.

First, modify show.rhtml for milestones and versions views, and roadmap.rhtml for projects view inside of ./vendor/plugins/advanced_roadmap/app/views by providing l_days and l_weeks functions

Index: vendor/plugins/advanced_roadmap/app/views/milestones/show.rthml
===================================================================
@@ -58,1 +58,1 @@
-        <td width="340px" class="total-hours"><%= "#{l_hours(rest_hours)} / #{l_hours(rest_hours / 8.0)} / #{l_hours(rest_hours / 40.0)}" %></td>
+        <td width="340px" class="total-hours"><%= "#{l_hours(rest_hours)} / #{l_days(rest_hours / 8.0)} / #{l_weeks(rest_hours / 40.0)}" %></td>
Index: vendor/plugins/advanced_roadmap/app/views/projects/roadmap.rthml
===================================================================
@@ -49,1 +49,1 @@
-      <td width="340px" class="total-hours"><%= "#{l_hours(rest_hours)} / #{l_hours(rest_hours / 8.0)} / #{l_hours(rest_hours / 40.0)}" %></td>
+      <td width="340px" class="total-hours"><%= "#{l_hours(rest_hours)} / #{l_days(rest_hours / 8.0)} / #{l_weeks(rest_hours / 40.0)}" %></td>
Index: vendor/plugins/advanced_roadmap/app/views/versions/show.rthml
===================================================================
@@ -26,1 +26,1 @@
-        <td width="240px" class="total-hours"><%= "#{l_hours(@version.rest_hours)} <br/> #{l_hours(@version.rest_hours / 8.0)} <br/> #{l_hours(@version.rest_hours / 40.0)}" %></td>
+        <td width="240px" class="total-hours"><%= "#{l_hours(@version.rest_hours)} <br/> #{l_days(@version.rest_hours / 8.0)} <br/> #{l_weeks(@version.rest_hours / 40.0)}" %></td>

Second, modify locales YAML file(s) to properly display output values from l_days and l_weeks functions inside of vendor/plugins/advanced_roadmap/config/locales

Index: vendor/plugins/advanced_roadmap/config/locales/en.yml
===================================================================
@@ -2,4 +2,4 @@
-  label_f_day: %.2f day
-  label_f_day_plural: %.2f days
-  label_f_week: %.2f week
-  label_f_week_plural: %.2f weeks
+  label_f_day: "{{value}} day" 
+  label_f_day_plural: "{{value}} days" 
+  label_f_week: "{{value}} week" 
+  label_f_week_plural: "{{value}} weeks" 

Third, extend i18b.rb Redmine's library with l_days and l_weeks functions inside of lib/redmine

Index: lib/redmine/i18n.rb
===================================================================
@@ -29,8 +29,18 @@
     def l_hours(hours)
       hours = hours.to_f
       l((hours < 2.0 ? :label_f_hour : :label_f_hour_plural), :value => ("%.2f" % hours.to_f))
     end

+    def l_days(days)
+      days = days.to_f
+      l((days < 2.0 ? :label_f_day : :label_f_day_plural), :value => ("%.2f" % days.to_f))
+    end
+ 
+    def l_weeks(weeks)
+      weeks = weeks.to_f
+      l((weeks < 2.0 ? :label_f_week : :label_f_week_plural), :value => ("%.2f" % weeks.to_f))
+    end
+ 
    def ll(lang, str, value=nil)
      ::I18n.t(str.to_s, :value => value, :locale => lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" })
    end

Of course, we might create/extend helpers for milestones, projects and versions with l_days and l_weeks functions but I prefer to extend i18n.rb instead due to leak of experience how to extend helpers :).

Fourth, restart your application server (webrick, mongrel, apache+mod_passenger, etc.) and Enjoy!


#2

Updated by Andrew Rudenko about 11 years ago

Updated Third action:
as I said before, we may not modify i18n.rb Redmine's library but put all necessary code into plugin helpers.

I'm a newbie in Ruby on Rails so sorry if do something wrongly. I understand that the code below conflicts with DRY principals of the RoR but don't know how to force this code work in compliance to DRY.
so what I have,

Third, create helpers inside of plugin folder, and add l_days and l_weeks functions there
vendor/plugins/advanced_roadmap/app/helpers/milestones_helper.rb

module MilestonesHelper

  def l_days(days)
    days = days.to_f
    l((days < 2.0 ? :label_f_day : :label_f_day_plural), :value => ("%.2f" % days.to_f))
  end

  def l_weeks(weeks)
    weeks = weeks.to_f
    l((weeks < 2.0 ? :label_f_week : :label_f_week_plural), :value => ("%.2f" % weeks.to_f))
  end

end

vendor/plugins/advanced_roadmap/app/helpers/projects_helper.rb
module ProjectsHelper

  def l_days(days)
    days = days.to_f
    l((days < 2.0 ? :label_f_day : :label_f_day_plural), :value => ("%.2f" % days.to_f))
  end

  def l_weeks(weeks)
    weeks = weeks.to_f
    l((weeks < 2.0 ? :label_f_week : :label_f_week_plural), :value => ("%.2f" % weeks.to_f))
  end

end

vendor/plugins/advanced_roadmap/app/helpers/versions_helper.rb
module VersionsHelper

  def l_days(days)
    days = days.to_f
    l((days < 2.0 ? :label_f_day : :label_f_day_plural), :value => ("%.2f" % days.to_f))
  end

  def l_weeks(weeks)
    weeks = weeks.to_f
    l((weeks < 2.0 ? :label_f_week : :label_f_week_plural), :value => ("%.2f" % weeks.to_f))
  end

end

#3

Updated by Emilio González Montaña about 11 years ago

  • Status changed from New to In progress
  • Target version set to Advanced roadmap 0.1.0
#4

Updated by Emilio González Montaña about 11 years ago

  • Due date set to 2010-08-23
  • Status changed from In progress to Resolved
  • % Done changed from 0 to 100

Thanks Andrew.

Also available in: Atom PDF