annotate app/controllers/activities_controller.rb @ 855:7294e8db2515 bug_162

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