Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-07-03 20:55:12 +08:00
commit 4041c509f6
2 changed files with 24 additions and 9 deletions

View file

@ -58,6 +58,7 @@ func filterRows(ret *av.AttributeView) {
}
}
}
colIndexes = util.RemoveDuplicatedElem(colIndexes)
var rows []*av.Row
for _, row := range ret.Rows {
@ -92,9 +93,9 @@ func sortRows(ret *av.AttributeView) {
}
}
}
colIndexes = util.RemoveDuplicatedElem(colIndexes)
sort.Slice(ret.Rows, func(i, j int) bool {
less := false
for _, index := range colIndexes {
c := ret.Columns[index]
if c.Type == av.ColumnTypeBlock {
@ -104,11 +105,13 @@ func sortRows(ret *av.AttributeView) {
result := ret.Rows[i].Cells[index].Value.Compare(ret.Rows[j].Cells[index].Value)
if 0 == result {
continue
} else if 0 > result {
less = true
}
if 0 > result {
return true
}
}
return less
return false
})
}
}
@ -407,12 +410,12 @@ func sortAttributeViewColumn(columnID, previousColumnID, avID string) (err error
break
}
}
attrView.Columns = util.InsertElement(attrView.Columns, previousIndex, col)
attrView.Columns = util.InsertElem(attrView.Columns, previousIndex, col)
for _, row := range attrView.Rows {
cel := row.Cells[index]
row.Cells = append(row.Cells[:index], row.Cells[index+1:]...)
row.Cells = util.InsertElement(row.Cells, previousIndex, cel)
row.Cells = util.InsertElem(row.Cells, previousIndex, cel)
}
err = av.SaveAttributeView(attrView)
@ -445,7 +448,7 @@ func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
break
}
}
attrView.Rows = util.InsertElement(attrView.Rows, previousIndex, row)
attrView.Rows = util.InsertElem(attrView.Rows, previousIndex, row)
err = av.SaveAttributeView(attrView)
return

View file

@ -24,9 +24,21 @@ import (
"github.com/88250/lute/html"
)
// InsertElement inserts a new element value at the specified index position.
// 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 InsertElement[T any](ret []T, index int, value T) []T {
func InsertElem[T any](ret []T, index int, value T) []T {
if len(ret) == index { // nil or empty slice or after last element
return append(ret, value)
}