Sort and search (#4,#10,#11)
This commit is contained in:
parent
3cc3bf27ed
commit
bd3df507c0
6 changed files with 56 additions and 7 deletions
|
|
@ -17,7 +17,7 @@
|
|||
<div class="container">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/">All</a>
|
||||
<a class="nav-link active" href="/home/">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="/online/">Online</a>
|
||||
|
|
@ -57,6 +57,12 @@
|
|||
</li>
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<form action="/search_hosts/" method="post">
|
||||
<li class="input-group nav-item">
|
||||
<input name="search" type="text" class="form-control text-dark" placeholder="Search">
|
||||
<button type="submit" class="btn btn-primary">Search</button>
|
||||
</li>
|
||||
</form>
|
||||
<li class="nav-item"><a class="nav-link active" href="https://github.com/aceberg/WatchYourLAN">
|
||||
<h3> <i class="bi bi-github"></i></h3>
|
||||
</a></li>
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="container mt-3">
|
||||
<h2>Offline</h2>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<form action="/sort_hosts/" method="post">
|
||||
<th>Name<br>
|
||||
<button type="submit" name="sort_method" value="date-up" class="btn btn-primary btn-sm">
|
||||
<button type="submit" name="sort_method" value="name-up" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-caret-up"></i>
|
||||
</button>
|
||||
<button type="submit" name="sort_method" value="date-down" class="btn btn-primary btn-sm">
|
||||
<button type="submit" name="sort_method" value="name-down" class="btn btn-primary btn-sm">
|
||||
<i class="bi bi-caret-down"></i>
|
||||
</button>
|
||||
</th>
|
||||
|
|
@ -45,6 +45,7 @@
|
|||
<i class="bi bi-caret-down"></i>
|
||||
</button>
|
||||
</th>
|
||||
</form>
|
||||
</tr>
|
||||
{{ range .Hosts }}
|
||||
<form action="/update_host/" method="post">
|
||||
|
|
@ -53,7 +54,7 @@
|
|||
<td>
|
||||
<input name="name" type="text" class="form-control text-dark" value="{{ .Name }}">
|
||||
</td>
|
||||
<td>{{ .Ip }}</td>
|
||||
<td><a href="http://{{ .Ip }}" target="_blank">{{ .Ip }}</a></td>
|
||||
<td>{{ .Mac }}</td>
|
||||
<td>{{ .Hw }}</td>
|
||||
<td>{{ .Date }}</td>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func update_host(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, r.Header.Get("Referer"), 302)
|
||||
}
|
||||
|
||||
func webgui() {
|
||||
|
|
@ -56,8 +56,10 @@ func webgui() {
|
|||
fmt.Println("=================================== \n")
|
||||
|
||||
http.HandleFunc("/", index)
|
||||
http.HandleFunc("/home/", home)
|
||||
http.HandleFunc("/offline/", offline)
|
||||
http.HandleFunc("/online/", online)
|
||||
http.HandleFunc("/search_hosts/", search_hosts)
|
||||
http.HandleFunc("/sort_hosts/", sort_hosts)
|
||||
http.HandleFunc("/theme/", theme)
|
||||
http.HandleFunc("/update_host/", update_host)
|
||||
|
|
|
|||
35
src/web-search.go
Normal file
35
src/web-search.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func search_hosts(w http.ResponseWriter, r *http.Request) {
|
||||
search := r.FormValue("search")
|
||||
|
||||
foundHosts := []Host{}
|
||||
for _, oneHost := range AllHosts {
|
||||
if in_string(oneHost.Name, search) {
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
} else if in_string(oneHost.Ip, search) {
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
} else if in_string(oneHost.Mac, search) {
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
} else if in_string(oneHost.Date, search) {
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
} else if in_string(oneHost.Hw, search) {
|
||||
foundHosts = append(foundHosts, oneHost)
|
||||
}
|
||||
}
|
||||
AllHosts = foundHosts
|
||||
|
||||
http.Redirect(w, r, r.Header.Get("Referer"), 302)
|
||||
}
|
||||
|
||||
func in_string (str1 string, str2 string) (bool) {
|
||||
return strings.Contains(
|
||||
strings.ToLower(str1),
|
||||
strings.ToLower(str2),
|
||||
)
|
||||
}
|
||||
|
|
@ -46,5 +46,5 @@ func sort_hosts(w http.ResponseWriter, r *http.Request) {
|
|||
AllHosts = db_select()
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
http.Redirect(w, r, r.Header.Get("Referer"), 302)
|
||||
}
|
||||
|
|
@ -17,5 +17,10 @@ func theme(w http.ResponseWriter, r *http.Request) {
|
|||
write_config()
|
||||
}
|
||||
|
||||
http.Redirect(w, r, r.Header.Get("Referer"), 302)
|
||||
}
|
||||
|
||||
func home(w http.ResponseWriter, r *http.Request) {
|
||||
AllHosts = db_select()
|
||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
}
|
||||
Loading…
Reference in a new issue