Commit 7e5df69214de08a96b47220ca41d581b231518cb
1 parent
7b83924b
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
dspace_plugin : make basic plugin structure
Showing
8 changed files
with
78 additions
and
95 deletions
Show diff stats
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +class Dspace::Resource < ActiveResource::Base | ||
| 2 | + | ||
| 3 | + %w(site).each do |attr| | ||
| 4 | + define_method(attr) do | ||
| 5 | + Thread.current["#{name}.active_resource.#{attr}"] | ||
| 6 | + end | ||
| 7 | + | ||
| 8 | + if attr.eql?('site') | ||
| 9 | + define_method("#{attr}=") do |site| | ||
| 10 | + @connection = nil | ||
| 11 | + site_uri = "http://localhost:8080/rest/" | ||
| 12 | + Thread.current["#{name}.active_resource.site"] = site_uri | ||
| 13 | + end | ||
| 14 | + end | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + class << self | ||
| 18 | + def element_path(id, prefix_options = {}, query_options = nil) | ||
| 19 | + prefix_options, query_options = split_options(prefix_options) if query_options.nil? | ||
| 20 | + "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}" | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | + def collection_path(prefix_options = {}, query_options = nil) | ||
| 24 | + prefix_options, query_options = split_options(prefix_options) if query_options.nil? | ||
| 25 | + "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}" | ||
| 26 | + end | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | +end |
plugins/dspace/lib/dspace_plugin.rb
| 1 | class DspacePlugin < Noosfero::Plugin | 1 | class DspacePlugin < Noosfero::Plugin |
| 2 | 2 | ||
| 3 | def self.plugin_name | 3 | def self.plugin_name |
| 4 | - "Relevant Content Plugin" | 4 | + "DSpace Plugin" |
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | def self.plugin_description | 7 | def self.plugin_description |
| 8 | - _("A plugin that lists the most accessed, most commented, most liked and most disliked contents.") | 8 | + _("A plugin that add a DSpace library feature to noosfero.") |
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def self.extra_blocks | 11 | def self.extra_blocks |
| 12 | - { | ||
| 13 | - DspacePlugin::DspaceBlock => {} | ||
| 14 | - } | 12 | + { DspacePlugin::DspaceBlock => {:type => ['community', 'profile'] } } |
| 15 | end | 13 | end |
| 16 | 14 | ||
| 17 | def stylesheet? | 15 | def stylesheet? |
| 18 | true | 16 | true |
| 19 | end | 17 | end |
| 20 | 18 | ||
| 19 | + def self.has_admin_url? | ||
| 20 | + false | ||
| 21 | + end | ||
| 22 | + | ||
| 21 | end | 23 | end |
plugins/dspace/lib/dspace_plugin/dspace_block.rb
| 1 | class DspacePlugin::DspaceBlock < Block | 1 | class DspacePlugin::DspaceBlock < Block |
| 2 | - def self.description | ||
| 3 | - _('Dspace content') | ||
| 4 | - end | ||
| 5 | 2 | ||
| 6 | - def default_title | ||
| 7 | - _('Dspace content') | 3 | + settings_items :dspace_server_url, :type => :string, :default => "" |
| 4 | + settings_items :collections, :type => :string, :default => "" | ||
| 5 | + | ||
| 6 | + attr_accessible :dspace_server_url, :collections | ||
| 7 | + | ||
| 8 | + def self.description | ||
| 9 | + _('DSpace library') | ||
| 8 | end | 10 | end |
| 9 | 11 | ||
| 10 | def help | 12 | def help |
| 11 | - _('This block displays dspace content.') | 13 | + _('This block displays a DSpace content.') |
| 12 | end | 14 | end |
| 13 | 15 | ||
| 14 | - settings_items :limit, :type => :integer, :default => 5 | ||
| 15 | - settings_items :show_most_read, :type => :boolean, :default => 1 | ||
| 16 | - settings_items :show_most_commented, :type => :boolean, :default => 1 | ||
| 17 | - settings_items :show_most_liked, :type => :boolean, :default => 1 | ||
| 18 | - settings_items :show_most_disliked, :type => :boolean, :default => 0 | ||
| 19 | - settings_items :show_most_voted, :type => :boolean, :default => 1 | ||
| 20 | - | ||
| 21 | - attr_accessible :limit, :show_most_voted, :show_most_disliked, :show_most_liked, :show_most_commented, :show_most_read | ||
| 22 | - | ||
| 23 | - include ActionView::Helpers | ||
| 24 | - include Rails.application.routes.url_helpers | ||
| 25 | - | ||
| 26 | def content(args={}) | 16 | def content(args={}) |
| 27 | - | ||
| 28 | - content = block_title(title) | ||
| 29 | - | ||
| 30 | - if self.show_most_read | ||
| 31 | - docs = Article.most_accessed(owner, self.limit) | ||
| 32 | - if !docs.blank? | ||
| 33 | - subcontent = "" | ||
| 34 | - subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n" | ||
| 35 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 36 | - content += content_tag(:div, subcontent, :class=>"block mread") + "\n" | 17 | + block = self |
| 18 | + proc do | ||
| 19 | + dspace_client = Dspace::Client.new(block.dspace_server_url) | ||
| 20 | + collection_items = dspace_client.get_collection_items(block.collections) | ||
| 21 | + if !collection_items.blank? | ||
| 22 | + content_tag('div', | ||
| 23 | + render(:file => 'blocks/dspace', :locals => {:collection_items => collection_items}) | ||
| 24 | + ) | ||
| 25 | + else | ||
| 26 | + '' | ||
| 37 | end | 27 | end |
| 38 | end | 28 | end |
| 39 | - | ||
| 40 | - if self.show_most_commented | ||
| 41 | - docs = Article.most_commented_dspace(owner, self.limit) | ||
| 42 | - if !docs.blank? | ||
| 43 | - subcontent = "" | ||
| 44 | - subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n" | ||
| 45 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 46 | - content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n" | ||
| 47 | - end | ||
| 48 | - end | ||
| 49 | - | ||
| 50 | - if owner.kind_of?(Environment) | ||
| 51 | - env = owner | ||
| 52 | - else | ||
| 53 | - env = owner.environment | ||
| 54 | - end | ||
| 55 | - | ||
| 56 | - if env.plugin_enabled?(VotePlugin) | ||
| 57 | - if self.show_most_liked | ||
| 58 | - docs = Article.more_positive_votes(owner, self.limit) | ||
| 59 | - if !docs.blank? | ||
| 60 | - subcontent = "" | ||
| 61 | - subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n" | ||
| 62 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 63 | - content += content_tag(:div, subcontent, :class=>"block mliked") + "\n" | ||
| 64 | - end | ||
| 65 | - end | ||
| 66 | - if self.show_most_disliked | ||
| 67 | - docs = Article.more_negative_votes(owner, self.limit) | ||
| 68 | - if !docs.blank? | ||
| 69 | - subcontent = "" | ||
| 70 | - subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n" | ||
| 71 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 72 | - content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n" | ||
| 73 | - end | ||
| 74 | - end | ||
| 75 | - | ||
| 76 | - if self.show_most_voted | ||
| 77 | - docs = Article.most_voted(owner, self.limit) | ||
| 78 | - if !docs.blank? | ||
| 79 | - subcontent = "" | ||
| 80 | - subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n" | ||
| 81 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 82 | - content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n" | ||
| 83 | - end | ||
| 84 | - end | ||
| 85 | - end | ||
| 86 | - return content | ||
| 87 | - end | ||
| 88 | - | ||
| 89 | - def timeout | ||
| 90 | - 4.hours | ||
| 91 | end | 29 | end |
| 92 | 30 | ||
| 93 | - def self.expire_on | ||
| 94 | - { :profile => [:article], :environment => [:article] } | 31 | + def cacheable? |
| 32 | + false | ||
| 95 | end | 33 | end |
| 96 | 34 | ||
| 97 | end | 35 | end |
plugins/dspace/views/box_organizer/dspace_plugin/_dspace_block.html.erb
| 1 | -<div id='edit-dspace-block'> | ||
| 2 | - <%= labelled_form_field _('Limit of items per category'), text_field(:block, :limit, :size => 3) %> | ||
| 3 | - <%= labelled_check_box _('Display most accessed content'), "block[show_most_read]", 1 ,@block.show_most_read %><BR> | ||
| 4 | - <%= labelled_check_box _('Display most commented content'), "block[show_most_commented]", 1 ,@block.show_most_commented %><BR> | ||
| 5 | - <%= labelled_check_box _('Display most liked content'), "block[show_most_liked]", 1 ,@block.show_most_liked %><BR> | ||
| 6 | - <%= labelled_check_box _('Display most voted content'), "block[show_most_voted]", 1 ,@block.show_most_voted %><BR> | ||
| 7 | - <%= labelled_check_box _('Display most disliked content'), "block[show_most_disliked]", 1 , @block.show_most_disliked %><BR> | ||
| 8 | -</div> | ||
| 9 | \ No newline at end of file | 1 | \ No newline at end of file |
| 2 | +<%= labelled_form_field _('DSpace/API Url:'), text_field(:block, :dspace_server_url) %> | ||
| 3 | + | ||
| 4 | +<%= labelled_form_field _('Colletions:'), text_field(:block, :collections) %> |