index.html 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>RAID</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../../script/semantic/semantic.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. <style>
  11. .mdevice{
  12. color: rgb(136, 136, 136);
  13. font-weight: lighter;
  14. }
  15. .mdevuuid{
  16. font-size: 0.6em !important;
  17. }
  18. .volinfo{
  19. text-align: left !important;
  20. margin-top: 0.6em !important;
  21. }
  22. .volinfo .numeric{
  23. font-weight: lighter;
  24. color: #0d79ea;
  25. }
  26. .volinfo .percentage{
  27. font-weight: lighter;
  28. color: rgb(102, 102, 102);
  29. position: absolute;
  30. text-align: right;
  31. right: 1em;
  32. top: 0em;
  33. }
  34. .raidVol .usedvol{
  35. margin-bottom: 2em !important;
  36. }
  37. .raidVol .usedvol .bar{
  38. background-color: #0d79ea !important;
  39. }
  40. .raidVol{
  41. cursor: pointer;
  42. }
  43. .raidVol:hover{
  44. background-color: rgb(240, 240, 240);
  45. }
  46. .raidVol.active{
  47. background-color: rgb(240, 240, 240);
  48. }
  49. .healthIcon{
  50. position: absolute;
  51. left: 35px;
  52. top: 38px;
  53. border-radius: 50% !important;
  54. background-color: white;
  55. }
  56. .healthIcon i {
  57. margin-right: 0 !important;
  58. }
  59. /* RAID Option Button */
  60. .raidOptionBtn{
  61. position: absolute;
  62. top: 1em;
  63. right: 1em;
  64. }
  65. /* Statistics of Device Status */
  66. .deviceOverview{
  67. background-color: #f3f3f3 !important;
  68. border-radius: 0.4em !important;
  69. }
  70. .deviceOverview .ui.statistics .statistic .label{
  71. text-transform: none !important;
  72. font-weight: 300;
  73. }
  74. /* RAID device members */
  75. .raiddevice{
  76. border-radius: 0.4em !important;
  77. margin-bottom: 0 !important;
  78. margin-top: 0 !important;
  79. position: relative;
  80. }
  81. .raiddevice:hover{
  82. background-color: #f3f3f3 !important;
  83. }
  84. .raiddevice .capinfo{
  85. position: absolute;
  86. color:rgb(136, 136, 136);
  87. right: 1em;
  88. top: 1em;
  89. text-align: right;
  90. }
  91. .raiddevice .capinfo .readonlytag{
  92. background-color: #cc3d3a;
  93. color:white;
  94. padding: 2px;
  95. padding-left: 5px;
  96. padding-right: 5px;
  97. }
  98. /* RAID memeber options */
  99. .raidDeviceOptions{
  100. width: 100%;
  101. min-height: 2em;
  102. }
  103. .raidDeviceOptions .content{
  104. float :right;
  105. }
  106. .notMountedLabel{
  107. color:rgb(194, 194, 194);
  108. font-weight: 300;
  109. }
  110. /* Danger zone css */
  111. .dangerzone{
  112. border: 1px solid #dedede;
  113. border-radius: 0.6em;
  114. overflow: hidden;
  115. padding-bottom: 1em;
  116. }
  117. .dangerzone .header{
  118. color:white;
  119. padding: 1em;
  120. background-color: #cc3d3a;
  121. margin-bottom: 1em;
  122. font-weight: bolder;
  123. }
  124. .dangerzone summary{
  125. cursor: pointer;
  126. user-select: none;
  127. }
  128. </style>
  129. </head>
  130. <body>
  131. <br>
  132. <div class="ui container">
  133. <!--
  134. <div class="ui basic segment">
  135. <h3 class="ui header">
  136. <span id="RAIDhealthyState"></span>
  137. <div class="sub header"><span id="RAIDvolCount">0</span> RAID Storage Volume Detected</div>
  138. </h3>
  139. </div>
  140. -->
  141. <div class="ui stackable grid">
  142. <div class="six wide column" style="border-right: 1px solid #e0e0e0;">
  143. <div id="raidVolList">
  144. <p style="text-align: center;"><i class="ui loading spinner icon"></i></p>
  145. </div>
  146. <div class="ui divider"></div>
  147. <div style="width: 100%;" align="center">
  148. <button title="Add new RAID volume" onclick="addNewRaidVolume()" class="circular basic green large ui icon button">
  149. <i class="green add icon"></i>
  150. </button>
  151. <button title="Assemble RAID Pools" onclick="assembleRaidVolumes()" class="circular basic orange large ui icon button">
  152. <i class="orange refresh icon"></i>
  153. </button>
  154. </div>
  155. </div>
  156. <div class="ten wide column">
  157. <div id="volumeDetail">
  158. <div id="raidDiskOverview">
  159. <h3 class="ui header">
  160. <i id="RAIDOverviewStateIcon" class="ui green check circle icon"></i>
  161. <div class="content">
  162. <span id="RAIDOverviewDiskpath">Loading device details</span>
  163. <div class="sub header">
  164. <span id="RAIDOverviewDetails"></span><br>
  165. <small style="font-weight: 300;" id="RAIDUUID"></small>
  166. </div>
  167. </div>
  168. </h3>
  169. <div class="ui divider"></div>
  170. <div class="ui basic segment deviceOverview">
  171. <div class="ui tiny four statistics">
  172. <div class="statistic">
  173. <div class="value">
  174. <img src="../disk/raid/img/drive.svg" class="ui inline image">
  175. <span id="RAIDActiveDevices">0</span>
  176. </div>
  177. <div class="label">
  178. Active Devices
  179. </div>
  180. </div>
  181. <div class="statistic">
  182. <div class="value">
  183. <img src="../disk/raid/img/drive-working.svg" class="ui inline image">
  184. <span id="RAIDWorkingDevices">0</span>
  185. </div>
  186. <div class="label">
  187. Working Devices
  188. </div>
  189. </div>
  190. <div class="statistic">
  191. <div class="value">
  192. <img src="../disk/raid/img/drive-failed.svg" class="ui inline image">
  193. <span id="RAIDFailedDevices">0</span>
  194. </div>
  195. <div class="label">
  196. Failed Devices
  197. </div>
  198. </div>
  199. <div class="statistic">
  200. <div class="value">
  201. <img src="../disk/raid/img/drive-spare.svg" class="ui inline image">
  202. <span id="RAIDSpareDevices">0</span>
  203. </div>
  204. <div class="label">
  205. Spare Devices
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <div class="raidOptionBtn">
  211. <button onclick="reloadRAIDVolDetail();" class="ui basic circular icon button"><i class="ui green refresh icon"></i></button>
  212. </div>
  213. <div>
  214. <button onclick="addDiskToArray();" title="Add new disk to this volume" class="circular small basic ui button">
  215. <i class="green add icon"></i> Add Disk
  216. </button>
  217. <button onclick="" title="Expand volume to fit disks capacity" class="circular small basic ui button">
  218. <i class="purple expand icon"></i> Expand Volume
  219. </button>
  220. </div>
  221. </div>
  222. <div class="ui divider"></div>
  223. <div id="raidDiskList">
  224. </div>
  225. <div class="ui yellow message" style="display:none;" id="raidDataLossWarning">
  226. <i class="yellow exclamation triangle icon"></i> Not enough redundant disks. Further removal / failure of disk will result in data loss.<br>
  227. </div>
  228. <div class="ui divider"></div>
  229. <div style="width: 100%; text-align: center; margin-bottom: 1em;">
  230. <p><i class="yellow exclamation triangle icon"></i> Danger Zone <i class="yellow exclamation triangle icon"></i></p>
  231. </div>
  232. <div style="width: 100%;" align="center">
  233. <button onclick="" class="circular basic red ui button">
  234. <i class="red stop icon"></i> Stop RAID
  235. </button>
  236. <button onclick="RAIDRemove();" class="circular red ui button">
  237. <i class="trash icon"></i> Remove RAID
  238. </button>
  239. </div>
  240. <br><br><br><br>
  241. </div>
  242. <div id="noRAIDVolumeWarning" style="display:none;">
  243. <div class="ui basic segment">
  244. <h4 class="ui header">
  245. <img src="../disk/raid/img/drive-notfound.svg">
  246. <div class="content">
  247. <span>No RAID Volume</span>
  248. <div class="sub header">Create a new RAID volume by pressing the <i class="ui green circle add icon" style="margin-right: 0;"></i> button</div>
  249. </div>
  250. </h4>
  251. </div>
  252. </div>
  253. </div>
  254. </div>
  255. <!-- Disk Remove Confirmation -->
  256. <div id="confirmDiskRemove" class="ui mini modal">
  257. <i class="close icon"></i>
  258. <div class="header">
  259. Confirm Disk Remove
  260. </div>
  261. <div class="image content">
  262. <div class="ui small image">
  263. <img src="../disk/raid/img/remove-warning.svg">
  264. </div>
  265. <div class="description">
  266. <p id="oprconfirm"></p>
  267. <p><b>Removing a disk from RAID volume might risk data loss.</b> Make sure you know what you are doing.<br></p>
  268. </div>
  269. </div>
  270. <div class="actions">
  271. <div class="ui black deny button">
  272. Cancel
  273. </div>
  274. <div class="ui negative left labeled icon button" onclick="confirmRemoveDisk();">
  275. <i class="trash icon"></i>
  276. REMOVE
  277. </div>
  278. </div>
  279. </div>
  280. <!-- RAID Remove Confirmation -->
  281. <div id="confirmRAIDRemove" class="ui small modal">
  282. <i class="close icon"></i>
  283. <div class="header">
  284. Confirm RAID Volume Remove
  285. </div>
  286. <div class="image content">
  287. <div class="ui small image">
  288. <img src="../disk/raid/img/remove-warning.svg">
  289. </div>
  290. <div class="description">
  291. <h4 style="color: rgb(206, 31, 31);"><span id="removingRAIDName"></span></h4>
  292. <p><b>This will clear all stored data in this volume. Please make sure you have backup all important data.</b> Confirm Remove?<br></p>
  293. </div>
  294. </div>
  295. <div class="actions">
  296. <div class="ui black deny button">
  297. Cancel
  298. </div>
  299. <div class="ui negative left labeled icon button" onclick="confirmRAIDRemove();">
  300. <i class="trash icon"></i>
  301. REMOVE
  302. </div>
  303. </div>
  304. </div>
  305. <script>
  306. var raidManager = {
  307. editingArray: "",
  308. removePendingDisk: "",
  309. removePendingSourceVol: ""
  310. };
  311. /* RAID Create Functions */
  312. function addNewRaidVolume(){
  313. //Open newRAID window
  314. parent.newFloatWindow({
  315. url: "SystemAO/disk/raid/newRAID.html#" + Date.now(),
  316. width: 940,
  317. height: 480,
  318. appicon: "SystemAO/disk/raid/img/raid.svg",
  319. title: `New RAID volume`,
  320. parent: ao_module_windowID,
  321. callback: "handleRAIDCreateCallback"
  322. });
  323. }
  324. window.handleRAIDCreateCallback = function(data){
  325. }
  326. /* RAID Remove Function */
  327. function RAIDRemove(){
  328. if (raidManager.editingArray == ""){
  329. console.log("RAID manager have no editing array set")
  330. return;
  331. }
  332. $("#removingRAIDName").text(raidManager.editingArray);
  333. $("#confirmRAIDRemove").modal("show");
  334. }
  335. function confirmRAIDRemove(){
  336. var apiObject = {
  337. api: "../system/disk/raid/remove",
  338. data: {
  339. "raidDev": raidManager.editingArray,
  340. },
  341. title: `<i class='yellow exclamation triangle icon'></i> REMOVE RAID VOLUME <i class='yellow exclamation triangle icon'></i>`,
  342. desc: `Confirm format and remove RAID: ${raidManager.editingArray}`,
  343. thisuser: true, //This username as default, set to false for entering other user
  344. method: "POST",
  345. success: undefined
  346. }
  347. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  348. parent.newFloatWindow({
  349. url: "SystemAO/security/authreq.html#" + apiObject,
  350. width: 480,
  351. height: 300,
  352. appicon: "SystemAO/security/img/lock.svg",
  353. title: `Confirm Disk Remove`,
  354. parent: ao_module_windowID,
  355. callback: "handleRAIDRemoveCallback"
  356. });
  357. }
  358. window.handleRAIDRemoveCallback = function(data){
  359. if (data.error != undefined){
  360. //Something went wrong
  361. alert(data.error);
  362. }else{
  363. setTimeout(function(){
  364. //RAID volume not exist anymore. Reset everything
  365. raidManager = {};
  366. initRAIDVolList();
  367. }, 300);
  368. }
  369. }
  370. /* New Disk Function */
  371. function addDiskToArray(arrayName=raidManager.editingArray){
  372. let payload = {
  373. "md": arrayName,
  374. }
  375. payload = encodeURIComponent(JSON.stringify(payload));
  376. parent.newFloatWindow({
  377. url: "SystemAO/disk/raid/newdisk.html#" + payload,
  378. width: 940,
  379. height: 480,
  380. appicon: "SystemAO/disk/raid/img/raid.svg",
  381. title: `Add new disk to RAID volume ${arrayName}`,
  382. parent: ao_module_windowID,
  383. callback: "handleAddDiskCallback"
  384. });
  385. }
  386. window.handleAddDiskCallback = function(data){
  387. //Done adding disk
  388. setTimeout(function(){
  389. reloadRAIDVolDetail();
  390. }, 300);
  391. }
  392. /* Disk Remove Functions */
  393. function removeDisk(arrayName, diskPath){
  394. console.log(arrayName, diskPath);
  395. $("#oprconfirm").html("Remove <b>" + diskPath + "</b> from <b>" + arrayName + "</b>");
  396. $("#confirmDiskRemove").modal('show');
  397. raidManager.removePendingDisk = diskPath;
  398. raidManager.removePendingSourceVol = arrayName;
  399. }
  400. function confirmRemoveDisk(){
  401. /*
  402. let raidName = raidManager.removePendingSourceVol.split("/").pop();
  403. var apiObject = {
  404. api: "../system/disk/raid/removeMemeber",
  405. data: {
  406. raidDev: raidManager.removePendingSourceVol,
  407. memDev: raidManager.removePendingDisk
  408. },
  409. title: `<i class='yellow exclamation triangle icon'></i> Remove Disk From Volume <i class='yellow exclamation triangle icon'></i>`,
  410. desc: `Confirm remove ${raidManager.removePendingDisk} from ${raidManager.removePendingSourceVol}`,
  411. thisuser: true, //This username as default, set to false for entering other user
  412. method: "POST",
  413. success: undefined
  414. }
  415. apiObject = encodeURIComponent(JSON.stringify(apiObject));
  416. parent.newFloatWindow({
  417. url: "SystemAO/security/authreq.html#" + apiObject,
  418. width: 480,
  419. height: 300,
  420. appicon: "SystemAO/security/img/lock.svg",
  421. title: `Confirm Disk Remove`,
  422. parent: ao_module_windowID,
  423. callback: "handleRemoveDiskCallback"
  424. });
  425. */
  426. $.ajax({
  427. url: "../../system/disk/raid/removeMemeber",
  428. data: {
  429. raidDev: raidManager.removePendingSourceVol,
  430. memDev: raidManager.removePendingDisk
  431. },
  432. method: "POST",
  433. success: function(data){
  434. handleRemoveDiskCallback(data);
  435. }
  436. })
  437. }
  438. //Remove disk completed
  439. window.handleRemoveDiskCallback = function(succ){
  440. console.log(data);
  441. raidManager.removePendingDisk = "";
  442. raidManager.removePendingSourceVol = "";
  443. setTimeout(function(){
  444. reloadRAIDVolDetail();
  445. }, 300);
  446. }
  447. //Quick function to check if the disk is healthy
  448. function isHealthy(stateText) {
  449. // Check if the stateText contains any unhealthy states
  450. if (stateText.includes('faulty') || stateText.includes('resyncing') ||
  451. stateText.includes('recovering') || stateText.includes('degraded') ||
  452. stateText.includes('inactive')) {
  453. return false; // Array is not healthy
  454. } else {
  455. return true; // Array is healthy
  456. }
  457. }
  458. //Get the RAID health state icon from state Text
  459. function getStateIconFromStateText(stateText) {
  460. if (stateText.includes('faulty')) {
  461. return 'ui red times circle icon';
  462. } else if (stateText.includes('resyncing')) {
  463. return 'ui green loading sync icon';
  464. } else if (stateText.includes('recovering')) {
  465. return 'ui yellow loading sync icon';
  466. } else if (stateText.includes('degraded')) {
  467. return 'ui yellow exclamation circle icon';
  468. } else if (stateText.includes('inactive')) {
  469. return 'ui grey check sync icon';
  470. } else if (stateText.includes('active')) {
  471. return 'ui green check circle icon';
  472. } else if (stateText.includes('clean')) {
  473. return 'ui green check circle icon';
  474. } else if (stateText.includes('spare')) {
  475. return 'ui blue check circle icon';
  476. } else if (stateText.includes('reshape')) {
  477. return 'ui blue loading sync icon';
  478. } else if (stateText.includes('frozen')) {
  479. return 'ui blue snowflake icon';
  480. } else {
  481. return 'ui blue question circle icon';
  482. }
  483. }
  484. //Reload the current raid volume detail
  485. function reloadRAIDVolDetail(){
  486. if (raidManager.editingArray != undefined){
  487. initRAIDVolList(raidManager.editingArray);
  488. }
  489. }
  490. function loadRAIDVolDetail(deviceName){
  491. function capitalize(string) {
  492. return string.charAt(0).toUpperCase() + string.slice(1);
  493. }
  494. function bytesToSize(bytes) {
  495. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
  496. if (bytes == 0) return 'n/a';
  497. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  498. if (i == 0) return bytes + ' ' + sizes[i];
  499. return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
  500. };
  501. function uuidv4() {
  502. return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c =>
  503. (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16)
  504. );
  505. }
  506. //Highlight the vol selected
  507. $(".raidVol").removeClass('active');
  508. $(".raidVol").each(function(){
  509. if ($(this).attr("devpath") == deviceName){
  510. $(this).addClass('active');
  511. }
  512. })
  513. let deiviceSizeMap = {};
  514. let workingDiskCount = 0;
  515. //Load the device size map
  516. $.get("../../system/disk/raid/devinfo?devName=" + deviceName, function(sizemap){
  517. deiviceSizeMap = sizemap;
  518. raidManager.editingArray = deviceName;
  519. //Get the information of the device
  520. $.get("../../system/disk/raid/detail?devName=" + deviceName, function(data){
  521. if (data.error != undefined){
  522. $("#raidDiskList").html(`<h3 class="ui header">
  523. <i class="ui red circle times icon"></i>
  524. <div class="content" style="font-weight: 300;">
  525. Unable to load RAID volume information
  526. <div class="sub header">${capitalize(data.error)}</div>
  527. </div>
  528. </h3>`);
  529. return;
  530. }
  531. //Update the active disks info
  532. $("#RAIDOverviewDiskpath").html(data.DevicePath + ` <span class="mdevice">(${data.RaidLevel.toUpperCase()})</span>`);
  533. $("#RAIDOverviewDetails").text("State: " + capitalize(data.State));
  534. $("#RAIDUUID").text(data.UUID);
  535. $("#RAIDActiveDevices").text(data.ActiveDevices);
  536. $("#RAIDWorkingDevices").text(data.WorkingDevices);
  537. $("#RAIDFailedDevices").text(data.FailedDevices);
  538. $("#RAIDSpareDevices").text(data.SpareDevices);
  539. $("#RAIDOverviewStateIcon").attr("class", getStateIconFromStateText(data.State));
  540. //Render the disk list
  541. $("#raidDiskList").html("");
  542. workingDiskCount = data.DeviceInfo.length;
  543. for (var i = 0; i < data.DeviceInfo.length; i++){
  544. let thisDeviceInfo = data.DeviceInfo[i];
  545. let raidDeviceNo = thisDeviceInfo.RaidDevice;
  546. let drivePath = thisDeviceInfo.DevicePath
  547. let driveName = drivePath.split("/").pop();
  548. let driveIcon = "drive-working.svg";
  549. let driveSize = "Unknown";
  550. let driveRWState = "Read Write";
  551. if (thisDeviceInfo.DevicePath = ""){
  552. driveIcon = "drive-notfound.svg"
  553. drivePath = "(Drive unplugged or damaged)"
  554. }
  555. let diskIsFailed = false;
  556. if (thisDeviceInfo.State.includes("faulty")){
  557. //Disk labeled as failed
  558. driveIcon = "drive-failed.svg"
  559. workingDiskCount--;
  560. diskIsFailed = true;
  561. }else if (thisDeviceInfo.State.includes("removed")){
  562. driveIcon = "drive-notfound.svg"
  563. workingDiskCount--;
  564. }else if (thisDeviceInfo.State.includes("rebuilding")){
  565. driveIcon = "drive-spare.svg"
  566. }
  567. if (deiviceSizeMap[driveName] == undefined){
  568. //Disk not found. Is it failed?
  569. driveSize = "";
  570. driveRWState = "";
  571. }else{
  572. driveSize = bytesToSize(deiviceSizeMap[driveName].size);
  573. driveRWState = deiviceSizeMap[driveName].ro?"<span class='readonlytag'>Read Only</span>":"Read Write";
  574. }
  575. //Handle case where raidDeviceNo is -1 (Not mounted / failed)
  576. if (raidDeviceNo == -1){
  577. if (thisDeviceInfo.State.includes("complete")){
  578. raidDeviceNo = "Rebuilding";
  579. }else{
  580. raidDeviceNo = "Faulty";
  581. }
  582. }
  583. //A random UID for this DOM element to make handling easier
  584. let raiddeviceUID = uuidv4();
  585. $("#raidDiskList").append(`<div class="ui basic segment raiddevice ${raiddeviceUID}" domid="${raiddeviceUID}">
  586. <h4 class="ui header">
  587. <img src="../disk/raid/img/${driveIcon}">
  588. <div class="content">
  589. ${raidDeviceNo}: <span class="raidMemberLabel ${driveName}"></span><br>
  590. <small><i class="ui yellow folder icon" style="margin-right: 0.3em;"></i>${drivePath!=""?drivePath:`<span class="notMountedLabel">[Not Mounted]</span>`}</small>
  591. <div class="sub header">${thisDeviceInfo.State.join(" | ")}</div>
  592. </div>
  593. </h4>
  594. <div class="capinfo">
  595. ${driveSize}<br>
  596. <span style="font-size: 0.8em;">${driveRWState}</span>
  597. </div>
  598. <div class="raidDeviceOptions">
  599. <div class="content">
  600. <button class="ui tiny basic button removeDiskBtn ${diskIsFailed?"faulty":"normal"}" onclick="removeDisk('${deviceName}','${driveName}');"><i class="ui red trash icon"></i> Remove Disk</button>
  601. </div>
  602. </div>
  603. </div>`);
  604. if (driveName != "" && drivePath != ""){
  605. $(".raidMemberLabel." + driveName).html(`<i class="ui loading circle notch icon"></i> Resolving disk label`);
  606. resolveDiskLabelToDOM(drivePath, ".raidMemberLabel." + driveName);
  607. }else{
  608. //Invalid disk, e.g. Removed
  609. $(".raiddevice." + raiddeviceUID).find(".raidDeviceOptions").hide();
  610. }
  611. }
  612. //Check if the current setup is already at the min no. of disk
  613. let allowRemoveDisk = true;
  614. if (data.RaidLevel == "raid0"){
  615. //Do not allow for disk remove
  616. allowRemoveDisk = false;
  617. }else if (data.RaidLevel == "raid1" && workingDiskCount < 2){
  618. allowRemoveDisk = false;
  619. }else if (data.RaidLevel == "raid5" && workingDiskCount < 3){
  620. allowRemoveDisk = false;
  621. }else if (data.RaidLevel == "raid6" && workingDiskCount < 4){
  622. allowRemoveDisk = false;
  623. }
  624. if (!allowRemoveDisk){
  625. $(".removeDiskBtn.normal").addClass("disabled");
  626. $("#raidDataLossWarning").show();
  627. }
  628. });
  629. });
  630. }
  631. function resolveDiskLabelToDOM(diskPath, domSelector){
  632. $.get("../../system/disk/devices/model?devName=" + diskPath, function(data){
  633. let diskLabelName = ""
  634. if (data.error == undefined){
  635. //[0] is disk labeled name
  636. //[1] is disk labeled size
  637. diskLabelName = data[0];
  638. }
  639. $(domSelector).html(diskLabelName);
  640. });
  641. }
  642. //Initialize the RAID volume list on this system
  643. //Give selectMDName for auto selecting a volume
  644. function initRAIDVolList(selectMDName=""){
  645. $("#raidVolList").html(`<p style="text-align: center;"><i class="ui loading spinner icon"></i></p>`);
  646. $.get("../../system/disk/raid/list", function(data){
  647. if (data.error != undefined){
  648. $("#raidVolList").html(`<p style="text-align: center;"><i class="ui red circle remove icon"></i> ${data.error}</p>`);
  649. return;
  650. }
  651. $("#raidVolList").html("");
  652. let containUnhealthyDisk = false;
  653. for (var i = 0; i < data.length; i++){
  654. let thisDiskInfo = data[i];
  655. $("#raidVolList").append(`<div class="ui segment raidVol" devpath="${thisDiskInfo.DevicePath}">
  656. <h4 class="ui header">
  657. <img src="../disk/raid/img/raid.svg">
  658. <div class="healthIcon"><i class="${getStateIconFromStateText(thisDiskInfo.State)}"></i></div>
  659. <div class="content" style="margin-left: 0.6em;">
  660. <span>${thisDiskInfo.DevicePath}</span> <span class="mdevice">(${thisDiskInfo.RaidLevel.toUpperCase()})</span>
  661. <div class="sub header mdevuuid" style="margin-top: 0.4em;">
  662. ${thisDiskInfo.UUID}
  663. </div>
  664. </div>
  665. </h4>
  666. </div>`);
  667. if (!isHealthy(thisDiskInfo.State)){
  668. containUnhealthyDisk = true;
  669. }
  670. console.log(thisDiskInfo);
  671. }
  672. if (data.length == 0){
  673. $("#raidVolList").html(`<div><i class="ui green check circle icon"></i> No RAID Volumes</div>`);
  674. $("#volumeDetail").hide();
  675. $("#noRAIDVolumeWarning").show();
  676. }else{
  677. $("#volumeDetail").show();
  678. $("#noRAIDVolumeWarning").hide();
  679. //Load the first RAID vol info
  680. if (selectMDName){
  681. loadRAIDVolDetail(selectMDName);
  682. }else{
  683. loadRAIDVolDetail(data[0].DevicePath);
  684. }
  685. }
  686. $("#RAIDvolCount").text(data.length);
  687. //Update the overall health text
  688. if (containUnhealthyDisk){
  689. $("#RAIDhealthyState").html("<i class='ui yellow exclamation triangle icon'></i> Attention Needed!");
  690. }else{
  691. $("#RAIDhealthyState").html("<i class='ui green circle check icon'></i> Healthy");
  692. }
  693. });
  694. }
  695. initRAIDVolList();
  696. </script>
  697. </body>
  698. </html>