From d65b28bd21dfceaef7ecd66ec8f1aee127fc5e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Sun, 1 Sep 2024 15:46:34 +0200 Subject: [PATCH] Tweak instances page in web UI --- src/ui/app/static/js/pages/instances.js | 213 ++++++++++++------------ src/ui/app/templates/instances.html | 27 ++- 2 files changed, 129 insertions(+), 111 deletions(-) diff --git a/src/ui/app/static/js/pages/instances.js b/src/ui/app/static/js/pages/instances.js index 186bc42bb..801fc3aa1 100644 --- a/src/ui/app/static/js/pages/instances.js +++ b/src/ui/app/static/js/pages/instances.js @@ -1,13 +1,116 @@ $(document).ready(function () { - const getSelectedInstances = (action) => { + var toastNum = 0; + var actionLock = false; + const instanceNumber = parseInt($("#instances_number").val()); + + const layout = { + topStart: {}, + bottomEnd: { + buttons: [ + { + extend: "ping_instances", + }, + { + extend: "exec_form", + text: 'Reload', + className: "btn btn-sm btn-outline-primary", + }, + { + extend: "exec_form", + text: 'Stop', + className: "btn btn-sm btn-outline-primary", + }, + { + extend: "delete_instances", + }, + ], + }, + }; + + if (instanceNumber > 10) { + layout.topStart.pageLength = { + menu: [10, 25, 50, 100, { label: "All", value: -1 }], + }; + layout.bottomEnd.paging = true; + } + + layout.topStart.buttons = [ + { + extend: "colvis", + columns: "th:not(:first-child)", + text: 'Columns', + className: "btn btn-sm btn-outline-primary", + columnText: function (dt, idx, title) { + return idx + 1 + ". " + title; + }, + }, + { + extend: "colvisRestore", + text: 'Reset columns', + className: "btn btn-sm btn-outline-primary", + }, + { + extend: "collection", + text: 'Export', + className: "btn btn-sm btn-outline-primary", + buttons: [ + { + extend: "copy", + text: 'Copy current page', + exportOptions: { + modifier: { + page: "current", + }, + }, + }, + { + extend: "csv", + text: 'CSV', + bom: true, + filename: "bw_instances", + exportOptions: { + modifier: { + search: "none", + }, + }, + }, + { + extend: "excel", + text: 'Excel', + filename: "bw_instances", + exportOptions: { + modifier: { + search: "none", + }, + }, + }, + ], + }, + { + extend: "create_instance", + }, + ]; + + $(document).on("hidden.bs.toast", ".toast", function (event) { + if (event.target.id.startsWith("feedback-toast")) { + setTimeout(() => { + $(this).remove(); + }, 100); + } + }); + + $("#modal-delete-instances").on("hidden.bs.modal", function () { + $("#selected-instances").empty(); + $("#selected-instances-input").val(""); + }); + + const getSelectedInstances = () => { const instances = []; $("tr.selected").each(function () { instances.push($(this).find("td:first").text()); }); return instances; }; - var toastNum = 0; - var actionLock = false; $.fn.dataTable.ext.buttons.create_instance = { text: 'Create new instance', @@ -31,7 +134,7 @@ $(document).ready(function () { } actionLock = true; - const instances = getSelectedInstances("ping"); + const instances = getSelectedInstances(); if (instances.length === 0) { actionLock = false; return; @@ -98,7 +201,7 @@ $(document).ready(function () { } actionLock = true; - const instances = getSelectedInstances("ping"); + const instances = getSelectedInstances(); if (instances.length === 0) { actionLock = false; return; @@ -151,7 +254,7 @@ $(document).ready(function () { } actionLock = true; - const instances = getSelectedInstances("ping"); + const instances = getSelectedInstances(); if (instances.length === 0) { actionLock = false; return; @@ -200,90 +303,7 @@ $(document).ready(function () { select: { style: "multi+shift", }, - layout: { - topStart: { - pageLength: { - menu: [10, 25, 50, 100, { label: "All", value: -1 }], - }, - buttons: [ - { - extend: "colvis", - columns: "th:not(:first-child)", - text: 'Columns', - className: "btn btn-sm btn-outline-primary", - columnText: function (dt, idx, title) { - return idx + 1 + ". " + title; - }, - }, - { - extend: "colvisRestore", - text: 'Reset columns', - className: "btn btn-sm btn-outline-primary", - }, - { - extend: "collection", - text: 'Export', - className: "btn btn-sm btn-outline-primary", - buttons: [ - { - extend: "copy", - text: 'Copy current page', - exportOptions: { - modifier: { - page: "current", - }, - }, - }, - { - extend: "csv", - text: 'CSV', - bom: true, - filename: "bw_instances", - exportOptions: { - modifier: { - search: "none", - }, - }, - }, - { - extend: "excel", - text: 'Excel', - filename: "bw_instances", - exportOptions: { - modifier: { - search: "none", - }, - }, - }, - ], - }, - { - extend: "create_instance", - }, - ], - }, - bottomEnd: { - buttons: [ - { - extend: "ping_instances", - }, - { - extend: "exec_form", - text: 'Reload', - className: "btn btn-sm btn-outline-primary", - }, - { - extend: "exec_form", - text: 'Stop', - className: "btn btn-sm btn-outline-primary", - }, - { - extend: "delete_instances", - }, - ], - paging: true, - }, - }, + layout: layout, }); instances_table.on("mouseenter", "td", function () { @@ -299,17 +319,4 @@ $(document).ready(function () { .nodes() .each((el) => el.classList.add("highlight")); }); - - $(document).on("hidden.bs.toast", ".toast", function (event) { - if (event.target.id.startsWith("feedback-toast")) { - setTimeout(() => { - $(this).remove(); - }, 100); - } - }); - - $("#modal-delete-instances").on("hidden.bs.modal", function () { - $("#selected-instances").empty(); - $("#selected-instances-input").val(""); - }); }); diff --git a/src/ui/app/templates/instances.html b/src/ui/app/templates/instances.html index eb82bb114..eb9d96340 100644 --- a/src/ui/app/templates/instances.html +++ b/src/ui/app/templates/instances.html @@ -18,6 +18,9 @@
+ - Hostname - Name - Method - Health - Type - Creation date - Last seen + Hostname + Name + Method + Health + Type + Created + Last Seen @@ -52,7 +55,15 @@ class="badge rounded-pill bg-label-warning">Loading {% endif %} - {{ instance.type }} + + {% if instance.type == "container" %} +  Container + {% elif instance.type == "pod" %} +  Pod + {% else %} +  Static + {% endif %} + {{ instance.creation_date.astimezone().strftime("%Y-%m-%d %H:%M:%S %Z") }} {{ instance.last_seen.astimezone().strftime("%Y-%m-%d %H:%M:%S %Z") }}