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