Add tables to helper
This commit is contained in:
parent
397710c882
commit
5685c5ff6e
@ -33,8 +33,18 @@ class ApplicationController < ActionController::Base
|
|||||||
return df
|
return df
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkDir
|
def chdir
|
||||||
@current_dir = params[:path]
|
@current_dir = params[:next_dir]
|
||||||
|
puts "current_dir : " + @current_dir
|
||||||
render :json => {:dir => @current_dir}
|
render :json => {:dir => @current_dir}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rmdir
|
||||||
|
file_name = params[:file_name]
|
||||||
|
command = String.new
|
||||||
|
command << "sudo rm -rf #{file_name}"
|
||||||
|
puts command
|
||||||
|
`#{command}`
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -26,14 +26,4 @@ class HomeController < ApplicationController
|
|||||||
redirect_to '/home/index'
|
redirect_to '/home/index'
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_file
|
|
||||||
file_name = params[:file_name]
|
|
||||||
# delete file
|
|
||||||
command = String.new
|
|
||||||
command << "sudo rm -rf #{file_name}"
|
|
||||||
puts command
|
|
||||||
`#{command}`
|
|
||||||
redirect_to '/home/index'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -85,8 +85,7 @@ module ApplicationHelper
|
|||||||
|
|
||||||
def file_manager_table(dir = "/mnt", id = "datatable", class_option = "table table-striped table-bordered jambo_table")
|
def file_manager_table(dir = "/mnt", id = "datatable", class_option = "table table-striped table-bordered jambo_table")
|
||||||
html = String.new
|
html = String.new
|
||||||
html << "<table id='" + id + "' class='" + class_option + "'>"
|
html << "<table id='#{id}' class='#{class_option}'>"
|
||||||
|
|
||||||
html << "<thead>"
|
html << "<thead>"
|
||||||
html << "<tr class='headings'>"
|
html << "<tr class='headings'>"
|
||||||
html << "<th>Name</th>"
|
html << "<th>Name</th>"
|
||||||
@ -95,12 +94,11 @@ module ApplicationHelper
|
|||||||
html << "<th>Date</th>"
|
html << "<th>Date</th>"
|
||||||
html << "</tr>"
|
html << "</tr>"
|
||||||
html << "</thead>"
|
html << "</thead>"
|
||||||
|
html << "<tbody id='#{id}_body'>"
|
||||||
html << "<tbody id='" + id + "_body'>"
|
|
||||||
html << "<tr>"
|
html << "<tr>"
|
||||||
html << "<td>"
|
html << "<td>"
|
||||||
html << "<a style='cursor: pointer' onclick='change_upper(" + "\"" + dir + "\"" + ")'><i class='fa fa-reply'></i></a>"
|
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a>"
|
||||||
html << " " + dir
|
html << "<span style='line-height:0'> #{dir}</span>"
|
||||||
html << "<a class='pull-right' href='#popup_mkdir'><i class='fa fa-plus'></i><i class='fa fa-folder'></i></a>"
|
html << "<a class='pull-right' href='#popup_mkdir'><i class='fa fa-plus'></i><i class='fa fa-folder'></i></a>"
|
||||||
html << "</td>"
|
html << "</td>"
|
||||||
html << "<td></td>"
|
html << "<td></td>"
|
||||||
@ -112,24 +110,24 @@ module ApplicationHelper
|
|||||||
html << "<tr class='dir_delete'>"
|
html << "<tr class='dir_delete'>"
|
||||||
if file["auth"][0]=='d'
|
if file["auth"][0]=='d'
|
||||||
html << "<td style='color:#0d8ade;'><i class='fa fa-folder-open-o'></i>"
|
html << "<td style='color:#0d8ade;'><i class='fa fa-folder-open-o'></i>"
|
||||||
html << "<a style='cursor: pointer' onclick='change_directory(" + "\"" + dir + "/" + file['name'] + "\"" + ")'> " + file['name'] + "</a>"
|
html << "<a class='chdir' style='cursor: pointer'> #{file['name']}</a>"
|
||||||
html << "</td>"
|
html << "</td>"
|
||||||
else
|
else
|
||||||
|
conv_name = (dir + '/' + file['name']).gsub("/", "+")
|
||||||
html << "<td><i class='fa fa-file-o'></i>"
|
html << "<td><i class='fa fa-file-o'></i>"
|
||||||
html << "<a href='/file_download?file_name=" + (dir + '/' + file['name']).gsub("/", "+") + "'> " + file['name'] + "</a>"
|
html << "<a href='/file_download?file_name=#{conv_name}'> #{file['name']}</a>"
|
||||||
html << "</td>"
|
html << "</td>"
|
||||||
end
|
end
|
||||||
html << "<td>" + file['auth'] + "</td>"
|
html << "<td>#{file['auth']}</td>"
|
||||||
html << "<td>" + file['size'] + "</td>"
|
html << "<td>#{file['size']}</td>"
|
||||||
html << "<td>"
|
html << "<td>#{file["date"]}"
|
||||||
html << file["date"]
|
html << "<a class='pull-right rmdir' href='#'><i class='fa fa-trash'></i></a>"
|
||||||
html << "<a class='pull-right' onclick='delete_file(" + "\"" + dir + "/" + file["name"] + "\"" + ")' href='#'><i class='fa fa-trash'></i></a>"
|
|
||||||
html << "</td>"
|
html << "</td>"
|
||||||
html << "</tr>"
|
html << "</tr>"
|
||||||
end
|
end
|
||||||
|
|
||||||
html << "</tbody>"
|
html << "</tbody>"
|
||||||
html << "</table>"
|
html << "</table>"
|
||||||
return html
|
return raw html
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,7 @@ module HomeHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
command = ""
|
||||||
command << "sudo du -s #{dir}/*"
|
command << "sudo du -s #{dir}/*"
|
||||||
puts command
|
puts command
|
||||||
output = `#{command}`.split("\n")
|
output = `#{command}`.split("\n")
|
||||||
@ -39,4 +40,39 @@ module HomeHelper
|
|||||||
return du
|
return du
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disk_usage_table(dir = "/mnt")
|
||||||
|
html = String.new
|
||||||
|
html << "<table class='' style='width:100%'>"
|
||||||
|
html << "<tr>"
|
||||||
|
html << "<th style='width:37%;'>"
|
||||||
|
html << "<p>Chart</p>"
|
||||||
|
html << "</th><th>"
|
||||||
|
html << "<div class='col-lg-7 col-md-7 col-sm-7 col-xs-7'>"
|
||||||
|
html << "<p class=''>Name</p></div>"
|
||||||
|
html << "<div class='col-lg-5 col-md-5 col-sm-5 col-xs-5'>"
|
||||||
|
html << "<p class=''>Usage</p></div>"
|
||||||
|
html << "</th></tr>"
|
||||||
|
html << "<tr>"
|
||||||
|
html << "<td><canvas id='canvas1' height='140' width='140' style='margin: 15px 10px 10px 0'></canvas></td>"
|
||||||
|
html << "<td>"
|
||||||
|
html << "<table class='tile_info'>"
|
||||||
|
|
||||||
|
get_du(dir).each_with_index do |t, index|
|
||||||
|
color = ['blue', 'green', 'red', 'purple', 'grey'][index % 5]
|
||||||
|
html << "<tr><td>"
|
||||||
|
html << "<p><i class='fa fa-square #{color}'></i>"
|
||||||
|
html << t['file_name']
|
||||||
|
html << "</p></td>"
|
||||||
|
html << "<td><p>"
|
||||||
|
html << format("%.2f", t['usage']*100) + "%"
|
||||||
|
html << "</p></td>"
|
||||||
|
html << "</tr>"
|
||||||
|
end
|
||||||
|
|
||||||
|
html << "</table>"
|
||||||
|
html << "</td></tr>"
|
||||||
|
html << "</table>"
|
||||||
|
return html
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
<a class="close" href="#">×</a>
|
<a class="close" href="#">×</a>
|
||||||
<form id="form_make_directory" data-parsley-validate class="form-horizontal form-label-left" action="/home/mkdir" method="post">
|
<form id="form_make_directory" data-parsley-validate class="form-horizontal form-label-left" action="/home/mkdir" method="post">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="current-dir">Current Directory <span class="required">*</span>
|
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="current_dir">Current Directory <span class="required">*</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="col-md-6 col-sm-6 col-xs-12">
|
<div class="col-md-6 col-sm-6 col-xs-12">
|
||||||
<input type="text" id="current-dir" required="required" class="form-control col-md-7 col-xs-12" name="current_dir" value="<%=@current_dir%>" readonly/>
|
<input type="text" id="current_dir" required="required" class="form-control col-md-7 col-xs-12" name="current_dir" value="<%= @current_dir %>" readonly/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -103,6 +103,7 @@
|
|||||||
<!-- /top tiles -->
|
<!-- /top tiles -->
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<!-- file manager -->
|
<!-- file manager -->
|
||||||
<div class="col-md-8 col-sm-8 col-xs-12">
|
<div class="col-md-8 col-sm-8 col-xs-12">
|
||||||
<div class="x_panel">
|
<div class="x_panel">
|
||||||
@ -124,8 +125,8 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="x_content">
|
<div class="x_content">
|
||||||
<div class="col-md-12 col-sm-12 col-xs-12" id="table_div">
|
<div class="col-md-12 col-sm-12 col-xs-12" id="file_manager_div">
|
||||||
<%= raw file_manager_table %>
|
<%= file_manager_table @current_dir %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -138,46 +139,8 @@
|
|||||||
<div class="x_title">
|
<div class="x_title">
|
||||||
<h4>Disk usage</h4>
|
<h4>Disk usage</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row" id="disk_usage_div">
|
||||||
<table class="" style="width:100%">
|
<%= raw disk_usage_table %>
|
||||||
<tr>
|
|
||||||
<th style="width:37%;">
|
|
||||||
<p>Chart</p>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">
|
|
||||||
<p class="">Name</p>
|
|
||||||
</div>
|
|
||||||
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
|
|
||||||
<p class="">Usage</p>
|
|
||||||
</div>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<canvas id="canvas1" height="140" width="140" style="margin: 15px 10px 10px 0"></canvas>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<table class="tile_info">
|
|
||||||
<% get_du(@current_dir).each_with_index do |t, index| %>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<p>
|
|
||||||
<i class="fa fa-square <%= ["blue", "green", "red", "purple", "grey"][index % 5] %>"></i>
|
|
||||||
<%= t['file_name'] %>
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<p>
|
|
||||||
<%= format("%.2f", t['usage']*100) %>%
|
|
||||||
</p>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -302,51 +265,77 @@
|
|||||||
|
|
||||||
<!-- File manager functions -->
|
<!-- File manager functions -->
|
||||||
<script>
|
<script>
|
||||||
function delete_file(directory){
|
$(document).on("click", "#file_manager_div .chdir", function(){
|
||||||
if (confirm("Are you sure you want to delete '"+ directory+"' ?")) {
|
var file_name = $(this).text().trim();
|
||||||
|
var current_dir = $("#file_manager_div span").text();
|
||||||
|
var next_dir = current_dir + "/" + file_name;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/home/delete",
|
url: "/application/chdir",
|
||||||
data: { file_name: directory },
|
data: { next_dir : next_dir },
|
||||||
success : function(result){
|
success : function(result){
|
||||||
location.reload(true);
|
$("#current_dir").val(next_dir);
|
||||||
}
|
$("#file_manager_div").empty();
|
||||||
})
|
$("#file_manager_div").append("<%= file_manager_table(@current_dir) %>");
|
||||||
}
|
|
||||||
//alert(directory);
|
|
||||||
}
|
|
||||||
function change_upper(directory){
|
|
||||||
if(directory == "/") return;
|
|
||||||
var lastindex = directory.lastIndexOf("/");
|
|
||||||
if(lastindex == 0) lastindex++;
|
|
||||||
change_directory(directory.substring(0, lastindex));
|
|
||||||
}
|
|
||||||
function change_directory(dir){
|
|
||||||
$.ajax({
|
|
||||||
method: "POST",
|
|
||||||
url: "/application/changeDir",
|
|
||||||
data: { path: dir },
|
|
||||||
success : function(result){
|
|
||||||
$("#current-dir").val(dir);
|
|
||||||
$("#table_div").empty();
|
|
||||||
$("#table_div").append("<%= file_manager_table @current_dir %>");
|
|
||||||
$('#datatable').dataTable( {"bSort": false});
|
$('#datatable').dataTable( {"bSort": false});
|
||||||
|
|
||||||
// disk usage
|
// disk usage
|
||||||
$("table .tile_info").empty();
|
$("disk_usage_div").empty();
|
||||||
var new_tr = "";
|
$("disk_usage_div").append("<%= disk_usage_table %>");
|
||||||
<% (get_du @current_dir).each_with_index do |t, index| %>
|
|
||||||
new_tr += "<tr><td>";
|
|
||||||
new_tr += "<p><i class='fa fa-square <%= ["blue", "green", "red", "purple", "grey"][index % 5] %>''></i>";
|
|
||||||
new_tr += "<%= t['file_name'] %></td><td>";
|
|
||||||
new_tr += "<p><%= format("%.2f", t['usage']*100) %>%</p>"
|
|
||||||
new_tr += "</p></td></tr>"
|
|
||||||
<% end %>
|
|
||||||
$("table .tile_info").append(new_tr);
|
|
||||||
draw_chart();
|
draw_chart();
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
}
|
})
|
||||||
|
|
||||||
|
$(document).on("click", "#file_manager_div .chupper", function(){
|
||||||
|
var current_dir = $("#file_manager_div .chupper span").text();
|
||||||
|
if(current_dir == "/") return;
|
||||||
|
var lastindex = current_dir.lastIndexOf("/");
|
||||||
|
if(lastindex == 0) lastindex++;
|
||||||
|
var next_dir = current_dir.substring(0, lastindex);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "/application/chdir",
|
||||||
|
data: { next_dir : next_dir },
|
||||||
|
success : function(result){
|
||||||
|
$("#current_dir").val(next_dir);
|
||||||
|
$("#file_manager_div").empty();
|
||||||
|
$("#file_manager_div").append("<%= file_manager_table(@current_dir) %>");
|
||||||
|
$('#datatable').dataTable( {"bSort": false});
|
||||||
|
|
||||||
|
// disk usage
|
||||||
|
$("disk_usage_div").empty();
|
||||||
|
$("disk_usage_div").append("<%= disk_usage_table %>");
|
||||||
|
draw_chart();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$(document).on("click", "#file_manager_div .rmdir", function(){
|
||||||
|
var file_name = $(this).text();
|
||||||
|
var current_dir = $("#file_manager_div .chupper span").text();
|
||||||
|
var target = current_dir + "/" + file_name;
|
||||||
|
if(confirm("Are you sure you want to delete '"+ file_name +"' ?")) {
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "/application/delete",
|
||||||
|
data: { target : target },
|
||||||
|
success : function(result){
|
||||||
|
$("#current_dir").val(current_dir);
|
||||||
|
$("#file_manager_div").empty();
|
||||||
|
$("#file_manager_div").append("<%= file_manager_table(@current_dir) %>");
|
||||||
|
$('#datatable').dataTable( {"bSort": false});
|
||||||
|
|
||||||
|
// disk usage
|
||||||
|
$("disk_usage_div").empty();
|
||||||
|
$("disk_usage_div").append("<%= disk_usage_table %>");
|
||||||
|
draw_chart();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Doughnut Chart -->
|
<!-- Doughnut Chart -->
|
||||||
|
@ -6,7 +6,8 @@ Rails.application.routes.draw do
|
|||||||
# You can have the root of your site routed with "root"
|
# You can have the root of your site routed with "root"
|
||||||
root 'home#index'
|
root 'home#index'
|
||||||
|
|
||||||
post 'application/changeDir' => 'application#checkDir'
|
post 'application/chdir' => 'application#chdir'
|
||||||
|
post 'application/rmdir' => 'application#rmdir'
|
||||||
|
|
||||||
get 'index' => 'plainpage#index'
|
get 'index' => 'plainpage#index'
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ Rails.application.routes.draw do
|
|||||||
get 'file_download' => 'home#file_download'
|
get 'file_download' => 'home#file_download'
|
||||||
get 'home/index' => 'home#index'
|
get 'home/index' => 'home#index'
|
||||||
post 'home/mkdir' => 'home#make_directory'
|
post 'home/mkdir' => 'home#make_directory'
|
||||||
post 'home/delete' => 'home#delete_file'
|
|
||||||
|
|
||||||
#Volume
|
#Volume
|
||||||
get 'volume/index' => 'volume#index'
|
get 'volume/index' => 'volume#index'
|
||||||
|
Loading…
Reference in New Issue
Block a user