To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / lib / redmine / activity / fetcher.rb @ 912:5e80956cc792
History | View | Annotate | Download (2.91 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 909:cbb26bc654de | Chris | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 909:cbb26bc654de | Chris | #
|
| 9 | 0:513646585e45 | Chris | # 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 | 909:cbb26bc654de | Chris | #
|
| 14 | 0:513646585e45 | Chris | # 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 | module Redmine |
||
| 19 | module Activity |
||
| 20 | # Class used to retrieve activity events
|
||
| 21 | class Fetcher |
||
| 22 | attr_reader :user, :project, :scope |
||
| 23 | 909:cbb26bc654de | Chris | |
| 24 | 0:513646585e45 | Chris | # Needs to be unloaded in development mode
|
| 25 | @@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } } |
||
| 26 | 909:cbb26bc654de | Chris | |
| 27 | 0:513646585e45 | Chris | def initialize(user, options={}) |
| 28 | options.assert_valid_keys(:project, :with_subprojects, :author) |
||
| 29 | @user = user
|
||
| 30 | @project = options[:project] |
||
| 31 | @options = options
|
||
| 32 | 909:cbb26bc654de | Chris | |
| 33 | 0:513646585e45 | Chris | @scope = event_types
|
| 34 | end
|
||
| 35 | 909:cbb26bc654de | Chris | |
| 36 | 0:513646585e45 | Chris | # Returns an array of available event types
|
| 37 | def event_types |
||
| 38 | return @event_types unless @event_types.nil? |
||
| 39 | 909:cbb26bc654de | Chris | |
| 40 | 0:513646585e45 | Chris | @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 |
||
| 42 | @event_types
|
||
| 43 | end
|
||
| 44 | 909:cbb26bc654de | Chris | |
| 45 | 0:513646585e45 | Chris | # Yields to filter the activity scope
|
| 46 | def scope_select(&block) |
||
| 47 | @scope = @scope.select {|t| yield t } |
||
| 48 | end
|
||
| 49 | 909:cbb26bc654de | Chris | |
| 50 | 0:513646585e45 | Chris | # Sets the scope
|
| 51 | # Argument can be :all, :default or an array of event types
|
||
| 52 | def scope=(s) |
||
| 53 | case s
|
||
| 54 | when :all |
||
| 55 | @scope = event_types
|
||
| 56 | when :default |
||
| 57 | default_scope! |
||
| 58 | else
|
||
| 59 | @scope = s & event_types
|
||
| 60 | end
|
||
| 61 | end
|
||
| 62 | 909:cbb26bc654de | Chris | |
| 63 | 0:513646585e45 | Chris | # Resets the scope to the default scope
|
| 64 | def default_scope! |
||
| 65 | @scope = Redmine::Activity.default_event_types |
||
| 66 | end
|
||
| 67 | 909:cbb26bc654de | Chris | |
| 68 | 0:513646585e45 | Chris | # Returns an array of events for the given date range
|
| 69 | # sorted in reverse chronological order
|
||
| 70 | def events(from = nil, to = nil, options={}) |
||
| 71 | e = [] |
||
| 72 | @options[:limit] = options[:limit] |
||
| 73 | 909:cbb26bc654de | Chris | |
| 74 | 0:513646585e45 | Chris | @scope.each do |event_type| |
| 75 | constantized_providers(event_type).each do |provider|
|
||
| 76 | e += provider.find_events(event_type, @user, from, to, @options) |
||
| 77 | end
|
||
| 78 | end
|
||
| 79 | 909:cbb26bc654de | Chris | |
| 80 | 0:513646585e45 | Chris | e.sort! {|a,b| b.event_datetime <=> a.event_datetime}
|
| 81 | 909:cbb26bc654de | Chris | |
| 82 | 0:513646585e45 | Chris | if options[:limit] |
| 83 | e = e.slice(0, options[:limit]) |
||
| 84 | end
|
||
| 85 | e |
||
| 86 | end
|
||
| 87 | 909:cbb26bc654de | Chris | |
| 88 | 0:513646585e45 | Chris | private |
| 89 | 909:cbb26bc654de | Chris | |
| 90 | 0:513646585e45 | Chris | def constantized_providers(event_type) |
| 91 | @@constantized_providers[event_type]
|
||
| 92 | end
|
||
| 93 | end
|
||
| 94 | end
|
||
| 95 | end |