diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 16080c3..639be94 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -33,8 +33,18 @@ class ApplicationController < ActionController::Base return df end - def checkDir - @current_dir = params[:path] + def chdir + @current_dir = params[:next_dir] + puts "current_dir : " + @current_dir render :json => {:dir => @current_dir} end + + def rmdir + file_name = params[:file_name] + command = String.new + command << "sudo rm -rf #{file_name}" + puts command + `#{command}` + end + end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 01ebf5d..e318978 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -26,14 +26,4 @@ class HomeController < ApplicationController redirect_to '/home/index' 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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3e839b5..28f86df 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -85,8 +85,7 @@ module ApplicationHelper def file_manager_table(dir = "/mnt", id = "datatable", class_option = "table table-striped table-bordered jambo_table") html = String.new - html << "" - + html << "
" html << "" html << "" html << "" @@ -95,12 +94,11 @@ module ApplicationHelper html << "" html << "" html << "" - - html << "" + html << "" html << "" html << "" html << "" @@ -112,24 +110,24 @@ module ApplicationHelper html << "" if file["auth"][0]=='d' html << "" else + conv_name = (dir + '/' + file['name']).gsub("/", "+") html << "" end - html << "" - html << "" - html << "" + html << "" + html << "" html << "" end html << "" html << "
NameDate
" - html << "" - html << " " + dir + html << "" + html << " #{dir}" html << "" html << "
" - html << " " + file['name'] + "" + html << " #{file['name']}" html << "" - html << " " + file['name'] + "" + html << " #{file['name']}" html << "" + file['auth'] + "" + file['size'] + "" - html << file["date"] - html << "" + html << "#{file['auth']}#{file['size']}#{file["date"]}" + html << "" html << "
" - return html + return raw html end end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 0b1e255..01a1cfc 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -19,6 +19,7 @@ module HomeHelper end end + command = "" command << "sudo du -s #{dir}/*" puts command output = `#{command}`.split("\n") @@ -39,4 +40,39 @@ module HomeHelper return du end + def disk_usage_table(dir = "/mnt") + html = String.new + html << "" + html << "" + html << "" + html << "" + html << "" + html << "" + html << "
" + html << "

Chart

" + html << "
" + html << "
" + html << "

Name

" + html << "
" + html << "

Usage

" + html << "
" + html << "" + + get_du(dir).each_with_index do |t, index| + color = ['blue', 'green', 'red', 'purple', 'grey'][index % 5] + html << "" + html << "" + html << "" + end + + html << "
" + html << "

" + html << t['file_name'] + html << "

" + html << format("%.2f", t['usage']*100) + "%" + html << "

" + html << "
" + return html + end + end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index ea08f1f..71cca8f 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -6,10 +6,10 @@ ×
-
@@ -103,6 +103,7 @@
+
@@ -124,8 +125,8 @@
-
- <%= raw file_manager_table %> +
+ <%= file_manager_table @current_dir %>
@@ -138,46 +139,8 @@

Disk usage

-
- - - - - - - - - -
-

Chart

-
-
-

Name

-
-
-

Usage

-
-
- - - - <% get_du(@current_dir).each_with_index do |t, index| %> - - - - - <% end %> -
-

- "> - <%= t['file_name'] %> -

-
-

- <%= format("%.2f", t['usage']*100) %>% -

-
-
+
+ <%= raw disk_usage_table %>
@@ -302,51 +265,77 @@ diff --git a/config/routes.rb b/config/routes.rb index 05aeea8..41b7439 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,8 @@ Rails.application.routes.draw do # You can have the root of your site routed with "root" root 'home#index' - post 'application/changeDir' => 'application#checkDir' + post 'application/chdir' => 'application#chdir' + post 'application/rmdir' => 'application#rmdir' get 'index' => 'plainpage#index' @@ -14,7 +15,6 @@ Rails.application.routes.draw do get 'file_download' => 'home#file_download' get 'home/index' => 'home#index' post 'home/mkdir' => 'home#make_directory' - post 'home/delete' => 'home#delete_file' #Volume get 'volume/index' => 'volume#index'