dspace_plugin.rb
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class DspacePlugin < Noosfero::Plugin
def self.plugin_name
"DSpace Plugin"
end
def self.plugin_description
_("A plugin that add a DSpace library feature to noosfero.")
end
def content_types
return [] if !context.kind_of?(CmsController)
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::Communityy
elsif parent.kind_of?(DspacePlugin::Communityy)
types << DspacePlugin::Collection
end
types
else
[DspacePlugin::Library, DspacePlugin::Collection, DspacePlugin::Communityy]
end
end
def stylesheet?
true
end
def self.has_admin_url?
false
end
def cms_controller_filters
block = proc do
dspace_content_type = params[:type]
case dspace_content_type
when 'DspacePlugin::Communityy'
parent = DspacePlugin::Library.find_by_id(params[:parent_id])
children = Dspace::Community.get_all_communities_from parent.dspace_server_url
when 'DspacePlugin::Collection'
parent = DspacePlugin::Communityy.find_by_id(params[:parent_id])
children = Dspace::Collection.get_all_collections_from parent.parent.dspace_server_url
end
if dspace_content_type == 'DspacePlugin::Communityy' || dspace_content_type == 'DspacePlugin::Collection'
if children.nil?
session[:notice] = _('Unable to contact DSpace server')
redirect_to parent.view_url
end
end
end
{ :type => 'before_filter',
:method_name => 'new',
:block => block }
end
end