Commit e7af48474d154790cd24b6d3ac94c403ae366e9b

Authored by Gabriel Silva
1 parent 0e741a07

Adds action/ajax to fetch uploaded files

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: ArthurJahn <stutrzbecher@gmail.com>
src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb
... ... @@ -15,7 +15,10 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
15 15 end
16 16  
17 17 def get_block_template
18   - render 'box_organizer/_download_list_template', :layout => false
  18 + # render 'box_organizer/_download_list_template', :layout => false
  19 + profile = Profile.find_by_identifier(params[:profile])
  20 + downloads_folder = Folder.where(name: "Downloads", type: "Folder", profile_id: profile.id)
  21 + render 'box_organizer/_download_uploaded_files', :locals=>{ :uploaded_files => get_node(downloads_folder) }
19 22 end
20 23  
21 24 def get_field_data
... ... @@ -45,4 +48,15 @@ class SoftwareCommunitiesPluginController &lt; ApplicationController
45 48 return DatabaseDescription unless params[:field] == "software_language"
46 49 return ProgrammingLanguage
47 50 end
  51 +
  52 + def get_node(articles)
  53 + nodes = []
  54 + articles.each do |article|
  55 + if article.type == "UploadedFile"
  56 + nodes << article
  57 + end
  58 + nodes += get_node(article.children)
  59 + end
  60 + nodes
  61 + end
48 62 end
... ...
src/noosfero-spb/software_communities/public/blocks/software-download.js
... ... @@ -9,16 +9,14 @@ modulejs.define(&#39;SoftwareDownload&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;], function($, Noos
9 9 var $download_html_template;
10 10  
11 11 function getDownloadListTemplate() {
12   - var block_template = sessionStorage.getItem('download_list_block_template');
13   -
14   - if(block_template && block_template.length > 0) {
15   - $download_html_template = block_template;
16   - } else {
17   - $.get(AJAX_URL.get_download_template, function(response) {
  12 + $.get(AJAX_URL.get_download_template, { profile: noosfero.profile })
  13 + .done(function(response) {
  14 + console.log("asdasd");
  15 + console.log(response);
18 16 $download_html_template = response;
19   - sessionStorage.setItem('download_list_block_template', response);
20   - });
21   - }
  17 + }).fail(function() {
  18 + alert( "error" );
  19 + });
22 20 }
23 21  
24 22  
... ...
src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<div class="asdasd">
  2 + result: <%= uploaded_files.collect{|u| u.name} %>
  3 +</div>
... ...