Commit fa30ade226ac8c8a456e738f1d19c96b70d62ed6
1 parent
e34ffc64
Exists in
staging
and in
15 other branches
Ticket #76: Adding a plugin "recent_activities" which adds a block that list the…
… recent activities of the profile who owns it
Showing
9 changed files
with
168 additions
and
0 deletions
Show diff stats
plugins/recent_activities/lib/recent_activities_plugin.rb
0 → 100644
... | ... | @@ -0,0 +1,23 @@ |
1 | +class RecentActivitiesPlugin < Noosfero::Plugin | |
2 | + def self.plugin_name | |
3 | + "RecentActivitiesPlugin" | |
4 | + end | |
5 | + | |
6 | + def self.plugin_description | |
7 | + _("Adds a block that lists recent profile activity.") | |
8 | + end | |
9 | + | |
10 | + def self.extra_blocks | |
11 | + { | |
12 | + RecentActivitiesPlugin::ActivitiesBlock => { type: [Community, Person] } | |
13 | + } | |
14 | + end | |
15 | + | |
16 | + def self.has_admin_url? | |
17 | + false | |
18 | + end | |
19 | + | |
20 | + def stylesheet? | |
21 | + true | |
22 | + end | |
23 | +end | ... | ... |
plugins/recent_activities/lib/recent_activities_plugin/activities_block.rb
0 → 100644
... | ... | @@ -0,0 +1,37 @@ |
1 | +class RecentActivitiesPlugin::ActivitiesBlock < Block | |
2 | + attr_accessible :limit | |
3 | + settings_items :limit, type: :integer, default: 5 | |
4 | + | |
5 | + def view_title | |
6 | + self.default_title | |
7 | + end | |
8 | + | |
9 | + def activities | |
10 | + list = self.limit.nil? ? owner.activities : owner.activities.limit(self.get_limit) | |
11 | + list.map(&:activity) | |
12 | + end | |
13 | + | |
14 | + def extra_option | |
15 | + { } | |
16 | + end | |
17 | + | |
18 | + def self.description | |
19 | + _('Display the latest activities by the owner of the context where the block is available.') | |
20 | + end | |
21 | + | |
22 | + def help | |
23 | + _('This block lists your latest activities.') | |
24 | + end | |
25 | + | |
26 | + def default_title | |
27 | + _('Recent activities') | |
28 | + end | |
29 | + | |
30 | + def api_content | |
31 | + Api::Entities::Activity.represent(activities).as_json | |
32 | + end | |
33 | + | |
34 | + def display_api_content_by_default? | |
35 | + false | |
36 | + end | |
37 | +end | ... | ... |
... | ... | @@ -0,0 +1,29 @@ |
1 | +.recent-activities-block ul { | |
2 | + padding: 0; | |
3 | +} | |
4 | + | |
5 | +.recent-activities-block li { | |
6 | + list-style: none; | |
7 | + border-bottom: 1px solid #ccc; | |
8 | +} | |
9 | + | |
10 | +.recent-activities-block time, | |
11 | +.recent-activities-block p { | |
12 | + margin: 10px 0; | |
13 | +} | |
14 | + | |
15 | +.recent-activities-block time { | |
16 | + display: block; | |
17 | + margin-bottom: 10px; | |
18 | + color: #ccc; | |
19 | +} | |
20 | + | |
21 | +.recent-activities-block img { | |
22 | + padding: 1px; | |
23 | + border: 1px solid #ccc; | |
24 | + margin: 3px 3px 0 0; | |
25 | +} | |
26 | + | |
27 | +.recent-activities-block p:first-letter { | |
28 | + text-transform: capitalize | |
29 | +} | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require_relative '../../../test/test_helper' | ... | ... |
plugins/recent_activities/test/unit/recent_activities_block_test.rb
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class RecentActivitiesBlockTest < ActiveSupport::TestCase | |
4 | + should 'describe itself' do | |
5 | + assert_not_equal Block.description, RecentActivitiesPlugin::ActivitiesBlock.description | |
6 | + end | |
7 | + | |
8 | + should 'is editable' do | |
9 | + block = RecentActivitiesPlugin::ActivitiesBlock.new | |
10 | + assert block.editable? | |
11 | + end | |
12 | + | |
13 | + should 'return last activities' do | |
14 | + profile = create_user('testuser').person | |
15 | + a1 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now) | |
16 | + a2 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now) | |
17 | + ProfileActivity.create! profile_id: profile.id, activity: a1 | |
18 | + ProfileActivity.create! profile_id: profile.id, activity: a2 | |
19 | + | |
20 | + block = RecentActivitiesPlugin::ActivitiesBlock.new | |
21 | + block.stubs(:owner).returns(profile) | |
22 | + | |
23 | + assert_equal [a2, a1].map(&:id), block.activities.map(&:id) | |
24 | + end | |
25 | + | |
26 | + should 'return last activities with limit' do | |
27 | + profile = create_user('testuser').person | |
28 | + a1 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now) | |
29 | + a2 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now) | |
30 | + ProfileActivity.create! profile_id: profile.id, activity: a1 | |
31 | + ProfileActivity.create! profile_id: profile.id, activity: a2 | |
32 | + | |
33 | + block = RecentActivitiesPlugin::ActivitiesBlock.new | |
34 | + block.stubs(:owner).returns(profile) | |
35 | + block.limit = 1 | |
36 | + | |
37 | + assert_equal [a2].map(&:id), block.activities.map(&:id) | |
38 | + end | |
39 | +end | |
40 | + | |
41 | +require 'boxes_helper' | |
42 | + | |
43 | +class RecentActivitiesBlockViewTest < ActionView::TestCase | |
44 | + include BoxesHelper | |
45 | + | |
46 | + should 'return activities in api_content' do | |
47 | + profile = create_user('testuser').person | |
48 | + | |
49 | + a = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now) | |
50 | + ProfileActivity.create! profile_id: profile.id, activity: a | |
51 | + | |
52 | + block = RecentActivitiesPlugin::ActivitiesBlock.new | |
53 | + block.stubs(:owner).returns(profile) | |
54 | + | |
55 | + assert_equal [a.id], block.api_content['activities'].map{ |a| a[:id] } | |
56 | + end | |
57 | +end | ... | ... |
plugins/recent_activities/views/blocks/activities.html.erb
0 → 100644
... | ... | @@ -0,0 +1,16 @@ |
1 | +<%= block_title(block.view_title, block.subtitle) %> | |
2 | + | |
3 | +<div class="recent-activities-block"> | |
4 | + <% unless block.activities.size == 0 %> | |
5 | + <ul> | |
6 | + <% block.activities.each do |activity| %> | |
7 | + <li> | |
8 | + <p><%= describe(activity).html_safe %></p> | |
9 | + <time datetime="<%= activity.created_at %>"><%= time_ago_in_words(activity.created_at) %></time> | |
10 | + </li> | |
11 | + <% end %> | |
12 | + </ul> | |
13 | + <% else %> | |
14 | + <div class="recent-activities-block-none"><%= c_('None') %></div> | |
15 | + <% end %> | |
16 | +</div> | ... | ... |
plugins/recent_activities/views/box_organizer/recent_activities_plugin/_activities_block.html.erb
0 → 100644