##// END OF EJS Templates
Rename the Member column to User on the time entries list....
Jean-Philippe Lang -
r10741:d6ecfcf50cfa
parent child
Show More
@@ -1,55 +1,55
1 <%= form_tag({}) do -%>
1 <%= form_tag({}) do -%>
2 <%= hidden_field_tag 'back_url', url_for(params) %>
2 <%= hidden_field_tag 'back_url', url_for(params) %>
3 <div class="autoscroll">
3 <div class="autoscroll">
4 <table class="list time-entries">
4 <table class="list time-entries">
5 <thead>
5 <thead>
6 <tr>
6 <tr>
7 <th class="checkbox hide-when-print">
7 <th class="checkbox hide-when-print">
8 <%= link_to image_tag('toggle_check.png'),
8 <%= link_to image_tag('toggle_check.png'),
9 {},
9 {},
10 :onclick => 'toggleIssuesSelection(this); return false;',
10 :onclick => 'toggleIssuesSelection(this); return false;',
11 :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
11 :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
12 </th>
12 </th>
13 <%= sort_header_tag('spent_on', :caption => l(:label_date), :default_order => 'desc') %>
13 <%= sort_header_tag('spent_on', :caption => l(:label_date), :default_order => 'desc') %>
14 <%= sort_header_tag('user', :caption => l(:label_member)) %>
14 <%= sort_header_tag('user', :caption => l(:label_user)) %>
15 <%= sort_header_tag('activity', :caption => l(:label_activity)) %>
15 <%= sort_header_tag('activity', :caption => l(:label_activity)) %>
16 <%= sort_header_tag('project', :caption => l(:label_project)) %>
16 <%= sort_header_tag('project', :caption => l(:label_project)) %>
17 <%= sort_header_tag('issue', :caption => l(:label_issue), :default_order => 'desc') %>
17 <%= sort_header_tag('issue', :caption => l(:label_issue), :default_order => 'desc') %>
18 <th><%= l(:field_comments) %></th>
18 <th><%= l(:field_comments) %></th>
19 <%= sort_header_tag('hours', :caption => l(:field_hours)) %>
19 <%= sort_header_tag('hours', :caption => l(:field_hours)) %>
20 <th></th>
20 <th></th>
21 </tr>
21 </tr>
22 </thead>
22 </thead>
23 <tbody>
23 <tbody>
24 <% entries.each do |entry| -%>
24 <% entries.each do |entry| -%>
25 <tr class="time-entry <%= cycle("odd", "even") %> hascontextmenu">
25 <tr class="time-entry <%= cycle("odd", "even") %> hascontextmenu">
26 <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", entry.id, false, :id => nil) %></td>
26 <td class="checkbox hide-when-print"><%= check_box_tag("ids[]", entry.id, false, :id => nil) %></td>
27 <td class="spent_on"><%= format_date(entry.spent_on) %></td>
27 <td class="spent_on"><%= format_date(entry.spent_on) %></td>
28 <td class="user"><%= link_to_user(entry.user) %></td>
28 <td class="user"><%= link_to_user(entry.user) %></td>
29 <td class="activity"><%=h entry.activity %></td>
29 <td class="activity"><%=h entry.activity %></td>
30 <td class="project"><%= link_to_project(entry.project) %></td>
30 <td class="project"><%= link_to_project(entry.project) %></td>
31 <td class="subject">
31 <td class="subject">
32 <% if entry.issue -%>
32 <% if entry.issue -%>
33 <%= entry.issue.visible? ? link_to_issue(entry.issue, :truncate => 50) : "##{entry.issue.id}" -%>
33 <%= entry.issue.visible? ? link_to_issue(entry.issue, :truncate => 50) : "##{entry.issue.id}" -%>
34 <% end -%>
34 <% end -%>
35 </td>
35 </td>
36 <td class="comments"><%=h entry.comments %></td>
36 <td class="comments"><%=h entry.comments %></td>
37 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
37 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
38 <td align="center">
38 <td align="center">
39 <% if entry.editable_by?(User.current) -%>
39 <% if entry.editable_by?(User.current) -%>
40 <%= link_to image_tag('edit.png'), edit_time_entry_path(entry),
40 <%= link_to image_tag('edit.png'), edit_time_entry_path(entry),
41 :title => l(:button_edit) %>
41 :title => l(:button_edit) %>
42 <%= link_to image_tag('delete.png'), time_entry_path(entry),
42 <%= link_to image_tag('delete.png'), time_entry_path(entry),
43 :data => {:confirm => l(:text_are_you_sure)},
43 :data => {:confirm => l(:text_are_you_sure)},
44 :method => :delete,
44 :method => :delete,
45 :title => l(:button_delete) %>
45 :title => l(:button_delete) %>
46 <% end -%>
46 <% end -%>
47 </td>
47 </td>
48 </tr>
48 </tr>
49 <% end -%>
49 <% end -%>
50 </tbody>
50 </tbody>
51 </table>
51 </table>
52 </div>
52 </div>
53 <% end -%>
53 <% end -%>
54
54
55 <%= context_menu time_entries_context_menu_path %>
55 <%= context_menu time_entries_context_menu_path %>
@@ -1,153 +1,153
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module Redmine
18 module Redmine
19 module Helpers
19 module Helpers
20 class TimeReport
20 class TimeReport
21 attr_reader :criteria, :columns, :hours, :total_hours, :periods
21 attr_reader :criteria, :columns, :hours, :total_hours, :periods
22
22
23 def initialize(project, issue, criteria, columns, time_entry_scope)
23 def initialize(project, issue, criteria, columns, time_entry_scope)
24 @project = project
24 @project = project
25 @issue = issue
25 @issue = issue
26
26
27 @criteria = criteria || []
27 @criteria = criteria || []
28 @criteria = @criteria.select{|criteria| available_criteria.has_key? criteria}
28 @criteria = @criteria.select{|criteria| available_criteria.has_key? criteria}
29 @criteria.uniq!
29 @criteria.uniq!
30 @criteria = @criteria[0,3]
30 @criteria = @criteria[0,3]
31
31
32 @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month'
32 @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month'
33 @scope = time_entry_scope
33 @scope = time_entry_scope
34
34
35 run
35 run
36 end
36 end
37
37
38 def available_criteria
38 def available_criteria
39 @available_criteria || load_available_criteria
39 @available_criteria || load_available_criteria
40 end
40 end
41
41
42 private
42 private
43
43
44 def run
44 def run
45 unless @criteria.empty?
45 unless @criteria.empty?
46 time_columns = %w(tyear tmonth tweek spent_on)
46 time_columns = %w(tyear tmonth tweek spent_on)
47 @hours = []
47 @hours = []
48 @scope.sum(:hours, :include => :issue, :group => @criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).each do |hash, hours|
48 @scope.sum(:hours, :include => :issue, :group => @criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns).each do |hash, hours|
49 h = {'hours' => hours}
49 h = {'hours' => hours}
50 (@criteria + time_columns).each_with_index do |name, i|
50 (@criteria + time_columns).each_with_index do |name, i|
51 h[name] = hash[i]
51 h[name] = hash[i]
52 end
52 end
53 @hours << h
53 @hours << h
54 end
54 end
55
55
56 @hours.each do |row|
56 @hours.each do |row|
57 case @columns
57 case @columns
58 when 'year'
58 when 'year'
59 row['year'] = row['tyear']
59 row['year'] = row['tyear']
60 when 'month'
60 when 'month'
61 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
61 row['month'] = "#{row['tyear']}-#{row['tmonth']}"
62 when 'week'
62 when 'week'
63 row['week'] = "#{row['tyear']}-#{row['tweek']}"
63 row['week'] = "#{row['tyear']}-#{row['tweek']}"
64 when 'day'
64 when 'day'
65 row['day'] = "#{row['spent_on']}"
65 row['day'] = "#{row['spent_on']}"
66 end
66 end
67 end
67 end
68
68
69 min = @hours.collect {|row| row['spent_on']}.min
69 min = @hours.collect {|row| row['spent_on']}.min
70 @from = min ? min.to_date : Date.today
70 @from = min ? min.to_date : Date.today
71
71
72 max = @hours.collect {|row| row['spent_on']}.max
72 max = @hours.collect {|row| row['spent_on']}.max
73 @to = max ? max.to_date : Date.today
73 @to = max ? max.to_date : Date.today
74
74
75 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
75 @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f}
76
76
77 @periods = []
77 @periods = []
78 # Date#at_beginning_of_ not supported in Rails 1.2.x
78 # Date#at_beginning_of_ not supported in Rails 1.2.x
79 date_from = @from.to_time
79 date_from = @from.to_time
80 # 100 columns max
80 # 100 columns max
81 while date_from <= @to.to_time && @periods.length < 100
81 while date_from <= @to.to_time && @periods.length < 100
82 case @columns
82 case @columns
83 when 'year'
83 when 'year'
84 @periods << "#{date_from.year}"
84 @periods << "#{date_from.year}"
85 date_from = (date_from + 1.year).at_beginning_of_year
85 date_from = (date_from + 1.year).at_beginning_of_year
86 when 'month'
86 when 'month'
87 @periods << "#{date_from.year}-#{date_from.month}"
87 @periods << "#{date_from.year}-#{date_from.month}"
88 date_from = (date_from + 1.month).at_beginning_of_month
88 date_from = (date_from + 1.month).at_beginning_of_month
89 when 'week'
89 when 'week'
90 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
90 @periods << "#{date_from.year}-#{date_from.to_date.cweek}"
91 date_from = (date_from + 7.day).at_beginning_of_week
91 date_from = (date_from + 7.day).at_beginning_of_week
92 when 'day'
92 when 'day'
93 @periods << "#{date_from.to_date}"
93 @periods << "#{date_from.to_date}"
94 date_from = date_from + 1.day
94 date_from = date_from + 1.day
95 end
95 end
96 end
96 end
97 end
97 end
98 end
98 end
99
99
100 def load_available_criteria
100 def load_available_criteria
101 @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
101 @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id",
102 :klass => Project,
102 :klass => Project,
103 :label => :label_project},
103 :label => :label_project},
104 'status' => {:sql => "#{Issue.table_name}.status_id",
104 'status' => {:sql => "#{Issue.table_name}.status_id",
105 :klass => IssueStatus,
105 :klass => IssueStatus,
106 :label => :field_status},
106 :label => :field_status},
107 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
107 'version' => {:sql => "#{Issue.table_name}.fixed_version_id",
108 :klass => Version,
108 :klass => Version,
109 :label => :label_version},
109 :label => :label_version},
110 'category' => {:sql => "#{Issue.table_name}.category_id",
110 'category' => {:sql => "#{Issue.table_name}.category_id",
111 :klass => IssueCategory,
111 :klass => IssueCategory,
112 :label => :field_category},
112 :label => :field_category},
113 'member' => {:sql => "#{TimeEntry.table_name}.user_id",
113 'user' => {:sql => "#{TimeEntry.table_name}.user_id",
114 :klass => User,
114 :klass => User,
115 :label => :label_member},
115 :label => :label_user},
116 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
116 'tracker' => {:sql => "#{Issue.table_name}.tracker_id",
117 :klass => Tracker,
117 :klass => Tracker,
118 :label => :label_tracker},
118 :label => :label_tracker},
119 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
119 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id",
120 :klass => TimeEntryActivity,
120 :klass => TimeEntryActivity,
121 :label => :label_activity},
121 :label => :label_activity},
122 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
122 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id",
123 :klass => Issue,
123 :klass => Issue,
124 :label => :label_issue}
124 :label => :label_issue}
125 }
125 }
126
126
127 # Add list and boolean custom fields as available criteria
127 # Add list and boolean custom fields as available criteria
128 custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
128 custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields)
129 custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
129 custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
130 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id ORDER BY c.value LIMIT 1)",
130 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Issue' AND c.customized_id = #{Issue.table_name}.id ORDER BY c.value LIMIT 1)",
131 :format => cf.field_format,
131 :format => cf.field_format,
132 :label => cf.name}
132 :label => cf.name}
133 end if @project
133 end if @project
134
134
135 # Add list and boolean time entry custom fields
135 # Add list and boolean time entry custom fields
136 TimeEntryCustomField.all.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
136 TimeEntryCustomField.all.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
137 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id ORDER BY c.value LIMIT 1)",
137 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'TimeEntry' AND c.customized_id = #{TimeEntry.table_name}.id ORDER BY c.value LIMIT 1)",
138 :format => cf.field_format,
138 :format => cf.field_format,
139 :label => cf.name}
139 :label => cf.name}
140 end
140 end
141
141
142 # Add list and boolean time entry activity custom fields
142 # Add list and boolean time entry activity custom fields
143 TimeEntryActivityCustomField.all.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
143 TimeEntryActivityCustomField.all.select {|cf| %w(list bool).include? cf.field_format }.each do |cf|
144 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id ORDER BY c.value LIMIT 1)",
144 @available_criteria["cf_#{cf.id}"] = {:sql => "(SELECT c.value FROM #{CustomValue.table_name} c WHERE c.custom_field_id = #{cf.id} AND c.customized_type = 'Enumeration' AND c.customized_id = #{TimeEntry.table_name}.activity_id ORDER BY c.value LIMIT 1)",
145 :format => cf.field_format,
145 :format => cf.field_format,
146 :label => cf.name}
146 :label => cf.name}
147 end
147 end
148
148
149 @available_criteria
149 @available_criteria
150 end
150 end
151 end
151 end
152 end
152 end
153 end
153 end
@@ -1,332 +1,332
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Redmine - project management software
2 # Redmine - project management software
3 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # Copyright (C) 2006-2012 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.expand_path('../../test_helper', __FILE__)
19 require File.expand_path('../../test_helper', __FILE__)
20
20
21 class TimeEntryReportsControllerTest < ActionController::TestCase
21 class TimeEntryReportsControllerTest < ActionController::TestCase
22 tests TimelogController
22 tests TimelogController
23
23
24 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
24 fixtures :projects, :enabled_modules, :roles, :members, :member_roles,
25 :issues, :time_entries, :users, :trackers, :enumerations,
25 :issues, :time_entries, :users, :trackers, :enumerations,
26 :issue_statuses, :custom_fields, :custom_values
26 :issue_statuses, :custom_fields, :custom_values
27
27
28 include Redmine::I18n
28 include Redmine::I18n
29
29
30 def setup
30 def setup
31 Setting.default_language = "en"
31 Setting.default_language = "en"
32 end
32 end
33
33
34 def test_report_at_project_level
34 def test_report_at_project_level
35 get :report, :project_id => 'ecookbook'
35 get :report, :project_id => 'ecookbook'
36 assert_response :success
36 assert_response :success
37 assert_template 'report'
37 assert_template 'report'
38 assert_tag :form,
38 assert_tag :form,
39 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
39 :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'}
40 end
40 end
41
41
42 def test_report_all_projects
42 def test_report_all_projects
43 get :report
43 get :report
44 assert_response :success
44 assert_response :success
45 assert_template 'report'
45 assert_template 'report'
46 assert_tag :form,
46 assert_tag :form,
47 :attributes => {:action => "/time_entries/report", :id => 'query_form'}
47 :attributes => {:action => "/time_entries/report", :id => 'query_form'}
48 end
48 end
49
49
50 def test_report_all_projects_denied
50 def test_report_all_projects_denied
51 r = Role.anonymous
51 r = Role.anonymous
52 r.permissions.delete(:view_time_entries)
52 r.permissions.delete(:view_time_entries)
53 r.permissions_will_change!
53 r.permissions_will_change!
54 r.save
54 r.save
55 get :report
55 get :report
56 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
56 assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport'
57 end
57 end
58
58
59 def test_report_all_projects_one_criteria
59 def test_report_all_projects_one_criteria
60 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
60 get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
61 assert_response :success
61 assert_response :success
62 assert_template 'report'
62 assert_template 'report'
63 assert_not_nil assigns(:report)
63 assert_not_nil assigns(:report)
64 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
64 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
65 end
65 end
66
66
67 def test_report_all_time
67 def test_report_all_time
68 get :report, :project_id => 1, :criteria => ['project', 'issue']
68 get :report, :project_id => 1, :criteria => ['project', 'issue']
69 assert_response :success
69 assert_response :success
70 assert_template 'report'
70 assert_template 'report'
71 assert_not_nil assigns(:report)
71 assert_not_nil assigns(:report)
72 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
72 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
73 end
73 end
74
74
75 def test_report_all_time_by_day
75 def test_report_all_time_by_day
76 get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day'
76 get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day'
77 assert_response :success
77 assert_response :success
78 assert_template 'report'
78 assert_template 'report'
79 assert_not_nil assigns(:report)
79 assert_not_nil assigns(:report)
80 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
80 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
81 assert_tag :tag => 'th', :content => '2007-03-12'
81 assert_tag :tag => 'th', :content => '2007-03-12'
82 end
82 end
83
83
84 def test_report_one_criteria
84 def test_report_one_criteria
85 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
85 get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project']
86 assert_response :success
86 assert_response :success
87 assert_template 'report'
87 assert_template 'report'
88 assert_not_nil assigns(:report)
88 assert_not_nil assigns(:report)
89 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
89 assert_equal "8.65", "%.2f" % assigns(:report).total_hours
90 end
90 end
91
91
92 def test_report_two_criteria
92 def test_report_two_criteria
93 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
93 get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"]
94 assert_response :success
94 assert_response :success
95 assert_template 'report'
95 assert_template 'report'
96 assert_not_nil assigns(:report)
96 assert_not_nil assigns(:report)
97 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
97 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
98 end
98 end
99
99
100 def test_report_custom_field_criteria_with_multiple_values
100 def test_report_custom_field_criteria_with_multiple_values
101 field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2'])
101 field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2'])
102 entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today)
102 entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today)
103 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1')
103 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1')
104 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2')
104 CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2')
105
105
106 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"]
106 get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"]
107 assert_response :success
107 assert_response :success
108 end
108 end
109
109
110 def test_report_one_day
110 def test_report_one_day
111 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["member", "activity"]
111 get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"]
112 assert_response :success
112 assert_response :success
113 assert_template 'report'
113 assert_template 'report'
114 assert_not_nil assigns(:report)
114 assert_not_nil assigns(:report)
115 assert_equal "4.25", "%.2f" % assigns(:report).total_hours
115 assert_equal "4.25", "%.2f" % assigns(:report).total_hours
116 end
116 end
117
117
118 def test_report_at_issue_level
118 def test_report_at_issue_level
119 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["member", "activity"]
119 get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"]
120 assert_response :success
120 assert_response :success
121 assert_template 'report'
121 assert_template 'report'
122 assert_not_nil assigns(:report)
122 assert_not_nil assigns(:report)
123 assert_equal "154.25", "%.2f" % assigns(:report).total_hours
123 assert_equal "154.25", "%.2f" % assigns(:report).total_hours
124 assert_tag :form,
124 assert_tag :form,
125 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
125 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'}
126 end
126 end
127
127
128 def test_report_custom_field_criteria
128 def test_report_custom_field_criteria
129 get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7']
129 get :report, :project_id => 1, :criteria => ['project', 'cf_1', 'cf_7']
130 assert_response :success
130 assert_response :success
131 assert_template 'report'
131 assert_template 'report'
132 assert_not_nil assigns(:report)
132 assert_not_nil assigns(:report)
133 assert_equal 3, assigns(:report).criteria.size
133 assert_equal 3, assigns(:report).criteria.size
134 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
134 assert_equal "162.90", "%.2f" % assigns(:report).total_hours
135 # Custom field column
135 # Custom field column
136 assert_tag :tag => 'th', :content => 'Database'
136 assert_tag :tag => 'th', :content => 'Database'
137 # Custom field row
137 # Custom field row
138 assert_tag :tag => 'td', :content => 'MySQL',
138 assert_tag :tag => 'td', :content => 'MySQL',
139 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
139 :sibling => { :tag => 'td', :attributes => { :class => 'hours' },
140 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
140 :child => { :tag => 'span', :attributes => { :class => 'hours hours-int' },
141 :content => '1' }}
141 :content => '1' }}
142 # Second custom field column
142 # Second custom field column
143 assert_tag :tag => 'th', :content => 'Billable'
143 assert_tag :tag => 'th', :content => 'Billable'
144 end
144 end
145
145
146 def test_report_one_criteria_no_result
146 def test_report_one_criteria_no_result
147 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project']
147 get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project']
148 assert_response :success
148 assert_response :success
149 assert_template 'report'
149 assert_template 'report'
150 assert_not_nil assigns(:report)
150 assert_not_nil assigns(:report)
151 assert_equal "0.00", "%.2f" % assigns(:report).total_hours
151 assert_equal "0.00", "%.2f" % assigns(:report).total_hours
152 end
152 end
153
153
154 def test_report_status_criterion
154 def test_report_status_criterion
155 get :report, :project_id => 1, :criteria => ['status']
155 get :report, :project_id => 1, :criteria => ['status']
156 assert_response :success
156 assert_response :success
157 assert_template 'report'
157 assert_template 'report'
158 assert_tag :tag => 'th', :content => 'Status'
158 assert_tag :tag => 'th', :content => 'Status'
159 assert_tag :tag => 'td', :content => 'New'
159 assert_tag :tag => 'td', :content => 'New'
160 end
160 end
161
161
162 def test_report_all_projects_csv_export
162 def test_report_all_projects_csv_export
163 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
163 get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30",
164 :criteria => ["project", "member", "activity"], :format => "csv"
164 :criteria => ["project", "user", "activity"], :format => "csv"
165 assert_response :success
165 assert_response :success
166 assert_equal 'text/csv; header=present', @response.content_type
166 assert_equal 'text/csv; header=present', @response.content_type
167 lines = @response.body.chomp.split("\n")
167 lines = @response.body.chomp.split("\n")
168 # Headers
168 # Headers
169 assert_equal 'Project,Member,Activity,2007-3,2007-4,Total', lines.first
169 assert_equal 'Project,User,Activity,2007-3,2007-4,Total', lines.first
170 # Total row
170 # Total row
171 assert_equal 'Total,"","",154.25,8.65,162.90', lines.last
171 assert_equal 'Total,"","",154.25,8.65,162.90', lines.last
172 end
172 end
173
173
174 def test_report_csv_export
174 def test_report_csv_export
175 get :report, :project_id => 1, :columns => 'month',
175 get :report, :project_id => 1, :columns => 'month',
176 :from => "2007-01-01", :to => "2007-06-30",
176 :from => "2007-01-01", :to => "2007-06-30",
177 :criteria => ["project", "member", "activity"], :format => "csv"
177 :criteria => ["project", "user", "activity"], :format => "csv"
178 assert_response :success
178 assert_response :success
179 assert_equal 'text/csv; header=present', @response.content_type
179 assert_equal 'text/csv; header=present', @response.content_type
180 lines = @response.body.chomp.split("\n")
180 lines = @response.body.chomp.split("\n")
181 # Headers
181 # Headers
182 assert_equal 'Project,Member,Activity,2007-3,2007-4,Total', lines.first
182 assert_equal 'Project,User,Activity,2007-3,2007-4,Total', lines.first
183 # Total row
183 # Total row
184 assert_equal 'Total,"","",154.25,8.65,162.90', lines.last
184 assert_equal 'Total,"","",154.25,8.65,162.90', lines.last
185 end
185 end
186
186
187 def test_csv_big_5
187 def test_csv_big_5
188 Setting.default_language = "zh-TW"
188 Setting.default_language = "zh-TW"
189 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
189 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
190 str_big5 = "\xa4@\xa4\xeb"
190 str_big5 = "\xa4@\xa4\xeb"
191 if str_utf8.respond_to?(:force_encoding)
191 if str_utf8.respond_to?(:force_encoding)
192 str_utf8.force_encoding('UTF-8')
192 str_utf8.force_encoding('UTF-8')
193 str_big5.force_encoding('Big5')
193 str_big5.force_encoding('Big5')
194 end
194 end
195 user = User.find_by_id(3)
195 user = User.find_by_id(3)
196 user.firstname = str_utf8
196 user.firstname = str_utf8
197 user.lastname = "test-lastname"
197 user.lastname = "test-lastname"
198 assert user.save
198 assert user.save
199 comments = "test_csv_big_5"
199 comments = "test_csv_big_5"
200 te1 = TimeEntry.create(:spent_on => '2011-11-11',
200 te1 = TimeEntry.create(:spent_on => '2011-11-11',
201 :hours => 7.3,
201 :hours => 7.3,
202 :project => Project.find(1),
202 :project => Project.find(1),
203 :user => user,
203 :user => user,
204 :activity => TimeEntryActivity.find_by_name('Design'),
204 :activity => TimeEntryActivity.find_by_name('Design'),
205 :comments => comments)
205 :comments => comments)
206
206
207 te2 = TimeEntry.find_by_comments(comments)
207 te2 = TimeEntry.find_by_comments(comments)
208 assert_not_nil te2
208 assert_not_nil te2
209 assert_equal 7.3, te2.hours
209 assert_equal 7.3, te2.hours
210 assert_equal 3, te2.user_id
210 assert_equal 3, te2.user_id
211
211
212 get :report, :project_id => 1, :columns => 'day',
212 get :report, :project_id => 1, :columns => 'day',
213 :from => "2011-11-11", :to => "2011-11-11",
213 :from => "2011-11-11", :to => "2011-11-11",
214 :criteria => ["member"], :format => "csv"
214 :criteria => ["user"], :format => "csv"
215 assert_response :success
215 assert_response :success
216 assert_equal 'text/csv; header=present', @response.content_type
216 assert_equal 'text/csv; header=present', @response.content_type
217 lines = @response.body.chomp.split("\n")
217 lines = @response.body.chomp.split("\n")
218 # Headers
218 # Headers
219 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
219 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xc1`\xadp"
220 s2 = "\xc1`\xadp"
220 s2 = "\xc1`\xadp"
221 if s1.respond_to?(:force_encoding)
221 if s1.respond_to?(:force_encoding)
222 s1.force_encoding('Big5')
222 s1.force_encoding('Big5')
223 s2.force_encoding('Big5')
223 s2.force_encoding('Big5')
224 end
224 end
225 assert_equal s1, lines.first
225 assert_equal s1, lines.first
226 # Total row
226 # Total row
227 assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
227 assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1]
228 assert_equal "#{s2},7.30,7.30", lines[2]
228 assert_equal "#{s2},7.30,7.30", lines[2]
229
229
230 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
230 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
231 if str_tw.respond_to?(:force_encoding)
231 if str_tw.respond_to?(:force_encoding)
232 str_tw.force_encoding('UTF-8')
232 str_tw.force_encoding('UTF-8')
233 end
233 end
234 assert_equal str_tw, l(:general_lang_name)
234 assert_equal str_tw, l(:general_lang_name)
235 assert_equal 'Big5', l(:general_csv_encoding)
235 assert_equal 'Big5', l(:general_csv_encoding)
236 assert_equal ',', l(:general_csv_separator)
236 assert_equal ',', l(:general_csv_separator)
237 assert_equal '.', l(:general_csv_decimal_separator)
237 assert_equal '.', l(:general_csv_decimal_separator)
238 end
238 end
239
239
240 def test_csv_cannot_convert_should_be_replaced_big_5
240 def test_csv_cannot_convert_should_be_replaced_big_5
241 Setting.default_language = "zh-TW"
241 Setting.default_language = "zh-TW"
242 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
242 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
243 if str_utf8.respond_to?(:force_encoding)
243 if str_utf8.respond_to?(:force_encoding)
244 str_utf8.force_encoding('UTF-8')
244 str_utf8.force_encoding('UTF-8')
245 end
245 end
246 user = User.find_by_id(3)
246 user = User.find_by_id(3)
247 user.firstname = str_utf8
247 user.firstname = str_utf8
248 user.lastname = "test-lastname"
248 user.lastname = "test-lastname"
249 assert user.save
249 assert user.save
250 comments = "test_replaced"
250 comments = "test_replaced"
251 te1 = TimeEntry.create(:spent_on => '2011-11-11',
251 te1 = TimeEntry.create(:spent_on => '2011-11-11',
252 :hours => 7.3,
252 :hours => 7.3,
253 :project => Project.find(1),
253 :project => Project.find(1),
254 :user => user,
254 :user => user,
255 :activity => TimeEntryActivity.find_by_name('Design'),
255 :activity => TimeEntryActivity.find_by_name('Design'),
256 :comments => comments)
256 :comments => comments)
257
257
258 te2 = TimeEntry.find_by_comments(comments)
258 te2 = TimeEntry.find_by_comments(comments)
259 assert_not_nil te2
259 assert_not_nil te2
260 assert_equal 7.3, te2.hours
260 assert_equal 7.3, te2.hours
261 assert_equal 3, te2.user_id
261 assert_equal 3, te2.user_id
262
262
263 get :report, :project_id => 1, :columns => 'day',
263 get :report, :project_id => 1, :columns => 'day',
264 :from => "2011-11-11", :to => "2011-11-11",
264 :from => "2011-11-11", :to => "2011-11-11",
265 :criteria => ["member"], :format => "csv"
265 :criteria => ["user"], :format => "csv"
266 assert_response :success
266 assert_response :success
267 assert_equal 'text/csv; header=present', @response.content_type
267 assert_equal 'text/csv; header=present', @response.content_type
268 lines = @response.body.chomp.split("\n")
268 lines = @response.body.chomp.split("\n")
269 # Headers
269 # Headers
270 s1 = "\xa6\xa8\xad\xfb,2011-11-11,\xc1`\xadp"
270 s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xc1`\xadp"
271 if s1.respond_to?(:force_encoding)
271 if s1.respond_to?(:force_encoding)
272 s1.force_encoding('Big5')
272 s1.force_encoding('Big5')
273 end
273 end
274 assert_equal s1, lines.first
274 assert_equal s1, lines.first
275 # Total row
275 # Total row
276 s2 = ""
276 s2 = ""
277 if s2.respond_to?(:force_encoding)
277 if s2.respond_to?(:force_encoding)
278 s2 = "\xa5H?"
278 s2 = "\xa5H?"
279 s2.force_encoding('Big5')
279 s2.force_encoding('Big5')
280 elsif RUBY_PLATFORM == 'java'
280 elsif RUBY_PLATFORM == 'java'
281 s2 = "??"
281 s2 = "??"
282 else
282 else
283 s2 = "\xa5H???"
283 s2 = "\xa5H???"
284 end
284 end
285 assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
285 assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1]
286 end
286 end
287
287
288 def test_csv_fr
288 def test_csv_fr
289 with_settings :default_language => "fr" do
289 with_settings :default_language => "fr" do
290 str1 = "test_csv_fr"
290 str1 = "test_csv_fr"
291 user = User.find_by_id(3)
291 user = User.find_by_id(3)
292 te1 = TimeEntry.create(:spent_on => '2011-11-11',
292 te1 = TimeEntry.create(:spent_on => '2011-11-11',
293 :hours => 7.3,
293 :hours => 7.3,
294 :project => Project.find(1),
294 :project => Project.find(1),
295 :user => user,
295 :user => user,
296 :activity => TimeEntryActivity.find_by_name('Design'),
296 :activity => TimeEntryActivity.find_by_name('Design'),
297 :comments => str1)
297 :comments => str1)
298
298
299 te2 = TimeEntry.find_by_comments(str1)
299 te2 = TimeEntry.find_by_comments(str1)
300 assert_not_nil te2
300 assert_not_nil te2
301 assert_equal 7.3, te2.hours
301 assert_equal 7.3, te2.hours
302 assert_equal 3, te2.user_id
302 assert_equal 3, te2.user_id
303
303
304 get :report, :project_id => 1, :columns => 'day',
304 get :report, :project_id => 1, :columns => 'day',
305 :from => "2011-11-11", :to => "2011-11-11",
305 :from => "2011-11-11", :to => "2011-11-11",
306 :criteria => ["member"], :format => "csv"
306 :criteria => ["user"], :format => "csv"
307 assert_response :success
307 assert_response :success
308 assert_equal 'text/csv; header=present', @response.content_type
308 assert_equal 'text/csv; header=present', @response.content_type
309 lines = @response.body.chomp.split("\n")
309 lines = @response.body.chomp.split("\n")
310 # Headers
310 # Headers
311 s1 = "Membre;2011-11-11;Total"
311 s1 = "Utilisateur;2011-11-11;Total"
312 s2 = "Total"
312 s2 = "Total"
313 if s1.respond_to?(:force_encoding)
313 if s1.respond_to?(:force_encoding)
314 s1.force_encoding('ISO-8859-1')
314 s1.force_encoding('ISO-8859-1')
315 s2.force_encoding('ISO-8859-1')
315 s2.force_encoding('ISO-8859-1')
316 end
316 end
317 assert_equal s1, lines.first
317 assert_equal s1, lines.first
318 # Total row
318 # Total row
319 assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
319 assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1]
320 assert_equal "#{s2};7,30;7,30", lines[2]
320 assert_equal "#{s2};7,30;7,30", lines[2]
321
321
322 str_fr = "Fran\xc3\xa7ais"
322 str_fr = "Fran\xc3\xa7ais"
323 if str_fr.respond_to?(:force_encoding)
323 if str_fr.respond_to?(:force_encoding)
324 str_fr.force_encoding('UTF-8')
324 str_fr.force_encoding('UTF-8')
325 end
325 end
326 assert_equal str_fr, l(:general_lang_name)
326 assert_equal str_fr, l(:general_lang_name)
327 assert_equal 'ISO-8859-1', l(:general_csv_encoding)
327 assert_equal 'ISO-8859-1', l(:general_csv_encoding)
328 assert_equal ';', l(:general_csv_separator)
328 assert_equal ';', l(:general_csv_separator)
329 assert_equal ',', l(:general_csv_decimal_separator)
329 assert_equal ',', l(:general_csv_decimal_separator)
330 end
330 end
331 end
331 end
332 end
332 end
General Comments 0
You need to be logged in to leave comments. Login now