mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
More CSS & sorting of T array by keys
This commit is contained in:
76
providers/xmlprovider/xmlitemarray.go
Normal file
76
providers/xmlprovider/xmlitemarray.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package xmlprovider
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Sort[T XMLItem](i, j T) int {
|
||||
|
||||
keys_a := i.Keys()
|
||||
keys_b := j.Keys()
|
||||
|
||||
if len(keys_a) == 0 && len(keys_b) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
if len(keys_a) == 0 && len(keys_b) > 0 {
|
||||
return -1
|
||||
}
|
||||
|
||||
if len(keys_a) > 0 && len(keys_b) == 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
sort_a := strings.Split(keys_a[0], "-")
|
||||
sort_b := strings.Split(keys_b[0], "-")
|
||||
|
||||
for i, item := range sort_a {
|
||||
if i >= len(sort_b) {
|
||||
return 1
|
||||
}
|
||||
|
||||
// INFO: this is a bit lazy since
|
||||
// - we are comparing bit values not unicode code points
|
||||
// - the comparison is case sensitive
|
||||
int_a, err := strconv.Atoi(item)
|
||||
if err != nil {
|
||||
if item < sort_b[i] {
|
||||
return -1
|
||||
}
|
||||
|
||||
if item > sort_b[i] {
|
||||
return 1
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
int_b, err := strconv.Atoi(sort_b[i])
|
||||
if err != nil {
|
||||
if item < sort_b[i] {
|
||||
return -1
|
||||
}
|
||||
|
||||
if item > sort_b[i] {
|
||||
return 1
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if int_a < int_b {
|
||||
return -1
|
||||
}
|
||||
|
||||
if int_a > int_b {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
if len(sort_b) > len(sort_a) {
|
||||
return -1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -125,6 +125,8 @@ func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
|
||||
p.Array = append(p.Array, *item)
|
||||
p.addResolvable(*item)
|
||||
}
|
||||
|
||||
slices.SortFunc(p.Array, Sort)
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) addResolvable(item T) {
|
||||
|
||||
Reference in New Issue
Block a user