Commit c70ae1ba0e8a4621ff5737f06b22aae52689aa98
Committed by
Daniela Feitosa
1 parent
955f8e1a
Exists in
fix_sign_up_form
Ticket #118: Adding a profile_images plugin that adds a block that exposes the i…
…mages inside the profile Signed-off-by: Daniela Soares Feitosa <danielafeitosa@colivre.coop.br> See merge request !988
Showing
8 changed files
with
188 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,23 @@ |
1 | +class ProfileImagesPlugin < Noosfero::Plugin | |
2 | + def self.plugin_name | |
3 | + 'ProfileImagesPlugin' | |
4 | + end | |
5 | + | |
6 | + def self.plugin_description | |
7 | + _('Adds a block that lists all images inside a profile.') | |
8 | + end | |
9 | + | |
10 | + def self.extra_blocks | |
11 | + { | |
12 | + ProfileImagesPlugin::ProfileImagesBlock => { type: [Person, Community, Enterprise] } | |
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/profile_images/lib/profile_images_plugin/profile_images_block.rb
0 → 100644
... | ... | @@ -0,0 +1,49 @@ |
1 | +class ProfileImagesPlugin::ProfileImagesBlock < Block | |
2 | + attr_accessible :limit | |
3 | + settings_items :limit, type: :integer, default: 6 | |
4 | + | |
5 | + def view_title | |
6 | + self.default_title | |
7 | + end | |
8 | + | |
9 | + def images | |
10 | + images = owner.articles.images | |
11 | + self.limit.nil? ? images : images.first(self.get_limit) | |
12 | + end | |
13 | + | |
14 | + def extra_option | |
15 | + { } | |
16 | + end | |
17 | + | |
18 | + def self.description | |
19 | + _('Display the images inside the context where the block is available.') | |
20 | + end | |
21 | + | |
22 | + def help | |
23 | + _('This block lists the images inside this profile.') | |
24 | + end | |
25 | + | |
26 | + def default_title | |
27 | + _('Profile images') | |
28 | + end | |
29 | + | |
30 | + def api_content | |
31 | + content = [] | |
32 | + images.each do |image| | |
33 | + content << { title: image.title, view_url: image.view_url, path: image.public_filename(:thumb), id: image.id } | |
34 | + end | |
35 | + { images: content } | |
36 | + end | |
37 | + | |
38 | + def display_api_content_by_default? | |
39 | + false | |
40 | + end | |
41 | + | |
42 | + def timeout | |
43 | + 4.hours | |
44 | + end | |
45 | + | |
46 | + def self.expire_on | |
47 | + { profile: [:article] } | |
48 | + end | |
49 | +end | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +.profile-images-block ul { | |
2 | + padding: 0; | |
3 | + display: block; | |
4 | + width: 100%; | |
5 | +} | |
6 | + | |
7 | +.profile-images-block li { | |
8 | + list-style: none; | |
9 | +} | |
10 | + | |
11 | +.profile-images-block a { | |
12 | + display: block; | |
13 | + width: 53px; | |
14 | + height: 53px; | |
15 | + float: left; | |
16 | + padding: 1px; | |
17 | + border: 1px solid #ccc; | |
18 | + margin: 3px; | |
19 | + background-size: cover; | |
20 | +} | |
21 | + | |
22 | +.profile-images-block a:hover { | |
23 | + border: 1px solid #000; | |
24 | +} | |
25 | + | |
26 | +.profile-images-block a span { | |
27 | + display: none; | |
28 | +} | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +require_relative '../../../test/test_helper' | ... | ... |
plugins/profile_images/test/unit/profile_images_block_test.rb
0 → 100644
... | ... | @@ -0,0 +1,69 @@ |
1 | +require_relative '../test_helper' | |
2 | + | |
3 | +class ProfileImagesBlockTest < ActiveSupport::TestCase | |
4 | + should 'describe itself' do | |
5 | + assert_not_equal Block.description, ProfileImagesPlugin::ProfileImagesBlock.description | |
6 | + end | |
7 | + | |
8 | + should 'is editable' do | |
9 | + block = ProfileImagesPlugin::ProfileImagesBlock.new | |
10 | + assert block.editable? | |
11 | + end | |
12 | + | |
13 | + should 'return images' do | |
14 | + # profile | |
15 | + # |- image1 | |
16 | + # |- file | |
17 | + # |- folder1/ | |
18 | + # |--- image2 | |
19 | + # |--- folder2/ | |
20 | + # |------ image3 | |
21 | + profile = create(Profile, name: 'Test') | |
22 | + image1 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile) | |
23 | + file = fast_create(UploadedFile, profile_id: profile.id) | |
24 | + folder1 = fast_create(Folder, profile_id: profile.id) | |
25 | + image2 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile, parent: folder1) | |
26 | + folder2 = fast_create(Folder, parent_id: folder1.id) | |
27 | + image3 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile, parent: folder2) | |
28 | + | |
29 | + block = ProfileImagesPlugin::ProfileImagesBlock.new | |
30 | + block.stubs(:owner).returns(profile) | |
31 | + | |
32 | + assert_equal [image1, image2, image3].map(&:id), block.images.map(&:id) | |
33 | + end | |
34 | + | |
35 | + should 'return images with limit' do | |
36 | + # profile | |
37 | + # |- image1 | |
38 | + # |- image2 | |
39 | + profile = create(Profile, name: 'Test') | |
40 | + image1 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile) | |
41 | + image2 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile) | |
42 | + | |
43 | + block = ProfileImagesPlugin::ProfileImagesBlock.new | |
44 | + block.stubs(:owner).returns(profile) | |
45 | + block.limit = 1 | |
46 | + | |
47 | + assert_equal [image1.id], block.images.map(&:id) | |
48 | + end | |
49 | +end | |
50 | + | |
51 | +require 'boxes_helper' | |
52 | + | |
53 | +class ProfileImagesBlockViewTest < ActionView::TestCase | |
54 | + include BoxesHelper | |
55 | + | |
56 | + should 'return images in api_content' do | |
57 | + # profile | |
58 | + # |- image1 | |
59 | + # |- image2 | |
60 | + profile = create(Profile, name: 'Test') | |
61 | + image1 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile) | |
62 | + image2 = create(UploadedFile, uploaded_data: fixture_file_upload('/files/rails.png', 'image/png'), profile: profile) | |
63 | + | |
64 | + block = ProfileImagesPlugin::ProfileImagesBlock.new | |
65 | + block.stubs(:owner).returns(profile) | |
66 | + | |
67 | + assert_equal [image1.id, image2.id], block.api_content[:images].map{ |a| a[:id] } | |
68 | + end | |
69 | +end | ... | ... |
plugins/profile_images/views/blocks/profile_images.html.erb
0 → 100644
... | ... | @@ -0,0 +1,14 @@ |
1 | +<%= block_title(block.view_title, block.subtitle) %> | |
2 | + | |
3 | +<div class="profile-images-block"> | |
4 | + <% unless block.images.size == 0 %> | |
5 | + <ul> | |
6 | + <% block.images.each do |image| %> | |
7 | + <li><%= link_to content_tag(:span, image.title), image.view_url, style: "background-image: url(#{image.public_filename(:thumb)})" %></li> | |
8 | + <% end %> | |
9 | + </ul> | |
10 | + <br style="clear: both;" /> | |
11 | + <% else %> | |
12 | + <div class="profile-images-block-none"><%= c_('None') %></div> | |
13 | + <% end %> | |
14 | +</div> | ... | ... |
plugins/profile_images/views/box_organizer/profile_images_plugin/_profile_images_block.html.erb
0 → 100644