@@ -30,22 +30,38 @@ def self.from_params(types, project_id, params)
30
30
conditions
31
31
end
32
32
33
- def self . to_options ( types )
33
+ def self . to_options ( project , types )
34
34
conditions = { }
35
- members = User . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
35
+
36
+ #members = User.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
37
+ members = project . members . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
38
+
36
39
types . each do |type |
37
40
case type
38
- when :user_ids then conditions [ :user_ids ] = members
39
- when :assigned_to_ids then conditions [ :assigned_to_ids ] = members
40
- when :author_ids then conditions [ :author_ids ] = members
41
- when :issue_ids then conditions [ :issue_ids ] = nil
42
- when :project_ids then conditions [ :project_ids ] = Project . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
43
- when :activity_ids then conditions [ :activity_ids ] = TimeEntryActivity . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
44
- when :category_ids then conditions [ :category_ids ] = IssueCategory . all . collect { |a | [ "#{ a . project . name } - #{ a . name } " , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
45
- when :fixed_version_ids then conditions [ :fixed_version_ids ] = Version . all . collect { |a | [ "#{ a . project . name } - #{ a . name } " , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
46
- when :tracker_ids then conditions [ :tracker_ids ] = Tracker . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
47
- when :priority_ids then conditions [ :priority_ids ] = IssuePriority . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
48
- when :status_ids then conditions [ :status_ids ] = IssueStatus . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
41
+ when :user_ids then conditions [ :user_ids ] = members unless members . size == 0
42
+ when :assigned_to_ids then conditions [ :assigned_to_ids ] = members unless members . size == 0
43
+ when :author_ids then conditions [ :author_ids ] = members unless members . size == 0
44
+ when :issue_ids then conditions [ :issue_ids ] = nil
45
+
46
+ #when :project_ids then conditions[:project_ids] = Project.all.collect { |a| [a.name, a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
47
+ #Gets Current project and sub projects (of current projects) to which user has access. Both arrays are merged using |
48
+ when :project_ids then conditions [ :project_ids ] = ( project . to_a . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase } ) | ( project . children . visible . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase } )
49
+
50
+ when :activity_ids then conditions [ :activity_ids ] = TimeEntryActivity . all ( :conditions => [ "active=?" , true ] ) . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
51
+
52
+ #when :category_ids then conditions[:category_ids] = IssueCategory.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
53
+ when :category_ids then
54
+ categories = project . issue_categories . all . collect { |a | [ "#{ a . project . name } - #{ a . name } " , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
55
+ conditions [ :category_ids ] = categories unless categories . size == 0
56
+
57
+ #when :fixed_version_ids then conditions[:fixed_version_ids] = Version.all.collect { |a| ["#{a.project.name} - #{a.name}", a.id] }.sort { |a,b| a[0].upcase <=> b[0].upcase }
58
+ when :fixed_version_ids then
59
+ versions = project . versions . all . collect { |a | [ "#{ a . project . name } - #{ a . name } " , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
60
+ conditions [ :fixed_version_ids ] = versions unless versions . size == 0
61
+
62
+ when :tracker_ids then conditions [ :tracker_ids ] = Tracker . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
63
+ when :priority_ids then conditions [ :priority_ids ] = IssuePriority . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
64
+ when :status_ids then conditions [ :status_ids ] = IssueStatus . all . collect { |a | [ a . name , a . id ] } . sort { |a , b | a [ 0 ] . upcase <=> b [ 0 ] . upcase }
49
65
end
50
66
end
51
67
conditions
0 commit comments