Project

General

Profile

Feature #9994 » timelog_report_links_patch.1.3.diff

Egidijus Zideckas, 2012-12-03 16:32

View differences:

app/controllers/timelog_controller.rb
retrieve_date_range
scope = TimeEntry.visible.spent_between(@from, @to)
scope = scope.on_user(params[:member]) unless params[:member].nil?
scope = scope.on_activity(params[:activity]) unless params[:activity].nil?
scope = scope.on_tracker(params[:tracker]) unless params[:tracker].nil?
scope = scope.on_version(params[:version]) unless params[:version].nil?
scope = scope.on_category(params[:category]) unless params[:category].nil?
scope = scope.on_project(Project.find(params[:project].to_i), false) unless params[:project].nil?
scope = scope.on_project(Project.find(params[:toplevel_project].to_i), true) unless params[:toplevel_project].nil?
@issue = Issue.find(params[:issue]) unless params[:issue].nil?
if @issue
scope = scope.on_issue(@issue)
elsif @project
app/helpers/timelog_helper.rb
elsif k = criteria_options[:klass]
obj = k.find_by_id(value.to_i)
if obj.is_a?(Issue)
obj.visible? ? "#{obj.tracker} ##{obj.id}: #{obj.subject}" : "##{obj.id}"
obj.visible? ? "#{obj.tracker} #{( links ? link_to("##{obj.id}", issue_path(obj.id)) : "##{obj.id}" )}: #{obj.subject}".html_safe : "##{obj.id}"
elsif links && (obj.is_a?(User) || obj.is_a?(Project))
link_to(h(obj.to_s), obj)
else
obj
end
......
format_value(value, criteria_options[:format])
end
end
def criteria_date_range(period, value)
from, to = nil, nil
case period
when 'day'
from = to = value
when 'week'
from = Date.commercial(value.split('-')[0].to_f, value.split('-')[1].to_f, 1); to = from + 6
when 'month'
from = Date.civil(value.split('-')[0].to_f, value.split('-')[1].to_f, 1); to = (from >> 1) - 1
when 'year'
from = Date.civil(value.split('-')[0].to_f, 1, 1); to = Date.civil(value.split('-')[0].to_f, 12, 31)
end
from = params[:from].to_s.to_date if !params[:from].blank? && params[:from].to_s.to_date > from.to_date
to = params[:to].to_s.to_date if !params[:to].blank? && params[:to].to_s.to_date < to.to_date
return {:from => from, :to => to}
end
def report_to_csv(report)
decimal_separator = l(:general_csv_decimal_separator)
app/models/time_entry.rb
end
}
scope :on_user, lambda {|user| {
:conditions => ["#{TimeEntry.table_name}.user_id = ?", user]
}}
scope :on_activity, lambda {|activity| {
:conditions => ["#{TimeEntry.table_name}.activity_id = ?", activity]
}}
scope :on_tracker, lambda {|tracker| {
:include => :issue,
:conditions => ["#{Issue.table_name}.tracker_id = ?", tracker]
}}
scope :on_version, lambda {|version| {
:include => :issue,
:conditions => ["#{Issue.table_name}.fixed_version_id = ?", version]
}}
scope :on_category, lambda {|category| {
:include => :issue,
:conditions => ["#{Issue.table_name}.category_id = ?", category]
}}
safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields'
def initialize(attributes=nil, *args)
app/views/timelog/_report_criteria.html.erb
<% @report.hours.collect {|h| h[criterias[level]].to_s}.uniq.each do |value| %>
<% hours_for_value = select_hours(hours, criterias[level], value) -%>
<% hours_for_value = grand_total ? hours: select_hours(hours, criterias[level], value) -%>
<% next if hours_for_value.empty? -%>
<tr class="<%= cycle('odd', 'even') %> <%= criterias.length > level+1 ? 'subtotal' : 'last-level' %>">
<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 %>">
<%= ("<td></td>" * level).html_safe %>
<td><%= h(format_criteria_value(@report.available_criteria[criterias[level]], value)) %></td>
<td><%= grand_total ? l(:label_total) : h(format_criteria_value(@report.available_criteria[criterias[level]], value, true)) %></td>
<%= ("<td></td>" * (criterias.length - level - 1)).html_safe -%>
<% total = 0 -%>
<% total = 0; criteria_values = {} if level == 0 -%>
<% criteria_level_values = criteria_values.merge({criterias[level].to_sym => value}) -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(hours_for_value, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<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>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
<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>
</tr>
<% break if grand_total %>
<% if criterias.length > level+1 -%>
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
<%= 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}) %>
<% end -%>
<% end %>
app/views/timelog/report.html.erb
</tr>
</thead>
<tbody>
<%= render :partial => 'report_criteria', :locals => {:criterias => @report.criteria, :hours => @report.hours, :level => 0} %>
<tr class="total">
<td><%= l(:label_total) %></td>
<%= ('<td></td>' * (@report.criteria.size - 1)).html_safe %>
<% total = 0 -%>
<% @report.periods.each do |period| -%>
<% sum = sum_hours(select_hours(@report.hours, @report.columns, period.to_s)); total += sum -%>
<td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
<% end -%>
<td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
</tr>
<%= render :partial => 'report_criteria', :locals => {:criterias => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => false} %>
<%= render :partial => 'report_criteria', :locals => {:criterias => @report.criteria, :hours => @report.hours, :level => 0, :grand_total => true} %>
</tbody>
</table>
</div>
(6-6/7)