Skip to content

Commit

Permalink
Uptime: filter refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Jul 19, 2023
1 parent 2f2e1b4 commit 283a4c7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 40 deletions.
16 changes: 8 additions & 8 deletions internal/web/templates/uptime.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@
{{ range .UptimeMon }}
<tr>
<td>
<a href="/uptime_filter/?panel={{ .Panel }}">{{ .Panel }}</a>
<a href="/uptime/?filter=yes&panel={{ .Panel }}">{{ .Panel }}</a>
</td>
<td>
<a href="/uptime_filter/?panel={{ .Panel }}&host={{ .Host }}">{{ .Host }}</a>
<a href="/uptime/?filter=yes&panel={{ .Panel }}&host={{ .Host }}">{{ .Host }}</a>
</td>
<td>
<a href="/uptime_filter/?addr={{ .Addr }}">{{ .Addr }}</a>
<a href="/uptime/?filter=yes&addr={{ .Addr }}">{{ .Addr }}</a>
</td>
<td>
<a href="/uptime_filter/?port={{ .Port }}">{{ .Port }}</a>
<a href="/uptime/?filter=yes&port={{ .Port }}">{{ .Port }}</a>
</td>
<td>
<a style="color: #{{ .Color }};" href="/uptime_filter/?date={{ .Date }}">{{ .Date }}</a>
<a style="color: #{{ .Color }};" href="/uptime/?filter=yes&date={{ .Date }}">{{ .Date }}</a>
</td>
<td>{{ .Time }}</td>
<td>
{{ if .State }}
<a href="/uptime_filter/?state=on"><i class="bi bi-circle-fill my-col-on"></i></a>
<a href="/uptime/?filter=yes&state=on"><i class="bi bi-circle-fill my-col-on"></i></a>
{{ else }}
<a href="/uptime_filter/?state=off"><i class="bi bi-circle-fill my-col-off"></i></a>
<a href="/uptime/?filter=yes&state=off"><i class="bi bi-circle-fill my-col-off"></i></a>
{{ end }}
</td>
<td>
{{ range .Notify }}
<a href="/uptime_filter/?notify={{ . }}">{{ . }}</a>
<a href="/uptime/?filter=yes&notify={{ . }}">{{ . }}</a>
{{ end }}
</td>
</tr>
Expand Down
22 changes: 2 additions & 20 deletions internal/web/uptime-filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ package web
import (
// "log"
"net/http"
"sort"

"github.com/aceberg/miniboard/internal/check"
"github.com/aceberg/miniboard/internal/models"
)

func uptimeFilterHandler(w http.ResponseWriter, r *http.Request) {
func filterUptime(r *http.Request) []models.MonData {
var resultUptimeMon []models.MonData
var guiData models.GuiData
guiData.Config = AppConfig
guiData.CurrentTab = "Uptime Monitor"
guiData.Links = AllLinks

panel := r.FormValue("panel")
host := r.FormValue("host")
Expand Down Expand Up @@ -43,18 +38,5 @@ func uptimeFilterHandler(w http.ResponseWriter, r *http.Request) {
}
}

guiData.UptimeMon = resultUptimeMon

sort.Slice(guiData.UptimeMon, func(i, j int) bool {
return guiData.UptimeMon[i].Time > guiData.UptimeMon[j].Time
})

if AllLinks.Uptime.Show < 1 {
AllLinks.Uptime.Show = 20
}
if len(guiData.UptimeMon) > AllLinks.Uptime.Show {
guiData.UptimeMon = guiData.UptimeMon[0:AllLinks.Uptime.Show]
}

execTemplate(w, "uptime", guiData)
return resultUptimeMon
}
8 changes: 7 additions & 1 deletion internal/web/uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ func uptimeHandler(w http.ResponseWriter, r *http.Request) {
guiData.CurrentTab = "Uptime Monitor"
guiData.Links = AllLinks

guiData.UptimeMon = UptimeMon
filter := r.FormValue("filter")

if filter == "yes" {
guiData.UptimeMon = filterUptime(r)
} else {
guiData.UptimeMon = UptimeMon
}

sort.Slice(guiData.UptimeMon, func(i, j int) bool {
return guiData.UptimeMon[i].Time > guiData.UptimeMon[j].Time
Expand Down
21 changes: 10 additions & 11 deletions internal/web/webgui.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ func Gui(confPath, yamlPath, nodePath string) {
log.Printf("Web GUI at http://%s", address)
log.Println("=================================== ")

http.HandleFunc("/", indexHandler) // index.go
http.HandleFunc("/config/", configHandler) // config.go
http.HandleFunc("/config_save/", saveConfigHandler) // config.go
http.HandleFunc("/host/", hostHandler) // host.go
http.HandleFunc("/panels/", panelsHandler) // panels.go
http.HandleFunc("/panel_edit/", panelEditHandler) // panel-edit.go
http.HandleFunc("/tabs/", tabsHandler) // tabs.go
http.HandleFunc("/tab_edit/", tabEditHandler) // tab-edit.go
http.HandleFunc("/uptime/", uptimeHandler) // uptime.go
http.HandleFunc("/uptime_edit/", uptimeEditHandler) // uptime-edit.go
http.HandleFunc("/uptime_filter/", uptimeFilterHandler) // uptime-filter.go
http.HandleFunc("/", indexHandler) // index.go
http.HandleFunc("/config/", configHandler) // config.go
http.HandleFunc("/config_save/", saveConfigHandler) // config.go
http.HandleFunc("/host/", hostHandler) // host.go
http.HandleFunc("/panels/", panelsHandler) // panels.go
http.HandleFunc("/panel_edit/", panelEditHandler) // panel-edit.go
http.HandleFunc("/tabs/", tabsHandler) // tabs.go
http.HandleFunc("/tab_edit/", tabEditHandler) // tab-edit.go
http.HandleFunc("/uptime/", uptimeHandler) // uptime.go
http.HandleFunc("/uptime_edit/", uptimeEditHandler) // uptime-edit.go
err := http.ListenAndServe(address, nil)
check.IfError(err)
}

0 comments on commit 283a4c7

Please sign in to comment.