diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 32df00f97..d292d65a4 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 c191ccba5..bff82c0a3 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| %> @@ -23,9 +23,9 @@
<%= link_to_content_update("\xc2\xab " + l(:label_previous), - params.merge(:from => @date_to - @days - 1), - :title => l(:label_date_from_to, :start => format_date(@date_to - 2*@days), :end => format_date(@date_to - @days - 1)), - :accesskey => accesskey(:previous)) %> + params.merge(:from => @date_from - 1), + :title => l(:label_date_from_to, :start => format_date(@date_from - @days), :end => format_date(@date_from - 1)), + :accesskey => accesskey(:previous)) unless @activity_before.nil? %>
<%= link_to_content_update(l(:label_next) + " \xc2\xbb", diff --git a/config/locales/en.yml b/config/locales/en.yml index 399c2e85a..3172839b2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -254,6 +254,7 @@ en: field_downloads: Downloads field_author: Author field_created_on: Created + field_last_activity: Last activity field_updated_on: Updated field_closed_on: Closed field_field_format: Format diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 2e2e159cc..99bb3b780 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -222,6 +222,7 @@ pt-BR: field_downloads: Downloads field_author: Autor field_created_on: Criado em + field_last_activity: Ăšltima atividade field_updated_on: Alterado em field_field_format: Formato field_is_for_all: Para todos os projetos diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb index 8f65eb720..18a1c8772 100644 --- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb +++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb @@ -55,9 +55,8 @@ module Redmine scope = (provider_options[:scope] || self) - if from && to - scope = scope.where("#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to) - end + scope = scope.where("#{provider_options[:timestamp]} >= ?", from) if from + scope = scope.where("#{provider_options[:timestamp]} <= ?", to) if to if options[:author] return [] if provider_options[:author_key].nil? @@ -78,6 +77,14 @@ module Redmine scope = scope.where(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) end + if options[:next_by_project] + scope = scope.group("projects.id").minimum(provider_options[:timestamp]) + end + + if options[:last_by_project] + scope = scope.group("projects.id").maximum(provider_options[:timestamp]) + end + scope.to_a end end diff --git a/lib/redmine/activity/fetcher.rb b/lib/redmine/activity/fetcher.rb index 627a08441..23c649e76 100644 --- a/lib/redmine/activity/fetcher.rb +++ b/lib/redmine/activity/fetcher.rb @@ -85,6 +85,8 @@ module Redmine def events(from = nil, to = nil, options={}) e = [] @options[:limit] = options[:limit] + @options[:last_by_project] = options[:last_by_project] if options[:last_by_project] + @options[:next_by_project] = options[:next_by_project] if options[:next_by_project] @scope.each do |event_type| constantized_providers(event_type).each do |provider| @@ -92,10 +94,16 @@ module Redmine end end - e.sort! {|a,b| b.event_datetime <=> a.event_datetime} + if options[:last_by_project] + e.sort! + elsif options[:next_by_project] + e.sort! {|a,b| b <=> a} + else + e.sort! {|a,b| b.event_datetime <=> a.event_datetime} - if options[:limit] - e = e.slice(0, options[:limit]) + if options[:limit] + e = e.slice(0, options[:limit]) + end end e end