You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

activities_controller.rb 2.9KB

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