mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-02-28 05:32:52 +00:00
🎨 Update av
This commit is contained in:
@@ -58,7 +58,6 @@ func filterRows(ret *av.AttributeView) {
|
||||
}
|
||||
}
|
||||
}
|
||||
colIndexes = util.RemoveDuplicatedElem(colIndexes)
|
||||
|
||||
var rows []*av.Row
|
||||
for _, row := range ret.Rows {
|
||||
@@ -84,32 +83,37 @@ func filterRows(ret *av.AttributeView) {
|
||||
|
||||
func sortRows(ret *av.AttributeView) {
|
||||
if 0 < len(ret.Sorts) {
|
||||
var colIndexes []int
|
||||
type ColIndexSort struct {
|
||||
Index int
|
||||
Order av.SortOrder
|
||||
}
|
||||
|
||||
var colIndexSorts []*ColIndexSort
|
||||
for _, s := range ret.Sorts {
|
||||
for i, c := range ret.Columns {
|
||||
if c.ID == s.Column {
|
||||
colIndexes = append(colIndexes, i)
|
||||
colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
colIndexes = util.RemoveDuplicatedElem(colIndexes)
|
||||
|
||||
sort.Slice(ret.Rows, func(i, j int) bool {
|
||||
for _, index := range colIndexes {
|
||||
c := ret.Columns[index]
|
||||
for _, colIndexSort := range colIndexSorts {
|
||||
c := ret.Columns[colIndexSort.Index]
|
||||
if c.Type == av.ColumnTypeBlock {
|
||||
continue
|
||||
}
|
||||
|
||||
result := ret.Rows[i].Cells[index].Value.Compare(ret.Rows[j].Cells[index].Value)
|
||||
result := ret.Rows[i].Cells[colIndexSort.Index].Value.Compare(ret.Rows[j].Cells[colIndexSort.Index].Value)
|
||||
if 0 == result {
|
||||
continue
|
||||
}
|
||||
|
||||
if 0 > result {
|
||||
return true
|
||||
if colIndexSort.Order == av.SortOrderAsc {
|
||||
return 0 > result
|
||||
}
|
||||
return 0 < result
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
@@ -24,18 +24,6 @@ import (
|
||||
"github.com/88250/lute/html"
|
||||
)
|
||||
|
||||
// RemoveDuplicatedElem removes the duplicated elements from the slice.
|
||||
func RemoveDuplicatedElem(slice []int) (ret []int) {
|
||||
allKeys := make(map[int]bool)
|
||||
for _, item := range slice {
|
||||
if _, value := allKeys[item]; !value {
|
||||
allKeys[item] = true
|
||||
ret = append(ret, item)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InsertElem inserts a new element value at the specified index position.
|
||||
// 0 <= index <= len(a)
|
||||
func InsertElem[T any](ret []T, index int, value T) []T {
|
||||
|
||||
Reference in New Issue
Block a user