poolList.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  6. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  7. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  8. <title>Storage Pool Manager</title>
  9. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  10. <style>
  11. .svg-icon {
  12. display: inline-flex;
  13. align-self: center;
  14. }.svg-icon svg {
  15. height:1em;
  16. width:1em;
  17. }
  18. .clickable{
  19. cursor: pointer;
  20. transition: opacity 0.1s ease-in-out;
  21. }
  22. .clickable:hover{
  23. opacity: 0.6;
  24. }
  25. .storagepool.active{
  26. background-color: #f7f7f7;
  27. }
  28. .reloadpoolBtn{
  29. position: absolute;
  30. right: 0.4em;
  31. top: 0.8em;
  32. }
  33. .statusTextWrapper{
  34. text-align: right;
  35. width: 100%;
  36. overflow: hidden;
  37. position: absolute;
  38. bottom: 0px;
  39. right: 0px;
  40. height: 3rem;
  41. display: flex;
  42. justify-content: end;
  43. }
  44. .statusText{
  45. opacity: 0.1;
  46. font-weight: lighter;
  47. font-size: 2em;
  48. align-self:flex-end;
  49. margin-bottom: 0.2em;
  50. margin-right: 0.2em;
  51. pointer-events: none;
  52. user-select: none;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="ui container">
  58. <div class="ui basic segment">
  59. <h3 class="ui header">
  60. Storage Pools
  61. <div class="sub header">Manage system and permission group storage pools</div>
  62. </h3>
  63. </div>
  64. <div id="ok" class="ui basic modal">
  65. <div class="ui icon header">
  66. <i class="green checkmark icon"></i>
  67. Storage Pool Reloaded
  68. </div>
  69. <div class="content" align="center">
  70. <p>Storage Pool has successfully reloaded.</p>
  71. </div>
  72. <div class="actions">
  73. <div class="ui green ok inverted button">
  74. <i class="checkmark icon"></i>
  75. OK
  76. </div>
  77. </div>
  78. </div>
  79. <div class="ui stackable grid">
  80. <div class="six wide column" style="border-right: 1px solid #e0e0e0;">
  81. <div id="poolNameList">
  82. </div>
  83. <div class="ui divider"></div>
  84. <div style="width: 100%;" align="center">
  85. <button title="Reload All Storage Pools" onclick="reloadAllStoragePool();" class="circular basic red large ui icon button">
  86. <i class="red refresh icon"></i>
  87. </button>
  88. </div>
  89. </div>
  90. <div class="ten wide column">
  91. <div id="disklist">
  92. </div>
  93. <div class="ui divider"></div>
  94. <div style="width: 100%;" align="center">
  95. <button onclick="newFsh();" title="Add Storage" class="circular basic large ui icon button">
  96. <i class="add icon"></i>
  97. </button>
  98. <button onclick="bridgeFsh();" title="Bridge Storage" class="circular basic blue large ui icon button">
  99. <i class="linkify icon"></i>
  100. </button>
  101. </div>
  102. </div>
  103. </div>
  104. <script>
  105. var selectedStoragePool = "system";
  106. var storagePoolList = [];
  107. //Create all elements
  108. $(".ui.dropdown").dropdown();
  109. //Render the poollist
  110. loadStoragePoolList();
  111. function loadStoragePoolList(){
  112. $("#poolList").html("");
  113. $.get("../../system/storage/pool/list", function(data){
  114. if (data.error !== undefined){
  115. $("#poolList").html("<p>" + data.error + "</p>");
  116. }else{
  117. $("#poolNameList").html(``);
  118. storagePoolList = data;
  119. data.forEach(storagePool => {
  120. $("#poolNameList").append(` <div class="ui clickable storagepool segment" uuid="${storagePool.Owner}" onclick="loadThisPoolDetails('${storagePool.Owner}');">
  121. <h4 class="ui header storagepool">
  122. <img src="../../img/system/cluster.svg">
  123. <div class="content">
  124. ${storagePool.Owner}
  125. <div class="sub header">
  126. Other's Permission: ${storagePool.OtherPermission}
  127. </div>
  128. </div>
  129. </h4>
  130. <button title="Reload Storage Pool" onclick="reloadStoagePool('${storagePool.Owner}', event);" class="circular tiny basic ui icon button reloadpoolBtn">
  131. <i class="green refresh icon"></i>
  132. </button>
  133. </div>`);
  134. });
  135. }
  136. loadThisPoolDetails(selectedStoragePool);
  137. });
  138. }
  139. function loadThisPoolDetails(owner){
  140. selectedStoragePool = owner;
  141. var targetStoragePool = undefined;
  142. for (var i = 0; i < storagePoolList.length; i++){
  143. let thisStoragePool = storagePoolList[i];
  144. if (thisStoragePool.Owner == owner){
  145. targetStoragePool = thisStoragePool;
  146. break;
  147. }
  148. }
  149. $(".storagepool.active").removeClass("active");
  150. $(".storagepool").each(function(){
  151. if ($(this).attr("uuid") == owner){
  152. $(this).addClass("active");
  153. }
  154. })
  155. $("#disklist").html("");
  156. var storages = targetStoragePool.Storages;
  157. storages.forEach(function(storage){
  158. var color = "#8adb9d";
  159. var isReserved = false;
  160. var driveIcon = "drive-virtual.svg";
  161. var statusText = "Online";
  162. var statusClass = ""
  163. if (storage.UUID == "tmp" || storage.UUID == "user"){
  164. isReserved = true;
  165. color = "#fade8e";
  166. statusClass = "online"
  167. }else if (storage.Closed == true){
  168. color = "#7d7d7d";
  169. statusText = "Stopped"
  170. statusClass = "stopped"
  171. }
  172. if (storage.Hierarchy == "public"){
  173. driveIcon = "drive-public.svg";
  174. }else if (isReserved){
  175. driveIcon = "drive.svg";
  176. }
  177. var editButtons = `<button onclick="editFsh('${storage.UUID}','${owner}');" title="Edit Virtual Disk" onclick="" class="circular tiny basic ui icon button editButton">
  178. <i class="edit icon"></i>
  179. </button>
  180. <button onclick="toggleFsh('${storage.UUID}','${owner}');" title="Toggle Virtual Disk IO" onclick="" class="circular tiny basic ui icon button shutdownButton">
  181. <i class="power icon"></i>
  182. </button>
  183. <button onclick="removeFsh('${storage.UUID}','${owner}');" title="Remove Virtual Disk" onclick="" class="circular tiny basic ui icon button removeFshButton">
  184. <i class="red remove icon"></i>
  185. </button>`;
  186. $("#disklist").append(`<div class="ui vdisk segment ${statusClass}" uuid="${storage.UUID}" style="border-left: 3px solid ${color};">
  187. <h4 class="ui header storagepool">
  188. <img src="../../img/system/${driveIcon}">
  189. <div class="content">
  190. ${storage.Name} (${storage.UUID}:/)
  191. <div class="sub header" style="margin-top: 0.4em;">
  192. <div class="ui list">
  193. <div class="item">Mount Point: ${storage.Path}</div>
  194. <div class="item">Hierarchy: ${storage.Hierarchy}</div>
  195. <div class="item">ReadOnly: ${storage.ReadOnly}</div>
  196. </div>
  197. </div>
  198. </div>
  199. </h4>
  200. <div class="fshbuttons" style="position: absolute; top: 0.8em; right: 0.8em;">
  201. ${isReserved?`<span style="color: #c9c9c9; pointer-events: none; user-select: none;">System Reserved</span>`:editButtons}
  202. </div>
  203. <div class="statusTextWrapper">
  204. <div class="statusText">
  205. ${statusText}
  206. </div>
  207. </div>
  208. </div>`);
  209. });
  210. if (storages.length == 0){
  211. $("#disklist").append(`<div class="ui segment nostorage" style="border-left: 3px solid #303030;">
  212. <h4 class="ui header storagepool">
  213. <img src="../../img/system/drive-notfound.svg">
  214. <div class="content">
  215. No Storage
  216. <div class="sub header" style="margin-top: 0.4em;">
  217. No storage found under this Storage Pool
  218. </div>
  219. </div>
  220. </h4>
  221. `);
  222. }
  223. $.get("../../system/storage/pool/listraw?target=" + owner, function(data){
  224. if (data.error == undefined){
  225. data.forEach(function(storage){
  226. console.log(storage);
  227. let thisStorageUUID = storage.uuid;
  228. let matchingDiskFound = false;
  229. $(".vdisk").each(function(){
  230. if ($(this).attr("uuid") == thisStorageUUID && !$(this).hasClass("stopped")){
  231. $(this).addClass("online");
  232. $(this).find(".statusText").text("Online");
  233. matchingDiskFound = true;
  234. }else if ($(this).hasClass("stopped")){
  235. //Found but it has been shutted
  236. matchingDiskFound = true;
  237. }
  238. });
  239. if (!matchingDiskFound){
  240. //Add offline disk record to the list
  241. $("#disklist").append(`<div class="ui vdisk segment offline" uuid="${storage.uuid}" style="border-left: 3px solid #3e3a39;">
  242. <h4 class="ui header storagepool">
  243. <img src="../../img/system/drive-notfound.svg">
  244. <div class="content">
  245. ${storage.name} (${storage.uuid}:/)
  246. <div class="sub header" style="margin-top: 0.4em;">
  247. <div class="ui list">
  248. <div class="item">Mount Point: ${storage.path}</div>
  249. <div class="item">Hierarchy: ${storage.hierarchy}</div>
  250. <div class="item">ReadOnly: ${storage.access=="readonly"}</div>
  251. </div>
  252. </div>
  253. </div>
  254. </h4>
  255. <div class="fshbuttons" style="position: absolute; top: 0.8em; right: 0.8em;">
  256. <button title="Edit Virtual Disk" onclick="editFsh('${storage.uuid}','${selectedStoragePool}');" class="circular tiny basic ui icon button">
  257. <i class="edit icon"></i>
  258. </button>
  259. <button onclick="removeFsh('${storage.uuid}','${selectedStoragePool}');" title="Remove Virtual Disk" onclick="" class="circular tiny basic ui icon button removeFshButton">
  260. <i class="red remove icon"></i>
  261. </button>
  262. </div>
  263. <div class="statusTextWrapper">
  264. <div class="statusText">
  265. Offline
  266. </div>
  267. </div>
  268. </div>`);
  269. }
  270. });
  271. $('.vdisk').each(function(){
  272. if (!$(this).hasClass("online") && !$(this).hasClass("offline") && !$(this).hasClass("stopped")){
  273. //This pool record not exists in json file, check if this is bridged
  274. var fshid = $(this).attr("uuid");
  275. let thisFsh = $(this);
  276. $.ajax({
  277. url: "../../system/storage/pool/checkBridge",
  278. data: {base: selectedStoragePool, fsh: fshid},
  279. success: function(data){
  280. if (data == true){
  281. thisFsh.find(".shutdownButton").hide();
  282. thisFsh.find(".editButton").hide();
  283. thisFsh.css({
  284. "border-left": "3px solid #e29eff",
  285. });
  286. thisFsh.find("img").attr('src', '../../img/system/drive-bridge.svg');
  287. thisFsh.find(".statusText").text("Bridged");
  288. }else{
  289. thisFsh.find(".fshbuttons").hide();
  290. thisFsh.css({
  291. "border-left": "3px dotted #ff6666",
  292. });
  293. thisFsh.find(".statusText").text("Removed");
  294. }
  295. }
  296. });
  297. }
  298. });
  299. }
  300. if ($(".vdisk").length > 0 && $(".nostorage").length > 0){
  301. $(".nostorage").remove();
  302. }
  303. });
  304. }
  305. function editSelectedPool(){
  306. if (selectedStoragePool == ""){
  307. console.log("Pool not selected: ", selectedStoragePool)
  308. return
  309. }
  310. ao_module_newfw({
  311. url:"SystemAO/storage/poolEditor.html#" + encodeURIComponent(selectedStoragePool),
  312. width: 530,
  313. height: 740,
  314. appicon: "SystemAO/storage/img/icon.png",
  315. title: "Edit Storage Pool",
  316. callback: "finishCreateHandler",
  317. parent: ao_module_windowID
  318. });
  319. }
  320. function finishCreateHandler(state){
  321. //Reload the list
  322. loadStoragePoolList();
  323. }
  324. function reloadAllStoragePool(){
  325. if (confirm("THIS WILL CRASH THE SYSTEM IF YOUR CONFIG IS INVALID. CONFIRM?")){
  326. //OK. Reload storage pool for this pool
  327. $.ajax({
  328. url: "../../system/storage/pool/reload?pool=1eb201a3-d0f6-6630-5e6d-2f40480115c5",
  329. success: function(data){
  330. console.log(data);
  331. loadStoragePoolList();
  332. $("#ok").modal("show");
  333. },
  334. error: function(){
  335. loadStoragePoolList();
  336. }
  337. });
  338. }
  339. }
  340. function bridgeFsh(){
  341. let url = "SystemAO/storage/fshBridge.html#" + encodeURIComponent(JSON.stringify({group: selectedStoragePool}))
  342. if (typeof(ao_module_newfw) == "undefined"){
  343. window.open("../../" + url);
  344. return
  345. }
  346. ao_module_newfw({
  347. url: url,
  348. width: 530,
  349. height: 740,
  350. appicon: "SystemAO/storage/img/bridge.svg",
  351. title: "New File System Handler Bridging",
  352. callback: "finishFshEdit",
  353. parent: ao_module_windowID
  354. });
  355. }
  356. function editFsh(uuid, gpname){
  357. if (typeof(ao_module_newfw) == "undefined"){
  358. window.open("../../SystemAO/storage/fshedit.html#" + encodeURIComponent(JSON.stringify({uuid: uuid, group: gpname})));
  359. return
  360. }
  361. ao_module_newfw({
  362. url:"SystemAO/storage/fshedit.html#" + encodeURIComponent(JSON.stringify({uuid: uuid, group: gpname})),
  363. width: 530,
  364. height: 740,
  365. appicon: "SystemAO/storage/img/fsh.svg",
  366. title: "Edit File System Handler",
  367. callback: "finishFshEdit",
  368. parent: ao_module_windowID
  369. });
  370. }
  371. function newFsh(){
  372. if (typeof(ao_module_newfw) == "undefined"){
  373. window.open("../../SystemAO/storage/fshedit.html#" + encodeURIComponent(JSON.stringify({group: selectedStoragePool})));
  374. return
  375. }
  376. ao_module_newfw({
  377. url:"SystemAO/storage/fshedit.html#" + encodeURIComponent(JSON.stringify({group: selectedStoragePool})),
  378. width: 530,
  379. height: 740,
  380. appicon: "SystemAO/storage/img/fsh.svg",
  381. title: "New File System Handler",
  382. callback: "finishFshEdit",
  383. parent: ao_module_windowID
  384. });
  385. }
  386. function reloadStoagePool(owner, event){
  387. event.preventDefault();
  388. event.stopImmediatePropagation();
  389. if (confirm("Confirm reloading " + owner + " storage pool?")){
  390. //OK. Reload storage pool for this pool
  391. $.ajax({
  392. url: "../../system/storage/pool/reload",
  393. data: {pool: owner},
  394. success: function(data){
  395. console.log(data);
  396. loadStoragePoolList();
  397. $("#ok").modal("show");
  398. },
  399. error: function(){
  400. loadStoragePoolList();
  401. }
  402. });
  403. }
  404. }
  405. function toggleFsh(uuid, gpname){
  406. $.ajax({
  407. url: "../../system/storage/pool/toggle",
  408. data: {"fsh":uuid, "group": gpname},
  409. success: function(data){
  410. if (data.error !== undefined){
  411. alert(data.error);
  412. }else{
  413. loadStoragePoolList();
  414. }
  415. }
  416. })
  417. }
  418. function removeFsh(uuid, group){
  419. if (confirm("Confirm removing FSH: " + uuid + ":/ ?")){
  420. $.ajax({
  421. url: "../../system/storage/pool/removeHandler",
  422. data: {uuid: uuid, group: group},
  423. success: function(data){
  424. if (data.error !== undefined){
  425. alert(data.error);
  426. }else{
  427. //Remove succeed
  428. loadStoragePoolList();
  429. }
  430. }
  431. });
  432. }
  433. }
  434. window.finishFshEdit = function(){
  435. loadStoragePoolList();
  436. }
  437. </script>
  438. </body>
  439. </html>