diff --git a/plugins/dspace/lib/dspace/client.rb b/plugins/dspace/lib/dspace/client.rb index ffbfdee..db3d3c6 100644 --- a/plugins/dspace/lib/dspace/client.rb +++ b/plugins/dspace/lib/dspace/client.rb @@ -3,8 +3,13 @@ class Dspace::Client def initialize(dspace_server_url) end - def get_collection_items(collection) - collection_items = Dspace::Collection.find(:all) + def get_collections + Dspace::Collection.find(:all) + end + + def get_communities + Dspace::Community.find(:all) end end + diff --git a/plugins/dspace/lib/dspace/collection.rb b/plugins/dspace/lib/dspace/collection.rb index 5e473a1..d37d4b2 100644 --- a/plugins/dspace/lib/dspace/collection.rb +++ b/plugins/dspace/lib/dspace/collection.rb @@ -1,4 +1,9 @@ class Dspace::Collection < Dspace::Resource - self.site = "http://localhost:8080/rest/" - self.element_name = "collections" + self.site = "http://dev.maljr.net:8080/rest/" + + def self.get_items(collection_id) + result = self.find collection_id, :params => { :expand => 'items' } + result.items + end + end diff --git a/plugins/dspace/lib/dspace/community.rb b/plugins/dspace/lib/dspace/community.rb new file mode 100644 index 0000000..1e6c138 --- /dev/null +++ b/plugins/dspace/lib/dspace/community.rb @@ -0,0 +1,9 @@ +class Dspace::Community < Dspace::Resource + self.site = "http://dev.maljr.net:8080/rest/" + + def self.get_collections(community_id) + result = self.find community_id, :params => { :expand => 'collections' } + result.collections + end + +end diff --git a/plugins/dspace/lib/dspace_plugin.rb b/plugins/dspace/lib/dspace_plugin.rb index 01b70b2..bf13365 100644 --- a/plugins/dspace/lib/dspace_plugin.rb +++ b/plugins/dspace/lib/dspace_plugin.rb @@ -8,12 +8,24 @@ class DspacePlugin < Noosfero::Plugin _("A plugin that add a DSpace library feature to noosfero.") end - def self.extra_blocks - { DspacePlugin::DspaceBlock => {:type => ['community', 'profile'] } } + def content_types + if context.respond_to?(:params) && context.params + types = [] + parent_id = context.params[:parent_id] + types << DspacePlugin::Library if context.profile.community? && !parent_id + parent = parent_id ? context.profile.articles.find(parent_id) : nil + if parent.kind_of?(DspacePlugin::Library) + types << DspacePlugin::Collection + types << DspacePlugin::Communityy + end + types + else + [DspacePlugin::Library, DspacePlugin::Collection, DspacePlugin::Communityy] + end end def stylesheet? - true + false end def self.has_admin_url? diff --git a/plugins/dspace/lib/dspace_plugin/collection.rb b/plugins/dspace/lib/dspace_plugin/collection.rb new file mode 100644 index 0000000..4ef2035 --- /dev/null +++ b/plugins/dspace/lib/dspace_plugin/collection.rb @@ -0,0 +1,26 @@ +class DspacePlugin::Collection < Article + + settings_items :dspace_collection_id, :type => :string + + attr_accessible :dspace_collection_id + + def self.icon_name(article = nil) + 'dspace' + end + + def self.short_description + _("Collection") + end + + def self.description + _("Defines a collection on DSpace library") + end + + def to_html(options = {}) + dspace_collection = self + proc do + render :file => 'content_viewer/collection', :locals => {:dspace_collection => dspace_collection} + end + end + +end diff --git a/plugins/dspace/lib/dspace_plugin/communityy.rb b/plugins/dspace/lib/dspace_plugin/communityy.rb new file mode 100644 index 0000000..3443685 --- /dev/null +++ b/plugins/dspace/lib/dspace_plugin/communityy.rb @@ -0,0 +1,26 @@ +class DspacePlugin::Communityy < Article + + settings_items :dspace_community_id, :type => :string + + attr_accessible :dspace_community_id + + def self.icon_name(article = nil) + 'dspace' + end + + def self.short_description + _("Community") + end + + def self.description + _("Defines a community on DSpace library") + end + + def to_html(options = {}) + dspace_community = self + proc do + render :file => 'content_viewer/community', :locals => {:dspace_community => dspace_community} + end + end + +end diff --git a/plugins/dspace/lib/dspace_plugin/item.rb b/plugins/dspace/lib/dspace_plugin/item.rb new file mode 100644 index 0000000..ce03f56 --- /dev/null +++ b/plugins/dspace/lib/dspace_plugin/item.rb @@ -0,0 +1,26 @@ +class DspacePlugin::Item < Article + + settings_items :dspace_collection_id, :type => :string + + attr_accessible :dspace_collection_id + + def self.icon_name(article = nil) + 'dspace' + end + + def self.short_description + _("DSpace item") + end + + def self.description + _("Defines a item on DSpace library") + end + + def to_html(options = {}) + dspace_item = self + proc do + render :file => 'content_viewer/item', :locals => {:dspace_item => dspace_item} + end + end + +end diff --git a/plugins/dspace/lib/dspace_plugin/library.rb b/plugins/dspace/lib/dspace_plugin/library.rb new file mode 100644 index 0000000..73ec731 --- /dev/null +++ b/plugins/dspace/lib/dspace_plugin/library.rb @@ -0,0 +1,31 @@ +class DspacePlugin::Library < Blog + + settings_items :server_url, :type => :string, :default => "http://dspace.example.com/" + settings_items :gather_option, :type => :string, :default => "collections" + + attr_accessible :server_url, :gather_option + + def self.icon_name(article = nil) + 'dspace' + end + + def self.short_description + _("DSpace library") + end + + def self.description + _("Defines a DSpace library") + end + + def to_html(options = {}) + dspace_library = self + proc do + render :file => 'content_viewer/library', :locals => {:dspace_library => dspace_library} + end + end + + def bli + 'bli' + end + +end diff --git a/plugins/dspace/public/style.css b/plugins/dspace/public/style.css deleted file mode 100644 index c7dc261..0000000 --- a/plugins/dspace/public/style.css +++ /dev/null @@ -1,79 +0,0 @@ -#content .dspace-plugin_dspace-block { - padding: 10px 0px 10px 10px; - word-wrap: break-word; -} - -.dspace-plugin_dspace-block ul { - margin: 0px; - padding: 0px 0px 0px 20px; -} -.dspace-plugin_dspace-block li { - margin: 0px; - padding: 0px; - list-style: none -} -.dspace-plugin_dspace-block a { - text-decoration: none; -} -.dspace-plugin_dspace-block .block-footer-content { - font-size: 10px; -} -.dspace-plugin_dspace-block .block-footer-content a:hover { - text-decoration: underline; -} - -.dspace-plugin_dspace-block p { - text-align:center; -} - -.dspace-plugin_dspace-block p.like{ - background-image: url('images/positive-hand.png'); - background-repeat: no-repeat; - min-width: 50px; - text-align:center; -} - -.dspace-plugin_dspace-block p.dislike{ - background-image: url('images/negative-hand.png'); - background-repeat: no-repeat; - min-width: 50px; - text-align:center; -} - - -.dspace-plugin_dspace-block { - //overflow: hidden; - display: block; - width: 100%; -} - - -.dspace-cover img { - width: 100%; -} - -.dspace-plugin_dspace-block span.title { - display: block; - margin: 20px 0px 0px; - padding: 0px 0px 0px 20px; -} - -.dspace-plugin_dspace-block span.title.mread { - -} - -.dspace-plugin_dspace-block span.title.mcommented { - -} - -.dspace-plugin_dspace-block span.title.mliked { - -} - -.dspace-plugin_dspace-block span.title.mdisliked { - -} - -.dspace-plugin_dspace-block span.title.mvoted { - -} diff --git a/plugins/dspace/test/unit/dspace_block_test.rb b/plugins/dspace/test/unit/dspace_block_test.rb deleted file mode 100644 index 24f8b49..0000000 --- a/plugins/dspace/test/unit/dspace_block_test.rb +++ /dev/null @@ -1,47 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -require 'comment_controller' -# Re-raise errors caught by the controller. -class CommentController; def rescue_action(e) raise e end; end - -class DspaceBlockTest < ActiveSupport::TestCase - - include AuthenticatedTestHelper - fixtures :users, :environments - - def setup - @controller = CommentController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - @profile = create_user('testinguser').person - @environment = @profile.environment - end - attr_reader :profile, :environment - - should 'have a default title' do - dspace_block = DspacePlugin::DspaceBlock.new - block = Block.new - assert_not_equal block.default_title, dspace_block.default_title - end - - should 'have a help tooltip' do - dspace_block = DspacePlugin::DspaceBlock.new - block = Block.new - assert_not_equal "", dspace_block.help - end - - should 'describe itself' do - assert_not_equal Block.description, DspacePlugin::DspaceBlock.description - end - - should 'is editable' do - block = DspacePlugin::DspaceBlock.new - assert block.editable? - end - - should 'expire' do - assert_equal DspacePlugin::DspaceBlock.expire_on, {:environment=>[:article], :profile=>[:article]} - end - -end diff --git a/plugins/dspace/views/blocks/dspace.html.erb b/plugins/dspace/views/blocks/dspace.html.erb deleted file mode 100644 index 9ba8433..0000000 --- a/plugins/dspace/views/blocks/dspace.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<% collection_items.each do |item| %> - <%= item.name %>
-<% end %> - diff --git a/plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb b/plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb deleted file mode 100644 index 0c31333..0000000 --- a/plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= labelled_form_field _('DSpace/API Url:'), text_field(:block, :dspace_server_url) %> - -<%= labelled_form_field _('Colletions:'), text_field(:block, :collections) %> diff --git a/plugins/dspace/views/cms/dspace_plugin/_collection.html.erb b/plugins/dspace/views/cms/dspace_plugin/_collection.html.erb new file mode 100644 index 0000000..b475f81 --- /dev/null +++ b/plugins/dspace/views/cms/dspace_plugin/_collection.html.erb @@ -0,0 +1,24 @@ +

<%= _('DSpace Collection') %>

+ +<%= required_fields_message %> + +<%= required f.text_field('name', :size => '64', :maxlength => 150) %> + +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %> + +<% dspace_client = Dspace::Client.new('') %> + +<% collections = dspace_client.get_collections %> + +<% +collections_2 = collections.map { |collection| + item = [_(collection.name), collection.id] +} +%> + +<%= labelled_form_field(_('Collections:'), + select(:article, + :dspace_collection_id, + options_for_select_with_title(collections_2))) %> + +<% #raise collections_2.inspect %> diff --git a/plugins/dspace/views/cms/dspace_plugin/_communityy.html.erb b/plugins/dspace/views/cms/dspace_plugin/_communityy.html.erb new file mode 100644 index 0000000..99da06f --- /dev/null +++ b/plugins/dspace/views/cms/dspace_plugin/_communityy.html.erb @@ -0,0 +1,24 @@ +

<%= _('DSpace Community') %>

+ +<%= required_fields_message %> + +<%= required f.text_field('name', :size => '64', :maxlength => 150) %> + +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %> + +<% dspace_client = Dspace::Client.new('') %> + +<% communities = dspace_client.get_communities %> + +<% +communities_2 = communities.map { |community| + item = [_(community.name), community.id] +} +%> + +<%= labelled_form_field(_('Communities:'), + select(:article, + :dspace_community_id, + options_for_select_with_title(communities_2))) %> + +<% #raise collections_2.inspect %> diff --git a/plugins/dspace/views/cms/dspace_plugin/_item.html.erb b/plugins/dspace/views/cms/dspace_plugin/_item.html.erb new file mode 100644 index 0000000..21c7b03 --- /dev/null +++ b/plugins/dspace/views/cms/dspace_plugin/_item.html.erb @@ -0,0 +1,24 @@ +

<%= _('DSpace Item') %>

+ +<%= required_fields_message %> + +<%= required f.text_field('name', :size => '64', :maxlength => 150) %> + +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %> + +<% dspace_client = Dspace::Client.new('') %> + +<% collections = dspace_client.get_collections %> + +<% +collections_2 = collections.map { |collection| + item = [_(collection.name), collection.id] +} +%> + +<%= labelled_form_field(_('Collections:'), + select(:article, + :dspace_collection_id, + options_for_select_with_title(collections_2))) %> + +<% #raise collections_2.inspect %> diff --git a/plugins/dspace/views/cms/dspace_plugin/_library.html.erb b/plugins/dspace/views/cms/dspace_plugin/_library.html.erb new file mode 100644 index 0000000..2807a20 --- /dev/null +++ b/plugins/dspace/views/cms/dspace_plugin/_library.html.erb @@ -0,0 +1,75 @@ +<%= error_messages_for 'library' %> + +

<%= _('My Library') %>

+ +<%= render :file => 'shared/tiny_mce' %> + +<%= required f.text_field(:name, :size => '64', :maxlength => 150, :onchange => "updateUrlField(this, 'article_slug')") %> + +<%= render :partial => 'general_fields' %> + + + +<%= hidden_field_tag 'old_article_slug', @article.slug %> +
+ <%= labelled_form_field( _('Address'), + content_tag('code', + url_for(@article.url).gsub(/#{@article.slug}$/, '') + + text_field(:article, :slug, :onchange => "warn_value_change()", :size => 25) + ) + + content_tag('div', + content_tag('strong', _('WARNING!')) + ' ' + + _("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?") + + content_tag('div', + button_to_function(:ok, _("Yes"), "confirm_change()") + ' ' + + button_to_function(:cancel, _('No'), 'no_change()') + ), + :id => 'slug-change-confirmation', + :class => 'change-confirmation', + :style => 'display: none;' + ) + ) + %> +
+ +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 10)) %> + +<%= f.fields_for :image_builder, @article.image do |i| %> + <%= file_field_or_thumbnail(_('Cover image:'), @article.image, i)%> + <%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %> +<% end %> + +<% unless @article.image.nil? %> + <%= labelled_check_box(_('Remove cover image'),'remove_image',true,false)%> +<% end %> + +<%= labelled_form_field(_('Show catalog as:'), f.select(:visualization_format, [ [ _('Listing with thumbnail'), 'full'], [ _('Listing without thumbnail'), 'short'], [ _('Type catalog'), 'catalog'] ])) %> + +<%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> + +<%= labelled_form_field(_('Address of DSpace library:'), text_field(:article, :server_url)) %> + +<%= content_tag( 'div', radio_button( :article, :gather_option, 'collections' ) + content_tag('label', _('Get collections'), :for => 'article_get_collections')) %> + +<%= content_tag( 'div', radio_button( :article, :gather_option, 'communities' ) + content_tag('label', _('Get communities'), :for => 'article_get_collections')) %> + diff --git a/plugins/dspace/views/content_viewer/collection.html.erb b/plugins/dspace/views/content_viewer/collection.html.erb new file mode 100644 index 0000000..8842a8b --- /dev/null +++ b/plugins/dspace/views/content_viewer/collection.html.erb @@ -0,0 +1,9 @@ +<% dspace_collection_id = 7 %> + +<% dspace_items_from_collection = Dspace::Collection.get_items(dspace_collection_id) %> + +<% dspace_items_from_collection.each { |item| %> +
+<%= item.name %> +
+<% } %> diff --git a/plugins/dspace/views/content_viewer/community.html.erb b/plugins/dspace/views/content_viewer/community.html.erb new file mode 100644 index 0000000..ca484b9 --- /dev/null +++ b/plugins/dspace/views/content_viewer/community.html.erb @@ -0,0 +1,9 @@ +<% dspace_community_id = 5 %> + +<% dspace_collections_from_community = Dspace::Community.get_collections(dspace_community_id) %> + +<% dspace_collections_from_community.each { |collection| %> +
+<%= collection.name %> +
+<% } %> diff --git a/plugins/dspace/views/content_viewer/library.html.erb b/plugins/dspace/views/content_viewer/library.html.erb new file mode 100644 index 0000000..f5ffa0c --- /dev/null +++ b/plugins/dspace/views/content_viewer/library.html.erb @@ -0,0 +1,34 @@ +
+ + <%= content_tag 'div', dspace_library.body %> + +

<%= _("Communities") %>

+ + <% if true %> + +
+ <%= 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 %> + <%= _("New %s") % DspacePlugin::Communityy.short_description %> + <% end %> +
+ + <% end %> + + + + +

<%= _("Collections") %>

+ + <% if true %> + +
+ <%= 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 %> + <%= _("New %s") % DspacePlugin::Collection.short_description %> + <% end %> +
+ + <% end %> + +
diff --git a/plugins/dspace/views/profile_design b/plugins/dspace/views/profile_design deleted file mode 120000 index 1b8d625..0000000 --- a/plugins/dspace/views/profile_design +++ /dev/null @@ -1 +0,0 @@ -box_organizer/ \ No newline at end of file -- libgit2 0.21.2