From be690c2e829be8418ed5d2d0c84490480fc7ade5 Mon Sep 17 00:00:00 2001 From: iFargle Date: Thu, 30 Mar 2023 10:38:40 +0900 Subject: [PATCH] test --- renderer.py | 21 ++------------------- static/js/custom.js | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/renderer.py b/renderer.py index 3f11ece..882a8d6 100644 --- a/renderer.py +++ b/renderer.py @@ -791,8 +791,8 @@ def render_routes(): route_id_list.append(route["id"]) # Set up the display code: - failover_enabled = "fiber_manual_record" - failover_disabled = "fiber_manual_record" + failover_enabled = "fiber_manual_record" + failover_disabled = "fiber_manual_record" failover_display = failover_disabled for route_id in route_id_list: @@ -822,23 +822,6 @@ def render_routes(): is_primary = all_routes["routes"][idx]["isPrimary"] is_enabled = all_routes["routes"][idx]["enabled"] - # route_id_list contains all routes associated with that prefix. - # To toggle which is primary, we need to transfer all routes - # and which route ID to make primary. We then toggle each route - # in order, with the primary route being toggled last - # Step 1: Create an array of all route_id's - # payload = "{" - # index = 0 - - # Is there a better way to do this?? - # for item in route_id_list: - # payload += "\""+str(index)+"\": \""+str(item)+"\"" - # index += 1 - # if index != len(route_id_list): payload += ", " - # payload+="}" - # app.logger.debug("JSON: %s", str(payload)) - # json_payload = json.loads(payload) - payload = [] for item in route_id_list: payload.append(int(item)) diff --git a/static/js/custom.js b/static/js/custom.js index 7b5e412..fecb104 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -861,8 +861,7 @@ function get_routes() { contentType: "application/json", success: function(response) { console.log("Got all routes. ") - console.log("Headscale response: "+JSON.stringify(response)) - return JSON.stringify(response.message) + return JSON.stringify(response) } }) } @@ -905,17 +904,27 @@ function toggle_failover_route_routespage(routeid, current_state, prefix, route_ } M.toast({html: 'Route '+action_taken}); - // Next, get the information for the primary route and the failover route status: + // Get all route info: console.log("Getting info for prefix "+prefix) var routes = get_routes() + var enabled_status = "False" + + // Debug. console.log("Routes: "+routes) - // Second, set the primary and enabled displays for the prefix: + // Get the primary and enabled displays for the prefix: for (let i=0; i < route_id_list.length; i++) { - var route_id = route_id_list[i] console.log("route_id_list["+i+"]: "+route_id_list[i]) - // If one of the two routes is enabled, keep the prefix's route green. - // Step 1: Get info for these routes: + // Set the Primary class: + var primary_element = document.getElementById(routeid+"-primary") + var primary_status = routes["route"][route_id_list[i]]["isPrimary"] + if (primary_status == "True") { + primary_element.className = enabledClass + } else if (primary_status == "False") { + primary_element.className = disabledClass + } + // Determine if any route is enabled: + } } })