diff --git a/plugins/dspace/lib/dspace/client.rb b/plugins/dspace/lib/dspace/client.rb
new file mode 100644
index 0000000..ffbfdee
--- /dev/null
+++ b/plugins/dspace/lib/dspace/client.rb
@@ -0,0 +1,10 @@
+class Dspace::Client
+
+ def initialize(dspace_server_url)
+ end
+
+ def get_collection_items(collection)
+ collection_items = Dspace::Collection.find(:all)
+ end
+
+end
diff --git a/plugins/dspace/lib/dspace/collection.rb b/plugins/dspace/lib/dspace/collection.rb
new file mode 100644
index 0000000..5e473a1
--- /dev/null
+++ b/plugins/dspace/lib/dspace/collection.rb
@@ -0,0 +1,4 @@
+class Dspace::Collection < Dspace::Resource
+ self.site = "http://localhost:8080/rest/"
+ self.element_name = "collections"
+end
diff --git a/plugins/dspace/lib/dspace/resource.rb b/plugins/dspace/lib/dspace/resource.rb
new file mode 100644
index 0000000..8c9f23e
--- /dev/null
+++ b/plugins/dspace/lib/dspace/resource.rb
@@ -0,0 +1,29 @@
+class Dspace::Resource < ActiveResource::Base
+
+ %w(site).each do |attr|
+ define_method(attr) do
+ Thread.current["#{name}.active_resource.#{attr}"]
+ end
+
+ if attr.eql?('site')
+ define_method("#{attr}=") do |site|
+ @connection = nil
+ site_uri = "http://localhost:8080/rest/"
+ Thread.current["#{name}.active_resource.site"] = site_uri
+ end
+ end
+ end
+
+ class << self
+ def element_path(id, prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
+ end
+
+ def collection_path(prefix_options = {}, query_options = nil)
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
+ "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
+ end
+ end
+
+end
diff --git a/plugins/dspace/lib/dspace_plugin.rb b/plugins/dspace/lib/dspace_plugin.rb
index 1dfc482..01b70b2 100644
--- a/plugins/dspace/lib/dspace_plugin.rb
+++ b/plugins/dspace/lib/dspace_plugin.rb
@@ -1,21 +1,23 @@
class DspacePlugin < Noosfero::Plugin
def self.plugin_name
- "Relevant Content Plugin"
+ "DSpace Plugin"
end
def self.plugin_description
- _("A plugin that lists the most accessed, most commented, most liked and most disliked contents.")
+ _("A plugin that add a DSpace library feature to noosfero.")
end
def self.extra_blocks
- {
- DspacePlugin::DspaceBlock => {}
- }
+ { DspacePlugin::DspaceBlock => {:type => ['community', 'profile'] } }
end
def stylesheet?
true
end
+ def self.has_admin_url?
+ false
+ end
+
end
diff --git a/plugins/dspace/lib/dspace_plugin/dspace_block.rb b/plugins/dspace/lib/dspace_plugin/dspace_block.rb
index 2b3b6d2..3838050 100644
--- a/plugins/dspace/lib/dspace_plugin/dspace_block.rb
+++ b/plugins/dspace/lib/dspace_plugin/dspace_block.rb
@@ -1,97 +1,35 @@
class DspacePlugin::DspaceBlock < Block
- def self.description
- _('Dspace content')
- end
- def default_title
- _('Dspace content')
+ settings_items :dspace_server_url, :type => :string, :default => ""
+ settings_items :collections, :type => :string, :default => ""
+
+ attr_accessible :dspace_server_url, :collections
+
+ def self.description
+ _('DSpace library')
end
def help
- _('This block displays dspace content.')
+ _('This block displays a DSpace content.')
end
- settings_items :limit, :type => :integer, :default => 5
- settings_items :show_most_read, :type => :boolean, :default => 1
- settings_items :show_most_commented, :type => :boolean, :default => 1
- settings_items :show_most_liked, :type => :boolean, :default => 1
- settings_items :show_most_disliked, :type => :boolean, :default => 0
- settings_items :show_most_voted, :type => :boolean, :default => 1
-
- attr_accessible :limit, :show_most_voted, :show_most_disliked, :show_most_liked, :show_most_commented, :show_most_read
-
- include ActionView::Helpers
- include Rails.application.routes.url_helpers
-
def content(args={})
-
- content = block_title(title)
-
- if self.show_most_read
- docs = Article.most_accessed(owner, self.limit)
- if !docs.blank?
- subcontent = ""
- subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n"
- subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
- content += content_tag(:div, subcontent, :class=>"block mread") + "\n"
+ block = self
+ proc do
+ dspace_client = Dspace::Client.new(block.dspace_server_url)
+ collection_items = dspace_client.get_collection_items(block.collections)
+ if !collection_items.blank?
+ content_tag('div',
+ render(:file => 'blocks/dspace', :locals => {:collection_items => collection_items})
+ )
+ else
+ ''
end
end
-
- if self.show_most_commented
- docs = Article.most_commented_dspace(owner, self.limit)
- if !docs.blank?
- subcontent = ""
- subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n"
- subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
- content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n"
- end
- end
-
- if owner.kind_of?(Environment)
- env = owner
- else
- env = owner.environment
- end
-
- if env.plugin_enabled?(VotePlugin)
- if self.show_most_liked
- docs = Article.more_positive_votes(owner, self.limit)
- if !docs.blank?
- subcontent = ""
- subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n"
- subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
- content += content_tag(:div, subcontent, :class=>"block mliked") + "\n"
- end
- end
- if self.show_most_disliked
- docs = Article.more_negative_votes(owner, self.limit)
- if !docs.blank?
- subcontent = ""
- subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n"
- subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
- content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n"
- end
- end
-
- if self.show_most_voted
- docs = Article.most_voted(owner, self.limit)
- if !docs.blank?
- subcontent = ""
- subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n"
- subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n"))
- content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n"
- end
- end
- end
- return content
- end
-
- def timeout
- 4.hours
end
- def self.expire_on
- { :profile => [:article], :environment => [:article] }
+ def cacheable?
+ false
end
end
diff --git a/plugins/dspace/views/blocks/dspace.html.erb b/plugins/dspace/views/blocks/dspace.html.erb
new file mode 100644
index 0000000..9ba8433
--- /dev/null
+++ b/plugins/dspace/views/blocks/dspace.html.erb
@@ -0,0 +1,4 @@
+<% 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
index 4322476..0c31333 100644
--- a/plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb
+++ b/plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb
@@ -1,8 +1,3 @@
-