UI: fix duplicate product entries (#13709)
This commit is contained in:
parent
887c96ec37
commit
a9a080f6ff
3 changed files with 10 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by "enumer -type Class"; DO NOT EDIT.
|
||||
// Code generated by "enumer -type Class -transform=lower"; DO NOT EDIT.
|
||||
|
||||
package templates
|
||||
|
||||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const _ClassName = "ChargerMeterVehicleTariffCircuit"
|
||||
const _ClassName = "chargermetervehicletariffcircuit"
|
||||
|
||||
var _ClassIndex = [...]uint8{0, 7, 12, 19, 25, 32}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"slices"
|
||||
"sync"
|
||||
"text/template"
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue