Project

General

Profile

Feature #3099 » activity_always-r3.4.patch

For Redmine 3.4 - Frederico Camara, 2018-03-09 22:15

View differences:

app/controllers/activities_controller.rb
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])
......
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])
......
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
app/views/activities/index.html.erb
<h2><%= @author.nil? ? l(:label_activity) : l(:label_user_activity, link_to_user(@author)).html_safe %></h2>
<p class="subtitle"><%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %></p>
<p class="subtitle"><%= l(:label_date_from_to, :start => format_date(@date_from), :end => format_date(@date_to-1)) unless @events_by_day.empty? %></p>
<div id="activity">
<% @events_by_day.keys.sort.reverse.each do |day| %>
......
<ul class="pages">
<li class="previous page">
<%= link_to("\xc2\xab " + l(:label_previous),
{:params => request.query_parameters.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 => request.query_parameters.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? %>
</li><% unless @date_to > User.current.today %><li class="next page">
<%= link_to(l(:label_next) + " \xc2\xbb",
{:params => request.query_parameters.merge(:from => @date_to + @days - 1)},
config/locales/en.yml
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
config/locales/pt-BR.yml
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
lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
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?
......
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
lib/redmine/activity/fetcher.rb
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|
......
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
(2-2/2)