gluster-web-interface/app/helpers/home_helper.rb

150 lines
5.7 KiB
Ruby
Raw Normal View History

2016-08-20 06:41:37 +00:00
module HomeHelper
2016-09-24 09:00:27 +00:00
2016-10-02 12:38:57 +00:00
def html_file_manager_table(dir = @current_dir, id = "file_manager_table", class_option = "table table-striped table-bordered jambo_table")
2016-09-27 03:14:39 +00:00
html = String.new
html << "<table id='#{id}' class='#{class_option}'>"
html << "<thead>"
html << "<tr class='headings'>"
html << "<th>Name</th>"
html << "<th>auth</th>"
html << "<th>Size</th>"
html << "<th>Date</th>"
html << "</tr>"
html << "</thead>"
html << "<tbody id='#{id}_body'>"
html << "<tr>"
html << "<td>"
2016-09-28 16:39:22 +00:00
html << "<a class='chupper' style='cursor: pointer'><i class='fa fa-reply'></i></a> "
html << "<span style='line-height:0'>#{dir}</span>"
2016-09-27 03:14:39 +00:00
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></td>"
html << "<td></td>"
html << "<td></td>"
html << "</tr>"
2016-09-27 03:14:39 +00:00
files(dir).each do |file|
html << "<tr class='dir_delete'>"
if file["auth"][0]=='d'
html << "<td style='color:#0d8ade;'><i class='fa fa-folder-open-o'></i>"
html << "<a class='chdir' style='cursor: pointer'> #{file['name']}</a>"
html << "</td>"
else
conv_name = (dir + '/' + file['name']).gsub("/", "+")
html << "<td><i class='fa fa-file-o'></i>"
html << "<a href='/file_download?file_name=#{conv_name}'> #{file['name']}</a>"
html << "</td>"
2016-09-26 09:06:53 +00:00
end
2016-09-27 03:14:39 +00:00
html << "<td>#{file['auth']}</td>"
html << "<td>#{file['size']}</td>"
html << "<td>#{file["date"]}"
html << "<a class='pull-right rmdir' href='#'><i class='fa fa-trash'></i></a>"
html << "</td>"
html << "</tr>"
end
2016-09-27 03:14:39 +00:00
html << "</tbody>"
html << "</table>"
return html
end
2016-10-02 12:38:57 +00:00
def html_disk_usage_table(dir = @current_dir, id = "disk_usage_table")
2016-09-26 16:53:09 +00:00
html = String.new
2016-09-27 03:36:30 +00:00
html << "<table id='#{id}' class='' style='width:100%'>"
2016-09-26 16:53:09 +00:00
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>"
2016-09-27 03:36:30 +00:00
html << "<td><canvas id='#{id}_canvas' height='140' width='140' style='margin: 15px 10px 10px 0'></canvas></td>"
2016-09-26 16:53:09 +00:00
html << "<td>"
2016-09-28 16:39:22 +00:00
html << "<table id='disk_usage_tile_table' class='tile_info'>"
html << "<thead>"
html << "<tr class='headings'>"
html << "<th></th>"
html << "<th></th>"
html << "</tr>"
html << "</thead>"
html << "<tbody>"
2016-09-26 16:53:09 +00:00
2016-09-27 03:14:39 +00:00
get_du(dir).each_with_index do |file, index|
2016-09-26 16:53:09 +00:00
color = ['blue', 'green', 'red', 'purple', 'grey'][index % 5]
html << "<tr><td>"
2016-09-27 09:57:48 +00:00
html << "<div class='col-lg-7 col-md-7 col-sm-7 col-xs-7'>"
html << "<p><i class='fa fa-square #{color}'></i> "
2016-09-27 03:14:39 +00:00
html << file['file_name']
2016-09-27 09:57:48 +00:00
html << "</p></div>"
html << "</td><td>"
html << "<div class='col-lg-7 col-md-7 col-sm-7 col-xs-7'>"
html << "<p style='float:right'>"
2016-09-27 03:14:39 +00:00
html << format("%.2f", file['usage']*100) + "%"
2016-09-27 09:57:48 +00:00
html << "</p></div>"
html << "</td></tr>"
2016-09-26 16:53:09 +00:00
end
2016-09-28 16:39:22 +00:00
html << "</tbody>"
2016-09-26 16:53:09 +00:00
html << "</table>"
html << "</td></tr>"
html << "</table>"
return html
end
2016-10-03 06:14:14 +00:00
def html_disk_file_table(dir = @current_dir, id = "disk_file_table")
html = String.new
2016-10-03 06:56:43 +00:00
html << "<div class='fixed_height_320' style='overflow-y:auto;'>"
2016-10-03 06:14:14 +00:00
html << "<table id='#{id}' 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='#{id}_canvas' height='140' width='140' style='margin: 15px 10px 10px 0'></canvas></td>"
html << "<td>"
html << "<table id='disk_file_table' class='tile_info'>"
html << "<thead>"
html << "<tr class='headings'>"
html << "<th></th>"
html << "<th></th>"
html << "</tr>"
html << "</thead>"
html << "<tbody>"
2016-10-03 07:33:46 +00:00
nodes = Node.all
2016-10-03 06:14:14 +00:00
get_df.each_with_index do |file, index|
2016-10-03 06:56:43 +00:00
# show mounted files only
2016-10-03 07:33:46 +00:00
ip = file['Filesystem'].split(":").first
next if nodes.select{|node| node["host_ip"].eql? ip}.length == 0
2016-10-03 06:56:43 +00:00
2016-10-03 06:14:14 +00:00
color = ['blue', 'green', 'red', 'purple', 'grey'][index % 5]
html << "<tr><td>"
html << "<div class='col-lg-7 col-md-7 col-sm-7 col-xs-7'>"
html << "<p><i class='fa fa-square #{color}'></i> "
2016-10-03 07:33:46 +00:00
html << file['Mounted on']
2016-10-03 06:14:14 +00:00
html << "</p></div>"
html << "</td><td>"
html << "<div class='col-lg-7 col-md-7 col-sm-7 col-xs-7'>"
html << "<p style='float:right'>"
2016-10-03 06:56:43 +00:00
html << file["Use%"]
2016-10-03 06:14:14 +00:00
html << "</p></div>"
html << "</td></tr>"
end
html << "</tbody>"
html << "</table>"
html << "</td></tr>"
html << "</table>"
2016-10-03 06:56:43 +00:00
html << "</div>"
2016-10-03 06:14:14 +00:00
return html
2016-10-03 05:20:56 +00:00
end
2016-08-20 06:41:37 +00:00
end