To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / activities_controller.rb @ 442:753f1380d6bc

History | View | Annotate | Download (1.97 KB)

1 22:40f7cfd4df19 chris
class ActivitiesController < ApplicationController
2
  menu_item :activity
3
  before_filter :find_optional_project
4
  accept_key_auth :index
5
6
  def index
7
    @days = Setting.activity_days_default.to_i
8 441:cbce1fd3b1b7 Chris
9 22:40f7cfd4df19 chris
    if params[:from]
10
      begin; @date_to = params[:from].to_date + 1; rescue; end
11
    end
12
13
    @date_to ||= Date.today + 1
14
    @date_from = @date_to - @days
15
    @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
16
    @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))
17 441:cbce1fd3b1b7 Chris
18
    @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
19 22:40f7cfd4df19 chris
                                                             :with_subprojects => @with_subprojects,
20
                                                             :author => @author)
21
    @activity.scope_select {|t| !params["show_#{t}"].nil?}
22
    @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?
23
24
    events = @activity.events(@date_from, @date_to)
25 441:cbce1fd3b1b7 Chris
26 119:8661b858af72 Chris
    if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, User.current, current_language])
27 22:40f7cfd4df19 chris
      respond_to do |format|
28 441:cbce1fd3b1b7 Chris
        format.html {
29 22:40f7cfd4df19 chris
          @events_by_day = events.group_by(&:event_date)
30
          render :layout => false if request.xhr?
31
        }
32
        format.atom {
33
          title = l(:label_activity)
34
          if @author
35
            title = @author.name
36
          elsif @activity.scope.size == 1
37
            title = l("label_#{@activity.scope.first.singularize}_plural")
38
          end
39
          render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
40
        }
41
      end
42
    end
43 441:cbce1fd3b1b7 Chris
44 22:40f7cfd4df19 chris
  rescue ActiveRecord::RecordNotFound
45
    render_404
46
  end
47
48
  private
49
50
  # TODO: refactor, duplicated in projects_controller
51
  def find_optional_project
52
    return true unless params[:id]
53
    @project = Project.find(params[:id])
54
    authorize
55
  rescue ActiveRecord::RecordNotFound
56
    render_404
57
  end
58
end