smart.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <html>
  2. <head>
  3. <title>Disk SMART</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. <link rel="stylesheet" href="../disk/quota/script/Chart.min.css">
  8. <script type="text/javascript" src="../../../script/jquery.min.js"></script>
  9. <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
  10. <script src="../disk/quota/script/Chart.min.js"></script>
  11. <style>
  12. </style>
  13. </head>
  14. <body>
  15. <div class="ui container">
  16. <p>Drive SMART</p>
  17. <h1 class="ui header">
  18. <span id="healthy">Loading</span>
  19. <div class="sub header"><span id="totaldisk">N/A</span> disks detected.</div>
  20. </h1>
  21. <div class="ui divider"></div>
  22. <p id="loadWarning"><i class="ui loading spinner icon"></i> Loading SMART data...</p>
  23. <div id="smart-holder" class="ui unstackable items">
  24. </div>
  25. <br>
  26. <div class="ui divider"></div>
  27. </div>
  28. <div class="ui modal">
  29. <i class="close icon"></i>
  30. <div class="header">
  31. SMART Information (<span id="modal_model"></span>)
  32. </div>
  33. <div class="content">
  34. <table class="ui very basic fluid celled table">
  35. <thead>
  36. <tr><th>ID</th>
  37. <th>Name</th>
  38. <th>Value</th>
  39. <th>Worst</th>
  40. <th>Thresh</th>
  41. <th>Status</th>
  42. </tr></thead>
  43. <tbody id="modal_smart">
  44. <tr>
  45. <td>
  46. ...
  47. </td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. </div>
  52. <div class="actions">
  53. <div class="ui black deny button">
  54. Close
  55. </div>
  56. </div>
  57. </div>
  58. <script>
  59. var smart_template = `<div class="item">
  60. <div class="tiny image" style="width: auto !important; margin-top: -10px;">
  61. <img src="/SystemAO/disk/smart/img/hard-drive.svg" style="height:60px;width:auto; padding: 8px;">
  62. </div>
  63. <div class="content">
  64. <p class="header">{model}</p>
  65. <button class="ui right floated icon button" id="{id}" onclick="showDetails(this)"><i class="info icon"></i></button>
  66. <div class="meta"><span>{status}</span></div>
  67. <div class="description"><p></p></div>
  68. <div class="extra">{capacity}</div>
  69. </div>
  70. </div>`;
  71. var smartDATA;
  72. $.getJSON("/system/disk/smart/getSMART", function(data) {
  73. smartDATA = data;
  74. $("#mainmenu").html("");
  75. if (data.devices == null || $(data).length == 0) {
  76. //$("#smart-holder").append(append("-1","No disk find!","",-1));
  77. $("#healthy").text("No disks detected.");
  78. $("#totaldisk").text("0");
  79. }else{
  80. $.each(data.devices, function(index, value) {
  81. $("#smart-holder").append(append(index,value.smart.model_name,value.smart.healthy,value.smart.user_capacity.bytes));
  82. });
  83. $("#healthy").text(data.healthy);
  84. $("#totaldisk").text(data.devices.length);
  85. }
  86. $("#loadWarning").remove();
  87. });
  88. //Execute once when the page load, to destroy the old model
  89. /*
  90. This section was added because once the page changed, multiple modal
  91. is appended to the page which lead to duplication of modal when calling
  92. modal("show"). Do not remove the 3 lines below.
  93. */
  94. $(".loadedModal").modal('destroy');
  95. $(".loadedModal").remove();
  96. $(".ui.modal").addClass("loadedModal");
  97. function append(id, name, status, capacity){
  98. var tmp = smart_template;
  99. tmp = tmp.replaceAll("{id}",id);
  100. tmp = tmp.replaceAll("{model}",name);
  101. tmp = tmp.replaceAll("{status}",status);
  102. tmp = tmp.replaceAll("{capacity}",disksize(capacity));
  103. return tmp;
  104. }
  105. function disksize(size) {
  106. if (size >= 1000000000000) {
  107. return Math.floor(size / 1000000000000) + " TB";
  108. } else if (size >= 1000000000) {
  109. return Math.floor(size / 1000000000) + " GB";
  110. } else if (size >= 1000000) {
  111. return Math.floor(size / 1000000) + " MB";
  112. } else if (size >= 1024) {
  113. return Math.floor(size / 1000) + " KB";
  114. } else if (size > 0) {
  115. return size + " Bytes";
  116. } else if (size == 0) {
  117. return "Unknown capacity";
  118. } else {
  119. return "";
  120. }
  121. }
  122. function showDetails(selector) {
  123. $("#modal_smart").html("");
  124. var id = $(selector).attr("id");
  125. $("#modal_model").text(smartDATA.devices[id].smart.model_name);
  126. $.each(smartDATA.devices[id].smart.ata_smart_attributes.table, function(index, value) {
  127. $("#modal_smart").append("<tr>");
  128. $("#modal_smart").append("<td>" + value.id + "</td>");
  129. $("#modal_smart").append("<td>" + value.name + "</td>");
  130. $("#modal_smart").append("<td>" + value.value + "</td>");
  131. $("#modal_smart").append("<td>" + value.worst + "</td>");
  132. $("#modal_smart").append("<td>" + value.thresh + "</td>");
  133. $("#modal_smart").append("<td>" + value.healthy + "</td>");
  134. $("#modal_smart").append("</tr>");
  135. });
  136. $('.ui.modal').modal('show');
  137. }
  138. </script>
  139. </body>
  140. </html>