no historical data shenanigans

This commit is contained in:
iacore 2024-09-25 18:44:55 +00:00
parent 204849fe82
commit f874e95a9d
Signed by: iacore
GPG key ID: F8C16E5157A63006
2 changed files with 30 additions and 13 deletions

39
main.go
View file

@ -26,7 +26,7 @@ var staticAssets embed.FS
//go:embed all:templates
var templateAssets embed.FS
func parseAndRenderTemplate(templateName, siteName, iconSrc string, data []core.Row) (string, error) {
func parseAndRenderTemplate(templateName, siteName, iconSrc string, data scanner.ServiceStatusBatch) (string, error) {
rawTemplate, err := templateAssets.ReadFile(templateName)
if err != nil {
return "", err
@ -87,12 +87,13 @@ func index(w http.ResponseWriter, r *http.Request) {
if (!accept_html || prefer_text) && accept_text {
indexForVT100(w, r, data)
} else if accept_html {
historical_data, err := dbm.QueryAllAfter(time.Now().Add(-7 * 24 * time.Hour))
if err != nil {
http.Error(w, err.Error(), 500)
return
}
indexForBrowserWithHistoricalData(w, r, historical_data, config.SiteName, config.IconSrc)
// historical_data, err := dbm.QueryAllAfter(time.Now().Add(-7 * 24 * time.Hour))
// if err != nil {
// http.Error(w, err.Error(), 500)
// return
// }
// indexForBrowserWithHistoricalData(w, r, historical_data, config.SiteName, config.IconSrc)
indexForBrowser(w, r, data, config.SiteName, config.IconSrc)
} else { // when no valid content type is requested
// not to-spec. still sends plain text anyway
indexForVT100(w, r, data)
@ -105,13 +106,14 @@ func indexForVT100(w http.ResponseWriter, _ *http.Request, data scanner.ServiceS
w.Write([]byte(parsedTemplate))
}
func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, historical_data []core.Row, siteName string, iconSrc string) {
func indexForBrowser(w http.ResponseWriter, _ *http.Request, data scanner.ServiceStatusBatch, siteName string, iconSrc string) {
// the basic idea here:
// - create new template and render it with historical_data
// - create new template and render it with data
//
// reference: see `indexForBrowser` above
parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, historical_data)
parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, data)
if err != nil {
http.Error(w, err.Error(), 500)
return
@ -120,6 +122,21 @@ func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, h
w.Write([]byte(parsedTemplate))
}
// func indexForBrowserWithHistoricalData(w http.ResponseWriter, _ *http.Request, historical_data []core.Row, siteName string, iconSrc string) {
// // the basic idea here:
// // - create new template and render it with historical_data
// //
// // reference: see `indexForBrowser` above
// parsedTemplate, err := parseAndRenderTemplate("templates/index.html", siteName, iconSrc, historical_data)
// if err != nil {
// http.Error(w, err.Error(), 500)
// return
// }
// w.Write([]byte(parsedTemplate))
// }
var config *core.Config
var dbm core.Database
var client *core.MatrixClient
@ -221,7 +238,7 @@ func main() {
if err != nil {
log.Printf("Error in core.GetBootTime: %v", err)
} else {
time_passed := time.Now().Sub(btime)
time_passed := time.Since(btime)
time.Sleep(core.WaitDurationAfterBoot - time_passed)
}

View file

@ -15,7 +15,7 @@
<main>
<ul class="serviceContainer">
{{#Data}}{{#Data}}
{{#Data}}
<li>
<div class="service {{#Ok}}serviceUp{{/Ok}}{{^Ok}}serviceDown{{/Ok}}">
<div>
@ -31,7 +31,7 @@
</div>
</div>
</li>
{{/Data}}{{/Data}}
{{/Data}}
</ul>
</main>