##// END OF EJS Templates
Propagates time tracking to the parent project (closes #433). Time report enhancements....
Jean-Philippe Lang -
r1162:200842ba5e75
parent child
Show More
@@ -0,0 +1,41
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 class ARCondition
19 attr_reader :conditions
20
21 def initialize(condition=nil)
22 @conditions = ['1=1']
23 @conditions.add(condition) if condition
24 end
25
26 def add(condition)
27 if condition.is_a?(Array)
28 @conditions.first << " AND (#{condition.first})"
29 @conditions += condition[1..-1]
30 elsif condition.is_a?(String)
31 @conditions.first << " AND (#{condition})"
32 else
33 raise "Unsupported #{condition.class} condition: #{condition}"
34 end
35 self
36 end
37
38 def <<(condition)
39 add(condition)
40 end
41 end
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -90,7 +90,11 class ProjectsController < ApplicationController
90 @trackers = @project.trackers
90 @trackers = @project.trackers
91 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
91 @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
92 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
92 @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
93 @total_hours = @project.time_entries.sum(:hours)
93 TimeEntry.visible_by(User.current) do
94 @total_hours = TimeEntry.sum(:hours,
95 :include => :project,
96 :conditions => ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id]).to_f
97 end
94 @key = User.current.rss_key
98 @key = User.current.rss_key
95 end
99 end
96
100
@@ -26,26 +26,30 class TimelogController < ApplicationController
26 include TimelogHelper
26 include TimelogHelper
27
27
28 def report
28 def report
29 @available_criterias = { 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
29 @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
30 :values => @project.versions,
30 :klass => Project,
31 :label => :label_project},
32 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
33 :klass => Version,
31 :label => :label_version},
34 :label => :label_version},
32 'category' => {:sql => "#{Issue.table_name}.category_id",
35 'category' => {:sql => "#{Issue.table_name}.category_id",
33 :values => @project.issue_categories,
36 :klass => IssueCategory,
34 :label => :field_category},
37 :label => :field_category},
35 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
38 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
36 :values => @project.users,
39 :klass => User,
37 :label => :label_member},
40 :label => :label_member},
38 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
41 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
39 :values => Tracker.find(:all),
42 :klass => Tracker,
40 :label => :label_tracker},
43 :label => :label_tracker},
41 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
44 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
42 :values => Enumeration::get_values('ACTI'),
45 :klass => Enumeration,
43 :label => :label_activity}
46 :label => :label_activity}
44 }
47 }
45
48
46 @criterias = params[:criterias] || []
49 @criterias = params[:criterias] || []
47 @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
50 @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria}
48 @criterias.uniq!
51 @criterias.uniq!
52 @criterias = @criterias[0,3]
49
53
50 @columns = (params[:period] && %w(year month week).include?(params[:period])) ? params[:period] : 'month'
54 @columns = (params[:period] && %w(year month week).include?(params[:period])) ? params[:period] : 'month'
51
55
@@ -63,8 +67,11 class TimelogController < ApplicationController
63 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
67 sql_group_by = @criterias.collect{|criteria| @available_criterias[criteria][:sql]}.join(', ')
64
68
65 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
69 sql = "SELECT #{sql_select}, tyear, tmonth, tweek, SUM(hours) AS hours"
66 sql << " FROM #{TimeEntry.table_name} LEFT JOIN #{Issue.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id"
70 sql << " FROM #{TimeEntry.table_name}"
67 sql << " WHERE #{TimeEntry.table_name}.project_id = %s" % @project.id
71 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"
73 sql << " WHERE (#{Project.table_name}.id = %s OR #{Project.table_name}.parent_id = %s)" % [@project.id, @project.id]
74 sql << " AND (%s)" % Project.allowed_to_condition(User.current, :view_time_entries)
68 sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
75 sql << " AND spent_on BETWEEN '%s' AND '%s'" % [ActiveRecord::Base.connection.quoted_date(@date_from.to_time), ActiveRecord::Base.connection.quoted_date(@date_to.to_time)]
69 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
76 sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek"
70
77
@@ -80,6 +87,8 class TimelogController < ApplicationController
80 row['week'] = "#{row['tyear']}-#{row['tweek']}"
87 row['week'] = "#{row['tyear']}-#{row['tweek']}"
81 end
88 end
82 end
89 end
90
91 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
83 end
92 end
84
93
85 @periods = []
94 @periods = []
@@ -147,41 +156,44 class TimelogController < ApplicationController
147
156
148 @from, @to = @to, @from if @from && @to && @from > @to
157 @from, @to = @to, @from if @from && @to && @from > @to
149
158
150 conditions = nil
159 cond = ARCondition.new
160 cond << (@issue.nil? ? ["(#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?)", @project.id, @project.id] :
161 ["#{TimeEntry.table_name}.issue_id = ?", @issue.id])
162
151 if @from
163 if @from
152 if @to
164 if @to
153 conditions = ['spent_on BETWEEN ? AND ?', @from, @to]
165 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
154 else
166 else
155 conditions = ['spent_on >= ?', @from]
167 cond << ['spent_on >= ?', @from]
156 end
168 end
157 elsif @to
169 elsif @to
158 conditions = ['spent_on <= ?', @to]
170 cond << ['spent_on <= ?', @to]
159 end
171 end
160
161 @owner_id = User.current.id
162
172
163 respond_to do |format|
173 TimeEntry.visible_by(User.current) do
164 format.html {
174 respond_to do |format|
165 # Paginate results
175 format.html {
166 @entry_count = (@issue ? @issue : @project).time_entries.count(:conditions => conditions)
176 # Paginate results
167 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
177 @entry_count = TimeEntry.count(:include => :project, :conditions => cond.conditions)
168 @entries = (@issue ? @issue : @project).time_entries.find(:all,
178 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
169 :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
179 @entries = TimeEntry.find(:all,
170 :conditions => conditions,
180 :include => [:project, :activity, :user, {:issue => :tracker}],
171 :order => sort_clause,
181 :conditions => cond.conditions,
172 :limit => @entry_pages.items_per_page,
182 :order => sort_clause,
173 :offset => @entry_pages.current.offset)
183 :limit => @entry_pages.items_per_page,
174 @total_hours = (@issue ? @issue : @project).time_entries.sum(:hours, :conditions => conditions).to_f
184 :offset => @entry_pages.current.offset)
175 render :layout => !request.xhr?
185 @total_hours = TimeEntry.sum(:hours, :include => :project, :conditions => cond.conditions).to_f
176 }
186 render :layout => !request.xhr?
177 format.csv {
187 }
178 # Export all entries
188 format.csv {
179 @entries = (@issue ? @issue : @project).time_entries.find(:all,
189 # Export all entries
180 :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
190 @entries = TimeEntry.find(:all,
181 :conditions => conditions,
191 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
182 :order => sort_clause)
192 :conditions => cond.conditions,
183 send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
193 :order => sort_clause)
184 }
194 send_data(entries_to_csv(@entries).read, :type => 'text/csv; header=present', :filename => 'timelog.csv')
195 }
196 end
185 end
197 end
186 end
198 end
187
199
@@ -17,7 +17,7
17
17
18 module TimelogHelper
18 module TimelogHelper
19 def select_hours(data, criteria, value)
19 def select_hours(data, criteria, value)
20 data.select {|row| row[criteria] == value.to_s}
20 data.select {|row| row[criteria] == value}
21 end
21 end
22
22
23 def sum_hours(data)
23 def sum_hours(data)
@@ -50,6 +50,7 module TimelogHelper
50 headers = [l(:field_spent_on),
50 headers = [l(:field_spent_on),
51 l(:field_user),
51 l(:field_user),
52 l(:field_activity),
52 l(:field_activity),
53 l(:field_project),
53 l(:field_issue),
54 l(:field_issue),
54 l(:field_tracker),
55 l(:field_tracker),
55 l(:field_subject),
56 l(:field_subject),
@@ -62,6 +63,7 module TimelogHelper
62 fields = [l_date(entry.spent_on),
63 fields = [l_date(entry.spent_on),
63 entry.user,
64 entry.user,
64 entry.activity,
65 entry.activity,
66 entry.project,
65 (entry.issue ? entry.issue.id : nil),
67 (entry.issue ? entry.issue.id : nil),
66 (entry.issue ? entry.issue.tracker : nil),
68 (entry.issue ? entry.issue.tracker : nil),
67 (entry.issue ? entry.issue.subject : nil),
69 (entry.issue ? entry.issue.subject : nil),
@@ -110,6 +110,21 class Project < ActiveRecord::Base
110 end
110 end
111 end
111 end
112
112
113 def self.allowed_to_condition(user, permission)
114 statements = []
115 active_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
116 if user.admin?
117 # no restriction
118 elsif user.logged?
119 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
120 allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
121 statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})"
122 else
123 statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.anonymous.allowed_to?(permission)
124 end
125 statements.empty? ? active_statement : "(#{active_statement} AND (#{statements.join(' OR ')}))"
126 end
127
113 def self.find(*args)
128 def self.find(*args)
114 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
129 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
115 project = find_by_identifier(*args)
130 project = find_by_identifier(*args)
@@ -52,4 +52,10 class TimeEntry < ActiveRecord::Base
52 def editable_by?(usr)
52 def editable_by?(usr)
53 usr == self.user
53 usr == self.user
54 end
54 end
55
56 def self.visible_by(usr)
57 with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
58 yield
59 end
60 end
55 end
61 end
@@ -3,6 +3,7
3 <%= sort_header_tag('spent_on', :caption => l(:label_date), :default_order => 'desc') %>
3 <%= sort_header_tag('spent_on', :caption => l(:label_date), :default_order => 'desc') %>
4 <%= sort_header_tag('user_id', :caption => l(:label_member)) %>
4 <%= sort_header_tag('user_id', :caption => l(:label_member)) %>
5 <%= sort_header_tag('activity_id', :caption => l(:label_activity)) %>
5 <%= sort_header_tag('activity_id', :caption => l(:label_activity)) %>
6 <%= sort_header_tag("#{Project.table_name}.name", :caption => l(:label_project)) %>
6 <%= sort_header_tag('issue_id', :caption => l(:label_issue), :default_order => 'desc') %>
7 <%= sort_header_tag('issue_id', :caption => l(:label_issue), :default_order => 'desc') %>
7 <th><%= l(:field_comments) %></th>
8 <th><%= l(:field_comments) %></th>
8 <%= sort_header_tag('hours', :caption => l(:field_hours)) %>
9 <%= sort_header_tag('hours', :caption => l(:field_hours)) %>
@@ -12,17 +13,16
12 <% entries.each do |entry| -%>
13 <% entries.each do |entry| -%>
13 <tr class="time-entry <%= cycle("odd", "even") %>">
14 <tr class="time-entry <%= cycle("odd", "even") %>">
14 <td class="spent_on"><%= format_date(entry.spent_on) %></td>
15 <td class="spent_on"><%= format_date(entry.spent_on) %></td>
15 <td class="user"><%= entry.user.name %></td>
16 <td class="user"><%=h entry.user %></td>
16 <td class="activity"><%= entry.activity.name %></td>
17 <td class="activity"><%=h entry.activity %></td>
18 <td class="project"><%=h entry.project %></td>
17 <td class="subject">
19 <td class="subject">
18 <% if entry.issue -%>
20 <% if entry.issue -%>
19 <div class="tooltip"><%= link_to_issue entry.issue %>: <%= h(truncate(entry.issue.subject, 50)) -%>
21 <%= link_to_issue entry.issue %>: <%= h(truncate(entry.issue.subject, 50)) -%>
20 <span class="tip"><%= render_issue_tooltip entry.issue %></span>
22 <% end -%>
21 </div>
22 <% end -%>
23 </td>
23 </td>
24 <td class="comments"><%=h entry.comments %></td>
24 <td class="comments"><%=h entry.comments %></td>
25 <td class="hours"><%= entry.hours %></td>
25 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
26 <td align="center"><%= link_to_if_authorized(l(:button_edit),
26 <td align="center"><%= link_to_if_authorized(l(:button_edit),
27 {:controller => 'timelog', :action => 'edit', :id => entry},
27 {:controller => 'timelog', :action => 'edit', :id => entry},
28 :class => 'icon icon-edit') if entry.editable_by?(User.current) %></td>
28 :class => 'icon icon-edit') if entry.editable_by?(User.current) %></td>
@@ -1,17 +1,17
1 <% @available_criterias[criterias[level]][:values].each do |value| %>
1 <% @hours.collect {|h| h[criterias[level]]}.uniq.each do |value| %>
2 <tr class="<%= cycle('odd', 'even') if criterias.length < level + 2 %>">
2 <% hours_for_value = select_hours(hours, criterias[level], value) -%>
3 <% next if hours_for_value.empty? -%>
4 <tr class="<%= cycle('odd', 'even') %> <%= 'last-level' unless criterias.length > level+1 %>">
3 <%= '<td></td>' * level %>
5 <%= '<td></td>' * level %>
4 <td><%= value.name %></td>
6 <td><%= value.nil? ? l(:label_none) : @available_criterias[criterias[level]][:klass].find_by_id(value) %></td>
5 <%= '<td></td>' * (criterias.length - level - 1) %>
7 <%= '<td></td>' * (criterias.length - level - 1) -%>
6 <% hours_for_value = select_hours(hours, criterias[level], value.id) %>
8 <% @periods.each do |period| -%>
7 <% @periods.each do |period| %>
8 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) %>
9 <% sum = sum_hours(select_hours(hours_for_value, @columns, period.to_s)) %>
9 <td align="center"><%= sum > 0 ? "%.2f" % sum : "-" %></td>
10 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
10 <% end %>
11 <% end -%>
11 </tr>
12 </tr>
12 <% if criterias.length > level+1 %>
13 <% if criterias.length > level+1 -%>
13 <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
14 <%= render(:partial => 'report_criteria', :locals => {:criterias => criterias, :hours => hours_for_value, :level => (level + 1)}) %>
14 <% end %>
15 <% end -%>
15
16
16 <% end %>
17 <% end %>
17 <% reset_cycle %>
@@ -1,4 +1,5
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') %>
2 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
3 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time' %>
3 </div>
4 </div>
4
5
@@ -25,7 +26,7
25 <%= text_field_tag 'from', @from, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('from') %>
26 <%= text_field_tag 'from', @from, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('from') %>
26 <%= l(:label_date_to) %>
27 <%= l(:label_date_to) %>
27 <%= text_field_tag 'to', @to, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('to') %>
28 <%= text_field_tag 'to', @to, :size => 10, :onfocus => '$("period_type_2").checked = true;' %> <%= calendar_for('to') %>
28 <%= submit_tag l(:button_submit), :name => nil, :onclick => '$("period_type_2").checked = true;' %>
29 <%= submit_tag l(:button_apply), :name => nil, :onclick => '$("period_type_2").checked = true;' %>
29 </p>
30 </p>
30 </fieldset>
31 </fieldset>
31 <% end %>
32 <% end %>
@@ -1,31 +1,43
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' %>
4 </div>
5
1 <h2><%= l(:label_spent_time) %></h2>
6 <h2><%= l(:label_spent_time) %></h2>
2
7
3 <% form_remote_tag(:url => {:project_id => @project}, :update => 'content') do %>
8 <% form_remote_tag(:url => {:project_id => @project}, :update => 'content') do %>
4 <% @criterias.each do |criteria| %>
9 <% @criterias.each do |criteria| %>
5 <%= hidden_field_tag 'criterias[]', criteria %>
10 <%= hidden_field_tag 'criterias[]', criteria %>
6 <% end %>
11 <% end %>
12 <fieldset><legend><%= l(:label_date_range) %></legend>
7 <p>
13 <p>
8 <%= l(:label_date_from) %>: <%= text_field_tag 'date_from', @date_from, :size => 10 %><%= calendar_for('date_from') %>
14 <%= l(:label_date_from) %>
9 &nbsp;
15 <%= text_field_tag 'date_from', @date_from, :size => 10 %><%= calendar_for('date_from') %>
10 <%= l(:label_date_to) %>: <%= text_field_tag 'date_to', @date_to, :size => 10 %><%= calendar_for('date_to') %>
16 <%= l(:label_date_to) %>
11 &nbsp;
17 <%= text_field_tag 'date_to', @date_to, :size => 10 %><%= calendar_for('date_to') %>
12 <%= l(:label_details) %>:
18 <%= l(:label_details) %>
13 <%= select_tag 'period', options_for_select([[l(:label_year), 'year'],
19 <%= select_tag 'period', options_for_select([[l(:label_year), 'year'],
14 [l(:label_month), 'month'],
20 [l(:label_month), 'month'],
15 [l(:label_week), 'week']], @columns) %>
21 [l(:label_week), 'week']], @columns) %>
16 &nbsp;
22 &nbsp;
17 <%= submit_tag l(:button_apply) %>
23 <%= submit_tag l(:button_apply) %>
18 <%= link_to_remote l(:button_clear), {:url => {:project_id => @project}, :update => 'content'}, :class => 'icon icon-reload' %>
19 </p>
24 </p>
25 </fieldset>
20
26
21 <% if @criterias.length < 3 %>
27 <p><%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@available_criterias.keys - @criterias).collect{|k| [l(@available_criterias[k][:label]), k]}),
22 <p><%= l(:button_add) %>: <%= select_tag('criterias[]', options_for_select([[]] + (@available_criterias.keys - @criterias).collect{|k| [l(@available_criterias[k][:label]), k]}), :onchange => "this.form.onsubmit();") %></p>
28 :onchange => "this.form.onsubmit();",
23 <% end %>
29 :style => 'width: 200px',
30 :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'},
32 :class => 'icon icon-reload' %></p>
24
33
25 <br />
34 <% unless @criterias.empty? %>
35 <div class="total-hours">
36 <p><%= l(:label_total) %>: <%= html_hours(lwr(:label_f_hour, @total_hours)) %></p>
37 </div>
26
38
27 <% unless @criterias.empty? %>
39 <% unless @hours.empty? %>
28 <table class="list">
40 <table class="list" id="time-report">
29 <thead>
41 <thead>
30 <tr>
42 <tr>
31 <% @criterias.each do |criteria| %>
43 <% @criterias.each do |criteria| %>
@@ -36,13 +48,21
36 <% end %>
48 <% end %>
37 </tr>
49 </tr>
38 </thead>
50 </thead>
39
40 <tbody>
51 <tbody>
41 <%= render :partial => 'report_criteria', :locals => {:criterias => @criterias, :hours => @hours, :level => 0} %>
52 <%= render :partial => 'report_criteria', :locals => {:criterias => @criterias, :hours => @hours, :level => 0} %>
53 <tr class="total">
54 <td><%= l(:label_total) %></td>
55 <%= '<td></td>' * (@criterias.size - 1) %>
56 <% @periods.each do |period| -%>
57 <% sum = sum_hours(select_hours(@hours, @columns, period.to_s)) %>
58 <td class="hours"><%= html_hours("%.2f" % sum) if sum > 0 %></td>
59 <% end -%>
60 </tr>
42 </tbody>
61 </tbody>
43 </table>
62 </table>
44 <% end %>
63 <% end %>
45 <% end %>
64 <% end %>
65 <% end %>
46
66
47 <% content_for :header_tags do %>
67 <% content_for :header_tags do %>
48 <%= javascript_include_tag 'calendar/calendar' %>
68 <%= javascript_include_tag 'calendar/calendar' %>
@@ -112,7 +112,8 tr.user.locked a, tr.user.registered a { color: #aaa; }
112
112
113 tr.time-entry { text-align: center; white-space: nowrap; }
113 tr.time-entry { text-align: center; white-space: nowrap; }
114 tr.time-entry td.subject, tr.time-entry td.comments { text-align: left; }
114 tr.time-entry td.subject, tr.time-entry td.comments { text-align: left; }
115 tr.time-entry td.hours { text-align: right; font-weight: bold; padding-right: 0.6em; }
115 tr.time-entry td.hours { text-align: right; font-weight: bold; padding-right: 0.5em; }
116 tr.time-entry .hours-dec { font-size: 0.9em; }
116
117
117 table.list tbody tr:hover { background-color:#ffffdd; }
118 table.list tbody tr:hover { background-color:#ffffdd; }
118 table td {padding:2px;}
119 table td {padding:2px;}
@@ -173,6 +174,12 div#roadmap .wiki h1:first-child { display: none; }
173 div#roadmap .wiki h1 { font-size: 120%; }
174 div#roadmap .wiki h1 { font-size: 120%; }
174 div#roadmap .wiki h2 { font-size: 110%; }
175 div#roadmap .wiki h2 { font-size: 110%; }
175
176
177 table#time-report td.hours { text-align: right; padding-right: 0.5em; }
178 table#time-report tbody tr { font-style: italic; color: #777; }
179 table#time-report tbody tr.last-level { font-style: normal; color: #555; }
180 table#time-report tbody tr.total { font-style: normal; font-weight: bold; color: #555; background-color:#EEEEEE; }
181 table#time-report .hours-dec { font-size: 0.9em; }
182
176 div.total-hours { text-align: left; font-size: 110%; font-weight: bold; }
183 div.total-hours { text-align: left; font-size: 110%; font-weight: bold; }
177 div.total-hours span.hours-int { font-size: 120%; }
184 div.total-hours span.hours-int { font-size: 120%; }
178
185
@@ -536,6 +543,8 vertical-align: middle;
536 .icon-lock { background-image: url(../images/locked.png); }
543 .icon-lock { background-image: url(../images/locked.png); }
537 .icon-unlock { background-image: url(../images/unlock.png); }
544 .icon-unlock { background-image: url(../images/unlock.png); }
538 .icon-checked { background-image: url(../images/true.png); }
545 .icon-checked { background-image: url(../images/true.png); }
546 .icon-details { background-image: url(../images/zoom_in.png); }
547 .icon-report { background-image: url(../images/report.png); }
539
548
540 .icon22-projects { background-image: url(../images/22x22/projects.png); }
549 .icon22-projects { background-image: url(../images/22x22/projects.png); }
541 .icon22-users { background-image: url(../images/22x22/users.png); }
550 .icon22-users { background-image: url(../images/22x22/users.png); }
@@ -6,7 +6,7 time_entries_001:
6 project_id: 1
6 project_id: 1
7 comments: My hours
7 comments: My hours
8 updated_on: 2007-03-23 12:54:18 +01:00
8 updated_on: 2007-03-23 12:54:18 +01:00
9 activity_id: 8
9 activity_id: 9
10 spent_on: 2007-03-23
10 spent_on: 2007-03-23
11 issue_id: 1
11 issue_id: 1
12 id: 1
12 id: 1
@@ -20,7 +20,7 time_entries_002:
20 project_id: 1
20 project_id: 1
21 comments: ""
21 comments: ""
22 updated_on: 2007-03-23 14:11:04 +01:00
22 updated_on: 2007-03-23 14:11:04 +01:00
23 activity_id: 8
23 activity_id: 9
24 spent_on: 2007-03-12
24 spent_on: 2007-03-12
25 issue_id: 1
25 issue_id: 1
26 id: 2
26 id: 2
@@ -34,10 +34,25 time_entries_003:
34 project_id: 1
34 project_id: 1
35 comments: ""
35 comments: ""
36 updated_on: 2007-04-21 12:20:48 +02:00
36 updated_on: 2007-04-21 12:20:48 +02:00
37 activity_id: 8
37 activity_id: 9
38 spent_on: 2007-04-21
38 spent_on: 2007-04-21
39 issue_id: 2
39 issue_id: 2
40 id: 3
40 id: 3
41 hours: 1.0
41 hours: 1.0
42 user_id: 1
42 user_id: 1
43 tyear: 2007
43 tyear: 2007
44 time_entries_004:
45 created_on: 2007-04-22 12:20:48 +02:00
46 tweek: 16
47 tmonth: 4
48 project_id: 3
49 comments: Time spent on a subproject
50 updated_on: 2007-04-22 12:20:48 +02:00
51 activity_id: 10
52 spent_on: 2007-04-22
53 issue_id:
54 id: 4
55 hours: 7.65
56 user_id: 1
57 tyear: 2007
58 No newline at end of file
@@ -37,27 +37,39 class TimelogControllerTest < Test::Unit::TestCase
37 end
37 end
38
38
39 def test_report_one_criteria
39 def test_report_one_criteria
40 get :report, :project_id => 1, :period => "month", :date_from => "2007-01-01", :date_to => "2007-12-31", :criterias => ["member"]
40 get :report, :project_id => 1, :period => 'week', :date_from => "2007-04-01", :date_to => "2007-04-30", :criterias => ['project']
41 assert_response :success
41 assert_response :success
42 assert_template 'report'
42 assert_template 'report'
43 assert_not_nil assigns(:hours)
43 assert_not_nil assigns(:total_hours)
44 end
44 assert_equal "8.65", "%.2f" % assigns(:total_hours)
45 end
45
46
46 def test_report_two_criterias
47 def test_report_two_criterias
47 get :report, :project_id => 1, :period => "week", :date_from => "2007-01-01", :date_to => "2007-12-31", :criterias => ["member", "activity"]
48 get :report, :project_id => 1, :period => 'month', :date_from => "2007-01-01", :date_to => "2007-12-31", :criterias => ["member", "activity"]
48 assert_response :success
49 assert_response :success
49 assert_template 'report'
50 assert_template 'report'
50 assert_not_nil assigns(:hours)
51 assert_not_nil assigns(:total_hours)
52 assert_equal "162.90", "%.2f" % assigns(:total_hours)
51 end
53 end
52
54
55 def test_report_one_criteria_no_result
56 get :report, :project_id => 1, :period => 'week', :date_from => "1998-04-01", :date_to => "1998-04-30", :criterias => ['project']
57 assert_response :success
58 assert_template 'report'
59 assert_not_nil assigns(:total_hours)
60 assert_equal "0.00", "%.2f" % assigns(:total_hours)
61 end
62
53 def test_details_at_project_level
63 def test_details_at_project_level
54 get :details, :project_id => 1
64 get :details, :project_id => 1
55 assert_response :success
65 assert_response :success
56 assert_template 'details'
66 assert_template 'details'
57 assert_not_nil assigns(:entries)
67 assert_not_nil assigns(:entries)
58 assert_equal 3, assigns(:entries).size
68 assert_equal 4, assigns(:entries).size
69 # project and subproject
70 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
59 assert_not_nil assigns(:total_hours)
71 assert_not_nil assigns(:total_hours)
60 assert_equal 155.25, assigns(:total_hours)
72 assert_equal "162.90", "%.2f" % assigns(:total_hours)
61 # display all time by default
73 # display all time by default
62 assert_nil assigns(:from)
74 assert_nil assigns(:from)
63 assert_nil assigns(:to)
75 assert_nil assigns(:to)
@@ -68,9 +80,9 class TimelogControllerTest < Test::Unit::TestCase
68 assert_response :success
80 assert_response :success
69 assert_template 'details'
81 assert_template 'details'
70 assert_not_nil assigns(:entries)
82 assert_not_nil assigns(:entries)
71 assert_equal 2, assigns(:entries).size
83 assert_equal 3, assigns(:entries).size
72 assert_not_nil assigns(:total_hours)
84 assert_not_nil assigns(:total_hours)
73 assert_equal 5.25, assigns(:total_hours)
85 assert_equal "12.90", "%.2f" % assigns(:total_hours)
74 assert_equal '2007-03-20'.to_date, assigns(:from)
86 assert_equal '2007-03-20'.to_date, assigns(:from)
75 assert_equal '2007-04-30'.to_date, assigns(:to)
87 assert_equal '2007-04-30'.to_date, assigns(:to)
76 end
88 end
General Comments 0
You need to be logged in to leave comments. Login now