@@ -19,6 +19,7 class TimelogController < ApplicationController | |||
|
19 | 19 | menu_item :issues |
|
20 | 20 | before_filter :find_project, :authorize, :only => [:edit, :destroy] |
|
21 | 21 | before_filter :find_optional_project, :only => [:report, :details] |
|
22 | before_filter :load_available_criterias, :only => [:report] | |
|
22 | 23 | |
|
23 | 24 | verify :method => :post, :only => :destroy, :redirect_to => { :action => :details } |
|
24 | 25 | |
@@ -30,51 +31,6 class TimelogController < ApplicationController | |||
|
30 | 31 | include CustomFieldsHelper |
|
31 | 32 | |
|
32 | 33 | def report |
|
33 | @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", | |
|
34 | :klass => Project, | |
|
35 | :label => :label_project}, | |
|
36 | 'version' => {:sql => "#{Issue.table_name}.fixed_version_id", | |
|
37 | :klass => Version, | |
|
38 | :label => :label_version}, | |
|
39 | 'category' => {:sql => "#{Issue.table_name}.category_id", | |
|
40 | :klass => IssueCategory, | |
|
41 | :label => :field_category}, | |
|
42 | 'member' => {:sql => "#{TimeEntry.table_name}.user_id", | |
|
43 | :klass => User, | |
|
44 | :label => :label_member}, | |
|
45 | 'tracker' => {:sql => "#{Issue.table_name}.tracker_id", | |
|
46 | :klass => Tracker, | |
|
47 | :label => :label_tracker}, | |
|
48 | 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", | |
|
49 | :klass => TimeEntryActivity, | |
|
50 | :label => :label_activity}, | |
|
51 | 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id", | |
|
52 | :klass => Issue, | |
|
53 | :label => :label_issue} | |
|
54 | } | |
|
55 | ||
|
56 | # Add list and boolean custom fields as available criterias | |
|
57 | custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) | |
|
58 | custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
59 | @available_criterias["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)", | |
|
60 | :format => cf.field_format, | |
|
61 | :label => cf.name} | |
|
62 | end if @project | |
|
63 | ||
|
64 | # Add list and boolean time entry custom fields | |
|
65 | TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
66 | @available_criterias["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)", | |
|
67 | :format => cf.field_format, | |
|
68 | :label => cf.name} | |
|
69 | end | |
|
70 | ||
|
71 | # Add list and boolean time entry activity custom fields | |
|
72 | TimeEntryActivityCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
73 | @available_criterias["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)", | |
|
74 | :format => cf.field_format, | |
|
75 | :label => cf.name} | |
|
76 | end | |
|
77 | ||
|
78 | 34 | @criterias = params[:criterias] || [] |
|
79 | 35 | @criterias = @criterias.select{|criteria| @available_criterias.has_key? criteria} |
|
80 | 36 | @criterias.uniq! |
@@ -308,4 +264,53 private | |||
|
308 | 264 | @from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1 |
|
309 | 265 | @to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) |
|
310 | 266 | end |
|
267 | ||
|
268 | def load_available_criterias | |
|
269 | @available_criterias = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", | |
|
270 | :klass => Project, | |
|
271 | :label => :label_project}, | |
|
272 | 'version' => {:sql => "#{Issue.table_name}.fixed_version_id", | |
|
273 | :klass => Version, | |
|
274 | :label => :label_version}, | |
|
275 | 'category' => {:sql => "#{Issue.table_name}.category_id", | |
|
276 | :klass => IssueCategory, | |
|
277 | :label => :field_category}, | |
|
278 | 'member' => {:sql => "#{TimeEntry.table_name}.user_id", | |
|
279 | :klass => User, | |
|
280 | :label => :label_member}, | |
|
281 | 'tracker' => {:sql => "#{Issue.table_name}.tracker_id", | |
|
282 | :klass => Tracker, | |
|
283 | :label => :label_tracker}, | |
|
284 | 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", | |
|
285 | :klass => TimeEntryActivity, | |
|
286 | :label => :label_activity}, | |
|
287 | 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id", | |
|
288 | :klass => Issue, | |
|
289 | :label => :label_issue} | |
|
290 | } | |
|
291 | ||
|
292 | # Add list and boolean custom fields as available criterias | |
|
293 | custom_fields = (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) | |
|
294 | custom_fields.select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
295 | @available_criterias["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)", | |
|
296 | :format => cf.field_format, | |
|
297 | :label => cf.name} | |
|
298 | end if @project | |
|
299 | ||
|
300 | # Add list and boolean time entry custom fields | |
|
301 | TimeEntryCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
302 | @available_criterias["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)", | |
|
303 | :format => cf.field_format, | |
|
304 | :label => cf.name} | |
|
305 | end | |
|
306 | ||
|
307 | # Add list and boolean time entry activity custom fields | |
|
308 | TimeEntryActivityCustomField.find(:all).select {|cf| %w(list bool).include? cf.field_format }.each do |cf| | |
|
309 | @available_criterias["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)", | |
|
310 | :format => cf.field_format, | |
|
311 | :label => cf.name} | |
|
312 | end | |
|
313 | ||
|
314 | @available_criterias | |
|
315 | end | |
|
311 | 316 | end |
General Comments 0
You need to be logged in to leave comments.
Login now