add directory

This commit is contained in:
bee0005 2016-08-27 13:21:08 +00:00
parent 404e72f01c
commit f38432f3bc
3 changed files with 142 additions and 60 deletions

View File

@ -1,9 +1,11 @@
class VolumeController < ApplicationController
helper_method :file_directory
def info
file_directory('/home/ubuntu')
@volumes = Array.new
volume = Hash.new
i = 0
if get_info.blank?
flash[:danger] = "Check Server"
else
@ -35,38 +37,51 @@ class VolumeController < ApplicationController
end
def get_files(name)
mnt_path = "/opt/gluster-web-interface/app/mntpoint" + "/" + name.delete(' ')
files = Array.new
file = Hash.new
puts "start///////"
puts "path: " + mnt_path
`sudo mkdir #{dir}`
`sudo mount.glusterfs gluster-1:/#{dir_name} #{dir}`
dir_list = `ls #{dir} -l`
puts dir_list
def file_directory(dir)
@current_dir = dir
dir_list = `ls #{@current_dir} -l`
parsing_list = dir_list.split("\n")
@total = parsing_list[0]
@cur_dir = dir
@files = Array.new
file = Hash.new
i = 0
@total_list = parsing_list[0]
for t in 1..(parsing_list.length-1)
puts "@@@@@@@@@@@" + parsing_list[t]
parsing_file = parsing_list[t].split(" ")
file["auth"] = parsing_file[0]
file["size"] = parsing_file[4]
file["date"] = parsing_file[5] + " " + parsing_file[6] + " "+ parsing_file[7]
file["name"] = parsing_file[8]
files[i] = file
file = Hash.new
i+=1
parsing_file = parsing_list[t].split(" ")
file["auth"] = parsing_file[0]
file["size"] = parsing_file[4]
file["date"] = parsing_file[5] + " " + parsing_file[6] + " "+ parsing_file[7]
file["name"] = parsing_file[8]
@files[i] = file
file = Hash.new
i+=1
end
puts files
return files
puts @files
end
def change_file_directory(dir)
@change_dir = dir
dir_list = `ls #{@change_dir} -l`
parsing_list = dir_list.split("\n")
@change_files = Array.new
file = Hash.new
i = 0
@change_total_list = parsing_list[0]
for t in 1..(parsing_list.length-1)
parsing_file = parsing_list[t].split(" ")
file["auth"] = parsing_file[0]
file["size"] = parsing_file[4]
file["date"] = parsing_file[5] + " " + parsing_file[6] + " "+ parsing_file[7]
file["name"] = parsing_file[8]
@change_files[i] = file
file = Hash.new
i+=1
end
puts @change_files
end
def checkDir
file_directory(params[:path])
render :json => {:file => @files , :current => @current_dir}
end
end

View File

@ -4,7 +4,7 @@
<div class="">
<div class="page-title">
<div class="title_left">
<h3>Volume</h3>
<h3>Volume Info </h3>
</div>
<div class="title_right">
<div class="col-md-5 col-sm-5 col-xs-12 form-group pull-right top_search">
@ -67,14 +67,9 @@
<br/>
</div>
<%f = get_files(t["Volume Name"])%>
<%f.each do |t|%>
<div class="col-md-12 col-sm-12 col-xs-12">
Current directory : <%=@cur_dir%></br>
Numbers : <%=@total%></br>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="col-md-12 col-sm-12 col-xs-12" id="table_div">
<p class="text-muted font-13 m-b-30"><code>File Manager</code></p>
<p> Current directory : <%=@current_dir%></p></br>
<table id="datatable" class="table table-striped table-bordered jambo_table">
<thead>
<tr class="headings">
@ -85,20 +80,32 @@
</tr>
</thead>
<tbody>
<tbody id="tbody_volume1">
<tr>
<td><i class="fa fa-reply"></i>
<a onclick="change_upper('<%=@current_dir%>')"> ..</a>
</td>
<td></td>
<td></td>
<td></td>
</tr>
<%@files.each do |t|%>
<tr>
<td><%=t["name"]%></td>
<td><%=t["auth"][0]%></td>
<% if t["auth"][0]=='d'%>
<td style="color:#0d8ade;"><i class="fa fa-folder-open-o"></i>
<a onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"><%=t["name"]%></a>
</td>
<% else %>
<td><i class="fa fa-file-o"></i> <%=t["name"]%></td>
<% end %>
<td><%=t["auth"]%></td>
<td><%=t["size"]%></td>
<td><%=t["date"]%></td>
</tr>
<%end%>
</tbody>
</table>
</div>
<%end%>
</div>
</div>
</div>
@ -144,20 +151,79 @@
<script type="text/javascript">
$(document).ready(function() {
$('#datatable').dataTable();
$('#datatable-keytable').DataTable({
keys: true
});
$('#datatable-responsive').DataTable();
$('#datatable-scroller').DataTable({
ajax: "js/datatables/json/scroller-demo.json",
deferRender: true,
scrollY: 380,
scrollCollapse: true,
scroller: true
});
var table = $('#datatable-fixed-header').DataTable({
fixedHeader: true
});
});
TableManageButtons.init();
</script>
</script>
<script>
function change_upper(directory){
if(directory != "/"){
var path = directory.split("/");
var upper_path = "";
if(path.length == 2){
change_directory("/");
} else {
for(var i = 1; i < path.length - 1 ; i++){
if(path[i] != "")
upper_path += "/" + path[i];
}
change_directory(upper_path);
}
}
}
function change_directory(directory){
$.ajax({
method: "POST",
url: "/volume/changeDir",
data: { path: directory },
success : function(result){
$("#table_div").empty();
var new_table = "<p class='text-muted font-13 m-b-30'><code>File Manager</code></p>"
new_table += "<p>Current directory : " + directory + "</p></br>";
new_table += "<table id='datatable' class='table table-striped table-bordered jambo_table'>";
new_table += "<thead>";
new_table += "<tr class='headings'>";
new_table += "<th>Name</th>";
new_table += "<th>Auth</th>";
new_table += "<th>Size</th>";
new_table += "<th>Date</th>";
new_table += "</tr>";
new_table += "</thead>";
new_table += "<tbody id='tbody_volume1'>"
var new_tr = "<tr role='row' class='odd'> <td><i class='fa fa-reply'></i>";
new_tr += "<a onclick='change_upper(" + '"' + directory + '"' +")'> ..</a>"
new_tr += "</td><td> </td><td> </td><td> </td></tr>"
for( var i = 0; i < result.file.length; i++){
if(i % 2 == 0)
new_tr += "<tr role='row' class='odd'>";
else
new_tr += "<tr role='row' class='even'>";
if(result.file[i].auth[0] == "d"){
new_tr += "<td style='color:#0d8ade;' class='sorting_1'><i class='fa fa-folder-open-o'></i> ";
if(result.current != "/")
new_tr += "<a onclick='change_directory(" +'"' + result.current + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
else
new_tr += "<a onclick='change_directory(" +'"' + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
}else{
new_tr += "<td><i class='fa fa-file-o'></i> " + result.file[i].name + "</td>";
}
new_tr += "<td>"+result.file[i].auth+"</td>";
new_tr += "<td>"+result.file[i].size+"</td>";
new_tr += "<td>"+result.file[i].date+"</td>";
new_tr += "</tr>";
}
new_table += new_tr;
new_table += "</tbody></table>"
$("#table_div").append(new_table);
$('#datatable').dataTable();
TableManageButtons.init();
}
})
}
</script>

View File

@ -17,6 +17,7 @@ Rails.application.routes.draw do
get 'volume/info' => 'volume#info'
get 'peer/index' => 'peer#index'
post 'file_upload' => 'volume#file_upload'
post 'volume/changeDir' => 'volume#checkDir'
# Example of regular route:
# get 'products/:id' => 'catalog#view'