🎨 Update av

This commit is contained in:
Daniel 2023-07-03 18:45:41 +08:00
parent 7f9a8842f9
commit 4211248740
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 82 additions and 2 deletions

View file

@ -19,6 +19,7 @@ package model
import (
"errors"
"fmt"
"sort"
"strings"
"github.com/88250/gulu"
@ -40,6 +41,36 @@ func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return
}
if 0 < len(ret.Sorts) {
var colIndexes []int
for _, s := range ret.Sorts {
for i, c := range ret.Columns {
if c.ID == s.Column {
colIndexes = append(colIndexes, i)
break
}
}
}
sort.Slice(ret.Rows, func(i, j int) bool {
less := false
for _, index := range colIndexes {
c := ret.Columns[index]
if c.Type == av.ColumnTypeBlock {
continue
}
result := ret.Rows[i].Cells[index].Value.Compare(ret.Rows[j].Cells[index].Value)
if 0 == result {
continue
} else if 0 > result {
less = true
}
}
return less
})
}
return
}