software_communities_plugin_controller.rb
1.62 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
# apenas software
require 'csv'
class SoftwareCommunitiesPluginController < ApplicationController
def get_license_data
return render :json=>{} if !request.xhr? || params[:query].nil?
data = LicenseHelper.find_licenses(params[:query]) if params[:query]
data ||= LicenseInfo.all
render :json=> data.collect { |license|
{:id=>license.id, :label=>license.version}
}
end
def get_block_template
# render 'box_organizer/_download_list_template', :layout => false
profile = Profile.find_by_identifier(params[:profile])
downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: profile.id)
render 'box_organizer/_download_uploaded_files', :locals=>{ :uploaded_files => get_node(downloads_folder) }
end
def get_field_data
condition = !request.xhr? || params[:query].nil? || params[:field].nil?
return render :json=>{} if condition
model = get_model_by_params_field
data = model.where("name ILIKE ?", "%#{params[:query]}%").select("id, name")
.collect { |db|
{:id=>db.id, :label=>db.name}
}
other = [model.select("id, name").last].collect { |db|
{:id=>db.id, :label=>db.name}
}
# Always has other in the list
data |= other
render :json=> data
end
protected
def get_model_by_params_field
return DatabaseDescription unless params[:field] == "software_language"
return ProgrammingLanguage
end
def get_node(articles)
nodes = []
articles.each do |article|
if article.type == "UploadedFile"
nodes << article
end
nodes += get_node(article.children)
end
nodes
end
end