Skip to content

Commit

Permalink
UI: fix duplicate product entries (#13709)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed May 3, 2024
1 parent 887c96e commit a9a080f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion util/templates/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package templates

type Class int

//go:generate enumer -type Class
//go:generate enumer -type Class -transform=lower
const (
_ Class = iota
Charger
Expand Down
4 changes: 2 additions & 2 deletions util/templates/class_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 7 additions & 15 deletions util/templates/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"embed"
"fmt"
"io/fs"
"path"
"slices"
"sync"
"text/template"
Expand Down Expand Up @@ -33,8 +32,8 @@ func init() {

baseTmpl = template.Must(template.ParseFS(includeFS, "includes/*.tpl"))

for _, class := range ClassValues() {
loadTemplates(class)
for _, class := range []Class{Charger, Meter, Vehicle, Tariff} {
templates[class] = load(class)
}
}

Expand Down Expand Up @@ -66,12 +65,8 @@ func FromBytes(b []byte) (Template, error) {
return tmpl, err
}

func loadTemplates(class Class) {
if templates[class] != nil {
return
}

err := fs.WalkDir(definition.YamlTemplates, ".", func(filepath string, d fs.DirEntry, err error) error {
func load(class Class) (res []Template) {
err := fs.WalkDir(definition.YamlTemplates, class.String(), func(filepath string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
Expand All @@ -89,18 +84,15 @@ func loadTemplates(class Class) {
return fmt.Errorf("processing template '%s' failed: %w", filepath, err)
}

class, err := ClassString(path.Dir(filepath))
if err != nil {
return fmt.Errorf("invalid template class: '%s'", err)
}

templates[class] = append(templates[class], tmpl)
res = append(res, tmpl)

return nil
})
if err != nil {
panic(err)
}

return res
}

// EncoderLanguage sets the template language for encoding json
Expand Down

0 comments on commit a9a080f

Please sign in to comment.