Commit 9f2e206f authored by jplang's avatar jplang

Group events in the activity view (#12542).

git-svn-id: https://svn.redmine.org/redmine/trunk@10951 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent fab60b48
# encoding: utf-8
#
# Redmine - project management software
# Copyright (C) 2006-2012 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module ActivitiesHelper
def sort_activity_events(events)
events_by_group = events.group_by(&:event_group)
sorted_events = []
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event|
if group_events = events_by_group.delete(event.event_group)
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i|
sorted_events << [e, i > 0]
end
end
end
sorted_events
end
end
......@@ -28,6 +28,7 @@ class Journal < ActiveRecord::Base
acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" },
:description => :notes,
:author => :user,
:group => :issue,
:type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
......
......@@ -29,6 +29,7 @@ class Message < ActiveRecord::Base
:date_column => "#{table_name}.created_on"
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
:description => :content,
:group => :parent,
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
......
......@@ -30,6 +30,7 @@ class TimeEntry < ActiveRecord::Base
acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
:url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}},
:author => :user,
:group => :issue,
:description => :comments
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
......
......@@ -59,6 +59,7 @@ class WikiContent < ActiveRecord::Base
:description => :comments,
:datetime => :updated_on,
:type => 'wiki-page',
:group => :page,
:url => Proc.new {|o| {:controller => 'wiki', :action => 'show', :project_id => o.page.wiki.project, :id => o.page.title, :version => o.version}}
acts_as_activity_provider :type => 'wiki_edits',
......
......@@ -5,13 +5,14 @@
<% @events_by_day.keys.sort.reverse.each do |day| %>
<h3><%= format_activity_day(day) %></h3>
<dl>
<% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| -%>
<dt class="<%= e.event_type %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
<dt class="<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
<%= avatar(e.event_author, :size => "24") if e.respond_to?(:event_author) %>
<span class="time"><%= format_time(e.event_datetime, false) %></span>
<%= content_tag('span', h(e.project), :class => 'project') if @project.nil? || @project != e.project %>
<%= link_to format_activity_title(e.event_title), e.event_url %></dt>
<dd><span class="description"><%= format_activity_description(e.event_description) %></span>
<%= link_to format_activity_title(e.event_title), e.event_url %>
</dt>
<dd class="<%= "grouped" if in_group %>"><span class="description"><%= format_activity_description(e.event_description) %></span>
<span class="author"><%= link_to_user(e.event_author) if e.respond_to?(:event_author) %></span></dd>
<% end -%>
</dl>
......
......@@ -63,6 +63,11 @@ module Redmine
event_datetime.to_date
end
def event_group
group = event_options[:group] ? send(event_options[:group]) : self
group || self
end
def event_url(options = {})
option = event_options[:url]
if option.is_a?(Proc)
......
......@@ -372,6 +372,8 @@ div#activity dt .time { color: #777; font-size: 80%; }
div#activity dd .description, #search-results dd .description { font-style: italic; }
div#activity span.project:after, #search-results span.project:after { content: " -"; }
div#activity dd span.description, #search-results dd span.description { display:block; color: #808080; }
div#activity dt.grouped {margin-left:5em;}
div#activity dd.grouped {margin-left:9em;}
#search-results dd { margin-bottom: 1em; padding-left: 20px; margin-left:0px; }
......
......@@ -19,7 +19,8 @@ require File.expand_path('../../test_helper', __FILE__)
class ActivityTest < ActiveSupport::TestCase
fixtures :projects, :versions, :attachments, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
:trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages
:trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, :time_entries,
:wikis, :wiki_pages, :wiki_contents, :wiki_content_versions
def setup
@project = Project.find(1)
......@@ -87,6 +88,39 @@ class ActivityTest < ActiveSupport::TestCase
assert_equal %w(Project Version), events.collect(&:container_type).uniq.sort
end
def test_event_group_for_issue
issue = Issue.find(1)
assert_equal issue, issue.event_group
end
def test_event_group_for_journal
issue = Issue.find(1)
journal = issue.journals.first
assert_equal issue, journal.event_group
end
def test_event_group_for_issue_time_entry
time = TimeEntry.where(:issue_id => 1).first
assert_equal time.issue, time.event_group
end
def test_event_group_for_project_time_entry
time = TimeEntry.where(:issue_id => nil).first
assert_equal time, time.event_group
end
def test_event_group_for_message
message = Message.find(1)
reply = message.children.first
assert_equal message, message.event_group
assert_equal message, reply.event_group
end
def test_event_group_for_wiki_content_version
content = WikiContent::Version.find(1)
assert_equal content.page, content.event_group
end
private
def find_events(user, options={})
......
# Redmine - project management software
# Copyright (C) 2006-2012 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../test_helper', __FILE__)
class ActivitiesHelperTest < ActionView::TestCase
include ActivitiesHelper
class MockEvent
attr_reader :event_datetime, :event_group, :name
def initialize(group=nil)
@@count ||= 0
@name = "e#{@@count}"
@event_datetime = Time.now + @@count.hours
@event_group = group || self
@@count += 1
end
def self.clear
@@count = 0
end
end
def setup
MockEvent.clear
end
def test_sort_activity_events_should_sort_by_datetime
events = []
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new
assert_equal [
['e2', false],
['e1', false],
['e0', false]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_should_group_events
events = []
events << MockEvent.new
events << MockEvent.new(events[0])
events << MockEvent.new(events[0])
assert_equal [
['e2', false],
['e1', true],
['e0', true]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_with_group_not_in_set_should_group_events
e = MockEvent.new
events = []
events << MockEvent.new(e)
events << MockEvent.new(e)
assert_equal [
['e2', false],
['e1', true]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
def test_sort_activity_events_should_sort_by_datetime_and_group
events = []
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new
events << MockEvent.new(events[1])
events << MockEvent.new(events[2])
events << MockEvent.new
events << MockEvent.new(events[2])
assert_equal [
['e6', false],
['e4', true],
['e2', true],
['e5', false],
['e3', false],
['e1', true],
['e0', false]
], sort_activity_events(events).map {|event, grouped| [event.name, grouped]}
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment