From 8b57ffc3c750b253e316fbfd8871d5c2da045557 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Fri, 3 May 2024 13:14:18 +0000 Subject: Adds the date of the last activity to the list of available columns for Projects (#23954). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Frederico Camara (@fredsdc) and Marius BĂLTEANU (@marius.balteanu). git-svn-id: https://svn.redmine.org/redmine/trunk@22811 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../lib/acts_as_activity_provider.rb | 9 ++++++--- lib/redmine/activity/fetcher.rb | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'lib') 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 5954d501d..ac334c19a 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 @@ -64,9 +64,8 @@ module Redmine ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :scope option is deprecated. Please pass a scope on the #{self.name} as a proc." end - 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? @@ -87,6 +86,10 @@ module Redmine scope = scope.where(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) end + if options[:last_by_project] + scope = scope.group("#{Project.table_name}.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 cbd20425d..4264c2e5d 100644 --- a/lib/redmine/activity/fetcher.rb +++ b/lib/redmine/activity/fetcher.rb @@ -87,6 +87,7 @@ 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] @scope.each do |event_type| constantized_providers(event_type).each do |provider| @@ -94,10 +95,14 @@ module Redmine end end - e.sort! {|a, b| b.event_datetime <=> a.event_datetime} + if options[:last_by_project] + e.sort! + 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 -- cgit v1.2.3