Add download function at home controller
This commit is contained in:
parent
ab00afa513
commit
92a0d71bda
@ -1,19 +1,16 @@
|
||||
class HomeController < ApplicationController
|
||||
def index
|
||||
config = get_conf
|
||||
#@current_dir = config["project_path"]
|
||||
@current_dir = "/mnt"
|
||||
file_directory(@current_dir)
|
||||
end
|
||||
|
||||
def file_download
|
||||
@file_name = params[:file_name]
|
||||
puts "file_name: " + @file_name
|
||||
if File.exist?(@file_name)
|
||||
#File.delete(@file_name)
|
||||
puts "file exist!!"
|
||||
send_file(@file_name)
|
||||
puts "send success"
|
||||
@file_name = params[:file_name].gsub(" ", "/")
|
||||
if !@file_name.nil?
|
||||
send_file @file_name
|
||||
else
|
||||
puts "file name is nil"
|
||||
redirect_to '/home/index'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -162,11 +162,7 @@
|
||||
</td>
|
||||
<% else %>
|
||||
<td>
|
||||
<form class="form_file_download" data-parsley-validate>
|
||||
<i class="fa fa-file-o"></i>
|
||||
<input type="hidden", value="<%=@current_dir + '/' + t['name']%>">
|
||||
<button type="submit" style="border: none; background: none;"><%=t["name"]%></button>
|
||||
</form>
|
||||
<a href="/file_download?file_name=<%=(@current_dir+'/'+t['name']).gsub("/", "+")%>"><%=t['name']%></a>
|
||||
</td>
|
||||
<% end %>
|
||||
<td><%=t["auth"]%></td>
|
||||
@ -279,11 +275,7 @@ function change_directory(directory){
|
||||
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
|
||||
}else{
|
||||
new_tr += "<td>";
|
||||
new_tr += "<form class='form_file_download' data-parsley-validate>";
|
||||
new_tr += "<i class='fa fa-file-o'></i>";
|
||||
new_tr += "<input type='hidden', value='" + cur + "/" + result.file[i].name + "'>";
|
||||
new_tr += "<button type='submit' style='border: none; background: none;'>" + result.file[i].name + "</button>";
|
||||
new_tr += "</form>";
|
||||
new_tr += "<a href='/file_download?file_name="+ (cur + "/" + result.file[i].name).replace(/\//, "+") + "'>" + result.file[i].name + "</a>"
|
||||
new_tr += "</td>";
|
||||
}
|
||||
new_tr += "<td>"+result.file[i].auth+"</td>";
|
||||
@ -296,45 +288,16 @@ function change_directory(directory){
|
||||
$("#table_div").append(new_table);
|
||||
$('#datatable').dataTable();
|
||||
right_click();
|
||||
|
||||
$(".form_file_download").submit(function(){
|
||||
file_name = $(this).find("input").val();
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/file_download',
|
||||
data: {file_name: file_name},
|
||||
success: function(result){
|
||||
console.log("post success");
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
$("document").ready(function(){
|
||||
$(".form_file_download").submit(function(){
|
||||
file_name = $(this).find("input").val();
|
||||
$.ajax({
|
||||
type: 'post',
|
||||
url: '/file_download',
|
||||
data: {file_name: file_name},
|
||||
success: function(result){
|
||||
console.log("post success");
|
||||
}
|
||||
});
|
||||
return false;
|
||||
})
|
||||
});
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
<!--Test Page specific JS -->
|
||||
<script type="text/javascript">
|
||||
|
||||
|
@ -11,10 +11,10 @@ Rails.application.routes.draw do
|
||||
get 'index' => 'plainpage#index'
|
||||
|
||||
#Home
|
||||
get 'file_download' => 'home#file_download'
|
||||
get 'home/index' => 'home#index'
|
||||
post 'home/mkdir' => 'home#make_directory'
|
||||
post 'home/delete' => 'home#delete_file'
|
||||
post 'file_download' => 'home#file_download'
|
||||
|
||||
#Volume
|
||||
get 'volume/index' => 'volume#index'
|
||||
|
Loading…
Reference in New Issue
Block a user