annotate app/controllers/activities_controller.rb @ 1172:60d42b9850d2 bug_367

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