diskspace.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <html>
  2. <head>
  3. <title>Disk Space</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../../script/semantic/semantic.min.css">
  7. <script type="text/javascript" src="../../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
  9. <style>
  10. #diskInfo{
  11. padding-left:22px;
  12. }
  13. .usedSpace{
  14. margin-top: -0.8em;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <button class="ui small button" onclick="toggleTmpfs();">Toggle tmpfs</button>
  20. <div id="diskInfo" class="ui feed">
  21. </div>
  22. <script>
  23. initDiskInfo();
  24. function initDiskInfo(){
  25. $("#diskInfo").html("");
  26. $.get("../../system/disk/space/list",function(data){
  27. if (data.error !== undefined){
  28. alert(data.error);
  29. }else{
  30. for (var i = 0; i < data.length; i++){
  31. var thisDev = data[i];
  32. var usedPercentage = parseInt(thisDev.Used / thisDev.Volume * 100);
  33. var color = "blue";
  34. if (usedPercentage >= 90){
  35. color = "red";
  36. }
  37. if (thisDev.Used == 0 && thisDev.Volume == 0){
  38. color = "black";
  39. console.log("Oops");
  40. usedPercentage = 100;
  41. }
  42. var tmpfs = "";
  43. var style = "";
  44. if (thisDev.Device == "tmpfs"){
  45. tmpfs = "tmpfs";
  46. style = "display:none;";
  47. }
  48. $("#diskInfo").append(`<div class="event ${tmpfs}" style="${style}">
  49. <div class="label">
  50. <img src="../disk/space/img/disk.svg">
  51. </div>
  52. <div class="content">
  53. <div class="summary">
  54. ${thisDev.MountPoint}
  55. <div class="date">
  56. (${thisDev.Device})
  57. </div>
  58. </div>
  59. <div class="extra text" style="width:100% !important;">
  60. <div class="ui small ${color} active progress">
  61. <div class="bar" style="width:${usedPercentage}%;">
  62. <div class="progress">${usedPercentage}%</div>
  63. </div>
  64. <div class="label">Free: ${bytesToSize(thisDev.Available)} / Total: ${bytesToSize(thisDev.Volume)}</div>
  65. </div>
  66. </div>
  67. </div>
  68. </div>`);
  69. }
  70. }
  71. })
  72. }
  73. function bytesToSize(bytes) {
  74. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  75. if (bytes == 0) return '0 Byte';
  76. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  77. return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
  78. }
  79. function toggleTmpfs(){
  80. $(".tmpfs").slideToggle();
  81. }
  82. </script>
  83. </body>
  84. </html>