diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index f82f0110a..f936ef011 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -27,8 +27,6 @@ class ActivitiesController < ApplicationController begin; @date_to = params[:from].to_date + 1; rescue; end end - @date_to ||= User.current.today + 1 - @date_from = @date_to - @days @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') if params[:user_id].present? @author = User.active.find(params[:user_id]) @@ -53,6 +51,26 @@ class ActivitiesController < ApplicationController end end + @date_to ||= User.current.today + 1 + @date_from = @date_to + + # Expand to empty activity period + @activity_before = last_activity(@date_to) + if ! @activity_before.nil? + @date_from = @date_to - (((@date_to - @activity_before.to_date - 1) / @days).to_i + 1 ) * @days + @activity_before = last_activity(@date_from - 1) + if ! @activity_before.nil? + @date_from = @date_from - (((@date_from - @activity_before.to_date - 1) / @days).to_i) * @days + end + end + + @activity_after = next_activity(@date_to) + if @activity_after.nil? + @date_to = Date.today + 1 + else + @date_to = @date_to + (((@activity_after.to_date - @date_to) / @days).to_i) * @days + end + events = @activity.events(@date_from, @date_to) if events.empty? || stale?(:etag => [@activity.scope, @date_to, @date_from, @with_subprojects, @author, events.first, events.size, User.current, current_language]) @@ -87,4 +105,18 @@ class ActivitiesController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def last_activity(to=nil) + Redmine::Activity::Fetcher.new(User.current, :project => @project, + :with_subprojects => @with_subprojects, + :author => @author). + events(nil, to, :last_by_project => true).map{|e| e[1]}.sort.last + end + + def next_activity(from=nil) + Redmine::Activity::Fetcher.new(User.current, :project => @project, + :with_subprojects => @with_subprojects, + :author => @author). + events(from, nil, :next_by_project => true).map{|e| e[1]}.sort.first + end end diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb index c3026fb63..7ea451966 100644 --- a/app/views/activities/index.html.erb +++ b/app/views/activities/index.html.erb @@ -1,5 +1,5 @@

<%= @author.nil? ? l(:label_activity) : l(:label_user_activity, link_to_user(@author)).html_safe %>

-

<%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %>

+

<%= l(:label_date_from_to, :start => format_date(@date_from), :end => format_date(@date_to-1)) unless @events_by_day.empty? %>

<% @events_by_day.keys.sort.reverse.each do |day| %> @@ -25,9 +25,9 @@