poolList.html 17 KB

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