put page in container

This commit is contained in:
Jörg Thalheim 2013-10-04 14:58:58 +02:00
parent c7f6d46818
commit f4eebef8a9
3 changed files with 52 additions and 46 deletions

View File

@ -4,37 +4,40 @@ $(function() {
function refreshNodes() { function refreshNodes() {
$("#nodeTable tr[data-node]").each(function(){ $("#nodeTable tr[data-node]").each(function(){
var $this = $(this); refreshNode($(this));
var node = $this.data("node");
$.getJSON("/status/"+node, function (data) {
$this.find("span.loading").hide();
var label;
if (data["Status"] === "UP") {
label = "label-success";
$this.addClass("success");
$this.find("td.ping").text(data["Ping"] + "ms");
} else if (data["Status"] === "SLOW") {
label = "label-warning";
$this.addClass("warning");
$this.find("td.ping").text(data["Ping"] + "ms");
} else {
label = "label-danger";
$this.addClass("danger");
}
if (data["Domain"] === "devkid-nas.vpn") {
setNasWakeUpLink($this, data);
}
$this.find("span.status").addClass(label).text(data["Status"]);
})
}); });
} }
function setNasWakeUpLink($row, data) { function refreshNode($node) {
var $nasStatus = $row.find("#nasStatus"); var node = $node.data("node");
$.getJSON("/status/"+node, function (data) {
$node.find("span.loading").hide();
var label;
if (data["Status"] === "UP") {
label = "label-success";
$node.addClass("success");
$node.find("td.ping").text(data["Ping"] + "ms");
} else if (data["Status"] === "SLOW") {
label = "label-warning";
$node.addClass("warning");
$node.find("td.ping").text(data["Ping"] + "ms");
} else {
label = "label-danger";
$node.addClass("danger");
}
if (data["Domain"] === "devkid-nas.vpn") {
setNasWakeUpLink($node, data);
}
$node.find("span.status-text").addClass(label).text(data["Status"]);
})
}
function setNasWakeUpLink($node, data) {
var $nasStatus = $node.find("#nasStatus");
if ($nasStatus.length == 0){ if ($nasStatus.length == 0){
var ele = '<a id="nasStatus" href="http://devkid-router.vpn:8080/cgi-bin/wake-nas" class="btn btn-link btn-sm">Wake up NAS</a>' var ele = '<a id="nasStatus" href="http://devkid-router.vpn:8080/cgi-bin/wake-nas" class="btn btn-link btn-sm">Wake up NAS</a>'
$row.find(".host").append(ele); $node.find(".host").append(ele);
$nasStatus = $row.find("#nasStatus") $nasStatus = $node.find("#nasStatus")
} }
if (data["Status"] == "DOWN") { if (data["Status"] == "DOWN") {
$nasStatus.show(); $nasStatus.show();

View File

@ -1,16 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{{.Title}}</title> <title>{{.Title}}</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js" type="text/javascript"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/assets/app.js" type="text/javascript" charset="utf-8"></script> <script src="/assets/app.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="/assets/app.css"> <link rel="stylesheet" type="text/css" href="/assets/app.css">
</head> </head>
<body> <body>
<div class="container">
<div class="panel panel-default"> <div class="panel panel-default">
<!-- Default panel contents --> <!-- Default panel contents -->
<div class="panel-heading">{{.Title}}</div> <div class="panel-heading">{{.Title}}</div>
@ -21,17 +22,19 @@
<th>Ping</th> <th>Ping</th>
</tr> </tr>
{{range $node := .Nodes}} {{range $node := .Nodes}}
<tr data-node="{{$node}}"> <tr data-node="{{$node}}">
<td class="host">{{$node}}</td> <td class="host">{{$node}}</td>
<td> <td class="status">
<span class="loading"><i class="icon-spinner icon-spin"></i>Loading...</span> <span class="loading"><i class="icon-spinner icon-spin"></i>Loading...</span>
<span class="status label"></span> <span class="status-text label"></span>
</td> </td>
<td class="ping"> <td class="ping">
- -
</td> </td>
</tr> </tr>
{{end}} {{end}}
</table> </table>
</div> </div>
<a href="/assets/tinc-graph.svg" target="_blank">Show Network Graph</a>
</div>
</body> </body>

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"html/template" "html/template"
"os/exec"
"os" "os"
"os/exec"
"regexp" "regexp"
"strconv" "strconv"
"bytes" "bytes"
@ -106,6 +106,6 @@ func main() {
http.HandleFunc("/status/", statusHandler) http.HandleFunc("/status/", statusHandler)
http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets/")))) http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./assets/"))))
http.HandleFunc("/", indexHandler) http.HandleFunc("/", indexHandler)
fmt.Printf("Running on http://0.0.0.0:8080\n"); fmt.Printf("Running on http://0.0.0.0:8080\n")
http.ListenAndServe(":8080", nil) http.ListenAndServe(":8080", nil)
} }