From e7af48474d154790cd24b6d3ac94c403ae366e9b Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Fri, 22 Jan 2016 19:05:59 +0000 Subject: [PATCH] Adds action/ajax to fetch uploaded files --- src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb | 16 +++++++++++++++- src/noosfero-spb/software_communities/public/blocks/software-download.js | 16 +++++++--------- src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb | 3 +++ 3 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb diff --git a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb index 0d59ad8..46c7481 100644 --- a/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb +++ b/src/noosfero-spb/software_communities/controllers/software_communities_plugin_controller.rb @@ -15,7 +15,10 @@ class SoftwareCommunitiesPluginController < ApplicationController end def get_block_template - render 'box_organizer/_download_list_template', :layout => false + # 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 @@ -45,4 +48,15 @@ class SoftwareCommunitiesPluginController < ApplicationController 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 diff --git a/src/noosfero-spb/software_communities/public/blocks/software-download.js b/src/noosfero-spb/software_communities/public/blocks/software-download.js index 94bda3f..ea32258 100644 --- a/src/noosfero-spb/software_communities/public/blocks/software-download.js +++ b/src/noosfero-spb/software_communities/public/blocks/software-download.js @@ -9,16 +9,14 @@ modulejs.define('SoftwareDownload', ['jquery', 'NoosferoRoot'], function($, Noos var $download_html_template; function getDownloadListTemplate() { - var block_template = sessionStorage.getItem('download_list_block_template'); - - if(block_template && block_template.length > 0) { - $download_html_template = block_template; - } else { - $.get(AJAX_URL.get_download_template, function(response) { + $.get(AJAX_URL.get_download_template, { profile: noosfero.profile }) + .done(function(response) { + console.log("asdasd"); + console.log(response); $download_html_template = response; - sessionStorage.setItem('download_list_block_template', response); - }); - } + }).fail(function() { + alert( "error" ); + }); } diff --git a/src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb b/src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb new file mode 100644 index 0000000..1eaff79 --- /dev/null +++ b/src/noosfero-spb/software_communities/views/box_organizer/_download_uploaded_files.html.erb @@ -0,0 +1,3 @@ +
+ result: <%= uploaded_files.collect{|u| u.name} %> +
-- libgit2 0.21.2