diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ecdb1ec..e0e9c9d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. # protect_from_forgery with: :exception + include ApplicationHelper def require_login unless user_signed_in? @@ -32,29 +33,8 @@ class ApplicationController < ActionController::Base return df end - def file_directory(dir) - @current_dir = dir - dir_list = `ls #{@current_dir} -l` - parsing_list = dir_list.split("\n") - @files = Array.new - file = Hash.new - - @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] - @files << file - file = Hash.new - end - puts @files - return @files - end - def checkDir - files = file_directory(params[:path]) - render :json => {:file => files , :current => @current_dir} + @current_dir = params[:path] + render :json => {:file => files(@current_dir) , :current => @current_dir} end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 31f552d..01ebf5d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,7 +3,6 @@ class HomeController < ApplicationController def index @current_dir = "/mnt" - file_directory(@current_dir) end def file_download diff --git a/app/controllers/volume_controller.rb b/app/controllers/volume_controller.rb index 7aeb605..5160b82 100644 --- a/app/controllers/volume_controller.rb +++ b/app/controllers/volume_controller.rb @@ -2,7 +2,7 @@ class VolumeController < ApplicationController before_action :require_login def index - file_directory("/mnt") + @current_dir = "/mnt" end def file_upload diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2da8832..c868440 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -51,4 +51,21 @@ module ApplicationHelper return volumes end + def files(dir) + files = Array.new + file = Hash.new + output = `ls #{dir} -l`.split("\n") + output.each do |t| + next if t.equal? output.first + s = t.split(" ") + file["auth"] = s[0] + file["size"] = s[4] + file["date"] = s[5] + " " + s[6] + " " + s[7] + file["name"] = s[8] + files << file + file = Hash.new + end + return files + end + end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 26052bd..99247fd 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -1,3 +1,28 @@ module HomeHelper + def get_du(dir) + du = Array.new + du_each = Hash.new + command = String.new + if dir.eql? "/" + command = "sudo df /" + s = `#{command}`.split("\n")[1].split(" ") + avail = s[2].to_f + s[3].to_f + else + command << "sudo du -s #{dir}" + avail = `#{command}`.split(" ")[0].to_f + end + + command << "sudo du -s #{dir}/*" + puts command + output = `#{command}`.split("\n") + output.each do |t| + du_each['usage'] = t.split(" ")[0].to_f / avail + du_each['file_name'] = t.split(" ")[1].split("/").last + du << du_each + du_each = Hash.new + end + return du + end + end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index c11cbe4..ebddc6b 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -113,7 +113,6 @@
-
@@ -136,7 +135,7 @@ - <% @files.each do |t| %> + <% (files @current_dir).each do |t| %> <% if t["auth"][0]=='d'%> "; new_tr += "" new_tr += ""; + for( var i = 0; i < result.file.length; i++){ var row_class = i % 2 == 0 ? 'odd' : 'even'; var cur = result.current != "/" ? result.current : ''; @@ -374,14 +396,26 @@ function change_directory(directory){ new_tr += ""; new_tr += ""; new_tr += ""; - - new_tr += ""; } + new_table += new_tr; new_table += "
@@ -167,31 +166,53 @@
-

Easy Pie Chart

+

Disk usage

-

Easy pie chart is a jQuery plugin that uses the canvas element to render highly customizable, very easy to implement, simple pie charts for single values.

-
- - - -
-
- - - -
-
- - - -
-
+ + + + + + + + + +
+

Chart

+
+
+

Name

+
+
+

Usage

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

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

+
+

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

+
+
-
+
@@ -357,6 +378,7 @@ function change_directory(directory){ new_tr += "
"+result.file[i].auth+""+result.file[i].size+""+result.file[i].date+"
" $("#table_div").append(new_table); $('#datatable').dataTable( {"bSort": false}); + + // disk usage + $("table .tile_info").empty(); + var new_tr = ""; + <% (get_du @current_dir).each_with_index do |t, index| %> + new_tr += ""; + new_tr += "

"; + new_tr += "<%= t['file_name'] %>"; + new_tr += "

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

" + new_tr += "

" + <% end %> + $("table .tile_info").append(new_tr); + draw_chart(); } }) } @@ -389,57 +423,46 @@ function change_directory(directory){ - + + diff --git a/app/views/volume/index.html.erb b/app/views/volume/index.html.erb index f66f393..6c0fea4 100644 --- a/app/views/volume/index.html.erb +++ b/app/views/volume/index.html.erb @@ -83,7 +83,7 @@ - <% @files.each do |t| %> + <% (files @current_dir).each do |t| %> <% if t["auth"][0]=='d' %>