@@ -1,16 +1,16 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 |
# Copyright (C) 2006-20 |
|
2 | # Copyright (C) 2006-2011 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. | |
@@ -20,33 +20,33 module Redmine | |||||
20 | # Class used to retrieve activity events |
|
20 | # Class used to retrieve activity events | |
21 | class Fetcher |
|
21 | class Fetcher | |
22 | attr_reader :user, :project, :scope |
|
22 | attr_reader :user, :project, :scope | |
23 |
|
23 | |||
24 | # Needs to be unloaded in development mode |
|
24 | # Needs to be unloaded in development mode | |
25 | @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } } |
|
25 | @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } } | |
26 |
|
26 | |||
27 | def initialize(user, options={}) |
|
27 | def initialize(user, options={}) | |
28 | options.assert_valid_keys(:project, :with_subprojects, :author) |
|
28 | options.assert_valid_keys(:project, :with_subprojects, :author) | |
29 | @user = user |
|
29 | @user = user | |
30 | @project = options[:project] |
|
30 | @project = options[:project] | |
31 | @options = options |
|
31 | @options = options | |
32 |
|
32 | |||
33 | @scope = event_types |
|
33 | @scope = event_types | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | # Returns an array of available event types |
|
36 | # Returns an array of available event types | |
37 | def event_types |
|
37 | def event_types | |
38 | return @event_types unless @event_types.nil? |
|
38 | return @event_types unless @event_types.nil? | |
39 |
|
39 | |||
40 | @event_types = Redmine::Activity.available_event_types |
|
40 | @event_types = Redmine::Activity.available_event_types | |
41 | @event_types = @event_types.select {|o| @project.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}} if @project |
|
41 | @event_types = @event_types.select {|o| @project.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}} if @project | |
42 | @event_types |
|
42 | @event_types | |
43 | end |
|
43 | end | |
44 |
|
44 | |||
45 | # Yields to filter the activity scope |
|
45 | # Yields to filter the activity scope | |
46 | def scope_select(&block) |
|
46 | def scope_select(&block) | |
47 | @scope = @scope.select {|t| yield t } |
|
47 | @scope = @scope.select {|t| yield t } | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | # Sets the scope |
|
50 | # Sets the scope | |
51 | # Argument can be :all, :default or an array of event types |
|
51 | # Argument can be :all, :default or an array of event types | |
52 | def scope=(s) |
|
52 | def scope=(s) | |
@@ -59,34 +59,34 module Redmine | |||||
59 | @scope = s & event_types |
|
59 | @scope = s & event_types | |
60 | end |
|
60 | end | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | # Resets the scope to the default scope |
|
63 | # Resets the scope to the default scope | |
64 | def default_scope! |
|
64 | def default_scope! | |
65 | @scope = Redmine::Activity.default_event_types |
|
65 | @scope = Redmine::Activity.default_event_types | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | # Returns an array of events for the given date range |
|
68 | # Returns an array of events for the given date range | |
69 | # sorted in reverse chronological order |
|
69 | # sorted in reverse chronological order | |
70 | def events(from = nil, to = nil, options={}) |
|
70 | def events(from = nil, to = nil, options={}) | |
71 | e = [] |
|
71 | e = [] | |
72 | @options[:limit] = options[:limit] |
|
72 | @options[:limit] = options[:limit] | |
73 |
|
73 | |||
74 | @scope.each do |event_type| |
|
74 | @scope.each do |event_type| | |
75 | constantized_providers(event_type).each do |provider| |
|
75 | constantized_providers(event_type).each do |provider| | |
76 | e += provider.find_events(event_type, @user, from, to, @options) |
|
76 | e += provider.find_events(event_type, @user, from, to, @options) | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | e.sort! {|a,b| b.event_datetime <=> a.event_datetime} |
|
80 | e.sort! {|a,b| b.event_datetime <=> a.event_datetime} | |
81 |
|
81 | |||
82 | if options[:limit] |
|
82 | if options[:limit] | |
83 | e = e.slice(0, options[:limit]) |
|
83 | e = e.slice(0, options[:limit]) | |
84 | end |
|
84 | end | |
85 | e |
|
85 | e | |
86 | end |
|
86 | end | |
87 |
|
87 | |||
88 | private |
|
88 | private | |
89 |
|
89 | |||
90 | def constantized_providers(event_type) |
|
90 | def constantized_providers(event_type) | |
91 | @@constantized_providers[event_type] |
|
91 | @@constantized_providers[event_type] | |
92 | end |
|
92 | end |
General Comments 0
You need to be logged in to leave comments.
Login now