Makes timelog report work at issue level (#2935).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2893 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b4c55ea4de
commit
41cbd239c4
|
@ -80,14 +80,22 @@ class TimelogController < ApplicationController
|
||||||
unless @criterias.empty?
|
unless @criterias.empty?
|
||||||
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
||||||
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
||||||
|
sql_condition = ''
|
||||||
|
|
||||||
|
if @project.nil?
|
||||||
|
sql_condition = Project.allowed_to_condition(User.current, :view_time_entries)
|
||||||
|
elsif @issue.nil?
|
||||||
|
sql_condition = @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
|
else
|
||||||
|
sql_condition = "#{TimeEntry.table_name}.issue_id = #{@issue.id}"
|
||||||
|
end
|
||||||
|
|
||||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
||||||
sql << " FROM #{TimeEntry.table_name}"
|
sql << " FROM #{TimeEntry.table_name}"
|
||||||
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
|
||||||
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
|
sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
|
||||||
sql << " WHERE"
|
sql << " WHERE"
|
||||||
sql << " (%s) AND" % @project.project_condition(Setting.display_subprojects_issues?) if @project
|
sql << " (%s) AND" % sql_condition
|
||||||
sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
|
|
||||||
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
|
sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
|
||||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,9 @@
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
|
<% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
|
||||||
<ul>
|
<ul>
|
||||||
<li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project }),
|
<li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue }),
|
||||||
:class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li>
|
:class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li>
|
||||||
<li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project}),
|
<li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project, :issue_id => @issue}),
|
||||||
:class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li>
|
:class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<%# TODO: get rid of the project_id field, that should already be in the URL %>
|
<%# TODO: get rid of the project_id field, that should already be in the URL %>
|
||||||
<%= hidden_field_tag('project_id', params[:project_id]) if @project %>
|
<%= hidden_field_tag('project_id', params[:project_id]) if @project %>
|
||||||
|
<%= hidden_field_tag('issue_id', params[:issue_id]) if @issue %>
|
||||||
<%= render :partial => 'date_range' %>
|
<%= render :partial => 'date_range' %>
|
||||||
|
|
||||||
<p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
|
<p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
|
||||||
|
|
|
@ -206,6 +206,14 @@ class TimelogControllerTest < ActionController::TestCase
|
||||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_report_at_issue_level
|
||||||
|
get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"]
|
||||||
|
assert_response :success
|
||||||
|
assert_template 'report'
|
||||||
|
assert_not_nil assigns(:total_hours)
|
||||||
|
assert_equal "154.25", "%.2f" % assigns(:total_hours)
|
||||||
|
end
|
||||||
|
|
||||||
def test_report_custom_field_criteria
|
def test_report_custom_field_criteria
|
||||||
get :report, :project_id => 1, :criterias => ['project', 'cf_1']
|
get :report, :project_id => 1, :criterias => ['project', 'cf_1']
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
Loading…
Reference in New Issue