-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.templ
181 lines (177 loc) · 4.56 KB
/
log.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// -*- html -*-
package main
import (
"github.com/fingon/lixie/data"
"strconv"
)
templ LogListRuleLink(rule *data.LogRule) {
if rule != nil {
<a href={ ruleLink(rule.ID, "edit") }>{ strconv.Itoa(rule.ID) }</a>
}
}
templ LogListTable(m LogListModel) {
<table class="table table-hover">
<thead>
if !m.Config.AutoRefresh && !m.DisableActions {
<th scope="col">Op</th>
}
<th scope="col">
Time<i class="bi bi-arrow-down"></i>
</th>
<th scope="col">Stream</th>
<th scope="col">Fields</th>
<th scope="col">Rule</th>
<th scope="col">Message</th>
</thead>
<tbody>
for _, log := range m.Logs {
<tr id={ log.IDString() }>
if !m.Config.AutoRefresh {
<td>
<div class="btn-group">
if m.LogVerdict(log) != data.LogVerdictSpam {
<a class="btn btn-sm btn-primary" href={ logLink(log, "spam") }>-</a>
}
if m.LogVerdict(log) != data.LogVerdictHam {
<a class="btn btn-sm btn-primary" href={ logLink(log, "ham") }>!</a>
}
</div>
</td>
}
<td>{ log.Time.Format("15:04:05.000") }</td>
<td>
if m.Config.Expand != log.Hash() && !m.DisableActions {
{ primaryStreamKey }={ log.Stream[primaryStreamKey] }
<a href={ m.Config.WithExpand(log.Hash()).Query().ToLink() }>
+{ strconv.Itoa(len(log.StreamKeys)-1) }
</a>
} else {
<a href={ m.Config.WithExpand(0).Query().ToLink() }>-</a>
for _, k := range log.StreamKeys {
{ k }={ log.Stream[k] }
<br/>
}
}
</td>
<td>
if m.Config.Expand != log.Hash() && !m.DisableActions {
<a href={ m.Config.WithExpand(log.Hash()).Query().ToLink() }>
+{ strconv.Itoa(len(log.FieldsKeys)) }
</a>
} else {
<a href={ m.Config.WithExpand(0).Query().ToLink() }>-</a>
for _, k := range log.FieldsKeys {
{ k }={ toJSON(log.Fields[k]) }
<br/>
}
}
</td>
<td>
@LogListRuleLink(m.LogToRule(log))
</td>
<td>
if m.LogVerdict(log) == data.LogVerdictHam {
<b>{ log.Message }</b>
} else if m.LogVerdict(log) == data.LogVerdictSpam {
<em>{ log.Message }</em>
} else {
{ log.Message }
}
</td>
</tr>
}
if len(m.Logs) == m.Limit && !m.Config.AutoRefresh && !m.DisablePagination {
<tr>
<td colspan="4">
<span
hx-target="closest tr"
hx-trigger="revealed"
hx-swap="outerHTML"
hx-select="tbody > tr"
hx-get={ m.Config.WithBeforeHash(m.Logs[len(m.Logs)-1].Hash()).Query().ToLinkString() }
>
Loading More...
</span>
</td>
</tr>
}
</tbody>
</table>
}
templ LogList(st State, m LogListModel) {
@Base(st, TopLevelLog, "Log list") {
@Row("refresh-and-count") {
@Col(3) {
if m.Config.AutoRefresh {
<a
class="btn btn-sm btn-primary"
href={ m.Config.Query().Add(llAutoRefreshKey, "false").ToLink() }
>Turn off autorefresh</a>
<div
hx-get={ m.Config.Query().ToLinkString() }
hx-trigger="every 1s"
hx-target="#container"
hx-select="#container"
></div>
} else {
<a
class="btn btn-sm btn-primary"
href={ m.Config.Query().Add(llAutoRefreshKey, "true").ToLink() }
>Turn on autorefresh</a>
<a class="btn btn-sm btn-primary" href={ m.Config.Query().ToLink() }>Refresh</a>
}
}
@Col(2) {
<form>
<input
class="form-text"
type="text"
name={ globalSearchKey }
hx-trigger="change, keyup delay:200ms changed"
hx-post={ m.Config.Query().ToLinkString() }
hx-select="#logs"
hx-swap="outerHTML"
hx-target="#logs"
value={ m.Config.Global.Search }
placeholder="Search for text"
/>
</form>
}
@Col(5) {
<ul class="nav nav-pills">
for verdict := range data.NumLogVerdicts {
<li class="nav-item">
if m.Config.Filter == verdict {
<a class="nav-link active bg-success-subtle" href={ m.Config.Query().ToLink() }>
{ data.LogVerdictToString(verdict) } filtered
</a>
} else {
<a class="nav-link" href={ m.Config.Query().Add(llFilterKey, strconv.Itoa(verdict)).ToLink() }>
No { data.LogVerdictToString(verdict) }
</a>
}
</li>
}
</ul>
}
@Col(2) {
<div
class="float-end"
id="counts"
if m.Post {
hx-swap-oob="counts"
}
>
{ strconv.Itoa(m.TotalCount) } log entries
<br/>
{ strconv.Itoa(m.FilteredCount) } shown
</div>
}
}
@Row("logs") {
@Col(12) {
@LogListTable(m)
}
}
}
}