On/Offline fix
This commit is contained in:
parent
e159ad5a8c
commit
94464a3e36
5 changed files with 38 additions and 54 deletions
34
internal/web/line.go
Normal file
34
internal/web/line.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/check"
|
||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||
)
|
||||
|
||||
func lineHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var guiData models.GuiData
|
||||
|
||||
guiData.Config = AppConfig
|
||||
guiData.Hosts = []models.Host{}
|
||||
guiData.Icon = Icon
|
||||
|
||||
state := r.URL.Query().Get("state")
|
||||
|
||||
for _, oneHost := range AllHosts {
|
||||
if state == "off" && oneHost.Now == 0 {
|
||||
guiData.Hosts = append(guiData.Hosts, oneHost)
|
||||
}
|
||||
if state == "on" && oneHost.Now == 1 {
|
||||
guiData.Hosts = append(guiData.Hosts, oneHost)
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, _ := template.ParseFS(TemplHTML, TemplPath+"line.html", TemplPath+"header.html", TemplPath+"footer.html")
|
||||
err := tmpl.ExecuteTemplate(w, "header", guiData)
|
||||
check.IfError(err)
|
||||
err = tmpl.ExecuteTemplate(w, "line", guiData)
|
||||
check.IfError(err)
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/aceberg/WatchYourLAN/internal/check"
|
||||
"github.com/aceberg/WatchYourLAN/internal/models"
|
||||
)
|
||||
|
||||
func offlineHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var guiData models.GuiData
|
||||
|
||||
guiData.Config = AppConfig
|
||||
guiData.Hosts = []models.Host{}
|
||||
guiData.Icon = Icon
|
||||
|
||||
for _, oneHost := range AllHosts {
|
||||
if oneHost.Now == 0 {
|
||||
guiData.Hosts = append(guiData.Hosts, oneHost)
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, _ := template.ParseFS(TemplHTML, TemplPath+"offline.html", TemplPath+"header.html", TemplPath+"footer.html")
|
||||
err := tmpl.ExecuteTemplate(w, "header", guiData)
|
||||
check.IfError(err)
|
||||
err = tmpl.ExecuteTemplate(w, "offline", guiData)
|
||||
check.IfError(err)
|
||||
}
|
||||
|
||||
func onlineHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var guiData models.GuiData
|
||||
|
||||
guiData.Config = AppConfig
|
||||
guiData.Hosts = []models.Host{}
|
||||
guiData.Icon = Icon
|
||||
|
||||
for _, oneHost := range AllHosts {
|
||||
if oneHost.Now == 1 {
|
||||
guiData.Hosts = append(guiData.Hosts, oneHost)
|
||||
}
|
||||
}
|
||||
|
||||
tmpl, _ := template.ParseFS(TemplHTML, TemplPath+"offline.html", TemplPath+"header.html", TemplPath+"footer.html")
|
||||
err := tmpl.ExecuteTemplate(w, "header", guiData)
|
||||
check.IfError(err)
|
||||
err = tmpl.ExecuteTemplate(w, "offline", guiData)
|
||||
check.IfError(err)
|
||||
}
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
<a class="nav-link active" href="/home/">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/online/">Online</a>
|
||||
<a class="nav-link active" href="/line?state=on">Online</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/offline/">Offline</a>
|
||||
<a class="nav-link active" href="/line?state=off">Offline</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/config/">Config</a>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{{ define "offline"}}
|
||||
{{ define "line"}}
|
||||
<body>
|
||||
<div class="container mt-3">
|
||||
<table class="table table-striped">
|
||||
|
|
@ -60,8 +60,7 @@ func Gui(configPath string) {
|
|||
http.HandleFunc("/del_host/", delHandler)
|
||||
http.HandleFunc("/home/", homeHandler)
|
||||
http.HandleFunc("/host/", hostHandler)
|
||||
http.HandleFunc("/offline/", offlineHandler)
|
||||
http.HandleFunc("/online/", onlineHandler)
|
||||
http.HandleFunc("/line/", lineHandler)
|
||||
http.HandleFunc("/save_config/", saveConfigHandler)
|
||||
http.HandleFunc("/search_hosts/", searchHandler)
|
||||
http.HandleFunc("/sort_hosts/", sortHandler)
|
||||
|
|
|
|||
Loading…
Reference in a new issue