software_communities_plugin_controller.rb
2.72 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# apenas software
require 'csv'
class SoftwareCommunitiesPluginController < ApplicationController
def get_license_data
return render :json=>{} if !request.xhr? || params[:query].nil?
data = if params[:query].empty?
LicenseInfo.all
else
LicenseInfo.where("version ILIKE ?", "%#{params[:query]}%").select("id, version")
end
render :json=> data.collect { |license|
{:id=>license.id, :label=>license.version}
}
end
def download_file
download_block = Block.find(params[:block_id])
file_link = DownloadFileHelper.get_file_link(download_block, params[:link_index].to_i)
file = DownloadFileHelper.get_file(file_link)
owner = download_block.owner
download_software = owner.software_info
download_software.download_counter += 1
if not file.nil?
file_body = send_file file.full_filename
self.response.body = Enumerator::new do |enum|
file_body.each {|file_data| enum << file_data}
# Only save when the download is finished
download_software.save!
end
else
download_software.save!
# If it is not in noosfero(like a external link),
# just send the user to this location
redirect_to file_link
end
end
def hide_registration_incomplete_percentage
response = false
if request.xhr? && params[:hide]
session[:hide_incomplete_percentage] = true
response = session[:hide_incomplete_percentage]
end
render :json=>response.to_json
end
def create_institution
@show_sisp_field = environment.admins.include?(current_user.person)
@state_list = get_state_list()
>>>>>>> e8d6ff3... Retrive version logic.
data = if params[:query].empty?
LicenseInfo.all
else
LicenseInfo.where("version ILIKE ?", "%#{params[:query]}%").select("id, version")
end
render :json=> data.collect { |license|
{:id=>license.id, :label=>license.version}
}
end
def get_block_template
render 'box_organizer/_download_list_template', :layout => false
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
case params[:field]
when "software_language"
return ProgrammingLanguage
else
return DatabaseDescription
end
end
end