diff --git a/server/webserver.py b/server/webserver.py index de431c5..cd9e347 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -37,6 +37,7 @@ class WebServer: # Routes for templated pages bottle.get("/")(lambda: self.serve_template('webpage_spots')) bottle.get("/alerts")(lambda: self.serve_template('webpage_alerts')) + bottle.get("/status")(lambda: self.serve_template('webpage_status')) bottle.get("/about")(lambda: self.serve_template('webpage_about')) bottle.get("/apidocs")(lambda: self.serve_template('webpage_apidocs')) # Default route to serve from "webassets" @@ -58,7 +59,6 @@ class WebServer: self.status = "OK" response.content_type = 'application/json' response.set_header('Cache-Control', 'no-store') - print(data) return json.dumps(data, default=serialize_everything) # Accept a spot diff --git a/views/webpage_base.tpl b/views/webpage_base.tpl index 3788351..9777389 100644 --- a/views/webpage_base.tpl +++ b/views/webpage_base.tpl @@ -59,6 +59,7 @@ diff --git a/views/webpage_spots.tpl b/views/webpage_spots.tpl index ec014d0..e515b37 100644 --- a/views/webpage_spots.tpl +++ b/views/webpage_spots.tpl @@ -23,28 +23,10 @@

-

-
-
-
-
- Status -
-
- -
-
- -
-
-
-
-
-
diff --git a/views/webpage_status.tpl b/views/webpage_status.tpl new file mode 100644 index 0000000..5dde65b --- /dev/null +++ b/views/webpage_status.tpl @@ -0,0 +1,7 @@ +% rebase('webpage_base.tpl') + +
+ + + + \ No newline at end of file diff --git a/webassets/js/spots.js b/webassets/js/spots.js index ec08d0c..93c7725 100644 --- a/webassets/js/spots.js +++ b/webassets/js/spots.js @@ -146,54 +146,6 @@ function updateTable() { $('#table-container').html(table); } -// Load server status -function loadStatus() { - $.getJSON('/api/status', function(jsonData) { - $("#status-container").empty(); - $("#status-container").append(generateStatusCard("Server Information", [ - `Software Version: ${jsonData["software-version"]}`, - `Server Owner Callsign: ${jsonData["server-owner-callsign"]}`, - `Server Uptime: ${moment().subtract(jsonData["uptime"], 'seconds').fromNow()}`, - `Memory Use: ${jsonData["mem_use_mb"]} MB`, - `Total Spots: ${jsonData["num_spots"]}` - ])); - $("#status-container").append(generateStatusCard("Web Server", [ - `Status: ${jsonData["webserver"]["status"]}`, - `Last API Access: ${moment.unix(jsonData["webserver"]["last_api_access"]).utc().fromNow()}`, - `Last Page Access: ${moment.unix(jsonData["webserver"]["last_page_access"]).utc().fromNow()}` - ])); - $("#status-container").append(generateStatusCard("Cleanup Service", [ - `Status: ${jsonData["cleanup"]["status"]}`, - `Last Ran: ${moment.unix(jsonData["cleanup"]["last_ran"]).utc().fromNow()}` - ])); - jsonData["spot_providers"].forEach(p => { - $("#status-container").append(generateStatusCard("Provider: " + p["name"], [ - `Status: ${p["status"]}`, - `Last Updated: ${p["enabled"] ? moment.unix(p["last_updated"]).utc().fromNow() : "N/A"}`, - `Latest Spot: ${p["enabled"] ? moment.unix(p["last_spot"]).utc().fromNow() : "N/A"}` - ])); - }); - jsonData["alert_providers"].forEach(p => { - $("#status-container").append(generateStatusCard("Provider: " + p["name"], [ - `Status: ${p["status"]}`, - `Last Updated: ${p["enabled"] ? moment.unix(p["last_updated"]).utc().fromNow() : "N/A"}` - ])); - }); - }); -} - -// Generate a status card -function generateStatusCard(title, textLines) { - let $col = $("
"); - let $card = $("
"); - let $card_body = $("
"); - $card_body.append(`
${title}
`); - $card_body.append(`

${textLines.join("
")}

`); - $card.append($card_body); - $col.append($card); - return $col; -} - // Load server options. Once a successful callback is made from this, we then query spots and set up the timer to query // spots repeatedly. function loadOptions() { @@ -265,27 +217,7 @@ function filtersUpdated() { // Set up UI element event listeners, after the document is ready function setUpEventListeners() { - $("#status-button").click(function() { - // If we are going to display status, load the data for the status panel, and hide the filters panel - if (!$("#status-area").is(":visible")) { - loadStatus(); - if ($("#settings-area").is(":visible")) { - $("#settings-area").hide(); - $("#settings-button").button("toggle"); - } - } - $("#status-area").toggle(); - }); - $("#close-status-button").click(function() { - $("#status-button").button("toggle"); - $("#status-area").hide(); - }); $("#settings-button").click(function() { - // If we are going to display filters, hide the filters panel - if (!$("#settings-area").is(":visible") && $("#status-area").is(":visible")) { - $("#status-area").hide(); - $("#status-button").button("toggle"); - } $("#settings-area").toggle(); }); $("#close-settings-button").click(function() { diff --git a/webassets/js/status.js b/webassets/js/status.js new file mode 100644 index 0000000..9b30611 --- /dev/null +++ b/webassets/js/status.js @@ -0,0 +1,52 @@ +// Load server status +function loadStatus() { + $.getJSON('/api/status', function(jsonData) { + $("#status-container").empty(); + $("#status-container").append(generateStatusCard("Server Information", [ + `Software Version: ${jsonData["software-version"]}`, + `Server Owner Callsign: ${jsonData["server-owner-callsign"]}`, + `Server up since: ${moment().subtract(jsonData["uptime"], 'seconds').fromNow()}`, + `Memory Use: ${jsonData["mem_use_mb"]} MB`, + `Total Spots: ${jsonData["num_spots"]}` + ])); + $("#status-container").append(generateStatusCard("Web Server", [ + `Status: ${jsonData["webserver"]["status"]}`, + `Last API Access: ${moment.unix(jsonData["webserver"]["last_api_access"]).utc().fromNow()}`, + `Last Page Access: ${moment.unix(jsonData["webserver"]["last_page_access"]).utc().fromNow()}` + ])); + $("#status-container").append(generateStatusCard("Cleanup Service", [ + `Status: ${jsonData["cleanup"]["status"]}`, + `Last Ran: ${moment.unix(jsonData["cleanup"]["last_ran"]).utc().fromNow()}` + ])); + jsonData["spot_providers"].forEach(p => { + $("#status-container").append(generateStatusCard("Spot Provider: " + p["name"], [ + `Status: ${p["status"]}`, + `Last Updated: ${p["enabled"] ? moment.unix(p["last_updated"]).utc().fromNow() : "N/A"}`, + `Latest Spot: ${p["enabled"] ? moment.unix(p["last_spot"]).utc().fromNow() : "N/A"}` + ])); + }); + jsonData["alert_providers"].forEach(p => { + $("#status-container").append(generateStatusCard("Alert Provider: " + p["name"], [ + `Status: ${p["status"]}`, + `Last Updated: ${p["enabled"] ? moment.unix(p["last_updated"]).utc().fromNow() : "N/A"}` + ])); + }); + }); +} + +// Generate a status card +function generateStatusCard(title, textLines) { + let $col = $("
"); + let $card = $("
"); + let $card_body = $("
"); + $card_body.append(`
${title}
`); + $card_body.append(`

${textLines.join("
")}

`); + $card.append($card_body); + $col.append($card); + return $col; +} + +// Startup +$(document).ready(function() { + loadStatus(); +}); \ No newline at end of file