cluster_collections.templ 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. package app
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/admin/dash"
  5. )
  6. templ ClusterCollections(data dash.ClusterCollectionsData) {
  7. <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
  8. <h1 class="h2">
  9. <i class="fas fa-layer-group me-2"></i>Cluster Collections
  10. </h1>
  11. <div class="btn-toolbar mb-2 mb-md-0">
  12. <div class="btn-group me-2">
  13. <button type="button" class="btn btn-sm btn-outline-primary" onclick="exportCollections()">
  14. <i class="fas fa-download me-1"></i>Export
  15. </button>
  16. </div>
  17. </div>
  18. </div>
  19. <div id="collections-content">
  20. <!-- Summary Cards -->
  21. <div class="row mb-4">
  22. <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
  23. <div class="card border-left-primary shadow h-100 py-2">
  24. <div class="card-body">
  25. <div class="row no-gutters align-items-center">
  26. <div class="col mr-2">
  27. <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
  28. Total Collections
  29. </div>
  30. <div class="h5 mb-0 font-weight-bold text-gray-800">
  31. {fmt.Sprintf("%d", data.TotalCollections)}
  32. </div>
  33. </div>
  34. <div class="col-auto">
  35. <i class="fas fa-layer-group fa-2x text-gray-300"></i>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
  42. <div class="card border-left-info shadow h-100 py-2">
  43. <div class="card-body">
  44. <div class="row no-gutters align-items-center">
  45. <div class="col mr-2">
  46. <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
  47. Regular Volumes
  48. </div>
  49. <div class="h5 mb-0 font-weight-bold text-gray-800">
  50. {fmt.Sprintf("%d", data.TotalVolumes)}
  51. </div>
  52. </div>
  53. <div class="col-auto">
  54. <i class="fas fa-database fa-2x text-gray-300"></i>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
  61. <div class="card border-left-success shadow h-100 py-2">
  62. <div class="card-body">
  63. <div class="row no-gutters align-items-center">
  64. <div class="col mr-2">
  65. <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
  66. EC Volumes
  67. </div>
  68. <div class="h5 mb-0 font-weight-bold text-gray-800">
  69. {fmt.Sprintf("%d", data.TotalEcVolumes)}
  70. </div>
  71. </div>
  72. <div class="col-auto">
  73. <i class="fas fa-th-large fa-2x text-gray-300"></i>
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
  80. <div class="card border-left-warning shadow h-100 py-2">
  81. <div class="card-body">
  82. <div class="row no-gutters align-items-center">
  83. <div class="col mr-2">
  84. <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
  85. Total Files
  86. </div>
  87. <div class="h5 mb-0 font-weight-bold text-gray-800">
  88. {fmt.Sprintf("%d", data.TotalFiles)}
  89. </div>
  90. </div>
  91. <div class="col-auto">
  92. <i class="fas fa-file fa-2x text-gray-300"></i>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 mb-4">
  99. <div class="card border-left-secondary shadow h-100 py-2">
  100. <div class="card-body">
  101. <div class="row no-gutters align-items-center">
  102. <div class="col mr-2">
  103. <div class="text-xs font-weight-bold text-secondary text-uppercase mb-1">
  104. Total Storage Size (Logical)
  105. </div>
  106. <div class="h5 mb-0 font-weight-bold text-gray-800">
  107. {formatBytes(data.TotalSize)}
  108. </div>
  109. </div>
  110. <div class="col-auto">
  111. <i class="fas fa-hdd fa-2x text-gray-300"></i>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. <!-- Collections Table -->
  119. <div class="card shadow mb-4">
  120. <div class="card-header py-3">
  121. <h6 class="m-0 font-weight-bold text-primary">
  122. <i class="fas fa-layer-group me-2"></i>Collection Details
  123. </h6>
  124. </div>
  125. <div class="card-body">
  126. if len(data.Collections) > 0 {
  127. <div class="table-responsive">
  128. <table class="table table-hover" id="collectionsTable">
  129. <thead>
  130. <tr>
  131. <th>Collection Name</th>
  132. <th>Regular Volumes</th>
  133. <th>EC Volumes</th>
  134. <th>Files</th>
  135. <th>Size (Logical)</th>
  136. <th>Disk Types</th>
  137. <th>Actions</th>
  138. </tr>
  139. </thead>
  140. <tbody>
  141. for _, collection := range data.Collections {
  142. <tr>
  143. <td>
  144. <a href={templ.SafeURL(fmt.Sprintf("/cluster/collections/%s", collection.Name))} class="text-decoration-none">
  145. <strong>{collection.Name}</strong>
  146. </a>
  147. </td>
  148. <td>
  149. <a href={templ.SafeURL(fmt.Sprintf("/cluster/volumes?collection=%s", collection.Name))} class="text-decoration-none">
  150. <div class="d-flex align-items-center">
  151. <i class="fas fa-database me-2 text-muted"></i>
  152. if collection.VolumeCount > 0 {
  153. {fmt.Sprintf("%d", collection.VolumeCount)}
  154. } else {
  155. <span class="text-muted">0</span>
  156. }
  157. </div>
  158. </a>
  159. </td>
  160. <td>
  161. <a href={templ.SafeURL(fmt.Sprintf("/cluster/ec-shards?collection=%s", collection.Name))} class="text-decoration-none">
  162. <div class="d-flex align-items-center">
  163. <i class="fas fa-th-large me-2 text-muted"></i>
  164. if collection.EcVolumeCount > 0 {
  165. {fmt.Sprintf("%d", collection.EcVolumeCount)}
  166. } else {
  167. <span class="text-muted">0</span>
  168. }
  169. </div>
  170. </a>
  171. </td>
  172. <td>
  173. <div class="d-flex align-items-center">
  174. <i class="fas fa-file me-2 text-muted"></i>
  175. {fmt.Sprintf("%d", collection.FileCount)}
  176. </div>
  177. </td>
  178. <td>
  179. <div class="d-flex align-items-center">
  180. <i class="fas fa-hdd me-2 text-muted"></i>
  181. {formatBytes(collection.TotalSize)}
  182. </div>
  183. </td>
  184. <td>
  185. for i, diskType := range collection.DiskTypes {
  186. if i > 0 {
  187. <span class="me-1"></span>
  188. }
  189. <span class={fmt.Sprintf("badge bg-%s me-1", getDiskTypeColor(diskType))}>{diskType}</span>
  190. }
  191. if len(collection.DiskTypes) == 0 {
  192. <span class="text-muted">Unknown</span>
  193. }
  194. </td>
  195. <td>
  196. <button type="button"
  197. class="btn btn-outline-primary btn-sm"
  198. title="View Details"
  199. data-action="view-details"
  200. data-name={collection.Name}
  201. data-datacenter={collection.DataCenter}
  202. data-volume-count={fmt.Sprintf("%d", collection.VolumeCount)}
  203. data-ec-volume-count={fmt.Sprintf("%d", collection.EcVolumeCount)}
  204. data-file-count={fmt.Sprintf("%d", collection.FileCount)}
  205. data-total-size={fmt.Sprintf("%d", collection.TotalSize)}
  206. data-disk-types={formatDiskTypes(collection.DiskTypes)}>
  207. <i class="fas fa-eye"></i>
  208. </button>
  209. </td>
  210. </tr>
  211. }
  212. </tbody>
  213. </table>
  214. </div>
  215. } else {
  216. <div class="text-center py-5">
  217. <i class="fas fa-layer-group fa-3x text-muted mb-3"></i>
  218. <h5 class="text-muted">No Collections Found</h5>
  219. <p class="text-muted">No collections are currently configured in the cluster.</p>
  220. </div>
  221. }
  222. </div>
  223. </div>
  224. <!-- Last Updated -->
  225. <div class="row">
  226. <div class="col-12">
  227. <small class="text-muted">
  228. <i class="fas fa-clock me-1"></i>
  229. Last updated: {data.LastUpdated.Format("2006-01-02 15:04:05")}
  230. </small>
  231. </div>
  232. </div>
  233. </div>
  234. <!-- JavaScript for cluster collections functionality -->
  235. <script>
  236. document.addEventListener('DOMContentLoaded', function() {
  237. // Handle collection action buttons
  238. document.addEventListener('click', function(e) {
  239. const button = e.target.closest('[data-action]');
  240. if (!button) return;
  241. const action = button.getAttribute('data-action');
  242. switch(action) {
  243. case 'view-details':
  244. const collectionData = {
  245. name: button.getAttribute('data-name'),
  246. datacenter: button.getAttribute('data-datacenter'),
  247. volumeCount: parseInt(button.getAttribute('data-volume-count')),
  248. ecVolumeCount: parseInt(button.getAttribute('data-ec-volume-count')),
  249. fileCount: parseInt(button.getAttribute('data-file-count')),
  250. totalSize: parseInt(button.getAttribute('data-total-size')),
  251. diskTypes: button.getAttribute('data-disk-types')
  252. };
  253. showCollectionDetails(collectionData);
  254. break;
  255. }
  256. });
  257. });
  258. function showCollectionDetails(collection) {
  259. const modalHtml = '<div class="modal fade" id="collectionDetailsModal" tabindex="-1">' +
  260. '<div class="modal-dialog modal-lg">' +
  261. '<div class="modal-content">' +
  262. '<div class="modal-header">' +
  263. '<h5 class="modal-title"><i class="fas fa-layer-group me-2"></i>Collection Details: ' + collection.name + '</h5>' +
  264. '<button type="button" class="btn-close" data-bs-dismiss="modal"></button>' +
  265. '</div>' +
  266. '<div class="modal-body">' +
  267. '<div class="row">' +
  268. '<div class="col-md-6">' +
  269. '<h6 class="text-primary"><i class="fas fa-info-circle me-1"></i>Basic Information</h6>' +
  270. '<table class="table table-sm">' +
  271. '<tr><td><strong>Collection Name:</strong></td><td><code>' + collection.name + '</code></td></tr>' +
  272. '<tr><td><strong>Data Center:</strong></td><td>' +
  273. (collection.datacenter ? '<span class="badge bg-light text-dark">' + collection.datacenter + '</span>' : '<span class="text-muted">N/A</span>') +
  274. '</td></tr>' +
  275. '<tr><td><strong>Disk Types:</strong></td><td>' +
  276. (collection.diskTypes ? collection.diskTypes.split(', ').map(type =>
  277. '<span class="badge bg-' + getDiskTypeBadgeColor(type) + ' me-1">' + type + '</span>'
  278. ).join('') : '<span class="text-muted">Unknown</span>') +
  279. '</td></tr>' +
  280. '</table>' +
  281. '</div>' +
  282. '<div class="col-md-6">' +
  283. '<h6 class="text-primary"><i class="fas fa-chart-bar me-1"></i>Storage Statistics</h6>' +
  284. '<table class="table table-sm">' +
  285. '<tr><td><strong>Regular Volumes:</strong></td><td>' +
  286. '<div class="d-flex align-items-center">' +
  287. '<i class="fas fa-database me-2 text-muted"></i>' +
  288. '<span>' + collection.volumeCount.toLocaleString() + '</span>' +
  289. '</div>' +
  290. '</td></tr>' +
  291. '<tr><td><strong>EC Volumes:</strong></td><td>' +
  292. '<div class="d-flex align-items-center">' +
  293. '<i class="fas fa-th-large me-2 text-muted"></i>' +
  294. '<span>' + collection.ecVolumeCount.toLocaleString() + '</span>' +
  295. '</div>' +
  296. '</td></tr>' +
  297. '<tr><td><strong>Total Files:</strong></td><td>' +
  298. '<div class="d-flex align-items-center">' +
  299. '<i class="fas fa-file me-2 text-muted"></i>' +
  300. '<span>' + collection.fileCount.toLocaleString() + '</span>' +
  301. '</div>' +
  302. '</td></tr>' +
  303. '<tr><td><strong>Total Size (Logical):</strong></td><td>' +
  304. '<div class="d-flex align-items-center">' +
  305. '<i class="fas fa-hdd me-2 text-muted"></i>' +
  306. '<span>' + formatBytes(collection.totalSize) + '</span>' +
  307. '</div>' +
  308. '</td></tr>' +
  309. '</table>' +
  310. '</div>' +
  311. '</div>' +
  312. '<div class="row mt-3">' +
  313. '<div class="col-12">' +
  314. '<h6 class="text-primary"><i class="fas fa-link me-1"></i>Quick Actions</h6>' +
  315. '<div class="d-grid gap-2 d-md-flex">' +
  316. '<a href="/cluster/volumes?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-primary">' +
  317. '<i class="fas fa-database me-1"></i>View Volumes' +
  318. '</a>' +
  319. '<a href="/cluster/ec-shards?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-secondary">' +
  320. '<i class="fas fa-th-large me-1"></i>View EC Volumes' +
  321. '</a>' +
  322. '<a href="/files?collection=' + encodeURIComponent(collection.name) + '" class="btn btn-outline-info">' +
  323. '<i class="fas fa-folder me-1"></i>Browse Files' +
  324. '</a>' +
  325. '</div>' +
  326. '</div>' +
  327. '</div>' +
  328. '</div>' +
  329. '</div>' +
  330. '<div class="modal-footer">' +
  331. '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>' +
  332. '</div>' +
  333. '</div>' +
  334. '</div>' +
  335. '</div>';
  336. // Remove existing modal if present
  337. const existingModal = document.getElementById('collectionDetailsModal');
  338. if (existingModal) {
  339. existingModal.remove();
  340. }
  341. // Add modal to body and show
  342. document.body.insertAdjacentHTML('beforeend', modalHtml);
  343. const modal = new bootstrap.Modal(document.getElementById('collectionDetailsModal'));
  344. modal.show();
  345. // Remove modal when hidden
  346. document.getElementById('collectionDetailsModal').addEventListener('hidden.bs.modal', function() {
  347. this.remove();
  348. });
  349. }
  350. function getDiskTypeBadgeColor(diskType) {
  351. switch(diskType.toLowerCase()) {
  352. case 'ssd':
  353. return 'primary';
  354. case 'hdd':
  355. case '':
  356. return 'secondary';
  357. default:
  358. return 'info';
  359. }
  360. }
  361. function formatBytes(bytes) {
  362. if (bytes === 0) return '0 Bytes';
  363. const k = 1024;
  364. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  365. const i = Math.floor(Math.log(bytes) / Math.log(k));
  366. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  367. }
  368. function exportCollections() {
  369. // Simple CSV export of collections list
  370. const rows = Array.from(document.querySelectorAll('#collectionsTable tbody tr')).map(row => {
  371. const cells = row.querySelectorAll('td');
  372. if (cells.length > 1) {
  373. return {
  374. name: cells[0].textContent.trim(),
  375. volumes: cells[1].textContent.trim(),
  376. files: cells[2].textContent.trim(),
  377. size: cells[3].textContent.trim(),
  378. diskTypes: cells[4].textContent.trim()
  379. };
  380. }
  381. return null;
  382. }).filter(row => row !== null);
  383. const csvContent = "data:text/csv;charset=utf-8," +
  384. "Collection Name,Volumes,Files,Size,Disk Types\n" +
  385. rows.map(r => '"' + r.name + '","' + r.volumes + '","' + r.files + '","' + r.size + '","' + r.diskTypes + '"').join("\n");
  386. const encodedUri = encodeURI(csvContent);
  387. const link = document.createElement("a");
  388. link.setAttribute("href", encodedUri);
  389. link.setAttribute("download", "collections.csv");
  390. document.body.appendChild(link);
  391. link.click();
  392. document.body.removeChild(link);
  393. }
  394. </script>
  395. }
  396. func getDiskTypeColor(diskType string) string {
  397. switch diskType {
  398. case "ssd":
  399. return "primary"
  400. case "hdd", "":
  401. return "secondary"
  402. default:
  403. return "info"
  404. }
  405. }
  406. func formatDiskTypes(diskTypes []string) string {
  407. if len(diskTypes) == 0 {
  408. return "Unknown"
  409. }
  410. if len(diskTypes) == 1 {
  411. return diskTypes[0]
  412. }
  413. // For multiple disk types, join with comma
  414. result := ""
  415. for i, diskType := range diskTypes {
  416. if i > 0 {
  417. result += ", "
  418. }
  419. result += diskType
  420. }
  421. return result
  422. }