Alter 8 files

Update `index.go`
Update `index.html`
Update `main.css`
Update `main.css.map`
Update `main.scss`
Update `tables.go`
Rename `session.go` to `viewSession.go`
Update `webui.go`
This commit is contained in:
akp 2023-04-02 19:44:27 +01:00
parent 91d16e7339
commit b54400e1b3
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
8 changed files with 56 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/codemicro/analytics/analytics/db/models"
"github.com/flosch/pongo2/v6"
"github.com/gofiber/fiber/v2"
"strconv"
)
func (wui *WebUI) page_index(ctx *fiber.Ctx) error {
@ -55,3 +56,42 @@ func (wui *WebUI) partial_activeSessionsTable(ctx *fiber.Ctx) error {
}
return wui.renderHTMLTable(ctx, ht)
}
func (wui *WebUI) partial_topURLs(ctx *fiber.Ctx) error {
nStr := ctx.Query("n")
var n int
if nStr != "" {
n, _ = strconv.Atoi(nStr)
}
ht := &HTMLTable{
Headers: []*HTMLTableHeader{
{"Count", "", false, false},
{"Host", "", false, false},
{"Path", "", false, false},
},
Data: func(sortKey, sortDirection string) ([][]any, error) {
var counts []struct {
Host string
URI string
Count int
}
q := wui.db.DB.NewSelect().
ColumnExpr(`"host", "uri", COUNT(*) as "count"`).Table("requests").GroupExpr(`"host", "uri"`).OrderExpr(`"count" DESC`)
if n > 0 {
q = q.Limit(n)
}
if err := q.Scan(context.Background(), &counts); err != nil {
return nil, err
}
var res [][]any
for _, c := range counts {
res = append(res, []any{c.Count, c.Host, c.URI})
}
return res, nil
},
}
return wui.renderHTMLTable(ctx, ht)
}

View file

@ -1,6 +1,17 @@
{% extends "extendable/base.html" %}
{% block main %}
<h2>Top 10 URLs</h2>
<div hx-get="/partial/topURLs?n=10"
hx-trigger="load"
hx-swap="outerHTML"
>
Loading...
</div>
<a href="/top">[See all]</a>
<h2>Active sessions</h2>
<div hx-get="/partial/activeSessions"
@ -9,6 +20,4 @@
>
Loading...
</div>
</div>
{% endblock %}

View file

@ -46,6 +46,7 @@ div.table table {
width: 60%;
white-space: nowrap;
border-collapse: collapse;
margin-bottom: 10px;
overflow-y: scroll;
}
div.table table tr:nth-child(even) {

View file

@ -1 +1 @@
{"version":3,"sourceRoot":"","sources":["main.scss"],"names":[],"mappings":"AAAA;EACE;EAEA;EACA;EAEA;EACA;;;AAgBF;EAEE;;;AAKF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;AAIA;EACE;EACA,cAJY;;AAOd;EACE;;AAGF;EAfF;IAgBI;;EAEA;IAAW;IAAqB,eAdpB;;EAeZ;IAAsB,eAfV;;;;AAoBd;EACE;EACA;EACA;EAEA;;AAGE;EAAoB;;AACpB;EAAU;;AAGZ;EACE;;AAGF;EACE;EACA","file":"main.css"}
{"version":3,"sourceRoot":"","sources":["main.scss"],"names":[],"mappings":"AAAA;EACE;EAEA;EACA;EAEA;EACA;;;AAgBF;EAEE;;;AAKF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;;AAIA;EACE;EACA,cAJY;;AAOd;EACE;;AAGF;EAfF;IAgBI;;EAEA;IAAW;IAAqB,eAdpB;;EAeZ;IAAsB,eAfV;;;;AAoBd;EACE;EACA;EACA;EACA;EAEA;;AAGE;EAAoB;;AACpB;EAAU;;AAGZ;EACE;;AAGF;EACE;EACA","file":"main.css"}

View file

@ -64,6 +64,7 @@ div.table {
width: 60%;
white-space: nowrap;
border-collapse: collapse;
margin-bottom: 10px;
overflow-y: scroll;
@ -80,6 +81,5 @@ div.table {
border-bottom: 3px solid black;
background-color: unset;
}
}
}

View file

@ -1,7 +1,6 @@
package webui
import (
"fmt"
"github.com/flosch/pongo2/v6"
"github.com/gofiber/fiber/v2"
"strings"
@ -45,7 +44,6 @@ func (wui *WebUI) renderHTMLTable(ctx *fiber.Ctx, ht *HTMLTable) error {
}
if sortDirection == "" || !(sortDirection == "asc" || sortDirection == "desc") {
fmt.Println("ere", sortDirection, sortKey)
if sortKey == "" {
sortDirection = ""
} else {

View file

@ -102,6 +102,8 @@ func (wui *WebUI) registerHandlers() {
wui.app.Get("/session", wui.page_logsFromSession)
wui.app.Get("/partial/sessionLogs/:id", wui.partial_logsFromSession)
wui.app.Get("/partial/topURLs", wui.partial_topURLs)
wui.app.Use("/", filesystem.New(filesystem.Config{
Root: http.FS(static),
PathPrefix: "static",