Project

General

Profile

Feature #9994 » timelog_report_links_patch.1.1.diff

Egidijus Zideckas, 2012-11-13 14:55

View differences:

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[:toplevel_project].to_i), true) unless params[:toplevel_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 !value.empty? %>
10
        <%=  case criteria[level] 
11
         when 'issue': link_to_issue Issue.find(value), :project => true 
12
         when 'project': link_to_project Project.find(value) 
13
         when 'member': link_to_user User.find(value) 
14
         else h(format_criteria_value(@report.available_criteria[criteria[level]], value))
15
         end %>
16
      <% end %>
17
    </td>
18
    <%= ("<td></td>" * (criteria.length - level - 1)).html_safe -%>
19
    <% total = 0 -%>
20
    <% criteria_set = {} -%>
21
    <% @report.periods.each do |period| -%>
22
      <td class="hours">
23
        <% data = select_hours(hours_for_value, @report.columns, period.to_s) %>
24
        <% sum = sum_hours(data); total += sum -%>
25
        <% if sum > 0 %>
26
          <% period_from, period_to = nil, nil -%>
27
          <% case when @report.columns.to_s == 'day'; period_from = period_to = period -%>
28
          <% 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 -%>
29
          <% 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 -%>
30
          <% 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) -%>
31
          <% end -%>
32
          <% period_from = params[:from].to_s.to_date if !params[:from].blank? && params[:from].to_s.to_date > period_from.to_date %>
33
          <% period_to = params[:to].to_s.to_date if !params[:to].blank? && params[:to].to_s.to_date < period_to.to_date %>
34
          <% (level+1).times do |i|  -%>
35
            <%  criteria_set[criteria[i].to_sym] = data[0][criteria[i]].to_s -%>
36
          <% end unless grand_total %>
37
          <%= link_to html_hours("%.2f" % sum), {:controller => 'timelog', :action => 'index', :from => period_from, :to => period_to}.merge(criteria_set) %>
38
        <% end -%>
39
      </td>
40
    <% end -%>
41
    <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>
42
  </tr>
43
  <% break if grand_total  %>
44
  <% if criteria.length > level+1 -%>
45
    <%= render(:partial => 'report_criteria', :locals => {:criteria => criteria, :hours => hours_for_value, :level => (level + 1), :grand_total => false}) %>
12 46
  <% 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 47

  
19 48
<% 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>
(4-4/7)