mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
edbfd54494
4 changed files with 39 additions and 43 deletions
|
|
@ -81,16 +81,20 @@ type AttributeViewFilter struct {
|
|||
type FilterOperator string
|
||||
|
||||
const (
|
||||
FilterOperatorEq FilterOperator = "="
|
||||
FilterOperatorNe FilterOperator = "!="
|
||||
FilterOperatorGt FilterOperator = ">"
|
||||
FilterOperatorGe FilterOperator = ">="
|
||||
FilterOperatorLt FilterOperator = "<"
|
||||
FilterOperatorLe FilterOperator = "<="
|
||||
FilterOperatorContains FilterOperator = "CONTAINS"
|
||||
FilterOperatorNotContains FilterOperator = "NOT CONTAINS"
|
||||
FilterOperatorIsEmpty FilterOperator = "IS EMPTY"
|
||||
FilterOperatorIsNotEmpty FilterOperator = "IS NOT EMPTY"
|
||||
FilterOperatorIsEqual FilterOperator = "="
|
||||
FilterOperatorIsNotEqual FilterOperator = "!="
|
||||
FilterOperatorIsGreater FilterOperator = ">"
|
||||
FilterOperatorIsGreaterOrEqual FilterOperator = ">="
|
||||
FilterOperatorIsLess FilterOperator = "<"
|
||||
FilterOperatorIsLessOrEqual FilterOperator = "<="
|
||||
FilterOperatorContains FilterOperator = "Contains"
|
||||
FilterOperatorDoesNotContain FilterOperator = "Does not contains"
|
||||
FilterOperatorIsEmpty FilterOperator = "Is empty"
|
||||
FilterOperatorIsNotEmpty FilterOperator = "Is not empty"
|
||||
FilterOperatorStartsWith FilterOperator = "Starts with"
|
||||
FilterOperatorEndsWith FilterOperator = "Ends with"
|
||||
FilterOperatorIsBetween FilterOperator = "Is between"
|
||||
FilterOperatorIsRelativeToToday FilterOperator = "Is relative to today"
|
||||
)
|
||||
|
||||
type AttributeViewSort struct {
|
||||
|
|
|
|||
|
|
@ -110,33 +110,33 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
|
|||
}
|
||||
if nil != value.Number && nil != other.Number {
|
||||
switch operator {
|
||||
case FilterOperatorEq:
|
||||
case FilterOperatorIsEqual:
|
||||
return value.Number.Content == other.Number.Content
|
||||
case FilterOperatorNe:
|
||||
case FilterOperatorIsNotEqual:
|
||||
return value.Number.Content != other.Number.Content
|
||||
case FilterOperatorGt:
|
||||
case FilterOperatorIsGreater:
|
||||
return value.Number.Content > other.Number.Content
|
||||
case FilterOperatorGe:
|
||||
case FilterOperatorIsGreaterOrEqual:
|
||||
return value.Number.Content >= other.Number.Content
|
||||
case FilterOperatorLt:
|
||||
case FilterOperatorIsLess:
|
||||
return value.Number.Content < other.Number.Content
|
||||
case FilterOperatorLe:
|
||||
case FilterOperatorIsLessOrEqual:
|
||||
return value.Number.Content <= other.Number.Content
|
||||
}
|
||||
}
|
||||
if nil != value.Date && nil != other.Date {
|
||||
switch operator {
|
||||
case FilterOperatorEq:
|
||||
case FilterOperatorIsEqual:
|
||||
return value.Date.Content == other.Date.Content
|
||||
case FilterOperatorNe:
|
||||
case FilterOperatorIsNotEqual:
|
||||
return value.Date.Content != other.Date.Content
|
||||
case FilterOperatorGt:
|
||||
case FilterOperatorIsGreater:
|
||||
return value.Date.Content > other.Date.Content
|
||||
case FilterOperatorGe:
|
||||
case FilterOperatorIsGreaterOrEqual:
|
||||
return value.Date.Content >= other.Date.Content
|
||||
case FilterOperatorLt:
|
||||
case FilterOperatorIsLess:
|
||||
return value.Date.Content < other.Date.Content
|
||||
case FilterOperatorLe:
|
||||
case FilterOperatorIsLessOrEqual:
|
||||
return value.Date.Content <= other.Date.Content
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue