Skip to content

Commit 36e9f15

Browse files
committed
added MachineCount to system/list
1 parent 1dea8fc commit 36e9f15

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

app/handler/system/list.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package system
22

33
import (
4+
"cmp"
45
"encoding/json"
56
"github.com/gofiber/fiber/v2"
67
"github.com/typomedia/patchouli/app/store/boltdb"
78
"github.com/typomedia/patchouli/app/structs"
9+
"slices"
810
)
911

1012
func List(c *fiber.Ctx) error {
@@ -24,9 +26,16 @@ func List(c *fiber.Ctx) error {
2426
if err != nil {
2527
return err
2628
}
29+
machinesOfSystem, err := db.GetMachinesBySystem(system.Id)
30+
if err != nil {
31+
return err
32+
}
33+
system.MachineCount = len(machinesOfSystem)
2734
Systems = append(Systems, system)
2835
}
29-
36+
slices.SortFunc(Systems, func(a, b structs.System) int {
37+
return cmp.Compare(b.MachineCount, a.MachineCount)
38+
})
3039
defer db.Close()
3140

3241
return c.Render("app/views/system/list", fiber.Map{

app/views/system/list.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{{ template "header" . }}
2-
<table>
2+
<table id="sort">
33
<thead>
44
<tr>
55
<th><a href="/system/new"><i class="ri-edit-box-fill"></i> New</a></th>
6+
<th>Machines</th>
67
<th>LTS</th>
78
<th>EOL</th>
89
</tr>
@@ -11,6 +12,7 @@
1112
{{range .Systems}}
1213
<tr>
1314
<td><i class="ri-edit-line"></i> <a href="/system/edit/{{.Id}}">{{.Name}}</a></td>
15+
<td><a href="/machine/filter/system/{{.Id}}"><i class="ri-menu-search-line"></i>{{ .MachineCount }}</a></td>
1416
<td>
1517
{{ if .LTS }}
1618
<span role="button" class="primary">True</span>
@@ -23,4 +25,7 @@
2325
{{end}}
2426
</tbody>
2527
</table>
28+
<script>
29+
new Tablesort(document.getElementById('sort'));
30+
</script>
2631
{{ template "footer" . }}

0 commit comments

Comments
 (0)