Add mount table to volume index

This commit is contained in:
kyg516 2016-09-28 18:15:06 +09:00
parent e62a1eed16
commit ac1527acf0
7 changed files with 88 additions and 91 deletions

View File

@ -12,24 +12,5 @@ class ApplicationController < ActionController::Base
redirect_to "/users/sign_in" # halts request cycle
end
end
def chdir
@current_dir = params[:next_dir]
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:file_manager_table => file_manager_table(@current_dir),
:disk_usage_table => disk_usage_table(@current_dir),
:du => get_du(@current_dir),
}
end
def rmdir
file_name = params[:file_name]
command = String.new
command << "sudo rm -rf #{file_name}"
puts command
`#{command}`
end
end

View File

@ -26,4 +26,22 @@ class HomeController < ApplicationController
redirect_to '/home/index'
end
def chdir
@current_dir = params[:next_dir]
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:file_manager_table => file_manager_table(@current_dir),
:disk_usage_table => disk_usage_table(@current_dir),
:du => get_du(@current_dir),
}
end
def rmdir
file_name = params[:file_name]
command = String.new
command << "sudo rm -rf #{file_name}"
puts command
`#{command}`
end
end

View File

@ -5,6 +5,15 @@ class VolumeController < ApplicationController
@current_dir = "/mnt"
end
def chdir
@current_dir = params[:next_dir]
puts "current_dir : " + @current_dir
render :json => {
:dir => @current_dir,
:mount_table => mount_table(@current_dir),
}
end
def file_upload
df = get_df
mnt_dir = String.new

View File

@ -13,7 +13,7 @@ module VolumeHelper
html << "</div>"
raw(html)
end
def mount_table(dir = @current_dir, id = "mount_table", class_option = "table table-striped table-bordered jambo_table")
html = String.new
html << "<table id='#{id}' class='#{class_option}'>"
@ -21,20 +21,16 @@ module VolumeHelper
html << "<tr class='headings'>"
html << "<th>Name</th>"
html << "<th>auth</th>"
#html << "<th>Size</th>"
#html << "<th>Date</th>"
html << "<th></th>"
html << "</tr>"
html << "</thead>"
html << "<tbody id='#{id}_body'>"
html << "<tr>"
html << "<td>"
#html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a>"
html << "<i class='fa fa-reply'></i> <a style='cursor: pointer'> ..</a>"
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a> #{@current_dir}"
html << "</td>"
html << "<td></td>"
html << "<td></td>"
#html << "<td></td>"
html << "</tr>"
files(dir).each do |file|
@ -46,7 +42,7 @@ module VolumeHelper
html << "</td>"
html << "<td>"
html << "<form data-parsley-validate>"
hmtl << "<input type='hidden' value='#{@current_dir}/#{file["name"]}'>"
html << "<input type='hidden' value='#{@current_dir}/#{file["name"]}'>"
html << "<button type='submit' class='btn btn-primary pull-right'>select</button>"
html << "</form>"
html << "</td>"
@ -58,5 +54,5 @@ module VolumeHelper
html << "</table>"
return html
end
end
end

View File

@ -347,7 +347,7 @@ $(document).on("click", "#file_manager_div .chdir", function(){
$.ajax({
method: "post",
url: "/application/chdir",
url: "/home/chdir",
data: { next_dir : next_dir },
success : function(result){
$("#current_dir").val(next_dir);
@ -375,7 +375,7 @@ $(document).on("click", "#file_manager_div .chupper", function(){
$.ajax({
method: "POST",
url: "/application/chdir",
url: "/home/chdir",
data: { next_dir : next_dir },
success : function(result){
$("#current_dir").val(next_dir);
@ -399,7 +399,7 @@ $(document).on("click", "#file_manager_div .rmdir", function(){
if(confirm("Are you sure you want to delete '"+ file_name +"' ?")) {
$.ajax({
method: "POST",
url: "/application/rmdir",
url: "/home/rmdir",
data: { target : target },
success : function(result){
$("#current_dir").val(current_dir);

View File

@ -69,8 +69,10 @@
<div class="popup">
<h2> Choose mount point </h2>
<a class="close" href="#">&times;</a>
<div id="mount_table_div">
<%= raw mount_table %>
</div>
</div>
</div>
<!-- page content -->
<div class="right_col" role="main">
@ -185,63 +187,11 @@
</div>
<!-- /page content -->
<!-- File manager functions -->
<script>
function change_upper(directory){
if(directory == "/") return;
var lastindex = directory.lastIndexOf("/");
if(lastindex == 0) lastindex++;
change_directory(directory.substring(0, lastindex));
}
function change_directory(directory){
$.ajax({
method: "POST",
url: "/application/changeDir",
data: { path: directory },
success : function(result){
$("#datatable_body").empty();
var new_tr = "";
new_tr += "<tr role='row' class='odd'> <td><i class='fa fa-reply'></i>";
new_tr += "<a style='cursor: pointer' onclick='change_upper(" + '"' + directory + '"' +")'> ..</a>";
new_tr += "</td><td> </td><td>";
for( var i = 0; i < result.file.length; i++){
if(result.file[i].auth[0] != "d") continue;
var row_class = i % 2 == 0 ? 'odd' : 'even';
var cur = result.current != "/" ? result.current : '';
new_tr += "<tr role='row' class='" + row_class + "'>";
new_tr += "<td style='color:#0d8ade;' class='sorting_1'><i class='fa fa-folder-open-o'></i> ";
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
new_tr += "<td>"+result.file[i].auth+"</td>";
new_tr += "<td><form data-parsley-validate>";
new_tr += "<input type='hidden' value='" + cur + "/" + result.file[i].name + "'>";
new_tr += "<button type='submit' class='btn btn-primary pull-right'>select</botton>";
new_tr += "</form></td>"
new_tr += "</tr>";
}
$("#datatable_body").append(new_tr);
// Add mount overlay functions again
$("#popup_mount #datatable_body form").submit(function(){
var mnt_point = $(this).find("input").val();
var url = window.location + '';
var vol_name = url.match(/volume_name=([^#]+)/)[1];
$.ajax({
type: 'post',
url: '/volume/mount',
data: {mount_point: mnt_point, volume_name: vol_name},
success: function(result){
}
});
})
}
})
}
</script>
<!-- On document ready -->
<script>
$(document).ready(function(){
// Mount overlay functions
$("#popup_mount #datatable_body form").submit(function(){
$("#popup_mount #mount_table_body form").submit(function(){
var mnt_point = $(this).find("input").val();
var url = window.location + '';
var vol_name = url.match(/volume_name=([^#]+)/)[1];
@ -341,3 +291,45 @@
});
});
</script>
<!-- File manager functions -->
<script>
// change directory
$(document).on("click", "#mount_table_div .chdir", function(){
var file_name = $(this).text().trim();
var current_dir = $("#mount_table_div span").text().trim();
if(current_dir == "/") current_dir = "";
var next_dir = current_dir + "/" + file_name;
$.ajax({
method: "post",
url: "/volume/chdir",
data: { next_dir : next_dir },
success : function(result){
$("#mount_table_div").empty();
$("#mount_table_div").append(result.mount_table);
}
})
})
// change upper
$(document).on("click", "#mount_table_div .chupper", function(){
var current_dir = $("#mount_table_div span").text().trim();
if(current_dir == "/") return;
var lastindex = current_dir.lastIndexOf("/");
console.log("curdir : " + current_dir);
console.log("last idx : " + lastindex);
if(lastindex == 0) lastindex++;
var next_dir = current_dir.substring(0, lastindex);
$.ajax({
method: "POST",
url: "/volume/chdir",
data: { next_dir : next_dir },
success : function(result){
$("#mount_table_div").empty();
$("#mount_table_div").append(result.mount_table);
}
})
})
</script>
<!-- /File manager functions -->

View File

@ -6,25 +6,26 @@ Rails.application.routes.draw do
# You can have the root of your site routed with "root"
root 'home#index'
post 'application/chdir' => 'application#chdir'
post 'application/rmdir' => 'application#rmdir'
get 'index' => 'plainpage#index'
#Home
get 'file_download' => 'home#file_download'
get 'home/index' => 'home#index'
post 'home/mkdir' => 'home#make_directory'
post 'home/chdir' => 'home#chdir'
post 'home/rmdir' => 'home#rmdir'
#Volume
get 'volume/index' => 'volume#index'
post 'file_upload/:volume_name' => 'volume#file_upload'
post 'volume/mount' => "volume#volume_mount"
post 'volume/create' => "volume#volume_create"
get 'volume/unmount/:volume_name' => "volume#volume_unmount"
get 'volume/start/:volume_name' => "volume#volume_start"
get 'volume/stop/:volume_name' => "volume#volume_stop"
get 'volume/delete/:volume_name' => "volume#volume_delete"
post 'file_upload/:volume_name' => 'volume#file_upload'
post 'volume/mount' => "volume#volume_mount"
post 'volume/create' => "volume#volume_create"
post 'volume/chdir' => 'volume#chdir'
#Node
get 'node/index' => 'node#index'