code_junkie

Redmine - Add “Spent Time” Field to Issues Display

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. field_spent_hours: Spent time
  2.  
  3. field_spent_hours: Spent time
  4.  
  5. # Based on http://github.com/edavis10/question_plugin/blob/master/lib/question_query_patch.rb
  6. require_dependency 'query'
  7.  
  8. module QueryPatch
  9. def self.included(base) # :nodoc:
  10. base.extend(ClassMethods)
  11.  
  12. # Same as typing in the class
  13. base.class_eval do
  14. unloadable # Send unloadable so it will not be unloaded in development
  15. base.add_available_column(QueryColumn.new(:spent_hours))
  16. end
  17.  
  18. end
  19.  
  20. module ClassMethods
  21. unless Query.respond_to?(:available_columns=)
  22. # Setter for +available_columns+ that isn't provided by the core.
  23. def available_columns=(v)
  24. self.available_columns = (v)
  25. end
  26. end
  27.  
  28. unless Query.respond_to?(:add_available_column)
  29. # Method to add a column to the +available_columns+ that isn't provided by the core.
  30. def add_available_column(column)
  31. self.available_columns << (column)
  32. end
  33. end
  34. end
  35. end
  36.  
  37. require 'spent_time_query_patch'
  38.  
  39. Query.class_eval do
  40. include QueryPatch
  41. end
  42.  
  43. base.add_available_column(QueryColumn.new(:spent_hours,
  44. :sortable => "(select sum(hours) from time_entries where time_entries.issue_id = t0_r0)")
  45. )
  46.  
  47. when 'Fixnum', 'Float'
  48. if column.name == :done_ratio
  49. progress_bar(value, :width => '80px')
  50. else
  51. value.to_s
  52. end
  53.  
  54. when 'Fixnum', 'Float'
  55. if column.name == :done_ratio
  56. progress_bar(value, :width => '80px')
  57. elsif column.name == :spent_hours
  58. sprintf "%.2f", value
  59. else
  60. value.to_s
  61. end
Add Comment
Please, Sign In to add comment