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 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- 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_atom_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.visible.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 =
  52. if params[:format] == 'atom'
  53. @activity.events(nil, nil, :limit => Setting.feeds_limit.to_i)
  54. else
  55. @activity.events(@date_from, @date_to)
  56. end
  57. if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, events.size, User.current, current_language])
  58. respond_to do |format|
  59. format.html do
  60. @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
  61. render :layout => false if request.xhr?
  62. end
  63. format.atom do
  64. title = l(:label_activity)
  65. if @author
  66. title = @author.name
  67. elsif @activity.scope.size == 1
  68. title = l("label_#{@activity.scope.first.singularize}_plural")
  69. end
  70. render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
  71. end
  72. end
  73. end
  74. rescue ActiveRecord::RecordNotFound
  75. render_404
  76. end
  77. end