@@ -0,0 +1,16 | |||||
|
1 | <fieldset><legend><%= l(:label_date_range) %></legend> | |||
|
2 | <p> | |||
|
3 | <%= radio_button_tag 'period_type', '1', !@free_period %> | |||
|
4 | <%= select_tag 'period', options_for_period_select(params[:period]), | |||
|
5 | :onchange => 'this.form.onsubmit();', | |||
|
6 | :onfocus => '$("period_type_1").checked = true;' %> | |||
|
7 | </p> | |||
|
8 | <p> | |||
|
9 | <%= radio_button_tag 'period_type', '2', @free_period %> | |||
|
10 | <%= l(:label_date_from) %> | |||
|
11 | <%= text_field_tag 'from', @from, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('from') %> | |||
|
12 | <%= l(:label_date_to) %> | |||
|
13 | <%= text_field_tag 'to', @to, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('to') %> | |||
|
14 | <%= submit_tag l(:button_apply), :name => nil, :onclick => '$("period_type_2").checked = true;' %> | |||
|
15 | </p> | |||
|
16 | </fieldset> |
@@ -53,16 +53,11 class TimelogController < ApplicationController | |||||
53 | @criterias.uniq! |
|
53 | @criterias.uniq! | |
54 | @criterias = @criterias[0,3] |
|
54 | @criterias = @criterias[0,3] | |
55 |
|
55 | |||
56 |
@columns = (params[: |
|
56 | @columns = (params[:columns] && %w(year month week).include?(params[:columns])) ? params[:columns] : 'month' | |
57 |
|
57 | |||
58 | if params[:date_from] |
|
58 | retrieve_date_range | |
59 | begin; @date_from = params[:date_from].to_date; rescue; end |
|
59 | @from ||= TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today | |
60 | end |
|
60 | @to ||= TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today | |
61 | if params[:date_to] |
|
|||
62 | begin; @date_to = params[:date_to].to_date; rescue; end |
|
|||
63 | end |
|
|||
64 | @date_from ||= Date.civil(Date.today.year, 1, 1) |
|
|||
65 | @date_to ||= (Date.civil(Date.today.year, Date.today.month, 1) >> 1) - 1 |
|
|||
66 |
|
61 | |||
67 | unless @criterias.empty? |
|
62 | unless @criterias.empty? | |
68 | sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') |
|
63 | sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') | |
@@ -74,7 +69,7 class TimelogController < ApplicationController | |||||
74 | sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" |
|
69 | sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" | |
75 | sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?) |
|
70 | sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?) | |
76 | sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries) |
|
71 | sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries) | |
77 |
sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@ |
|
72 | sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)] | |
78 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek" |
|
73 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek" | |
79 |
|
74 | |||
80 | @hours = ActiveRecord::Base.connection.select_all(sql) |
|
75 | @hours = ActiveRecord::Base.connection.select_all(sql) | |
@@ -91,22 +86,23 class TimelogController < ApplicationController | |||||
91 | end |
|
86 | end | |
92 |
|
87 | |||
93 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} |
|
88 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} | |
94 |
|
|
89 | ||
95 |
|
90 | @periods = [] | ||
96 | @periods = [] |
|
91 | # Date#at_beginning_of_ not supported in Rails 1.2.x | |
97 |
date_from = @ |
|
92 | date_from = @from.to_time | |
98 | # 100 columns max |
|
93 | # 100 columns max | |
99 |
while date_from < @ |
|
94 | while date_from <= @to.to_time && @periods.length < 100 | |
100 | case @columns |
|
95 | case @columns | |
101 | when 'year' |
|
96 | when 'year' | |
102 | @periods << "#{date_from.year}" |
|
97 | @periods << "#{date_from.year}" | |
103 |
date_from = date_from |
|
98 | date_from = (date_from + 1.year).at_beginning_of_year | |
104 | when 'month' |
|
99 | when 'month' | |
105 | @periods << "#{date_from.year}-#{date_from.month}" |
|
100 | @periods << "#{date_from.year}-#{date_from.month}" | |
106 |
date_from = date_from |
|
101 | date_from = (date_from + 1.month).at_beginning_of_month | |
107 | when 'week' |
|
102 | when 'week' | |
108 | @periods << "#{date_from.year}-#{date_from.cweek}" |
|
103 | @periods << "#{date_from.year}-#{date_from.to_date.cweek}" | |
109 | date_from = date_from + 7 |
|
104 | date_from = (date_from + 7.day).at_beginning_of_week | |
|
105 | end | |||
110 | end |
|
106 | end | |
111 | end |
|
107 | end | |
112 |
|
108 | |||
@@ -116,52 +112,13 class TimelogController < ApplicationController | |||||
116 | def details |
|
112 | def details | |
117 | sort_init 'spent_on', 'desc' |
|
113 | sort_init 'spent_on', 'desc' | |
118 | sort_update |
|
114 | sort_update | |
119 |
|
||||
120 | @free_period = false |
|
|||
121 | @from, @to = nil, nil |
|
|||
122 |
|
||||
123 | if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) |
|
|||
124 | case params[:period].to_s |
|
|||
125 | when 'today' |
|
|||
126 | @from = @to = Date.today |
|
|||
127 | when 'yesterday' |
|
|||
128 | @from = @to = Date.today - 1 |
|
|||
129 | when 'current_week' |
|
|||
130 | @from = Date.today - (Date.today.cwday - 1)%7 |
|
|||
131 | @to = @from + 6 |
|
|||
132 | when 'last_week' |
|
|||
133 | @from = Date.today - 7 - (Date.today.cwday - 1)%7 |
|
|||
134 | @to = @from + 6 |
|
|||
135 | when '7_days' |
|
|||
136 | @from = Date.today - 7 |
|
|||
137 | @to = Date.today |
|
|||
138 | when 'current_month' |
|
|||
139 | @from = Date.civil(Date.today.year, Date.today.month, 1) |
|
|||
140 | @to = (@from >> 1) - 1 |
|
|||
141 | when 'last_month' |
|
|||
142 | @from = Date.civil(Date.today.year, Date.today.month, 1) << 1 |
|
|||
143 | @to = (@from >> 1) - 1 |
|
|||
144 | when '30_days' |
|
|||
145 | @from = Date.today - 30 |
|
|||
146 | @to = Date.today |
|
|||
147 | when 'current_year' |
|
|||
148 | @from = Date.civil(Date.today.year, 1, 1) |
|
|||
149 | @to = Date.civil(Date.today.year, 12, 31) |
|
|||
150 | end |
|
|||
151 | elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?)) |
|
|||
152 | begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end |
|
|||
153 | begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end |
|
|||
154 | @free_period = true |
|
|||
155 | else |
|
|||
156 | # default |
|
|||
157 | end |
|
|||
158 |
|
||||
159 | @from, @to = @to, @from if @from && @to && @from > @to |
|
|||
160 |
|
115 | |||
161 | cond = ARCondition.new |
|
116 | cond = ARCondition.new | |
162 | cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) : |
|
117 | cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) : | |
163 | ["#{TimeEntry.table_name}.issue_id = ?", @issue.id]) |
|
118 | ["#{TimeEntry.table_name}.issue_id = ?", @issue.id]) | |
164 |
|
119 | |||
|
120 | retrieve_date_range | |||
|
121 | ||||
165 | if @from |
|
122 | if @from | |
166 | if @to |
|
123 | if @to | |
167 | cond << ['spent_on BETWEEN ? AND ?', @from, @to] |
|
124 | cond << ['spent_on BETWEEN ? AND ?', @from, @to] | |
@@ -238,4 +195,48 private | |||||
238 | rescue ActiveRecord::RecordNotFound |
|
195 | rescue ActiveRecord::RecordNotFound | |
239 | render_404 |
|
196 | render_404 | |
240 | end |
|
197 | end | |
|
198 | ||||
|
199 | # Retreive the date range based on predefined ranges or specific from/to param dates | |||
|
200 | def retrieve_date_range | |||
|
201 | @free_period = false | |||
|
202 | @from, @to = nil, nil | |||
|
203 | ||||
|
204 | if params[:period_type] == '1' || (params[:period_type].nil? && !params[:period].nil?) | |||
|
205 | case params[:period].to_s | |||
|
206 | when 'today' | |||
|
207 | @from = @to = Date.today | |||
|
208 | when 'yesterday' | |||
|
209 | @from = @to = Date.today - 1 | |||
|
210 | when 'current_week' | |||
|
211 | @from = Date.today - (Date.today.cwday - 1)%7 | |||
|
212 | @to = @from + 6 | |||
|
213 | when 'last_week' | |||
|
214 | @from = Date.today - 7 - (Date.today.cwday - 1)%7 | |||
|
215 | @to = @from + 6 | |||
|
216 | when '7_days' | |||
|
217 | @from = Date.today - 7 | |||
|
218 | @to = Date.today | |||
|
219 | when 'current_month' | |||
|
220 | @from = Date.civil(Date.today.year, Date.today.month, 1) | |||
|
221 | @to = (@from >> 1) - 1 | |||
|
222 | when 'last_month' | |||
|
223 | @from = Date.civil(Date.today.year, Date.today.month, 1) << 1 | |||
|
224 | @to = (@from >> 1) - 1 | |||
|
225 | when '30_days' | |||
|
226 | @from = Date.today - 30 | |||
|
227 | @to = Date.today | |||
|
228 | when 'current_year' | |||
|
229 | @from = Date.civil(Date.today.year, 1, 1) | |||
|
230 | @to = Date.civil(Date.today.year, 12, 31) | |||
|
231 | end | |||
|
232 | elsif params[:period_type] == '2' || (params[:period_type].nil? && (!params[:from].nil? || !params[:to].nil?)) | |||
|
233 | begin; @from = params[:from].to_s.to_date unless params[:from].blank?; rescue; end | |||
|
234 | begin; @to = params[:to].to_s.to_date unless params[:to].blank?; rescue; end | |||
|
235 | @free_period = true | |||
|
236 | else | |||
|
237 | # default | |||
|
238 | end | |||
|
239 | ||||
|
240 | @from, @to = @to, @from if @from && @to && @from > @to | |||
|
241 | end | |||
241 | end |
|
242 | end |
@@ -12,23 +12,7 | |||||
12 | <% form_remote_tag( :url => {}, :method => :get, :update => 'content' ) do %> |
|
12 | <% form_remote_tag( :url => {}, :method => :get, :update => 'content' ) do %> | |
13 | <%= hidden_field_tag 'project_id', params[:project_id] %> |
|
13 | <%= hidden_field_tag 'project_id', params[:project_id] %> | |
14 | <%= hidden_field_tag 'issue_id', params[:issue_id] if @issue %> |
|
14 | <%= hidden_field_tag 'issue_id', params[:issue_id] if @issue %> | |
15 |
|
15 | <%= render :partial => 'date_range' %> | ||
16 | <fieldset><legend><%= l(:label_date_range) %></legend> |
|
|||
17 | <p> |
|
|||
18 | <%= radio_button_tag 'period_type', '1', !@free_period %> |
|
|||
19 | <%= select_tag 'period', options_for_period_select(params[:period]), |
|
|||
20 | :onchange => 'this.form.onsubmit();', |
|
|||
21 | :onfocus => '$("period_type_1").checked = true;' %> |
|
|||
22 | </p> |
|
|||
23 | <p> |
|
|||
24 | <%= radio_button_tag 'period_type', '2', @free_period %> |
|
|||
25 | <%= l(:label_date_from) %> |
|
|||
26 | <%= text_field_tag 'from', @from, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('from') %> |
|
|||
27 | <%= l(:label_date_to) %> |
|
|||
28 | <%= text_field_tag 'to', @to, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('to') %> |
|
|||
29 | <%= submit_tag l(:button_apply), :name => nil, :onclick => '$("period_type_2").checked = true;' %> |
|
|||
30 | </p> |
|
|||
31 | </fieldset> |
|
|||
32 | <% end %> |
|
16 | <% end %> | |
33 |
|
17 | |||
34 | <div class="total-hours"> |
|
18 | <div class="total-hours"> |
@@ -5,32 +5,27 | |||||
5 |
|
5 | |||
6 | <h2><%= l(:label_spent_time) %></h2> |
|
6 | <h2><%= l(:label_spent_time) %></h2> | |
7 |
|
7 | |||
8 |
<% form_remote_tag(:url => { |
|
8 | <% form_remote_tag(:url => {}, :update => 'content') do %> | |
9 | <% @criterias.each do |criteria| %> |
|
9 | <% @criterias.each do |criteria| %> | |
10 | <%= hidden_field_tag 'criterias[]', criteria %> |
|
10 | <%= hidden_field_tag 'criterias[]', criteria %> | |
11 | <% end %> |
|
11 | <% end %> | |
12 | <fieldset><legend><%= l(:label_date_range) %></legend> |
|
12 | <%= hidden_field_tag 'project_id', params[:project_id] %> | |
13 | <p> |
|
13 | <%= render :partial => 'date_range' %> | |
14 | <%= l(:label_date_from) %> |
|
|||
15 | <%= text_field_tag 'date_from', @date_from, :size => 10 %><%= calendar_for('date_from') %> |
|
|||
16 | <%= l(:label_date_to) %> |
|
|||
17 | <%= text_field_tag 'date_to', @date_to, :size => 10 %><%= calendar_for('date_to') %> |
|
|||
18 | <%= l(:label_details) %> |
|
|||
19 | <%= select_tag 'period', options_for_select([[l(:label_year), 'year'], |
|
|||
20 | [l(:label_month), 'month'], |
|
|||
21 | [l(:label_week), 'week']], @columns) %> |
|
|||
22 | |
|
|||
23 | <%= submit_tag l(:button_apply) %> |
|
|||
24 | </p> |
|
14 | </p> | |
25 | </fieldset> |
|
15 | </fieldset> | |
|
16 | <p><%= l(:label_details) %>: <%= select_tag 'columns', options_for_select([[l(:label_year), 'year'], | |||
|
17 | [l(:label_month), 'month'], | |||
|
18 | [l(:label_week), 'week']], @columns), | |||
|
19 | :onchange => "this.form.onsubmit();" %> | |||
26 |
|
20 | |||
27 |
|
|
21 | <%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@available_criterias.keys - @criterias).collect{|k| [l(@available_criterias[k][:label]), k]}), | |
28 | :onchange => "this.form.onsubmit();", |
|
22 | :onchange => "this.form.onsubmit();", | |
29 | :style => 'width: 200px', |
|
23 | :style => 'width: 200px', | |
30 | :disabled => (@criterias.length >= 3)) %> |
|
24 | :disabled => (@criterias.length >= 3)) %> | |
31 | <%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :date_from => @date_from, :date_to => @date_to, :period => @columns}, :update => 'content'}, |
|
25 | <%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :date_from => @date_from, :date_to => @date_to, :period => @columns}, :update => 'content'}, | |
32 | :class => 'icon icon-reload' %></p> |
|
26 | :class => 'icon icon-reload' %></p> | |
33 |
|
27 | <% end %> | ||
|
28 | ||||
34 | <% unless @criterias.empty? %> |
|
29 | <% unless @criterias.empty? %> | |
35 | <div class="total-hours"> |
|
30 | <div class="total-hours"> | |
36 | <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p> |
|
31 | <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p> | |
@@ -62,4 +57,3 | |||||
62 | </table> |
|
57 | </table> | |
63 | <% end %> |
|
58 | <% end %> | |
64 | <% end %> |
|
59 | <% end %> | |
65 | <% end %> |
|
@@ -78,17 +78,25 class TimelogControllerTest < Test::Unit::TestCase | |||||
78 | assert_response :success |
|
78 | assert_response :success | |
79 | assert_template 'report' |
|
79 | assert_template 'report' | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
|
82 | def test_report_all_time | |||
|
83 | get :report, :project_id => 1, :criterias => ['project'] | |||
|
84 | assert_response :success | |||
|
85 | assert_template 'report' | |||
|
86 | assert_not_nil assigns(:total_hours) | |||
|
87 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |||
|
88 | end | |||
|
89 | ||||
82 | def test_report_one_criteria |
|
90 | def test_report_one_criteria | |
83 |
get :report, :project_id => 1, : |
|
91 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criterias => ['project'] | |
84 | assert_response :success |
|
92 | assert_response :success | |
85 | assert_template 'report' |
|
93 | assert_template 'report' | |
86 | assert_not_nil assigns(:total_hours) |
|
94 | assert_not_nil assigns(:total_hours) | |
87 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
95 | assert_equal "8.65", "%.2f" % assigns(:total_hours) | |
88 | end |
|
96 | end | |
89 |
|
97 | |||
90 | def test_report_two_criterias |
|
98 | def test_report_two_criterias | |
91 |
get :report, :project_id => 1, : |
|
99 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criterias => ["member", "activity"] | |
92 | assert_response :success |
|
100 | assert_response :success | |
93 | assert_template 'report' |
|
101 | assert_template 'report' | |
94 | assert_not_nil assigns(:total_hours) |
|
102 | assert_not_nil assigns(:total_hours) | |
@@ -96,7 +104,7 class TimelogControllerTest < Test::Unit::TestCase | |||||
96 | end |
|
104 | end | |
97 |
|
105 | |||
98 | def test_report_one_criteria_no_result |
|
106 | def test_report_one_criteria_no_result | |
99 |
get :report, :project_id => 1, : |
|
107 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criterias => ['project'] | |
100 | assert_response :success |
|
108 | assert_response :success | |
101 | assert_template 'report' |
|
109 | assert_template 'report' | |
102 | assert_not_nil assigns(:total_hours) |
|
110 | assert_not_nil assigns(:total_hours) |
General Comments 0
You need to be logged in to leave comments.
Login now