timelog_report_links_patch.1.3.diff

Egidijus Zideckas, 2012-12-03 16:32

Download (8.01 KB)

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/helpers/timelog_helper.rb
135 135
    elsif k = criteria_options[:klass]
136 136
      obj = k.find_by_id(value.to_i)
137 137
      if obj.is_a?(Issue)
138
        obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
138
        obj.visible? ? "#{obj.tracker} #{( links ? link_to("##{obj.id}", issue_path(obj.id)) : "##{obj.id}" )}: #{obj.subject}".html_safe : "##{obj.id}"
139
      elsif links && (obj.is_a?(User) || obj.is_a?(Project))
140
        link_to(h(obj.to_s), obj)
139 141
      else
140 142
        obj
141 143
      end
......
143 145
      format_value(value, criteria_options[:format])
144 146
    end
145 147
  end
148
  
149
  def criteria_date_range(period, value)
150
    from, to = nil, nil 
151
    case period 
152
    when 'day' 
153
      from = to = value 
154
    when 'week'
155
      from = Date.commercial(value.split('-')[0].to_f, value.split('-')[1].to_f, 1); to = from + 6 
156
    when 'month' 
157
      from = Date.civil(value.split('-')[0].to_f, value.split('-')[1].to_f, 1); to = (from >> 1) - 1 
158
    when 'year' 
159
      from = Date.civil(value.split('-')[0].to_f, 1, 1); to = Date.civil(value.split('-')[0].to_f, 12, 31) 
160
    end 
161
    from = params[:from].to_s.to_date if !params[:from].blank? && params[:from].to_s.to_date > from.to_date 
162
    to = params[:to].to_s.to_date if !params[:to].blank? && params[:to].to_s.to_date < to.to_date 
163
    return {:from => from, :to => to}
164
  end
146 165

  
147 166
  def report_to_csv(report)
148 167
    decimal_separator = l(:general_csv_decimal_separator)
app/models/time_entry.rb
66 66
    end
67 67
  }
68 68

  
69
  scope :on_user, lambda {|user| {
70
    :conditions => ["#{TimeEntry.table_name}.user_id = ?", user]
71
  }}
72
  scope :on_activity, lambda {|activity| {
73
    :conditions => ["#{TimeEntry.table_name}.activity_id = ?", activity]
74
  }}
75
  scope :on_tracker, lambda {|tracker| {
76
    :include => :issue,
77
    :conditions => ["#{Issue.table_name}.tracker_id = ?", tracker]
78
  }}
79
  scope :on_version, lambda {|version| {
80
    :include => :issue,
81
    :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version]
82
  }}
83
  scope :on_category, lambda {|category| {
84
    :include => :issue,
85
    :conditions => ["#{Issue.table_name}.category_id = ?", category]
86
  }}
87
    
69 88
  safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields'
70 89

  
71 90
  def initialize(attributes=nil, *args)
app/views/timelog/_report_criteria.html.erb
1 1
<% @report.hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
2
<% hours_for_value = select_hours(hours, criterias[level], value) -%>
2
<% hours_for_value = grand_total ? hours: select_hours(hours, criterias[level], value) -%>
3 3
<% next if hours_for_value.empty? -%>
4
<tr class="<%= cycle('odd', 'even') %> <%= criterias.length > level+1 ? 'subtotal' : 'last-level' %>">
4
<tr class="<%= cycle('odd', 'even') %> <%= grand_total ? 'total' : criterias.length > level+1 ? 'subtotal' : 'last-level' %>  <%= 'current-users-row' if criterias[level] == 'member' && User.current.try(:id) == value.to_i %>">
5 5
<%= ("<td></td>" * level).html_safe %>
6
<td><%= h(format_criteria_value(@report.available_criteria[criterias[level]], value)) %></td>
6
<td><%= grand_total ? l(:label_total) : h(format_criteria_value(@report.available_criteria[criterias[level]], value, true)) %></td>
7 7
<%= ("<td></td>" * (criterias.length - level - 1)).html_safe -%>
8
  <% total = 0 -%>
8
  <% total = 0; criteria_values = {} if level == 0 -%>
9
  <% criteria_level_values = criteria_values.merge({criterias[level].to_sym => value}) -%>
9 10
  <% @report.periods.each do |period| -%>
10 11
    <% 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>
12
    <td class="hours"><%= link_to html_hours("%.2f" % sum), {:controller => 'timelog', :action => 'index'}.merge(criteria_level_values).merge(criteria_date_range(@report.columns.to_s, period)) if sum > 0 %></td>
12 13
  <% end -%>
13
  <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
14
  <td class="hours"><%= (link_to html_hours("%.2f" % total), {:controller => 'timelog', :action => 'index', :period => params[:period], :from => @from, :to => @to}.merge(criteria_level_values)) if total > 0 %></td>
14 15
</tr>
16
<% break if grand_total  %>
15 17
<% if criterias.length > level+1 -%>
16
  <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
18
  <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :criteria_values => criteria_level_values.merge({criterias[level].to_sym => value}), :hours => hours_for_value, :level => (level + 1), :grand_total => false}) %>
17 19
<% end -%>
18 20

  
19 21
<% 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 => {:criterias => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => false} %>
53
<%= render :partial => 'report_criteria', :locals => {:criterias => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => true} %>
63 54
</tbody>
64 55
</table>
65 56
</div>
66
-