From 420e556d9beac98cbe927cfae817e291c081b40b Mon Sep 17 00:00:00 2001 From: Emerson Felipe Date: Wed, 16 Oct 2024 19:52:14 +0000 Subject: [PATCH] Fix FastAPI status badge on homepage. --- .../templates/netbox_proxbox/home.html | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/netbox_proxbox/templates/netbox_proxbox/home.html b/netbox_proxbox/templates/netbox_proxbox/home.html index 05ae6a8..962f975 100755 --- a/netbox_proxbox/templates/netbox_proxbox/home.html +++ b/netbox_proxbox/templates/netbox_proxbox/home.html @@ -46,11 +46,11 @@ fullUpdateMessage.innerHTML = errorMessage - statusBadgeError = document.getElementById('fastapi-connection-status') - statusBadgeError.className = "text-bg-red badge p-2" + let statusBadgeError = document.getElementById('fastapi-connection-status') + statusBadgeError.className = "text-bg-red badge p-1" statusBadgeError.textContent = "Connection Failed!" - statusErrorMessage = document.getElementById('fastapi-connection-error') + let statusErrorMessage = document.getElementById('fastapi-connection-error') statusErrorMessage.className = "text-bg-red p-2" statusErrorMessage.innerHTML = errorMessage } @@ -61,6 +61,25 @@ event.preventDefault() } + async function FastAPIConnectionTest() { + let fastapi_docs_endpoint = `${fastapi_endpoint}/docs` + + const request_fastapi = await fetch(fastapi_docs_endpoint) + console.log("request_fastapi", request_fastapi) + if (request_fastapi.ok) { + console.log("FastAPI OK") + //onst response_fastapi = await request_fastapi.json() + + console.log("request_fastapi", request_fastapi) + + statusBadgeFastAPI = document.getElementById('fastapi-connection-status') + statusBadgeFastAPI.className = "text-bg-green badge p-1" + statusBadgeFastAPI.textContent = "Successful!" + + } + + } + function getBody () { // Load 'getVersion()' function on HTML @@ -71,9 +90,16 @@ } + + getBody() async function getVersion() { + // Test FastAPI Proxbox Backend Connection + console.log("1") + FastAPIConnectionTest() + console.log("2") + // Get Info from Proxmox and Add to GUI Page, like Connection Status and Error Messages let elemento = document.getElementsByClassName("proxmox_version")