Various timelog report enhancements:
* report can be done using days as columns (#993) * add a total column to the time report * replace upper-right links by tabs to switch between details and report * preserve date range filter when switching between details and report git-svn-id: http://redmine.rubyforge.org/svn/trunk@1326 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8d4aa6f9ad
commit
4e961f44ef
|
@ -56,24 +56,22 @@ class TimelogController < ApplicationController
|
|||
@criterias.uniq!
|
||||
@criterias = @criterias[0,3]
|
||||
|
||||
@columns = (params[:columns] && %w(year month week).include?(params[:columns])) ? params[:columns] : 'month'
|
||||
@columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
|
||||
|
||||
retrieve_date_range
|
||||
@from ||= TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today
|
||||
@to ||= TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today
|
||||
|
||||
unless @criterias.empty?
|
||||
sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
|
||||
sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
|
||||
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
|
||||
sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
|
||||
sql << " FROM #{TimeEntry.table_name}"
|
||||
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 << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
|
||||
sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
|
||||
sql << " AND 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"
|
||||
sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
|
||||
|
||||
@hours = ActiveRecord::Base.connection.select_all(sql)
|
||||
|
||||
|
@ -85,6 +83,8 @@ class TimelogController < ApplicationController
|
|||
row['month'] = "#{row['tyear']}-#{row['tmonth']}"
|
||||
when 'week'
|
||||
row['week'] = "#{row['tyear']}-#{row['tweek']}"
|
||||
when 'day'
|
||||
row['day'] = "#{row['spent_on']}"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -105,6 +105,9 @@ class TimelogController < ApplicationController
|
|||
when 'week'
|
||||
@periods << "#{date_from.year}-#{date_from.to_date.cweek}"
|
||||
date_from = (date_from + 7.day).at_beginning_of_week
|
||||
when 'day'
|
||||
@periods << "#{date_from.to_date}"
|
||||
date_from = date_from + 1.day
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -121,16 +124,7 @@ class TimelogController < ApplicationController
|
|||
["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
|
||||
|
||||
retrieve_date_range
|
||||
|
||||
if @from
|
||||
if @to
|
||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||
else
|
||||
cond << ['spent_on >= ?', @from]
|
||||
end
|
||||
elsif @to
|
||||
cond << ['spent_on <= ?', @to]
|
||||
end
|
||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||
|
||||
TimeEntry.visible_by(User.current) do
|
||||
respond_to do |format|
|
||||
|
@ -145,6 +139,7 @@ class TimelogController < ApplicationController
|
|||
:limit => @entry_pages.items_per_page,
|
||||
:offset => @entry_pages.current.offset)
|
||||
@total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
|
||||
|
||||
render :layout => !request.xhr?
|
||||
}
|
||||
format.csv {
|
||||
|
@ -241,5 +236,7 @@ private
|
|||
end
|
||||
|
||||
@from, @to = @to, @from if @from && @to && @from > @to
|
||||
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
|
||||
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,3 +14,13 @@
|
|||
<%= submit_tag l(:button_apply), :name => nil, :onclick => '$("period_type_2").checked = true;' %>
|
||||
</p>
|
||||
</fieldset>
|
||||
|
||||
<div class="tabs">
|
||||
<% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
|
||||
<ul>
|
||||
<li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project }),
|
||||
:class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li>
|
||||
<li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project}),
|
||||
:class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -5,10 +5,12 @@
|
|||
<%= '<td></td>' * level %>
|
||||
<td><%= value.nil? ? l(:label_none) : @available_criterias[criterias[level]][:klass].find_by_id(value) %></td>
|
||||
<%= '<td></td>' * (criterias.length - level - 1) -%>
|
||||
<% total = 0 -%>
|
||||
<% @periods.each do |period| -%>
|
||||
<% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) %>
|
||||
<% sum = sum_hours(select_hours(hours_for_value, @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>
|
||||
<% if criterias.length > level+1 -%>
|
||||
<%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<div class="contextual">
|
||||
<%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}, :class => 'icon icon-report') %>
|
||||
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<div class="contextual">
|
||||
<%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}, :class => 'icon icon-details') %>
|
||||
<%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
|
||||
</div>
|
||||
|
||||
|
@ -14,7 +13,8 @@
|
|||
|
||||
<p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
|
||||
[l(:label_month), 'month'],
|
||||
[l(:label_week), 'week']], @columns),
|
||||
[l(:label_week), 'week'],
|
||||
[l(:label_day_plural).titleize, 'day']], @columns),
|
||||
:onchange => "this.form.onsubmit();" %>
|
||||
|
||||
<%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@available_criterias.keys - @criterias).collect{|k| [l(@available_criterias[k][:label]), k]}),
|
||||
|
@ -22,8 +22,9 @@
|
|||
:style => 'width: 200px',
|
||||
:id => nil,
|
||||
:disabled => (@criterias.length >= 3)) %>
|
||||
<%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :date_from => @date_from, :date_to => @date_to, :period => @columns}, :update => 'content'},
|
||||
:class => 'icon icon-reload' %></p>
|
||||
<%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :period_type => params[:period_type], :period => params[:period], :from => @from, :to => @to, :columns => @columns},
|
||||
:update => 'content'
|
||||
}, :class => 'icon icon-reload' %></p>
|
||||
<% end %>
|
||||
|
||||
<% unless @criterias.empty? %>
|
||||
|
@ -38,9 +39,11 @@
|
|||
<% @criterias.each do |criteria| %>
|
||||
<th><%= l(@available_criterias[criteria][:label]) %></th>
|
||||
<% end %>
|
||||
<% columns_width = (40 / (@periods.length+1)).to_i %>
|
||||
<% @periods.each do |period| %>
|
||||
<th class="period" width="<%= (40 / @periods.length).to_i %>%"><%= period %></th>
|
||||
<th class="period" width="<%= columns_width %>%"><%= period %></th>
|
||||
<% end %>
|
||||
<th class="total" width="<%= columns_width %>%"><%= l(:label_total) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -48,10 +51,12 @@
|
|||
<tr class="total">
|
||||
<td><%= l(:label_total) %></td>
|
||||
<%= '<td></td>' * (@criterias.size - 1) %>
|
||||
<% total = 0 -%>
|
||||
<% @periods.each do |period| -%>
|
||||
<% sum = sum_hours(select_hours(@hours, @columns, period.to_s)) %>
|
||||
<% sum = sum_hours(select_hours(@hours, @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>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -183,7 +183,7 @@ div#version-summary { float:right; width:380px; margin-left: 16px; margin-bottom
|
|||
div#version-summary fieldset { margin-bottom: 1em; }
|
||||
div#version-summary .total-hours { text-align: right; }
|
||||
|
||||
table#time-report td.hours, table#time-report th.period { text-align: right; padding-right: 0.5em; }
|
||||
table#time-report td.hours, table#time-report th.period, table#time-report th.total { text-align: right; padding-right: 0.5em; }
|
||||
table#time-report tbody tr { font-style: italic; color: #777; }
|
||||
table#time-report tbody tr.last-level { font-style: normal; color: #555; }
|
||||
table#time-report tbody tr.total { font-style: normal; font-weight: bold; color: #555; background-color:#EEEEEE; }
|
||||
|
|
|
@ -15,7 +15,7 @@ time_entries_001:
|
|||
tyear: 2007
|
||||
time_entries_002:
|
||||
created_on: 2007-03-23 14:11:04 +01:00
|
||||
tweek: 12
|
||||
tweek: 11
|
||||
tmonth: 3
|
||||
project_id: 1
|
||||
comments: ""
|
||||
|
|
|
@ -22,7 +22,7 @@ require 'timelog_controller'
|
|||
class TimelogController; def rescue_action(e) raise e end; end
|
||||
|
||||
class TimelogControllerTest < Test::Unit::TestCase
|
||||
fixtures :projects, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses
|
||||
fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses
|
||||
|
||||
def setup
|
||||
@controller = TimelogController.new
|
||||
|
@ -87,6 +87,15 @@ class TimelogControllerTest < Test::Unit::TestCase
|
|||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
end
|
||||
|
||||
def test_report_all_time_by_day
|
||||
get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
|
||||
assert_response :success
|
||||
assert_template 'report'
|
||||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
assert_tag :tag => 'th', :content => '2007-03-12'
|
||||
end
|
||||
|
||||
def test_report_one_criteria
|
||||
get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
|
||||
assert_response :success
|
||||
|
@ -122,8 +131,8 @@ class TimelogControllerTest < Test::Unit::TestCase
|
|||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal "162.90", "%.2f" % assigns(:total_hours)
|
||||
# display all time by default
|
||||
assert_nil assigns(:from)
|
||||
assert_nil assigns(:to)
|
||||
assert_equal '2007-03-11'.to_date, assigns(:from)
|
||||
assert_equal '2007-04-22'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_at_project_level_with_date_range
|
||||
|
@ -157,8 +166,8 @@ class TimelogControllerTest < Test::Unit::TestCase
|
|||
assert_not_nil assigns(:total_hours)
|
||||
assert_equal 154.25, assigns(:total_hours)
|
||||
# display all time by default
|
||||
assert_nil assigns(:from)
|
||||
assert_nil assigns(:to)
|
||||
assert_equal '2007-03-11'.to_date, assigns(:from)
|
||||
assert_equal '2007-04-22'.to_date, assigns(:to)
|
||||
end
|
||||
|
||||
def test_details_csv_export
|
||||
|
|
Loading…
Reference in New Issue