Commit d6d614928bc81c8a3d9224d1c945263ae9aa8fe7

Authored by Leandro Santos
2 parents 9247134c 4d031bf1
Exists in staging and in 1 other branch production

Merge branch 'master' into staging

app/views/file_presenter/_image.html.erb
... ... @@ -4,15 +4,15 @@
4 4 current_index = images.index(image.encapsulated_file)
5 5 total_of_images = images.count
6 6 link_to_previous = if current_index >= 1
7   - link_to(_('« Previous'), images[current_index - 1].view_url, :class => 'previous')
  7 + link_to(_('« Previous').html_safe, images[current_index - 1].view_url, :class => 'previous')
8 8 else
9   - content_tag('span', _('« Previous'), :class => 'previous')
  9 + content_tag('span', _('« Previous').html_safe, :class => 'previous')
10 10 end
11 11  
12 12 link_to_next = if current_index < total_of_images - 1
13   - link_to(_('Next &raquo;'), images[current_index + 1].view_url, :class => 'next')
  13 + link_to(_('Next &raquo;').html_safe, images[current_index + 1].view_url, :class => 'next')
14 14 else
15   - content_tag('span', _('Next &raquo;'), :class => 'next')
  15 + content_tag('span', _('Next &raquo;').html_safe, :class => 'next')
16 16 end
17 17 %>
18 18  
... ...
plugins/recent_activities/lib/recent_activities_plugin.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  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
  24 +
  25 +ApplicationHelper.include ActionTrackerHelper
... ...
plugins/recent_activities/lib/recent_activities_plugin/activities_block.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  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 + activities = owner.activities.where(activity_type: ActionTracker::Record.to_s)
  11 + list = self.limit.nil? ? activities : activities.limit(self.get_limit)
  12 + list.map(&:activity)
  13 + end
  14 +
  15 + def extra_option
  16 + { }
  17 + end
  18 +
  19 + def self.description
  20 + _('Display the latest activities by the owner of the context where the block is available.')
  21 + end
  22 +
  23 + def help
  24 + _('This block lists your latest activities. By default, any user that goes to your profile will be able to see all activities. Configure the "Display to users" option if you don\'t want that.')
  25 + end
  26 +
  27 + def default_title
  28 + _('Recent activities')
  29 + end
  30 +
  31 + def api_content
  32 + Api::Entities::Activity.represent(activities).as_json
  33 + end
  34 +
  35 + def display_api_content_by_default?
  36 + false
  37 + end
  38 +
  39 + def timeout
  40 + 4.hours
  41 + end
  42 +
  43 + def self.expire_on
  44 + { profile: [:article] }
  45 + end
  46 +end
... ...
plugins/recent_activities/public/style.css 0 → 100644
... ... @@ -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 +}
... ...
plugins/recent_activities/test/test_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require_relative '../../../test/test_helper'
... ...
plugins/recent_activities/test/unit/recent_activities_block_test.rb 0 → 100644
... ... @@ -0,0 +1,73 @@
  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 +
  40 + should 'return only action tracker records as activities' do
  41 + profile = create_user('testuser').person
  42 + friend = create_user('friend').person
  43 + scrap = create(Scrap, defaults_for_scrap(sender: friend, receiver: profile))
  44 + a1 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now)
  45 + a2 = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now)
  46 + ProfileActivity.create! profile_id: profile.id, activity: a1
  47 + ProfileActivity.create! profile_id: profile.id, activity: a2
  48 +
  49 + block = RecentActivitiesPlugin::ActivitiesBlock.new
  50 + block.stubs(:owner).returns(profile)
  51 +
  52 + assert_equal [a2, a1, scrap], block.owner.activities.map(&:activity)
  53 + assert_equal [a2, a1], block.activities
  54 + end
  55 +end
  56 +
  57 +require 'boxes_helper'
  58 +
  59 +class RecentActivitiesBlockViewTest < ActionView::TestCase
  60 + include BoxesHelper
  61 +
  62 + should 'return activities in api_content' do
  63 + profile = create_user('testuser').person
  64 +
  65 + a = fast_create(ActionTracker::Record, user_id: profile.id, created_at: Time.now, updated_at: Time.now)
  66 + ProfileActivity.create! profile_id: profile.id, activity: a
  67 +
  68 + block = RecentActivitiesPlugin::ActivitiesBlock.new
  69 + block.stubs(:owner).returns(profile)
  70 +
  71 + assert_equal [a.id], block.api_content['activities'].map{ |a| a[:id] }
  72 + end
  73 +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
... ... @@ -0,0 +1,3 @@
  1 +<div id="activities_block_plugin">
  2 + <%= labelled_form_field(_('Limit'), text_field(:block, :limit, size: 3)) %>
  3 +</div>
... ...
plugins/recent_activities/views/environment_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer/
0 2 \ No newline at end of file
... ...
plugins/recent_activities/views/profile_design 0 → 120000
... ... @@ -0,0 +1 @@
  1 +box_organizer/
0 2 \ No newline at end of file
... ...