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