[#4289] Ported the billing plugin's timesheet hooks.

This commit is contained in:
Eric Davis
2010-07-23 10:16:41 -07:00
parent 7192adb231
commit e541270461
14 changed files with 180 additions and 15 deletions
@@ -0,0 +1,11 @@
module RedmineRate
module Hooks
class PluginTimesheetViewTimesheetsReportHeaderTagsHook < Redmine::Hook::ViewListener
def plugin_timesheet_view_timesheets_report_header_tags(context={})
return content_tag(:style,
'tr.missing-rate td.cost { color: red; }',
:type => 'text/css')
end
end
end
end
@@ -2,7 +2,7 @@ module RedmineRate
module Hooks
class PluginTimesheetViewsTimesheetGroupHeaderHook < Redmine::Hook::ViewListener
def plugin_timesheet_views_timesheet_group_header(context={})
return ''
return content_tag(:th, l(:rate_cost), :width => '8%')
end
end
end
@@ -1,9 +1,18 @@
module RedmineRate
module Hooks
class PluginTimesheetViewsTimesheetTimeEntryHook < Redmine::Hook::ViewListener
include TimesheetHookHelper
def plugin_timesheet_views_timesheet_time_entry(context={})
return ''
cost = cost_item(context[:time_entry])
if cost
td_cell(number_to_currency(cost))
else
td_cell('&nbsp;')
end
end
end
end
end
@@ -1,8 +1,16 @@
module RedmineRate
module Hooks
class PluginTimesheetViewsTimesheetTimeEntrySumHook < Redmine::Hook::ViewListener
include TimesheetHookHelper
def plugin_timesheet_views_timesheet_time_entry_sum(context={})
return ''
time_entries = context[:time_entries]
costs = time_entries.collect {|time_entry| cost_item(time_entry)}.compact.sum
if costs >= 0
return td_cell(number_to_currency(costs))
else
return td_cell('&nbsp;')
end
end
end
end
@@ -1,8 +1,20 @@
module RedmineRate
module Hooks
class PluginTimesheetViewsTimesheetsTimeEntryRowClassHook < Redmine::Hook::ViewListener
include TimesheetHookHelper
def plugin_timesheet_views_timesheets_time_entry_row_class(context={})
return ''
time_entry = context[:time_entry]
return "" unless time_entry
cost = cost_item(time_entry)
return "" unless cost # Permissions
if cost && cost <= 0
return "missing-rate"
else
return ""
end
end
end
end
@@ -0,0 +1,14 @@
module TimesheetHookHelper
# Returns the cost of a time entry, checking user permissions
def cost_item(time_entry)
if User.current.logged? && (User.current.allowed_to?(:view_rate, time_entry.project) || User.current.admin?)
return time_entry.cost
else
return nil
end
end
def td_cell(html)
return content_tag(:td, html, :align => 'right', :class => 'cost')
end
end