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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  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. #
  9. # 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. #
  14. # 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. class ActivitiesController < ApplicationController
  18. menu_item :activity
  19. before_action :find_optional_project_by_id, :authorize_global
  20. accept_rss_auth :index
  21. def index
  22. @days = Setting.activity_days_default.to_i
  23. if params[:from]
  24. begin; @date_to = params[:from].to_date + 1; rescue; end
  25. end
  26. @date_to ||= User.current.today + 1
  27. @date_from = @date_to - @days
  28. @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
  29. if params[:user_id].present?
  30. @author = User.active.find(params[:user_id])
  31. end
  32. @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
  33. :with_subprojects => @with_subprojects,
  34. :author => @author)
  35. pref = User.current.pref
  36. @activity.scope_select {|t| !params["show_#{t}"].nil?}
  37. if @activity.scope.present?
  38. if params[:submit].present?
  39. pref.activity_scope = @activity.scope
  40. pref.save
  41. end
  42. else
  43. if @author.nil?
  44. scope = pref.activity_scope & @activity.event_types
  45. @activity.scope = scope.present? ? scope : :default
  46. else
  47. @activity.scope = :all
  48. end
  49. end
  50. events = @activity.events(@date_from, @date_to)
  51. if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, events.size, User.current, current_language])
  52. respond_to do |format|
  53. format.html {
  54. @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)}
  55. render :layout => false if request.xhr?
  56. }
  57. format.atom {
  58. title = l(:label_activity)
  59. if @author
  60. title = @author.name
  61. elsif @activity.scope.size == 1
  62. title = l("label_#{@activity.scope.first.singularize}_plural")
  63. end
  64. render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
  65. }
  66. end
  67. end
  68. rescue ActiveRecord::RecordNotFound
  69. render_404
  70. end
  71. end