Chris@507
|
1 # Redmine - project management software
|
Chris@1115
|
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
|
Chris@507
|
3 #
|
Chris@507
|
4 # This program is free software; you can redistribute it and/or
|
Chris@507
|
5 # modify it under the terms of the GNU General Public License
|
Chris@507
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@507
|
7 # of the License, or (at your option) any later version.
|
Chris@507
|
8 #
|
Chris@507
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@507
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@507
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@507
|
12 # GNU General Public License for more details.
|
Chris@507
|
13 #
|
Chris@507
|
14 # You should have received a copy of the GNU General Public License
|
Chris@507
|
15 # along with this program; if not, write to the Free Software
|
Chris@507
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@507
|
17
|
chris@22
|
18 class ActivitiesController < ApplicationController
|
chris@22
|
19 menu_item :activity
|
chris@22
|
20 before_filter :find_optional_project
|
Chris@507
|
21 accept_rss_auth :index
|
chris@22
|
22
|
chris@22
|
23 def index
|
chris@22
|
24 @days = Setting.activity_days_default.to_i
|
Chris@441
|
25
|
chris@22
|
26 if params[:from]
|
chris@22
|
27 begin; @date_to = params[:from].to_date + 1; rescue; end
|
chris@22
|
28 end
|
chris@22
|
29
|
chris@22
|
30 @date_to ||= Date.today + 1
|
chris@22
|
31 @date_from = @date_to - @days
|
chris@22
|
32 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
chris@22
|
33 @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
|
Chris@441
|
34
|
Chris@441
|
35 @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
|
chris@22
|
36 :with_subprojects => @with_subprojects,
|
chris@22
|
37 :author => @author)
|
chris@22
|
38 @activity.scope_select {|t| !params["show_#{t}"].nil?}
|
chris@22
|
39 @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
|
chris@22
|
40
|
chris@22
|
41 events = @activity.events(@date_from, @date_to)
|
Chris@441
|
42
|
chris@1009
|
43 @institution_name = params[:institution]
|
chris@1009
|
44 if !@institution_name.blank?
|
chris@1009
|
45 events = events.select do |e|
|
chris@1009
|
46 e.respond_to?(:event_author) and e.event_author and
|
Chris@1014
|
47 e.event_author.respond_to?(:ssamr_user_detail) and
|
Chris@1014
|
48 !e.event_author.ssamr_user_detail.nil? and
|
chris@1009
|
49 e.event_author.ssamr_user_detail.institution_name == @institution_name
|
chris@1009
|
50 end
|
chris@1009
|
51 if events.empty?
|
chris@1009
|
52 # We don't want to dump into the output any arbitrary string
|
chris@1009
|
53 # from the URL that has no matching events
|
chris@1009
|
54 @institution_name = ""
|
chris@1009
|
55 end
|
chris@1009
|
56 end
|
chris@1009
|
57
|
Chris@1116
|
58 if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, @institution_name, events.first, events.size, User.current, current_language])
|
chris@22
|
59 respond_to do |format|
|
Chris@441
|
60 format.html {
|
Chris@1115
|
61 @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
|
chris@22
|
62 render :layout => false if request.xhr?
|
chris@22
|
63 }
|
chris@22
|
64 format.atom {
|
chris@22
|
65 title = l(:label_activity)
|
chris@22
|
66 if @author
|
chris@22
|
67 title = @author.name
|
chris@22
|
68 elsif @activity.scope.size == 1
|
chris@22
|
69 title = l("label_#{@activity.scope.first.singularize}_plural")
|
chris@22
|
70 end
|
chris@22
|
71 render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
|
chris@22
|
72 }
|
chris@22
|
73 end
|
chris@22
|
74 end
|
Chris@441
|
75
|
chris@22
|
76 rescue ActiveRecord::RecordNotFound
|
chris@22
|
77 render_404
|
chris@22
|
78 end
|
chris@22
|
79
|
chris@22
|
80 private
|
chris@22
|
81
|
chris@22
|
82 # TODO: refactor, duplicated in projects_controller
|
chris@22
|
83 def find_optional_project
|
chris@22
|
84 return true unless params[:id]
|
chris@22
|
85 @project = Project.find(params[:id])
|
chris@22
|
86 authorize
|
chris@22
|
87 rescue ActiveRecord::RecordNotFound
|
chris@22
|
88 render_404
|
chris@22
|
89 end
|
chris@22
|
90 end
|