##// END OF EJS Templates
Various timelog report enhancements:...
Jean-Philippe Lang -
r1311:4e961f44eff2
parent child
Show More
@@ -56,24 +56,22 class TimelogController < ApplicationController
56 56 @criterias.uniq!
57 57 @criterias = @criterias[0,3]
58 58
59 @columns = (params[:columns] && %w(year month week).include?(params[:columns])) ? params[:columns] : 'month'
59 @columns = (params[:columns] && %w(year month week day).include?(params[:columns])) ? params[:columns] : 'month'
60 60
61 61 retrieve_date_range
62 @from ||= TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today
63 @to ||= TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today
64 62
65 63 unless @criterias.empty?
66 64 sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ')
67 65 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
68 66
69 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
67 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, spent_on, SUM(hours) AS hours"
70 68 sql << " FROM #{TimeEntry.table_name}"
71 69 sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
72 70 sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id"
73 71 sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?)
74 72 sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
75 73 sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
76 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
74 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on"
77 75
78 76 @hours = ActiveRecord::Base.connection.select_all(sql)
79 77
@@ -85,6 +83,8 class TimelogController < ApplicationController
85 83 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
86 84 when 'week'
87 85 row['week'] = "#{row['tyear']}-#{row['tweek']}"
86 when 'day'
87 row['day'] = "#{row['spent_on']}"
88 88 end
89 89 end
90 90
@@ -105,6 +105,9 class TimelogController < ApplicationController
105 105 when 'week'
106 106 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
107 107 date_from = (date_from + 7.day).at_beginning_of_week
108 when 'day'
109 @periods << "#{date_from.to_date}"
110 date_from = date_from + 1.day
108 111 end
109 112 end
110 113 end
@@ -121,16 +124,7 class TimelogController < ApplicationController
121 124 ["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
122 125
123 126 retrieve_date_range
124
125 if @from
126 if @to
127 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
128 else
129 cond << ['spent_on >= ?', @from]
130 end
131 elsif @to
132 cond << ['spent_on <= ?', @to]
133 end
127 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
134 128
135 129 TimeEntry.visible_by(User.current) do
136 130 respond_to do |format|
@@ -145,6 +139,7 class TimelogController < ApplicationController
145 139 :limit => @entry_pages.items_per_page,
146 140 :offset => @entry_pages.current.offset)
147 141 @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
142
148 143 render :layout => !request.xhr?
149 144 }
150 145 format.csv {
@@ -241,5 +236,7 private
241 236 end
242 237
243 238 @from, @to = @to, @from if @from && @to && @from > @to
239 @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today) - 1
240 @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today)
244 241 end
245 242 end
@@ -14,3 +14,13
14 14 <%= submit_tag l(:button_apply), :name => nil, :onclick => '$("period_type_2").checked = true;' %>
15 15 </p>
16 16 </fieldset>
17
18 <div class="tabs">
19 <% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
20 <ul>
21 <li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'details', :project_id => @project }),
22 :class => (@controller.action_name == 'details' ? 'selected' : nil)) %></li>
23 <li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project}),
24 :class => (@controller.action_name == 'report' ? 'selected' : nil)) %></li>
25 </ul>
26 </div>
@@ -5,10 +5,12
5 5 <%= '<td></td>' * level %>
6 6 <td><%= value.nil? ? l(:label_none) : @available_criterias[criterias[level]][:klass].find_by_id(value) %></td>
7 7 <%= '<td></td>' * (criterias.length - level - 1) -%>
8 <% total = 0 -%>
8 9 <% @periods.each do |period| -%>
9 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) %>
10 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)); total += sum -%>
10 11 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
11 12 <% end -%>
13 <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
12 14 </tr>
13 15 <% if criterias.length > level+1 -%>
14 16 <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
@@ -1,5 +1,4
1 1 <div class="contextual">
2 <%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}, :class => 'icon icon-report') %>
3 2 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
4 3 </div>
5 4
@@ -1,5 +1,4
1 1 <div class="contextual">
2 <%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}, :class => 'icon icon-details') %>
3 2 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
4 3 </div>
5 4
@@ -14,7 +13,8
14 13
15 14 <p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'],
16 15 [l(:label_month), 'month'],
17 [l(:label_week), 'week']], @columns),
16 [l(:label_week), 'week'],
17 [l(:label_day_plural).titleize, 'day']], @columns),
18 18 :onchange => "this.form.onsubmit();" %>
19 19
20 20 <%= 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
22 22 :style => 'width: 200px',
23 23 :id => nil,
24 24 :disabled => (@criterias.length >= 3)) %>
25 <%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :date_from => @date_from, :date_to => @date_to, :period => @columns}, :update => 'content'},
26 :class => 'icon icon-reload' %></p>
25 <%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :period_type => params[:period_type], :period => params[:period], :from => @from, :to => @to, :columns => @columns},
26 :update => 'content'
27 }, :class => 'icon icon-reload' %></p>
27 28 <% end %>
28 29
29 30 <% unless @criterias.empty? %>
@@ -38,9 +39,11
38 39 <% @criterias.each do |criteria| %>
39 40 <th><%= l(@available_criterias[criteria][:label]) %></th>
40 41 <% end %>
42 <% columns_width = (40 / (@periods.length+1)).to_i %>
41 43 <% @periods.each do |period| %>
42 <th class="period" width="<%= (40 / @periods.length).to_i %>%"><%= period %></th>
44 <th class="period" width="<%= columns_width %>%"><%= period %></th>
43 45 <% end %>
46 <th class="total" width="<%= columns_width %>%"><%= l(:label_total) %></th>
44 47 </tr>
45 48 </thead>
46 49 <tbody>
@@ -48,10 +51,12
48 51 <tr class="total">
49 52 <td><%= l(:label_total) %></td>
50 53 <%= '<td></td>' * (@criterias.size - 1) %>
54 <% total = 0 -%>
51 55 <% @periods.each do |period| -%>
52 <% sum = sum_hours(select_hours(@hours, @columns, period.to_s)) %>
56 <% sum = sum_hours(select_hours(@hours, @columns, period.to_s)); total += sum -%>
53 57 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
54 58 <% end -%>
59 <td class="hours"><%= html_hours("%.2f" % total) if total > 0 %></td>
55 60 </tr>
56 61 </tbody>
57 62 </table>
@@ -183,7 +183,7 div#version-summary { float:right; width:380px; margin-left: 16px; margin-bottom
183 183 div#version-summary fieldset { margin-bottom: 1em; }
184 184 div#version-summary .total-hours { text-align: right; }
185 185
186 table#time-report td.hours, table#time-report th.period { text-align: right; padding-right: 0.5em; }
186 table#time-report td.hours, table#time-report th.period, table#time-report th.total { text-align: right; padding-right: 0.5em; }
187 187 table#time-report tbody tr { font-style: italic; color: #777; }
188 188 table#time-report tbody tr.last-level { font-style: normal; color: #555; }
189 189 table#time-report tbody tr.total { font-style: normal; font-weight: bold; color: #555; background-color:#EEEEEE; }
@@ -15,7 +15,7 time_entries_001:
15 15 tyear: 2007
16 16 time_entries_002:
17 17 created_on: 2007-03-23 14:11:04 +01:00
18 tweek: 12
18 tweek: 11
19 19 tmonth: 3
20 20 project_id: 1
21 21 comments: ""
@@ -22,7 +22,7 require 'timelog_controller'
22 22 class TimelogController; def rescue_action(e) raise e end; end
23 23
24 24 class TimelogControllerTest < Test::Unit::TestCase
25 fixtures :projects, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses
25 fixtures :projects, :enabled_modules, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses
26 26
27 27 def setup
28 28 @controller = TimelogController.new
@@ -86,7 +86,16 class TimelogControllerTest < Test::Unit::TestCase
86 86 assert_not_nil assigns(:total_hours)
87 87 assert_equal "162.90", "%.2f" % assigns(:total_hours)
88 88 end
89
89
90 def test_report_all_time_by_day
91 get :report, :project_id => 1, :criterias => ['project', 'issue'], :columns => 'day'
92 assert_response :success
93 assert_template 'report'
94 assert_not_nil assigns(:total_hours)
95 assert_equal "162.90", "%.2f" % assigns(:total_hours)
96 assert_tag :tag => 'th', :content => '2007-03-12'
97 end
98
90 99 def test_report_one_criteria
91 100 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project']
92 101 assert_response :success
@@ -122,8 +131,8 class TimelogControllerTest < Test::Unit::TestCase
122 131 assert_not_nil assigns(:total_hours)
123 132 assert_equal "162.90", "%.2f" % assigns(:total_hours)
124 133 # display all time by default
125 assert_nil assigns(:from)
126 assert_nil assigns(:to)
134 assert_equal '2007-03-11'.to_date, assigns(:from)
135 assert_equal '2007-04-22'.to_date, assigns(:to)
127 136 end
128 137
129 138 def test_details_at_project_level_with_date_range
@@ -157,8 +166,8 class TimelogControllerTest < Test::Unit::TestCase
157 166 assert_not_nil assigns(:total_hours)
158 167 assert_equal 154.25, assigns(:total_hours)
159 168 # display all time by default
160 assert_nil assigns(:from)
161 assert_nil assigns(:to)
169 assert_equal '2007-03-11'.to_date, assigns(:from)
170 assert_equal '2007-04-22'.to_date, assigns(:to)
162 171 end
163 172
164 173 def test_details_csv_export
General Comments 0
You need to be logged in to leave comments. Login now