This commit is contained in:
parent
dcbddfc6cd
commit
dbaa8f1de7
2 changed files with 56 additions and 0 deletions
|
@ -21,6 +21,9 @@ type StatsDisplay struct {
|
||||||
Charts []ChartData
|
Charts []ChartData
|
||||||
Libraries []Library
|
Libraries []Library
|
||||||
SelectedLibrary string
|
SelectedLibrary string
|
||||||
|
Size []int
|
||||||
|
Duration []int
|
||||||
|
Count []int
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChartData struct {
|
type ChartData struct {
|
||||||
|
@ -320,10 +323,27 @@ func handleStats(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var size int
|
||||||
|
var count int
|
||||||
|
var duration int
|
||||||
|
err = db.QueryRow(r.Context(),
|
||||||
|
`SELECT SUM(size) AS size,
|
||||||
|
COUNT(id) as count,
|
||||||
|
0 as duration
|
||||||
|
FROM files WHERE ($1 = -1 OR files.library_id = $1) AND status = $2`, id, constants.FILE_STATUS_EXISTS).Scan(&size, &count, &duration)
|
||||||
|
if err != nil {
|
||||||
|
size = 0
|
||||||
|
count = 0
|
||||||
|
duration = 0
|
||||||
|
}
|
||||||
|
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, StatsDisplay{
|
err = templates.ExecuteTemplate(&buf, constants.STATS_TEMPLATE_NAME, StatsDisplay{
|
||||||
Libraries: libraries,
|
Libraries: libraries,
|
||||||
SelectedLibrary: id,
|
SelectedLibrary: id,
|
||||||
|
Size: splitInt(size),
|
||||||
|
Count: splitInt(count),
|
||||||
|
Duration: splitInt(duration),
|
||||||
Charts: data,
|
Charts: data,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -8,6 +8,42 @@
|
||||||
<option {{if eq $.SelectedLibrary $l.ID }} selected {{end}}value="{{$l.ID}}">{{$l.Name}}</option>
|
<option {{if eq $.SelectedLibrary $l.ID }} selected {{end}}value="{{$l.ID}}">{{$l.Name}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<h4>Size</h4>
|
||||||
|
<div class="counter">
|
||||||
|
{{ $l := len .Size }}
|
||||||
|
{{range $i, $c := .Size}}
|
||||||
|
<img class="counter-image" alt="{{$c}}" src="/static/counter/{{$c}}.gif">
|
||||||
|
{{ $n := sub $l $i }}
|
||||||
|
{{ if eq $n 4 }}
|
||||||
|
KB
|
||||||
|
{{ else if eq $n 7 }}
|
||||||
|
MB
|
||||||
|
{{ else if eq $n 10 }}
|
||||||
|
GB
|
||||||
|
{{ else if eq $n 13 }}
|
||||||
|
TB
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h4>Files</h4>
|
||||||
|
<div class="counter">
|
||||||
|
{{ $l := len .Count }}
|
||||||
|
{{range $i, $c := .Count}}
|
||||||
|
<img class="counter-image" alt="{{$c}}" src="/static/counter/{{$c}}.gif">
|
||||||
|
{{ $n := sub $l $i }}
|
||||||
|
{{ if eq $n 4 }}
|
||||||
|
.
|
||||||
|
{{ else if eq $n 7 }}
|
||||||
|
.
|
||||||
|
{{ else if eq $n 10 }}
|
||||||
|
.
|
||||||
|
{{ else if eq $n 13 }}
|
||||||
|
.
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
<div class="stats">
|
<div class="stats">
|
||||||
{{range $c := .Charts}}
|
{{range $c := .Charts}}
|
||||||
{{$c.Element}} {{$c.Script}}
|
{{$c.Element}} {{$c.Script}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue