Feature #9994 » timelog_report_links.diff
| app/controllers/timelog_controller.rb | ||
|---|---|---|
| 49 | 49 |
retrieve_date_range |
| 50 | 50 | |
| 51 | 51 |
scope = TimeEntry.visible.spent_between(@from, @to) |
| 52 |
scope = scope.on_user(params[:member]) unless params[:member].nil? |
|
| 53 |
scope = scope.on_activity(params[:activity]) unless params[:activity].nil? |
|
| 54 |
scope = scope.on_tracker(params[:tracker]) unless params[:tracker].nil? |
|
| 55 |
scope = scope.on_version(params[:version]) unless params[:version].nil? |
|
| 56 |
scope = scope.on_category(params[:category]) unless params[:category].nil? |
|
| 57 |
scope = scope.on_project(Project.find(params[:project].to_i), false) unless params[:project].nil? |
|
| 58 |
scope = scope.on_project(Project.find(params[:parent_project].to_i), true) unless params[:parent_project].nil? |
|
| 59 |
@issue = Issue.find(params[:issue]) unless params[:issue].nil? |
|
| 52 | 60 |
if @issue |
| 53 | 61 |
scope = scope.on_issue(@issue) |
| 54 | 62 |
elsif @project |
| app/models/time_entry.rb | ||
|---|---|---|
| 65 | 65 |
{}
|
| 66 | 66 |
end |
| 67 | 67 |
} |
| 68 | ||
| 68 |
scope :on_user, lambda {|user| {
|
|
| 69 |
:conditions => ["#{TimeEntry.table_name}.user_id = ?", user]
|
|
| 70 |
}} |
|
| 71 |
scope :on_activity, lambda {|activity| {
|
|
| 72 |
:conditions => ["#{TimeEntry.table_name}.activity_id = ?", activity]
|
|
| 73 |
}} |
|
| 74 |
scope :on_tracker, lambda {|tracker| {
|
|
| 75 |
:include => :issue, |
|
| 76 |
:conditions => ["#{Issue.table_name}.tracker_id = ?", tracker]
|
|
| 77 |
}} |
|
| 78 |
scope :on_version, lambda {|version| {
|
|
| 79 |
:include => :issue, |
|
| 80 |
:conditions => ["#{Issue.table_name}.fixed_version_id = ?", version]
|
|
| 81 |
}} |
|
| 82 |
scope :on_category, lambda {|category| {
|
|
| 83 |
:include => :issue, |
|
| 84 |
:conditions => ["#{Issue.table_name}.category_id = ?", category]
|
|
| 85 |
}} |
|
| 86 |
|
|
| 69 | 87 |
safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields' |
| 70 | 88 | |
| 71 | 89 |
def initialize(attributes=nil, *args) |
| app/views/timelog/_report_criteria.html.erb | ||
|---|---|---|
| 1 |
<% @report.hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
|
|
| 2 |
<% hours_for_value = select_hours(hours, criterias[level], value) -%> |
|
| 3 |
<% next if hours_for_value.empty? -%> |
|
| 4 |
<tr class="<%= cycle('odd', 'even') %> <%= criterias.length > level+1 ? 'subtotal' : 'last-level' %>">
|
|
| 5 |
<%= ("<td></td>" * level).html_safe %>
|
|
| 6 |
<td><%= h(format_criteria_value(@report.available_criteria[criterias[level]], value)) %></td> |
|
| 7 |
<%= ("<td></td>" * (criterias.length - level - 1)).html_safe -%>
|
|
| 8 |
<% total = 0 -%> |
|
| 9 |
<% @report.periods.each do |period| -%> |
|
| 10 |
<% sum = sum_hours(select_hours(hours_for_value, @report.columns, period.to_s)); total += sum -%> |
|
| 11 |
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
|
|
| 1 |
<% @report.hours.collect {|h| h[criteria[level]].to_s}.uniq.each do |value| %>
|
|
| 2 |
<% hours_for_value = grand_total ? hours: select_hours(hours, criteria[level], value) -%> |
|
| 3 |
<% next if hours_for_value.empty? -%> |
|
| 4 |
<tr class="<%= cycle('odd', 'even') %> <%= grand_total ? 'total' : criteria.length > level+1 ? 'subtotal' : 'last-level' %> <%= 'current-users-row' if criteria[level] == 'member' && User.current.try(:id) == value.to_i %>">
|
|
| 5 |
<%= ("<td></td>" * level).html_safe %>
|
|
| 6 |
<td> |
|
| 7 |
<% if grand_total %> |
|
| 8 |
<%= l(:label_total) %> |
|
| 9 |
<% elsif criteria[level] == 'issue' && !value.empty? %> |
|
| 10 |
<%= link_to_issue Issue.find(value), :project => true %> |
|
| 11 |
<% else %> |
|
| 12 |
<%= h(format_criteria_value(@report.available_criteria[criteria[level]], value)) %> |
|
| 13 |
<% end %></td> |
|
| 14 |
<%= ("<td></td>" * (criteria.length - level - 1)).html_safe -%>
|
|
| 15 |
<% total = 0 -%> |
|
| 16 |
<% criteria_set = {} -%>
|
|
| 17 |
<% @report.periods.each do |period| -%> |
|
| 18 |
<td class="hours"> |
|
| 19 |
<% data = select_hours(hours_for_value, @report.columns, period.to_s) %> |
|
| 20 |
<% sum = sum_hours(data); total += sum -%> |
|
| 21 |
<% if sum > 0 %> |
|
| 22 |
<% period_from, period_to = nil, nil -%> |
|
| 23 |
<% case when @report.columns.to_s == 'day'; period_from = period_to = period -%> |
|
| 24 |
<% when @report.columns.to_s == 'week'; period_from = Date.commercial(data[0]['tyear'].to_f, data[0]['tweek'].to_f, 1); period_to = period_from + 6 -%> |
|
| 25 |
<% when @report.columns.to_s == 'month'; period_from = Date.civil(data[0]['tyear'].to_f, data[0]['tmonth'].to_f, 1); period_to = (period_from >> 1) - 1 -%> |
|
| 26 |
<% when @report.columns.to_s == 'year'; period_from = Date.civil(data[0]['tyear'].to_f, 1, 1); period_to = Date.civil(data[0]['tyear'].to_f, 12, 31) -%> |
|
| 27 |
<% end -%> |
|
| 28 |
<% (level+1).times do |i| -%> |
|
| 29 |
<% criteria_set[criteria[i].to_sym] = data[0][criteria[i]].to_s -%> |
|
| 30 |
<% end unless grand_total %> |
|
| 31 |
<%= link_to html_hours("%.2f" % sum), {:controller => 'timelog', :action => 'index', :from => period_from, :to => period_to}.merge(criteria_set) %>
|
|
| 32 |
<% end -%> |
|
| 33 |
</td> |
|
| 34 |
<% end -%> |
|
| 35 |
<td class="hours"><%= (link_to html_hours("%.2f" % total), {:controller => 'timelog', :action => 'index', :period => params[:period], :from => @from, :to => @to}.merge(criteria_set)) if total > 0 %></td>
|
|
| 36 |
</tr> |
|
| 37 |
<% break if grand_total %> |
|
| 38 |
<% if criteria.length > level+1 -%> |
|
| 39 |
<%= render(:partial => 'report_criteria', :locals => {:criteria => criteria, :hours => hours_for_value, :level => (level + 1), :grand_total => false}) %>
|
|
| 12 | 40 |
<% end -%> |
| 13 |
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
|
|
| 14 |
</tr> |
|
| 15 |
<% if criterias.length > level+1 -%> |
|
| 16 |
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
|
|
| 17 |
<% end -%> |
|
| 18 | 41 | |
| 19 | 42 |
<% end %> |
| app/views/timelog/report.html.erb | ||
|---|---|---|
| 49 | 49 |
</tr> |
| 50 | 50 |
</thead> |
| 51 | 51 |
<tbody> |
| 52 |
<%= render :partial => 'report_criteria', :locals => {:criterias => @report.criteria, :hours => @report.hours, :level => 0} %>
|
|
| 53 |
<tr class="total"> |
|
| 54 |
<td><%= l(:label_total) %></td> |
|
| 55 |
<%= ('<td></td>' * (@report.criteria.size - 1)).html_safe %>
|
|
| 56 |
<% total = 0 -%> |
|
| 57 |
<% @report.periods.each do |period| -%> |
|
| 58 |
<% sum = sum_hours(select_hours(@report.hours, @report.columns, period.to_s)); total += sum -%> |
|
| 59 |
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
|
|
| 60 |
<% end -%> |
|
| 61 |
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
|
|
| 62 |
</tr> |
|
| 52 |
<%= render :partial => 'report_criteria', :locals => {:criteria => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => false} %>
|
|
| 53 |
<%= render :partial => 'report_criteria', :locals => {:criteria => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => true} %>
|
|
| 63 | 54 |
</tbody> |
| 64 | 55 |
</table> |
| 65 | 56 |
</div> |