Compare View
Commits (7)
-
Recent activities plugin improvements: show author and better display for thumbnails See merge request !975
Showing
10 changed files
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
... | ... | @@ -18,7 +18,8 @@ |
18 | 18 | color: #ccc; |
19 | 19 | } |
20 | 20 | |
21 | -.recent-activities-block img { | |
21 | +.recent-activities-block img, | |
22 | +.recent-activities-block .upimg { | |
22 | 23 | padding: 1px; |
23 | 24 | border: 1px solid #ccc; |
24 | 25 | margin: 3px 3px 0 0; |
... | ... | @@ -27,3 +28,45 @@ |
27 | 28 | .recent-activities-block p:first-letter { |
28 | 29 | text-transform: capitalize |
29 | 30 | } |
31 | + | |
32 | +.recent-activities-block .upimg { | |
33 | + width: 20px; | |
34 | + height: 20px; | |
35 | + display: inline-block; | |
36 | + background-size: cover; | |
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_block_test.rb
... | ... | @@ -68,6 +68,31 @@ class RecentActivitiesBlockViewTest < ActionView::TestCase |
68 | 68 | block = RecentActivitiesPlugin::ActivitiesBlock.new |
69 | 69 | block.stubs(:owner).returns(profile) |
70 | 70 | |
71 | + api_activity = block.api_content['activities'].last | |
71 | 72 | assert_equal [a.id], block.api_content['activities'].map{ |a| a[:id] } |
73 | + assert_not_nil api_activity[:label] | |
74 | + assert_nil api_activity[:start_date] | |
75 | + end | |
76 | + | |
77 | + should 'return event information in api_content' do | |
78 | + person = fast_create(Person) | |
79 | + event = build(Event, { name: 'Event', start_date: DateTime.new(2020, 1, 1) }) | |
80 | + event.profile = person | |
81 | + event.save! | |
82 | + activity = create_activity(person, event) | |
83 | + | |
84 | + block = RecentActivitiesPlugin::ActivitiesBlock.new | |
85 | + block.stubs(:owner).returns(person) | |
86 | + | |
87 | + api_activity = block.api_content['activities'].last | |
88 | + assert_not_nil api_activity[:start_date] | |
89 | + end | |
90 | + | |
91 | + protected | |
92 | + | |
93 | + def create_activity(person, target) | |
94 | + activity = ActionTracker::Record.create! verb: :leave_scrap, user: person, target: target | |
95 | + ProfileActivity.create! profile_id: target.id, activity: activity | |
96 | + activity.reload | |
72 | 97 | end |
73 | 98 | end | ... | ... |
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> | |
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 %> | |
8 | 36 | <p><%= describe(activity).html_safe %></p> |
9 | - <time datetime="<%= activity.created_at %>"><%= time_ago_in_words(activity.created_at) %></time> | |
37 | + <% end %> | |
10 | 38 | </li> |
11 | 39 | <% end %> |
12 | 40 | </ul> | ... | ... |