Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
node display
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkasun committed Oct 30, 2021
1 parent 330e23a commit bc09d1e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
7 changes: 4 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,16 @@ func NodeHealth(c *gin.Context) {
var nodeHealth NodeStatus
for _, node := range nodes {
nodeHealth.Mac = node.MacAddress
nodeHealth.Network = node.Network
lastupdate := time.Now().Sub(time.Unix(node.LastCheckIn, 0))
if lastupdate.Minutes() > 15.0 {
nodeHealth.Status = "Dead: Node last checked in more than 15 minutes ago"
nodeHealth.Status = "Error: Node last checked in more than 15 minutes ago: "
nodeHealth.Color = "w3-deep-orange"
} else if lastupdate.Minutes() > 5.0 {
nodeHealth.Status = "Warning: Node last checked in more than 5 minutes ago"
nodeHealth.Status = "Warning: Node last checked in more than 5 minutes ago: "
nodeHealth.Color = "w3-khaki"
} else {
nodeHealth.Status = "Healthy: Node checked in within the last 5 minutes"
nodeHealth.Status = "Healthy: Node checked in within the last 5 minutes: "
nodeHealth.Color = "w3-teal"
}
response = append(response, nodeHealth)
Expand Down
10 changes: 5 additions & 5 deletions html/nodes.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{{ define "Nodes" }}
<div id="Nodes" class="w3-content w3-white tab" style="display=none">
{{range .Nodes}}
<p><button id="button{{.MacAddress}}" class="net {{.Network}} All w3-lightgrey" onclick="expand('node{{.MacAddress}}');">{{.Name}}@{{.Network}} {{.Endpoint}} {{.Address}}</button></p>
<p><button id="button{{.MacAddress}}{{.Network}}" class="net {{.Network}} All w3-lightgrey" onclick="expand('node{{.MacAddress}}{{.Network}}');">{{.Name}}@{{.Network}} {{.Endpoint}} {{.Address}}</button></p>
{{template "NodeDetails" .}}
{{end}}
</div>
{{end}}

{{define "NodeDetails"}}
<div class="w3-content net {{.Network}} w3-hide" id='node{{.MacAddress}}'>
<div class="w3-content net {{.Network}} w3-hide" id='node{{.MacAddress}}{{.Network}}'>
<fieldset>
<legend>{{.Name }}</legend>
<form action="/edit_node" method=POST>
<form action="/edit_node" method=POST style=display:inline>
<input type=hidden name="network" value='{{.Network}}'>
<input type=hidden name="mac" value='{{.MacAddress}}'>
<label>Public IP</label>
<input type="text" placeholder={{.Endpoint}} disabled><br>
<label>Subnet</label>
<input type="text" placeholder={{.Address}} disabled><br>
<label>Status: </label><label id="node_status{{.MacAddress}}">...Checking...</label><br>
<label>Status: </label><label id="node_status{{.MacAddress}}{{.Network}}">...Checking...</label><label> {{printTimestamp .LastCheckIn}} </label><br>
<button type=submit class="w3-button">Edit</button><br>
</form>
<form action="delete_node" method=POST>
<form action="delete_node" method=POST style=display:inline>
<input type=hidden name="net" value='{{.Network}}'>
<input type=hidden name="mac" value='{{.MacAddress}}'>
<button type=submit class="w3-button" onclick="alert('Are you sure you want to delete node {{.Name}} from Network {{.Network}}?')" >Delete</button>
Expand Down
12 changes: 6 additions & 6 deletions html/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@
}
const nodes = JSON.parse(this.responseText);
nodes.forEach((element, index, array) => {
document.getElementById("node_status"+element.Mac).innerHTML=element.Status;
document.getElementById("button"+element.Mac).classList.remove("w3-lightgrey")
document.getElementById("button"+element.Mac).classList.remove("w3-deep-orange")
document.getElementById("button"+element.Mac).classList.remove("w3-khaki")
document.getElementById("button"+element.Mac).classList.remove("w3-teal")
document.getElementById("button"+element.Mac).classList.add(element.Color)
document.getElementById("node_status"+element.Mac+element.Network).innerHTML=element.Status;
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-lightgrey")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-deep-orange")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-khaki")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-teal")
document.getElementById("button"+element.Mac+element.Network).classList.add(element.Color)
});
}
xHttp.send();
Expand Down
7 changes: 4 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

type NodeStatus struct {
Mac string
Status string
Color string
Mac string
Network string
Status string
Color string
}

type Relay struct {
Expand Down

0 comments on commit bc09d1e

Please sign in to comment.