@@ -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> |
@@ -1,241 +1,242 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class TimelogController < ApplicationController |
|
19 | 19 | layout 'base' |
|
20 | 20 | menu_item :issues |
|
21 | 21 | before_filter :find_project, :authorize |
|
22 | 22 | |
|
23 | 23 | verify :method => :post, :only => :destroy, :redirect_to => { :action => :details } |
|
24 | 24 | |
|
25 | 25 | helper :sort |
|
26 | 26 | include SortHelper |
|
27 | 27 | helper :issues |
|
28 | 28 | include TimelogHelper |
|
29 | 29 | |
|
30 | 30 | def report |
|
31 | 31 | @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", |
|
32 | 32 | :klass => Project, |
|
33 | 33 | :label => :label_project}, |
|
34 | 34 | 'version' => {:sql => "#{Issue.table_name}.fixed_version_id", |
|
35 | 35 | :klass => Version, |
|
36 | 36 | :label => :label_version}, |
|
37 | 37 | 'category' => {:sql => "#{Issue.table_name}.category_id", |
|
38 | 38 | :klass => IssueCategory, |
|
39 | 39 | :label => :field_category}, |
|
40 | 40 | 'member' => {:sql => "#{TimeEntry.table_name}.user_id", |
|
41 | 41 | :klass => User, |
|
42 | 42 | :label => :label_member}, |
|
43 | 43 | 'tracker' => {:sql => "#{Issue.table_name}.tracker_id", |
|
44 | 44 | :klass => Tracker, |
|
45 | 45 | :label => :label_tracker}, |
|
46 | 46 | 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", |
|
47 | 47 | :klass => Enumeration, |
|
48 | 48 | :label => :label_activity} |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | @criterias = params[:criterias] || [] |
|
52 | 52 | @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria} |
|
53 | 53 | @criterias.uniq! |
|
54 | 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] | |
|
59 | begin; @date_from = params[:date_from].to_date; rescue; end | |
|
60 | end | |
|
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 | |
|
58 | retrieve_date_range | |
|
59 | @from ||= TimeEntry.minimum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today | |
|
60 | @to ||= TimeEntry.maximum(:spent_on, :include => :project, :conditions => @project.project_condition(Setting.display_subprojects_issues?)) || Date.today | |
|
66 | 61 | |
|
67 | 62 | unless @criterias.empty? |
|
68 | 63 | sql_select = @criterias.collect{|criteria| @available_criterias[criteria][:sql] + " AS " + criteria}.join(', ') |
|
69 | 64 | sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ') |
|
70 | 65 | |
|
71 | 66 | sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours" |
|
72 | 67 | sql << " FROM #{TimeEntry.table_name}" |
|
73 | 68 | sql << " LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id" |
|
74 | 69 | sql << " LEFT JOIN #{Project.table_name} ON #{TimeEntry.table_name}.project_id = #{Project.table_name}.id" |
|
75 | 70 | sql << " WHERE (%s)" % @project.project_condition(Setting.display_subprojects_issues?) |
|
76 | 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 | 73 | sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek" |
|
79 | 74 | |
|
80 | 75 | @hours = ActiveRecord::Base.connection.select_all(sql) |
|
81 | 76 | |
|
82 | 77 | @hours.each do |row| |
|
83 | 78 | case @columns |
|
84 | 79 | when 'year' |
|
85 | 80 | row['year'] = row['tyear'] |
|
86 | 81 | when 'month' |
|
87 | 82 | row['month'] = "#{row['tyear']}-#{row['tmonth']}" |
|
88 | 83 | when 'week' |
|
89 | 84 | row['week'] = "#{row['tyear']}-#{row['tweek']}" |
|
90 | 85 | end |
|
91 | 86 | end |
|
92 | 87 | |
|
93 | 88 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} |
|
94 |
|
|
|
95 | ||
|
96 | @periods = [] | |
|
97 |
date_from = @ |
|
|
98 | # 100 columns max | |
|
99 |
while date_from < @ |
|
|
100 | case @columns | |
|
101 | when 'year' | |
|
102 | @periods << "#{date_from.year}" | |
|
103 |
date_from = date_from |
|
|
104 | when 'month' | |
|
105 | @periods << "#{date_from.year}-#{date_from.month}" | |
|
106 |
date_from = date_from |
|
|
107 | when 'week' | |
|
108 | @periods << "#{date_from.year}-#{date_from.cweek}" | |
|
109 | date_from = date_from + 7 | |
|
89 | ||
|
90 | @periods = [] | |
|
91 | # Date#at_beginning_of_ not supported in Rails 1.2.x | |
|
92 | date_from = @from.to_time | |
|
93 | # 100 columns max | |
|
94 | while date_from <= @to.to_time && @periods.length < 100 | |
|
95 | case @columns | |
|
96 | when 'year' | |
|
97 | @periods << "#{date_from.year}" | |
|
98 | date_from = (date_from + 1.year).at_beginning_of_year | |
|
99 | when 'month' | |
|
100 | @periods << "#{date_from.year}-#{date_from.month}" | |
|
101 | date_from = (date_from + 1.month).at_beginning_of_month | |
|
102 | when 'week' | |
|
103 | @periods << "#{date_from.year}-#{date_from.to_date.cweek}" | |
|
104 | date_from = (date_from + 7.day).at_beginning_of_week | |
|
105 | end | |
|
110 | 106 | end |
|
111 | 107 | end |
|
112 | 108 | |
|
113 | 109 | render :layout => false if request.xhr? |
|
114 | 110 | end |
|
115 | 111 | |
|
116 | 112 | def details |
|
117 | 113 | sort_init 'spent_on', 'desc' |
|
118 | 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 | 116 | cond = ARCondition.new |
|
162 | 117 | cond << (@issue.nil? ? @project.project_condition(Setting.display_subprojects_issues?) : |
|
163 | 118 | ["#{TimeEntry.table_name}.issue_id = ?", @issue.id]) |
|
164 | 119 | |
|
120 | retrieve_date_range | |
|
121 | ||
|
165 | 122 | if @from |
|
166 | 123 | if @to |
|
167 | 124 | cond << ['spent_on BETWEEN ? AND ?', @from, @to] |
|
168 | 125 | else |
|
169 | 126 | cond << ['spent_on >= ?', @from] |
|
170 | 127 | end |
|
171 | 128 | elsif @to |
|
172 | 129 | cond << ['spent_on <= ?', @to] |
|
173 | 130 | end |
|
174 | 131 | |
|
175 | 132 | TimeEntry.visible_by(User.current) do |
|
176 | 133 | respond_to do |format| |
|
177 | 134 | format.html { |
|
178 | 135 | # Paginate results |
|
179 | 136 | @entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions) |
|
180 | 137 | @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] |
|
181 | 138 | @entries = TimeEntry.find(:all, |
|
182 | 139 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
183 | 140 | :conditions => cond.conditions, |
|
184 | 141 | :order => sort_clause, |
|
185 | 142 | :limit => @entry_pages.items_per_page, |
|
186 | 143 | :offset => @entry_pages.current.offset) |
|
187 | 144 | @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f |
|
188 | 145 | render :layout => !request.xhr? |
|
189 | 146 | } |
|
190 | 147 | format.csv { |
|
191 | 148 | # Export all entries |
|
192 | 149 | @entries = TimeEntry.find(:all, |
|
193 | 150 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], |
|
194 | 151 | :conditions => cond.conditions, |
|
195 | 152 | :order => sort_clause) |
|
196 | 153 | send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv') |
|
197 | 154 | } |
|
198 | 155 | end |
|
199 | 156 | end |
|
200 | 157 | end |
|
201 | 158 | |
|
202 | 159 | def edit |
|
203 | 160 | render_403 and return if @time_entry && !@time_entry.editable_by?(User.current) |
|
204 | 161 | @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today) |
|
205 | 162 | @time_entry.attributes = params[:time_entry] |
|
206 | 163 | if request.post? and @time_entry.save |
|
207 | 164 | flash[:notice] = l(:notice_successful_update) |
|
208 | 165 | redirect_to :action => 'details', :project_id => @time_entry.project |
|
209 | 166 | return |
|
210 | 167 | end |
|
211 | 168 | @activities = Enumeration::get_values('ACTI') |
|
212 | 169 | end |
|
213 | 170 | |
|
214 | 171 | def destroy |
|
215 | 172 | render_404 and return unless @time_entry |
|
216 | 173 | render_403 and return unless @time_entry.editable_by?(User.current) |
|
217 | 174 | @time_entry.destroy |
|
218 | 175 | flash[:notice] = l(:notice_successful_delete) |
|
219 | 176 | redirect_to :back |
|
220 | 177 | rescue RedirectBackError |
|
221 | 178 | redirect_to :action => 'details', :project_id => @time_entry.project |
|
222 | 179 | end |
|
223 | 180 | |
|
224 | 181 | private |
|
225 | 182 | def find_project |
|
226 | 183 | if params[:id] |
|
227 | 184 | @time_entry = TimeEntry.find(params[:id]) |
|
228 | 185 | @project = @time_entry.project |
|
229 | 186 | elsif params[:issue_id] |
|
230 | 187 | @issue = Issue.find(params[:issue_id]) |
|
231 | 188 | @project = @issue.project |
|
232 | 189 | elsif params[:project_id] |
|
233 | 190 | @project = Project.find(params[:project_id]) |
|
234 | 191 | else |
|
235 | 192 | render_404 |
|
236 | 193 | return false |
|
237 | 194 | end |
|
238 | 195 | rescue ActiveRecord::RecordNotFound |
|
239 | 196 | render_404 |
|
240 | 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 | 242 | end |
@@ -1,46 +1,30 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}, :class => 'icon icon-report') %> |
|
3 | 3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %> |
|
4 | 4 | </div> |
|
5 | 5 | |
|
6 | 6 | <h2><%= l(:label_spent_time) %></h2> |
|
7 | 7 | |
|
8 | 8 | <% if @issue %> |
|
9 | 9 | <h3><%= link_to(@project.name, {:action => 'details', :project_id => @project}) %> / <%= link_to_issue(@issue) %></h3> |
|
10 | 10 | <% end %> |
|
11 | 11 | |
|
12 | 12 | <% form_remote_tag( :url => {}, :method => :get, :update => 'content' ) do %> |
|
13 | 13 | <%= hidden_field_tag 'project_id', params[:project_id] %> |
|
14 | 14 | <%= hidden_field_tag 'issue_id', params[:issue_id] if @issue %> |
|
15 | ||
|
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> | |
|
15 | <%= render :partial => 'date_range' %> | |
|
32 | 16 | <% end %> |
|
33 | 17 | |
|
34 | 18 | <div class="total-hours"> |
|
35 | 19 | <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p> |
|
36 | 20 | </div> |
|
37 | 21 | |
|
38 | 22 | <% unless @entries.empty? %> |
|
39 | 23 | <%= render :partial => 'list', :locals => { :entries => @entries }%> |
|
40 | 24 | <p class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></p> |
|
41 | 25 | |
|
42 | 26 | <p class="other-formats"> |
|
43 | 27 | <%= l(:label_export_to) %> |
|
44 | 28 | <span><%= link_to 'CSV', params.merge(:format => 'csv'), :class => 'csv' %></span> |
|
45 | 29 | </p> |
|
46 | 30 | <% end %> |
@@ -1,65 +1,59 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}, :class => 'icon icon-details') %> |
|
3 | 3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %> |
|
4 | 4 | </div> |
|
5 | 5 | |
|
6 | 6 | <h2><%= l(:label_spent_time) %></h2> |
|
7 | 7 | |
|
8 |
<% form_remote_tag(:url => { |
|
|
8 | <% form_remote_tag(:url => {}, :update => 'content') do %> | |
|
9 | 9 | <% @criterias.each do |criteria| %> |
|
10 | 10 | <%= hidden_field_tag 'criterias[]', criteria %> |
|
11 | 11 | <% end %> |
|
12 | <fieldset><legend><%= l(:label_date_range) %></legend> | |
|
13 | <p> | |
|
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) %> | |
|
12 | <%= hidden_field_tag 'project_id', params[:project_id] %> | |
|
13 | <%= render :partial => 'date_range' %> | |
|
24 | 14 | </p> |
|
25 | 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 | 22 | :onchange => "this.form.onsubmit();", |
|
29 | 23 | :style => 'width: 200px', |
|
30 | 24 | :disabled => (@criterias.length >= 3)) %> |
|
31 | 25 | <%= link_to_remote l(:button_clear), {:url => {:project_id => @project, :date_from => @date_from, :date_to => @date_to, :period => @columns}, :update => 'content'}, |
|
32 | 26 | :class => 'icon icon-reload' %></p> |
|
33 | ||
|
27 | <% end %> | |
|
28 | ||
|
34 | 29 | <% unless @criterias.empty? %> |
|
35 | 30 | <div class="total-hours"> |
|
36 | 31 | <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p> |
|
37 | 32 | </div> |
|
38 | 33 | |
|
39 | 34 | <% unless @hours.empty? %> |
|
40 | 35 | <table class="list" id="time-report"> |
|
41 | 36 | <thead> |
|
42 | 37 | <tr> |
|
43 | 38 | <% @criterias.each do |criteria| %> |
|
44 | 39 | <th width="15%"><%= l(@available_criterias[criteria][:label]) %></th> |
|
45 | 40 | <% end %> |
|
46 | 41 | <% @periods.each do |period| %> |
|
47 | 42 | <th width="<%= ((100 - @criterias.length * 15 - 15 ) / @periods.length).to_i %>%"><%= period %></th> |
|
48 | 43 | <% end %> |
|
49 | 44 | </tr> |
|
50 | 45 | </thead> |
|
51 | 46 | <tbody> |
|
52 | 47 | <%= render :partial => 'report_criteria', :locals => {:criterias => @criterias, :hours => @hours, :level => 0} %> |
|
53 | 48 | <tr class="total"> |
|
54 | 49 | <td><%= l(:label_total) %></td> |
|
55 | 50 | <%= '<td></td>' * (@criterias.size - 1) %> |
|
56 | 51 | <% @periods.each do |period| -%> |
|
57 | 52 | <% sum = sum_hours(select_hours(@hours, @columns, period.to_s)) %> |
|
58 | 53 | <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td> |
|
59 | 54 | <% end -%> |
|
60 | 55 | </tr> |
|
61 | 56 | </tbody> |
|
62 | 57 | </table> |
|
63 | 58 | <% end %> |
|
64 | 59 | <% end %> |
|
65 | <% end %> |
@@ -1,163 +1,171 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.dirname(__FILE__) + '/../test_helper' |
|
19 | 19 | require 'timelog_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class TimelogController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class TimelogControllerTest < Test::Unit::TestCase |
|
25 | 25 | fixtures :projects, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = TimelogController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def test_create |
|
34 | 34 | @request.session[:user_id] = 3 |
|
35 | 35 | post :edit, :project_id => 1, |
|
36 | 36 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
37 | 37 | :activity_id => '10', |
|
38 | 38 | :spent_on => '2008-03-14', |
|
39 | 39 | :issue_id => '1', |
|
40 | 40 | :hours => '7.3'} |
|
41 | 41 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
42 | 42 | |
|
43 | 43 | i = Issue.find(1) |
|
44 | 44 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
45 | 45 | assert_not_nil t |
|
46 | 46 | assert_equal 7.3, t.hours |
|
47 | 47 | assert_equal 3, t.user_id |
|
48 | 48 | assert_equal i, t.issue |
|
49 | 49 | assert_equal i.project, t.project |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_update |
|
53 | 53 | entry = TimeEntry.find(1) |
|
54 | 54 | assert_equal 1, entry.issue_id |
|
55 | 55 | assert_equal 2, entry.user_id |
|
56 | 56 | |
|
57 | 57 | @request.session[:user_id] = 1 |
|
58 | 58 | post :edit, :id => 1, |
|
59 | 59 | :time_entry => {:issue_id => '2', |
|
60 | 60 | :hours => '8'} |
|
61 | 61 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
62 | 62 | entry.reload |
|
63 | 63 | |
|
64 | 64 | assert_equal 8, entry.hours |
|
65 | 65 | assert_equal 2, entry.issue_id |
|
66 | 66 | assert_equal 2, entry.user_id |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def destroy |
|
70 | 70 | @request.session[:user_id] = 2 |
|
71 | 71 | post :destroy, :id => 1 |
|
72 | 72 | assert_redirected_to 'projects/ecookbook/timelog/details' |
|
73 | 73 | assert_nil TimeEntry.find_by_id(1) |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def test_report_no_criteria |
|
77 | 77 | get :report, :project_id => 1 |
|
78 | 78 | assert_response :success |
|
79 | 79 | assert_template 'report' |
|
80 | 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 | 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 | 92 | assert_response :success |
|
85 | 93 | assert_template 'report' |
|
86 | 94 | assert_not_nil assigns(:total_hours) |
|
87 | 95 | assert_equal "8.65", "%.2f" % assigns(:total_hours) |
|
88 | end | |
|
96 | end | |
|
89 | 97 | |
|
90 | 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 | 100 | assert_response :success |
|
93 | 101 | assert_template 'report' |
|
94 | 102 | assert_not_nil assigns(:total_hours) |
|
95 | 103 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
96 | 104 | end |
|
97 | 105 | |
|
98 | 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 | 108 | assert_response :success |
|
101 | 109 | assert_template 'report' |
|
102 | 110 | assert_not_nil assigns(:total_hours) |
|
103 | 111 | assert_equal "0.00", "%.2f" % assigns(:total_hours) |
|
104 | 112 | end |
|
105 | 113 | |
|
106 | 114 | def test_details_at_project_level |
|
107 | 115 | get :details, :project_id => 1 |
|
108 | 116 | assert_response :success |
|
109 | 117 | assert_template 'details' |
|
110 | 118 | assert_not_nil assigns(:entries) |
|
111 | 119 | assert_equal 4, assigns(:entries).size |
|
112 | 120 | # project and subproject |
|
113 | 121 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
114 | 122 | assert_not_nil assigns(:total_hours) |
|
115 | 123 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
116 | 124 | # display all time by default |
|
117 | 125 | assert_nil assigns(:from) |
|
118 | 126 | assert_nil assigns(:to) |
|
119 | 127 | end |
|
120 | 128 | |
|
121 | 129 | def test_details_at_project_level_with_date_range |
|
122 | 130 | get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' |
|
123 | 131 | assert_response :success |
|
124 | 132 | assert_template 'details' |
|
125 | 133 | assert_not_nil assigns(:entries) |
|
126 | 134 | assert_equal 3, assigns(:entries).size |
|
127 | 135 | assert_not_nil assigns(:total_hours) |
|
128 | 136 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
129 | 137 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
130 | 138 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
131 | 139 | end |
|
132 | 140 | |
|
133 | 141 | def test_details_at_project_level_with_period |
|
134 | 142 | get :details, :project_id => 1, :period => '7_days' |
|
135 | 143 | assert_response :success |
|
136 | 144 | assert_template 'details' |
|
137 | 145 | assert_not_nil assigns(:entries) |
|
138 | 146 | assert_not_nil assigns(:total_hours) |
|
139 | 147 | assert_equal Date.today - 7, assigns(:from) |
|
140 | 148 | assert_equal Date.today, assigns(:to) |
|
141 | 149 | end |
|
142 | 150 | |
|
143 | 151 | def test_details_at_issue_level |
|
144 | 152 | get :details, :issue_id => 1 |
|
145 | 153 | assert_response :success |
|
146 | 154 | assert_template 'details' |
|
147 | 155 | assert_not_nil assigns(:entries) |
|
148 | 156 | assert_equal 2, assigns(:entries).size |
|
149 | 157 | assert_not_nil assigns(:total_hours) |
|
150 | 158 | assert_equal 154.25, assigns(:total_hours) |
|
151 | 159 | # display all time by default |
|
152 | 160 | assert_nil assigns(:from) |
|
153 | 161 | assert_nil assigns(:to) |
|
154 | 162 | end |
|
155 | 163 | |
|
156 | 164 | def test_details_csv_export |
|
157 | 165 | get :details, :project_id => 1, :format => 'csv' |
|
158 | 166 | assert_response :success |
|
159 | 167 | assert_equal 'text/csv', @response.content_type |
|
160 | 168 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") |
|
161 | 169 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,2,Feature request,Add ingredients categories,1.0,\"\"\n") |
|
162 | 170 | end |
|
163 | 171 | end |
General Comments 0
You need to be logged in to leave comments.
Login now