Skip to content

Commit 64d8408

Browse files
authored
Merge pull request #11 from typomedia/v0.3.0
v0.3.0
2 parents dd7a4e5 + 8c11594 commit 64d8408

File tree

33 files changed

+346
-66
lines changed

33 files changed

+346
-66
lines changed

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ All data will be stored in a single `patchouli.boltdb` file in the current worki
2323

2424
## Cross compile
2525

26-
make compile
26+
make cross
2727

2828
## Technology
2929

@@ -35,14 +35,9 @@ All data will be stored in a single `patchouli.boltdb` file in the current worki
3535

3636
## Todo
3737

38-
- [ ] add delete functionality
3938
- [ ] add a login page
40-
- [ ] add a `toml` config file
41-
- [ ] email notifications
39+
- [ ] add a global search
4240
- [ ] protect api used by the frontend
43-
- [ ] optimize json/csv export
44-
- [ ] add json/csv import api
45-
- [ ] refactor some quirky code
4641
- [ ] write some tests...
4742

4843
## Systemd
@@ -61,4 +56,4 @@ If not running in a container, change the `User` and `Group` for security reason
6156
Patchouli is licensed under the [GNU General Public License v3.0](LICENSE).
6257

6358
---
64-
Copyright © 2024 Typomedia Foundation. All rights reserved.
59+
Copyright © 2025 Typomedia Foundation. All rights reserved.

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Application struct {
2020
func new() *Application {
2121
app = &Application{}
2222
app.Name = "Patchouli"
23-
app.Version = "0.2.1"
23+
app.Version = "0.3.0"
2424
app.Author = "Philipp Speck <[email protected]>"
2525
app.Description = "Patch Management Planner"
2626
err := app.LoadConfig()

app/handler/api/htmx/operator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func Operator(c *fiber.Ctx) error {
3939
if err != nil {
4040
return err
4141
}
42+
if operator.Inactive {
43+
continue
44+
}
4245
Operators = append(Operators, operator)
4346
}
4447

app/handler/api/htmx/operators.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func Operators(c *fiber.Ctx) error {
2626
if err != nil {
2727
return err
2828
}
29+
if operator.Inactive {
30+
continue
31+
}
2932
Operators = append(Operators, operator)
3033
}
3134

app/handler/machine/list.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package machine
22

33
import (
4+
"cmp"
45
"github.com/gofiber/fiber/v2"
56
"github.com/typomedia/patchouli/app/store/boltdb"
67
"github.com/typomedia/patchouli/app/structs"
8+
"slices"
9+
"strings"
710
)
811

912
func List(c *fiber.Ctx) error {
@@ -22,6 +25,14 @@ func List(c *fiber.Ctx) error {
2225
}
2326
}
2427

28+
slices.SortFunc(active, func(a, b structs.Machine) int {
29+
return cmp.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
30+
})
31+
32+
slices.SortFunc(inactive, func(a, b structs.Machine) int {
33+
return cmp.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
34+
})
35+
2536
Machines = append(active, inactive...)
2637

2738
defer db.Close()

app/handler/operator/edit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func Edit(c *fiber.Ctx) error {
2222
log.Error(err)
2323
}
2424

25+
machinesOfOperator, err := db.GetMachinesByOperator(operator.Id)
26+
if err != nil {
27+
return err
28+
}
29+
operator.MachineCount = len(machinesOfOperator)
30+
2531
defer db.Close()
2632

2733
return c.Render("app/views/operator/edit", fiber.Map{

app/handler/operator/list.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
11
package operator
22

33
import (
4+
"cmp"
45
"github.com/gofiber/fiber/v2"
56
"github.com/typomedia/patchouli/app/store/boltdb"
7+
"github.com/typomedia/patchouli/app/structs"
8+
"slices"
9+
"strings"
610
)
711

812
func List(c *fiber.Ctx) error {
913
db := boltdb.New()
1014

1115
operators, err := db.GetAllOperators()
16+
var Operators structs.Operators
1217
if err != nil {
1318
return err
1419
}
20+
for _, operator := range operators {
21+
operator.MachineCount = 0
22+
machinesOfOperator, err := db.GetMachinesByOperator(operator.Id)
23+
if err != nil {
24+
return err
25+
}
26+
operator.MachineCount = len(machinesOfOperator)
27+
Operators = append(Operators, operator)
28+
}
29+
30+
slices.SortFunc(Operators, func(a, b structs.Operator) int {
31+
return cmp.Compare(strings.ToLower(a.Name), strings.ToLower(b.Name))
32+
})
1533

1634
defer db.Close()
1735

1836
return c.Render("app/views/operator/list", fiber.Map{
19-
"Operators": operators,
37+
"Operators": Operators,
2038
})
2139
}

app/handler/system/delete.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package system
2+
3+
import (
4+
"errors"
5+
"github.com/gofiber/fiber/v2"
6+
"github.com/gofiber/fiber/v2/log"
7+
"github.com/typomedia/patchouli/app/store/boltdb"
8+
"github.com/typomedia/patchouli/app/structs"
9+
)
10+
11+
func Delete(c *fiber.Ctx) error {
12+
id := c.Params("id")
13+
14+
if id == "" {
15+
log.Error(errors.New("id is required"))
16+
}
17+
18+
db := boltdb.New()
19+
err := db.SetBucket("systems")
20+
if err != nil {
21+
log.Error(err)
22+
}
23+
24+
system := structs.System{}
25+
err = db.Get(id, &system, "systems")
26+
if err != nil {
27+
log.Error(err)
28+
}
29+
30+
err = db.Delete(system.Id, "systems")
31+
if err != nil {
32+
log.Error(err)
33+
}
34+
defer db.Close()
35+
36+
return c.Redirect("/system")
37+
}

app/handler/system/edit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ func Edit(c *fiber.Ctx) error {
2222
log.Error(err)
2323
}
2424

25+
machinesOfSystem, err := db.GetMachinesBySystem(system.Id)
26+
if err != nil {
27+
log.Error(err)
28+
}
29+
system.MachineCount = len(machinesOfSystem)
30+
2531
defer db.Close()
2632

2733
return c.Render("app/views/system/edit", fiber.Map{

app/handler/system/list.go

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

33
import (
4-
"cmp"
54
"encoding/json"
65
"github.com/gofiber/fiber/v2"
76
"github.com/typomedia/patchouli/app/store/boltdb"
87
"github.com/typomedia/patchouli/app/structs"
9-
"slices"
108
)
119

1210
func List(c *fiber.Ctx) error {
@@ -20,6 +18,7 @@ func List(c *fiber.Ctx) error {
2018
systems, _ := db.GetAll("systems")
2119

2220
Systems := structs.Systems{}
21+
systemsWithoutEOL := structs.Systems{}
2322
for _, v := range systems {
2423
system := structs.System{}
2524
err = json.Unmarshal(v, &system)
@@ -31,11 +30,16 @@ func List(c *fiber.Ctx) error {
3130
return err
3231
}
3332
system.MachineCount = len(machinesOfSystem)
34-
Systems = append(Systems, system)
33+
if system.EOL == "" {
34+
systemsWithoutEOL = append(systemsWithoutEOL, system)
35+
} else {
36+
Systems = append(Systems, system)
37+
}
3538
}
36-
slices.SortFunc(Systems, func(a, b structs.System) int {
37-
return cmp.Compare(b.MachineCount, a.MachineCount)
38-
})
39+
40+
Systems.OrderedBy(Systems.ByName(), Systems.ByEOL()).Sort(Systems)
41+
Systems = append(Systems, systemsWithoutEOL...)
42+
3943
defer db.Close()
4044

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

0 commit comments

Comments
 (0)