Commit 132e9a96f9586ded7d463833c587424131a5bb82

Authored by Francisco Júnior
1 parent 7e5df692

dspace_plugin : refactoring code

plugins/dspace/lib/dspace/client.rb
... ... @@ -3,8 +3,13 @@ class Dspace::Client
3 3 def initialize(dspace_server_url)
4 4 end
5 5  
6   - def get_collection_items(collection)
7   - collection_items = Dspace::Collection.find(:all)
  6 + def get_collections
  7 + Dspace::Collection.find(:all)
  8 + end
  9 +
  10 + def get_communities
  11 + Dspace::Community.find(:all)
8 12 end
9 13  
10 14 end
  15 +
... ...
plugins/dspace/lib/dspace/collection.rb
1 1 class Dspace::Collection < Dspace::Resource
2   - self.site = "http://localhost:8080/rest/"
3   - self.element_name = "collections"
  2 + self.site = "http://dev.maljr.net:8080/rest/"
  3 +
  4 + def self.get_items(collection_id)
  5 + result = self.find collection_id, :params => { :expand => 'items' }
  6 + result.items
  7 + end
  8 +
4 9 end
... ...
plugins/dspace/lib/dspace/community.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class Dspace::Community < Dspace::Resource
  2 + self.site = "http://dev.maljr.net:8080/rest/"
  3 +
  4 + def self.get_collections(community_id)
  5 + result = self.find community_id, :params => { :expand => 'collections' }
  6 + result.collections
  7 + end
  8 +
  9 +end
... ...
plugins/dspace/lib/dspace_plugin.rb
... ... @@ -8,12 +8,24 @@ class DspacePlugin &lt; Noosfero::Plugin
8 8 _("A plugin that add a DSpace library feature to noosfero.")
9 9 end
10 10  
11   - def self.extra_blocks
12   - { DspacePlugin::DspaceBlock => {:type => ['community', 'profile'] } }
  11 + def content_types
  12 + if context.respond_to?(:params) && context.params
  13 + types = []
  14 + parent_id = context.params[:parent_id]
  15 + types << DspacePlugin::Library if context.profile.community? && !parent_id
  16 + parent = parent_id ? context.profile.articles.find(parent_id) : nil
  17 + if parent.kind_of?(DspacePlugin::Library)
  18 + types << DspacePlugin::Collection
  19 + types << DspacePlugin::Communityy
  20 + end
  21 + types
  22 + else
  23 + [DspacePlugin::Library, DspacePlugin::Collection, DspacePlugin::Communityy]
  24 + end
13 25 end
14 26  
15 27 def stylesheet?
16   - true
  28 + false
17 29 end
18 30  
19 31 def self.has_admin_url?
... ...
plugins/dspace/lib/dspace_plugin/collection.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class DspacePlugin::Collection < Article
  2 +
  3 + settings_items :dspace_collection_id, :type => :string
  4 +
  5 + attr_accessible :dspace_collection_id
  6 +
  7 + def self.icon_name(article = nil)
  8 + 'dspace'
  9 + end
  10 +
  11 + def self.short_description
  12 + _("Collection")
  13 + end
  14 +
  15 + def self.description
  16 + _("Defines a collection on DSpace library")
  17 + end
  18 +
  19 + def to_html(options = {})
  20 + dspace_collection = self
  21 + proc do
  22 + render :file => 'content_viewer/collection', :locals => {:dspace_collection => dspace_collection}
  23 + end
  24 + end
  25 +
  26 +end
... ...
plugins/dspace/lib/dspace_plugin/communityy.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class DspacePlugin::Communityy < Article
  2 +
  3 + settings_items :dspace_community_id, :type => :string
  4 +
  5 + attr_accessible :dspace_community_id
  6 +
  7 + def self.icon_name(article = nil)
  8 + 'dspace'
  9 + end
  10 +
  11 + def self.short_description
  12 + _("Community")
  13 + end
  14 +
  15 + def self.description
  16 + _("Defines a community on DSpace library")
  17 + end
  18 +
  19 + def to_html(options = {})
  20 + dspace_community = self
  21 + proc do
  22 + render :file => 'content_viewer/community', :locals => {:dspace_community => dspace_community}
  23 + end
  24 + end
  25 +
  26 +end
... ...
plugins/dspace/lib/dspace_plugin/item.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +class DspacePlugin::Item < Article
  2 +
  3 + settings_items :dspace_collection_id, :type => :string
  4 +
  5 + attr_accessible :dspace_collection_id
  6 +
  7 + def self.icon_name(article = nil)
  8 + 'dspace'
  9 + end
  10 +
  11 + def self.short_description
  12 + _("DSpace item")
  13 + end
  14 +
  15 + def self.description
  16 + _("Defines a item on DSpace library")
  17 + end
  18 +
  19 + def to_html(options = {})
  20 + dspace_item = self
  21 + proc do
  22 + render :file => 'content_viewer/item', :locals => {:dspace_item => dspace_item}
  23 + end
  24 + end
  25 +
  26 +end
... ...
plugins/dspace/lib/dspace_plugin/library.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +class DspacePlugin::Library < Blog
  2 +
  3 + settings_items :server_url, :type => :string, :default => "http://dspace.example.com/"
  4 + settings_items :gather_option, :type => :string, :default => "collections"
  5 +
  6 + attr_accessible :server_url, :gather_option
  7 +
  8 + def self.icon_name(article = nil)
  9 + 'dspace'
  10 + end
  11 +
  12 + def self.short_description
  13 + _("DSpace library")
  14 + end
  15 +
  16 + def self.description
  17 + _("Defines a DSpace library")
  18 + end
  19 +
  20 + def to_html(options = {})
  21 + dspace_library = self
  22 + proc do
  23 + render :file => 'content_viewer/library', :locals => {:dspace_library => dspace_library}
  24 + end
  25 + end
  26 +
  27 + def bli
  28 + 'bli'
  29 + end
  30 +
  31 +end
... ...
plugins/dspace/public/style.css
... ... @@ -1,79 +0,0 @@
1   -#content .dspace-plugin_dspace-block {
2   - padding: 10px 0px 10px 10px;
3   - word-wrap: break-word;
4   -}
5   -
6   -.dspace-plugin_dspace-block ul {
7   - margin: 0px;
8   - padding: 0px 0px 0px 20px;
9   -}
10   -.dspace-plugin_dspace-block li {
11   - margin: 0px;
12   - padding: 0px;
13   - list-style: none
14   -}
15   -.dspace-plugin_dspace-block a {
16   - text-decoration: none;
17   -}
18   -.dspace-plugin_dspace-block .block-footer-content {
19   - font-size: 10px;
20   -}
21   -.dspace-plugin_dspace-block .block-footer-content a:hover {
22   - text-decoration: underline;
23   -}
24   -
25   -.dspace-plugin_dspace-block p {
26   - text-align:center;
27   -}
28   -
29   -.dspace-plugin_dspace-block p.like{
30   - background-image: url('images/positive-hand.png');
31   - background-repeat: no-repeat;
32   - min-width: 50px;
33   - text-align:center;
34   -}
35   -
36   -.dspace-plugin_dspace-block p.dislike{
37   - background-image: url('images/negative-hand.png');
38   - background-repeat: no-repeat;
39   - min-width: 50px;
40   - text-align:center;
41   -}
42   -
43   -
44   -.dspace-plugin_dspace-block {
45   - //overflow: hidden;
46   - display: block;
47   - width: 100%;
48   -}
49   -
50   -
51   -.dspace-cover img {
52   - width: 100%;
53   -}
54   -
55   -.dspace-plugin_dspace-block span.title {
56   - display: block;
57   - margin: 20px 0px 0px;
58   - padding: 0px 0px 0px 20px;
59   -}
60   -
61   -.dspace-plugin_dspace-block span.title.mread {
62   -
63   -}
64   -
65   -.dspace-plugin_dspace-block span.title.mcommented {
66   -
67   -}
68   -
69   -.dspace-plugin_dspace-block span.title.mliked {
70   -
71   -}
72   -
73   -.dspace-plugin_dspace-block span.title.mdisliked {
74   -
75   -}
76   -
77   -.dspace-plugin_dspace-block span.title.mvoted {
78   -
79   -}
plugins/dspace/test/unit/dspace_block_test.rb
... ... @@ -1,47 +0,0 @@
1   -require File.dirname(__FILE__) + '/../test_helper'
2   -
3   -require 'comment_controller'
4   -# Re-raise errors caught by the controller.
5   -class CommentController; def rescue_action(e) raise e end; end
6   -
7   -class DspaceBlockTest < ActiveSupport::TestCase
8   -
9   - include AuthenticatedTestHelper
10   - fixtures :users, :environments
11   -
12   - def setup
13   - @controller = CommentController.new
14   - @request = ActionController::TestRequest.new
15   - @response = ActionController::TestResponse.new
16   -
17   - @profile = create_user('testinguser').person
18   - @environment = @profile.environment
19   - end
20   - attr_reader :profile, :environment
21   -
22   - should 'have a default title' do
23   - dspace_block = DspacePlugin::DspaceBlock.new
24   - block = Block.new
25   - assert_not_equal block.default_title, dspace_block.default_title
26   - end
27   -
28   - should 'have a help tooltip' do
29   - dspace_block = DspacePlugin::DspaceBlock.new
30   - block = Block.new
31   - assert_not_equal "", dspace_block.help
32   - end
33   -
34   - should 'describe itself' do
35   - assert_not_equal Block.description, DspacePlugin::DspaceBlock.description
36   - end
37   -
38   - should 'is editable' do
39   - block = DspacePlugin::DspaceBlock.new
40   - assert block.editable?
41   - end
42   -
43   - should 'expire' do
44   - assert_equal DspacePlugin::DspaceBlock.expire_on, {:environment=>[:article], :profile=>[:article]}
45   - end
46   -
47   -end
plugins/dspace/views/blocks/dspace.html.erb
... ... @@ -1,4 +0,0 @@
1   -<% collection_items.each do |item| %>
2   - <%= item.name %><br />
3   -<% end %>
4   -
plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb
... ... @@ -1,3 +0,0 @@
1   -<%= labelled_form_field _('DSpace/API Url:'), text_field(:block, :dspace_server_url) %>
2   -
3   -<%= labelled_form_field _('Colletions:'), text_field(:block, :collections) %>
plugins/dspace/views/cms/dspace_plugin/_collection.html.erb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<h1><%= _('DSpace Collection') %></h1>
  2 +
  3 +<%= required_fields_message %>
  4 +
  5 +<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  6 +
  7 +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %>
  8 +
  9 +<% dspace_client = Dspace::Client.new('') %>
  10 +
  11 +<% collections = dspace_client.get_collections %>
  12 +
  13 +<%
  14 +collections_2 = collections.map { |collection|
  15 + item = [_(collection.name), collection.id]
  16 +}
  17 +%>
  18 +
  19 +<%= labelled_form_field(_('Collections:'),
  20 + select(:article,
  21 + :dspace_collection_id,
  22 + options_for_select_with_title(collections_2))) %>
  23 +
  24 +<% #raise collections_2.inspect %>
... ...
plugins/dspace/views/cms/dspace_plugin/_communityy.html.erb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<h1><%= _('DSpace Community') %></h1>
  2 +
  3 +<%= required_fields_message %>
  4 +
  5 +<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  6 +
  7 +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %>
  8 +
  9 +<% dspace_client = Dspace::Client.new('') %>
  10 +
  11 +<% communities = dspace_client.get_communities %>
  12 +
  13 +<%
  14 +communities_2 = communities.map { |community|
  15 + item = [_(community.name), community.id]
  16 +}
  17 +%>
  18 +
  19 +<%= labelled_form_field(_('Communities:'),
  20 + select(:article,
  21 + :dspace_community_id,
  22 + options_for_select_with_title(communities_2))) %>
  23 +
  24 +<% #raise collections_2.inspect %>
... ...
plugins/dspace/views/cms/dspace_plugin/_item.html.erb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +<h1><%= _('DSpace Item') %></h1>
  2 +
  3 +<%= required_fields_message %>
  4 +
  5 +<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  6 +
  7 +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %>
  8 +
  9 +<% dspace_client = Dspace::Client.new('') %>
  10 +
  11 +<% collections = dspace_client.get_collections %>
  12 +
  13 +<%
  14 +collections_2 = collections.map { |collection|
  15 + item = [_(collection.name), collection.id]
  16 +}
  17 +%>
  18 +
  19 +<%= labelled_form_field(_('Collections:'),
  20 + select(:article,
  21 + :dspace_collection_id,
  22 + options_for_select_with_title(collections_2))) %>
  23 +
  24 +<% #raise collections_2.inspect %>
... ...
plugins/dspace/views/cms/dspace_plugin/_library.html.erb 0 → 100644
... ... @@ -0,0 +1,75 @@
  1 +<%= error_messages_for 'library' %>
  2 +
  3 +<h1><%= _('My Library') %></h1>
  4 +
  5 +<%= render :file => 'shared/tiny_mce' %>
  6 +
  7 +<%= required f.text_field(:name, :size => '64', :maxlength => 150, :onchange => "updateUrlField(this, 'article_slug')") %>
  8 +
  9 +<%= render :partial => 'general_fields' %>
  10 +
  11 +<script type="text/javascript">
  12 + function submit_button(index) {
  13 + return $("article_slug").form.select("input.submit")[index];
  14 + }
  15 + function warn_value_change() {
  16 + show_warning('article-formitem', "slug-change-confirmation");
  17 + disable_button(submit_button(0));
  18 + disable_button(submit_button(1));
  19 + }
  20 + function confirm_change() {
  21 + enable_button(submit_button(0));
  22 + enable_button(submit_button(1));
  23 + hide_warning('slug-change-confirmation');
  24 + }
  25 + function no_change() {
  26 + $("article_slug").value = $("old_article_slug").value;
  27 + enable_button(submit_button(0));
  28 + enable_button(submit_button(1));
  29 + hide_warning('slug-change-confirmation');
  30 + }
  31 +</script>
  32 +
  33 +<%= hidden_field_tag 'old_article_slug', @article.slug %>
  34 +<div id="article-formitem">
  35 + <%= labelled_form_field( _('Address'),
  36 + content_tag('code',
  37 + url_for(@article.url).gsub(/#{@article.slug}$/, '') +
  38 + text_field(:article, :slug, :onchange => "warn_value_change()", :size => 25)
  39 + ) +
  40 + content_tag('div',
  41 + content_tag('strong', _('WARNING!')) + '&nbsp;' +
  42 + _("You are about to change the address, and this will break external links to this blog or to posts inside it. Do you really want to change?") +
  43 + content_tag('div',
  44 + button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' +
  45 + button_to_function(:cancel, _('No'), 'no_change()')
  46 + ),
  47 + :id => 'slug-change-confirmation',
  48 + :class => 'change-confirmation',
  49 + :style => 'display: none;'
  50 + )
  51 + )
  52 + %>
  53 +</div>
  54 +
  55 +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10)) %>
  56 +
  57 +<%= f.fields_for :image_builder, @article.image do |i| %>
  58 + <%= file_field_or_thumbnail(_('Cover image:'), @article.image, i)%>
  59 + <%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %>
  60 +<% end %>
  61 +
  62 +<% unless @article.image.nil? %>
  63 + <%= labelled_check_box(_('Remove cover image'),'remove_image',true,false)%>
  64 +<% end %>
  65 +
  66 +<%= labelled_form_field(_('Show catalog as:'), f.select(:visualization_format, [ [ _('Listing with thumbnail'), 'full'], [ _('Listing without thumbnail'), 'short'], [ _('Type catalog'), 'catalog'] ])) %>
  67 +
  68 +<%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %>
  69 +
  70 +<%= labelled_form_field(_('Address of DSpace library:'), text_field(:article, :server_url)) %>
  71 +
  72 +<%= content_tag( 'div', radio_button( :article, :gather_option, 'collections' ) + content_tag('label', _('Get collections'), :for => 'article_get_collections')) %>
  73 +
  74 +<%= content_tag( 'div', radio_button( :article, :gather_option, 'communities' ) + content_tag('label', _('Get communities'), :for => 'article_get_collections')) %>
  75 +
... ...
plugins/dspace/views/content_viewer/collection.html.erb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<% dspace_collection_id = 7 %>
  2 +
  3 +<% dspace_items_from_collection = Dspace::Collection.get_items(dspace_collection_id) %>
  4 +
  5 +<% dspace_items_from_collection.each { |item| %>
  6 +<br />
  7 +<%= item.name %>
  8 +<br />
  9 +<% } %>
... ...
plugins/dspace/views/content_viewer/community.html.erb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +<% dspace_community_id = 5 %>
  2 +
  3 +<% dspace_collections_from_community = Dspace::Community.get_collections(dspace_community_id) %>
  4 +
  5 +<% dspace_collections_from_community.each { |collection| %>
  6 +<br />
  7 +<%= collection.name %>
  8 +<br />
  9 +<% } %>
... ...
plugins/dspace/views/content_viewer/library.html.erb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +<div id="dspace_library">
  2 +
  3 + <%= content_tag 'div', dspace_library.body %>
  4 +
  5 + <h3><%= _("Communities") %></h3>
  6 +
  7 + <% if true %>
  8 +
  9 + <div class="library_actions">
  10 + <%= content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "DspacePlugin::Communityy", :parent_id => dspace_library.id}), :class => 'button with-text icon-add') do %>
  11 + <%= _("New %s") % DspacePlugin::Communityy.short_description %>
  12 + <% end %>
  13 + </div>
  14 +
  15 + <% end %>
  16 +
  17 + <ul id="sortable" class="step_list">
  18 + <%= render :partial => 'community_item', :collection => dspace_library.bli %>
  19 + </ul>
  20 +
  21 +
  22 + <h3><%= _("Collections") %></h3>
  23 +
  24 + <% if true %>
  25 +
  26 + <div class="library_actions">
  27 + <%= content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "DspacePlugin::Collection", :parent_id => dspace_library.id}), :class => 'button with-text icon-add') do %>
  28 + <%= _("New %s") % DspacePlugin::Collection.short_description %>
  29 + <% end %>
  30 + </div>
  31 +
  32 + <% end %>
  33 +
  34 +</div>
... ...
plugins/dspace/views/profile_design
... ... @@ -1 +0,0 @@
1   -box_organizer/
2 0 \ No newline at end of file