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