Commit e6f99d392f7015be655cb7f471f2048478af5948
1 parent
46aeed7e
Exists in
staging
and in
5 other branches
Ticket #116: Adding more information to the recent activities block
Showing
8 changed files
with
144 additions
and
3 deletions
Show diff stats
plugins/recent_activities/lib/ext/action_tracker_model.rb
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +require_dependency 'action_tracker_model' | |
2 | + | |
3 | +class ActionTracker::Record | |
4 | + def label | |
5 | + case self.target.class.name | |
6 | + when 'Event' | |
7 | + 'events' | |
8 | + when 'Community' | |
9 | + 'communities' | |
10 | + when 'Friendship' | |
11 | + 'people' | |
12 | + else | |
13 | + 'posts' | |
14 | + end | |
15 | + end | |
16 | +end | ... | ... |
plugins/recent_activities/public/style.css
... | ... | @@ -35,3 +35,38 @@ |
35 | 35 | display: inline-block; |
36 | 36 | background-size: cover; |
37 | 37 | } |
38 | + | |
39 | +.recent-activities-block .recent-activity-date, | |
40 | +.recent-activities-block .recent-activity-date a, | |
41 | +.recent-activities-block .recent-activity-date a:visited { | |
42 | + color: #888a85; | |
43 | +} | |
44 | + | |
45 | +.recent-activities-block .recent-activity-label { | |
46 | + padding: 2px; | |
47 | + text-transform: capitalize; | |
48 | + background: #333; | |
49 | + color: #fff; | |
50 | + margin-left: 5px; | |
51 | + display: inline-block; | |
52 | + font-size: 11px; | |
53 | +} | |
54 | + | |
55 | +.recent-activities-block .recent-activity-event { | |
56 | + display: table-row; | |
57 | +} | |
58 | + | |
59 | +.recent-activities-block .recent-activity-events img { | |
60 | + width: 32px; | |
61 | + height: 32px; | |
62 | + float: left; | |
63 | +} | |
64 | + | |
65 | +.recent-activities-block .recent-activity-events .lead { | |
66 | + width: 148px; | |
67 | + margin-left: 2px; | |
68 | + margin-top: 2px; | |
69 | + float: left; | |
70 | + display: block; | |
71 | + text-align: justify; | |
72 | +} | ... | ... |
plugins/recent_activities/test/unit/recent_activities_test.rb
0 → 100644
... | ... | @@ -0,0 +1,46 @@ |
1 | +require 'test_helper' | |
2 | + | |
3 | +class RecentActivitiesPluginTest < ActiveSupport::TestCase | |
4 | + def setup | |
5 | + @environment = Environment.default | |
6 | + @environment.enable_plugin(RecentActivitiesPlugin) | |
7 | + end | |
8 | + | |
9 | + should 'have label for events' do | |
10 | + person = fast_create(Person) | |
11 | + event = build(Event, { name: 'Event', start_date: DateTime.new(2020, 1, 1) }) | |
12 | + event.profile = person | |
13 | + event.save! | |
14 | + activity = create_activity(person, event) | |
15 | + assert_equal 'events', activity.label | |
16 | + end | |
17 | + | |
18 | + should 'have label for communities' do | |
19 | + person = fast_create(Person) | |
20 | + community = fast_create(Community) | |
21 | + activity = create_activity(person, community) | |
22 | + assert_equal 'communities', activity.label | |
23 | + end | |
24 | + | |
25 | + should 'have label for people' do | |
26 | + person = fast_create(Person) | |
27 | + friendship = fast_create(Friendship) | |
28 | + activity = create_activity(person, friendship) | |
29 | + assert_equal 'people', activity.label | |
30 | + end | |
31 | + | |
32 | + should 'have label for posts' do | |
33 | + person = fast_create(Person) | |
34 | + article = fast_create(Article) | |
35 | + activity = create_activity(person, article) | |
36 | + assert_equal 'posts', activity.label | |
37 | + end | |
38 | + | |
39 | + protected | |
40 | + | |
41 | + def create_activity(person, target) | |
42 | + activity = ActionTracker::Record.create! verb: :leave_scrap, user: person, target: target | |
43 | + ProfileActivity.create! profile_id: target.id, activity: activity | |
44 | + activity.reload | |
45 | + end | |
46 | +end | ... | ... |
plugins/recent_activities/views/blocks/activities.html.erb
... | ... | @@ -4,9 +4,37 @@ |
4 | 4 | <% unless block.activities.size == 0 %> |
5 | 5 | <ul> |
6 | 6 | <% block.activities.each do |activity| %> |
7 | - <li> | |
8 | - <p><%= link_to activity.user.name, activity.user.url %> <%= describe(activity).html_safe %></p> | |
9 | - <time datetime="<%= activity.created_at %>"><%= time_ago_in_words(activity.created_at) %></time> | |
7 | + <li class="recent-activity-<%= activity.label %>"> | |
8 | + <p class="recent-activity-date"> | |
9 | + <% if activity.label === 'events' %> | |
10 | + <%= | |
11 | + _('Event on <b>%s</b> at %s - %s').html_safe % | |
12 | + [ | |
13 | + l(activity.target.start_date, format: :medium), | |
14 | + activity.target.start_date.strftime("%H:%M"), | |
15 | + link_to(activity.user.name, activity.user.url) | |
16 | + ] | |
17 | + %> | |
18 | + <% else %> | |
19 | + <%= | |
20 | + _('On <b>%s</b> at %s - %s').html_safe % | |
21 | + [ | |
22 | + l(activity.created_at, format: :medium), | |
23 | + activity.created_at.strftime("%H:%M"), | |
24 | + link_to(activity.user.name, activity.user.url) | |
25 | + ] | |
26 | + %> | |
27 | + <% end %> | |
28 | + <span class="recent-activity-label"><%= activity.label %></span> | |
29 | + </p> | |
30 | + | |
31 | + <% if activity.label === 'events' %> | |
32 | + <%= image_tag(activity.params['first_image']) %> | |
33 | + <p class="lead"><b><%= activity.params['name'] %></b><br /><%= strip_tags(activity.params['lead']) %></p> | |
34 | + <br style="clear: both;" /> | |
35 | + <% else %> | |
36 | + <p><%= describe(activity).html_safe %></p> | |
37 | + <% end %> | |
10 | 38 | </li> |
11 | 39 | <% end %> |
12 | 40 | </ul> | ... | ... |