Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: class ActivitiesController < ApplicationController Chris@909: menu_item :activity Chris@909: before_filter :find_optional_project Chris@909: accept_rss_auth :index Chris@909: Chris@909: def index Chris@909: @days = Setting.activity_days_default.to_i Chris@909: Chris@909: if params[:from] Chris@909: begin; @date_to = params[:from].to_date + 1; rescue; end Chris@909: end Chris@909: Chris@909: @date_to ||= Date.today + 1 Chris@909: @date_from = @date_to - @days Chris@909: @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') Chris@909: @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) Chris@909: Chris@909: @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, Chris@909: :with_subprojects => @with_subprojects, Chris@909: :author => @author) Chris@909: @activity.scope_select {|t| !params["show_#{t}"].nil?} Chris@909: @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? Chris@909: Chris@909: events = @activity.events(@date_from, @date_to) Chris@909: Chris@909: if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, User.current, current_language]) Chris@909: respond_to do |format| Chris@909: format.html { Chris@909: @events_by_day = events.group_by(&:event_date) Chris@909: render :layout => false if request.xhr? Chris@909: } Chris@909: format.atom { Chris@909: title = l(:label_activity) Chris@909: if @author Chris@909: title = @author.name Chris@909: elsif @activity.scope.size == 1 Chris@909: title = l("label_#{@activity.scope.first.singularize}_plural") Chris@909: end Chris@909: render_feed(events, :title => "#{@project || Setting.app_title}: #{title}") Chris@909: } Chris@909: end Chris@909: end Chris@909: Chris@909: rescue ActiveRecord::RecordNotFound Chris@909: render_404 Chris@909: end Chris@909: Chris@909: private Chris@909: Chris@909: # TODO: refactor, duplicated in projects_controller Chris@909: def find_optional_project Chris@909: return true unless params[:id] Chris@909: @project = Project.find(params[:id]) Chris@909: authorize Chris@909: rescue ActiveRecord::RecordNotFound Chris@909: render_404 Chris@909: end Chris@909: end