Commit af2f1d06a89cd7382be6c8a19896364bc12fddf7

Authored by Francisco Júnior
1 parent 61c35502

dspace_plugin : refactoring navigation

plugins/dspace/lib/dspace/resource.rb
1 class Dspace::Resource < ActiveResource::Base 1 class Dspace::Resource < ActiveResource::Base
2 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 3 class << self
18 def element_path(id, prefix_options = {}, query_options = nil) 4 def element_path(id, prefix_options = {}, query_options = nil)
19 prefix_options, query_options = split_options(prefix_options) if query_options.nil? 5 prefix_options, query_options = split_options(prefix_options) if query_options.nil?
plugins/dspace/lib/dspace_plugin.rb
@@ -17,6 +17,8 @@ class DspacePlugin &lt; Noosfero::Plugin @@ -17,6 +17,8 @@ class DspacePlugin &lt; Noosfero::Plugin
17 if parent.kind_of?(DspacePlugin::Library) 17 if parent.kind_of?(DspacePlugin::Library)
18 types << DspacePlugin::Collection 18 types << DspacePlugin::Collection
19 types << DspacePlugin::Communityy 19 types << DspacePlugin::Communityy
  20 + elsif parent.kind_of?(DspacePlugin::Communityy)
  21 + types << DspacePlugin::Collection
20 end 22 end
21 types 23 types
22 else 24 else
plugins/dspace/lib/dspace_plugin/collection.rb
1 class DspacePlugin::Collection < Article 1 class DspacePlugin::Collection < Article
2 2
3 settings_items :dspace_collection_id, :type => :string 3 settings_items :dspace_collection_id, :type => :string
  4 + settings_items :dspace_community_id, :type => :integer
4 5
5 - attr_accessible :dspace_collection_id 6 + attr_accessible :dspace_collection_id, :dspace_community_id
6 7
7 def self.icon_name(article = nil) 8 def self.icon_name(article = nil)
8 'dspace' 9 'dspace'
plugins/dspace/lib/dspace_plugin/communityy.rb
@@ -24,7 +24,7 @@ class DspacePlugin::Communityy &lt; Article @@ -24,7 +24,7 @@ class DspacePlugin::Communityy &lt; Article
24 end 24 end
25 25
26 def collections(dspace_server, community_id) 26 def collections(dspace_server, community_id)
27 - Dspace::Community.get_all_collections_from dspace_server, community_id 27 + DspacePlugin::Collection.find(:all)
28 end 28 end
29 29
30 end 30 end
plugins/dspace/lib/dspace_plugin/library.rb
1 class DspacePlugin::Library < Blog 1 class DspacePlugin::Library < Blog
2 2
3 settings_items :dspace_server_url, :type => :string 3 settings_items :dspace_server_url, :type => :string
4 - settings_items :gather_option, :type => :string, :default => "collections"  
5 4
6 - attr_accessible :dspace_server_url, :gather_option 5 + attr_accessible :dspace_server_url
7 6
8 def dspace_server_url_valid 7 def dspace_server_url_valid
9 errors.add(self.dspace_server_url, _("is not a valid URL. Please correct it and resubmit.")) unless url_valid?(self.dspace_server_url) 8 errors.add(self.dspace_server_url, _("is not a valid URL. Please correct it and resubmit.")) unless url_valid?(self.dspace_server_url)
@@ -34,10 +33,6 @@ class DspacePlugin::Library &lt; Blog @@ -34,10 +33,6 @@ class DspacePlugin::Library &lt; Blog
34 DspacePlugin::Communityy.find(:all) 33 DspacePlugin::Communityy.find(:all)
35 end 34 end
36 35
37 - def collections  
38 - DspacePlugin::Collection.find(:all)  
39 - end  
40 -  
41 protected 36 protected
42 37
43 def url_valid?(url) 38 def url_valid?(url)
plugins/dspace/views/cms/dspace_plugin/_collection.html.erb
@@ -6,11 +6,15 @@ @@ -6,11 +6,15 @@
6 6
7 <%= hidden_field_tag 'article[parent_id]', @article.parent_id %> 7 <%= hidden_field_tag 'article[parent_id]', @article.parent_id %>
8 8
9 -<% dspace_server_url = @article.parent.dspace_server_url %> 9 +<%= hidden_field_tag 'article[dspace_community_id]', @article.parent.dspace_community_id %>
10 10
11 -<% dspace_client = Dspace::Client.new(dspace_server_url) %> 11 +<% dspace_server_url = @article.parent.parent.dspace_server_url %>
12 12
13 -<% collections = dspace_client.get_collections.map { |collection| item = [_(collection.name), collection.id] } %> 13 +<% community_id = @article.parent.dspace_community_id %>
  14 +
  15 +<% #dspace_client = Dspace::Client.new(dspace_server_url) %>
  16 +
  17 +<% collections = Dspace::Community.get_all_collections_from( dspace_server_url, community_id ).map { |collection| item = [_(collection.name), collection.id] } %>
14 18
15 <%= labelled_form_field(_('Collections:'), 19 <%= labelled_form_field(_('Collections:'),
16 select(:article, 20 select(:article,
plugins/dspace/views/cms/dspace_plugin/_library.html.erb
@@ -6,6 +6,8 @@ @@ -6,6 +6,8 @@
6 6
7 <%= required f.text_field(:name, :size => '64', :maxlength => 150, :onchange => "updateUrlField(this, 'article_slug')") %> 7 <%= required f.text_field(:name, :size => '64', :maxlength => 150, :onchange => "updateUrlField(this, 'article_slug')") %>
8 8
  9 +<%= required f.text_field(:dspace_server_url, :size => '150', :maxlength => 150) %>
  10 +
9 <%= render :partial => 'general_fields' %> 11 <%= render :partial => 'general_fields' %>
10 12
11 <script type="text/javascript"> 13 <script type="text/javascript">
@@ -66,10 +68,3 @@ @@ -66,10 +68,3 @@
66 <%= labelled_form_field(_('Show catalog as:'), f.select(:visualization_format, [ [ _('Listing with thumbnail'), 'full'], [ _('Listing without thumbnail'), 'short'], [ _('Type catalog'), 'catalog'] ])) %> 68 <%= labelled_form_field(_('Show catalog as:'), f.select(:visualization_format, [ [ _('Listing with thumbnail'), 'full'], [ _('Listing without thumbnail'), 'short'], [ _('Type catalog'), 'catalog'] ])) %>
67 69
68 <%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %> 70 <%= labelled_form_field(_('Items per page:'), f.select(:posts_per_page, Blog.posts_per_page_options)) %>
69 -  
70 -<%= required f.text_field(:dspace_server_url, :size => '150', :maxlength => 150) %>  
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
1 <li class="collection"> 1 <li class="collection">
2 - <span class="title"><%= collection.name %></span><br /> 2 + <span class="title"><%= link_to collection.name, :controller => 'content_viewer', :action => 'view_page', :page => collection.path %></span>
3 </li> 3 </li>
plugins/dspace/views/content_viewer/collection.html.erb
1 <% collection_id = dspace_collection.dspace_collection_id %> 1 <% collection_id = dspace_collection.dspace_collection_id %>
2 -<% dspace_server = dspace_collection.parent.dspace_server_url %> 2 +<% dspace_server = dspace_collection.parent.parent.dspace_server_url %>
3 3
4 <div id="dspace_library"> 4 <div id="dspace_library">
5 <div id="dspace_collection"> 5 <div id="dspace_collection">
plugins/dspace/views/content_viewer/community.html.erb
@@ -2,9 +2,24 @@ @@ -2,9 +2,24 @@
2 <% dspace_server = dspace_community.parent.dspace_server_url %> 2 <% dspace_server = dspace_community.parent.dspace_server_url %>
3 3
4 <div id="dspace_library"> 4 <div id="dspace_library">
  5 +
  6 + <% if true %>
  7 +
  8 + <div id="actions">
  9 + <%= content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "DspacePlugin::Collection", :parent_id => dspace_community.id}), :class => 'button with-text icon-add') do %>
  10 + <%= _("Add %s") % DspacePlugin::Collection.short_description %>
  11 + <% end %>
  12 + </div>
  13 +
  14 + <% end %>
  15 +
  16 + <% collections = dspace_community.collections dspace_server, community_id %>
  17 +
5 <div id="dspace_community"> 18 <div id="dspace_community">
6 <ul id="collection_list"> 19 <ul id="collection_list">
7 - <%= render :partial => 'collection', :collection => dspace_community.collections(dspace_server, community_id) %> 20 + <%= render :partial => 'collection', :collection => collections %>
8 </ul> 21 </ul>
9 </div> 22 </div>
  23 +
10 </div> 24 </div>
  25 +
plugins/dspace/views/content_viewer/library.html.erb
1 <div id="dspace_library"> 1 <div id="dspace_library">
2 2
3 - <%= content_tag 'div', dspace_library.body %>  
4 -  
5 - <% if dspace_library.gather_option == "communities" %>  
6 -  
7 <% if true %> 3 <% if true %>
8 4
9 <div id="actions"> 5 <div id="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 %> 6 <%= 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 %> 7 + <%= _("Add %s") % DspacePlugin::Communityy.short_description %>
12 <% end %> 8 <% end %>
13 </div> 9 </div>
14 10
@@ -20,28 +16,4 @@ @@ -20,28 +16,4 @@
20 <%= render :partial => 'community_item', :collection => communities %> 16 <%= render :partial => 'community_item', :collection => communities %>
21 </ul> 17 </ul>
22 18
23 - <% end %>  
24 -  
25 - <% if dspace_library.gather_option == "collections" %>  
26 -  
27 - <% if true %>  
28 -  
29 - <div id="actions">  
30 - <%= 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 %>  
31 - <%= _("New %s") % DspacePlugin::Collection.short_description %>  
32 - <% end %>  
33 - </div>  
34 -  
35 - <% end %>  
36 -  
37 - <% collections = dspace_library.collections %>  
38 -  
39 - <% unless collections.blank? %>  
40 - <ul id="collections_list" class="collections_list">  
41 - <%= render :partial => 'collection_item', :collection => collections %>  
42 - </ul>  
43 - <% end %>  
44 -  
45 - <% end %>  
46 -  
47 </div> 19 </div>