🎨 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

@ -94,8 +94,8 @@ const (
)
type AttributeViewSort struct {
Column string `json:"column"`
Order SortOrder `json:"order"`
Column string `json:"column"` // 列 ID
Order SortOrder `json:"order"` // 排序顺序
}
type SortOrder string

View file

@ -19,6 +19,7 @@ package av
import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"strings"
)
type Cell struct {
@ -46,6 +47,54 @@ func (value *Value) ToJSONString() string {
return string(data)
}
func (value *Value) Compare(other *Value) int {
if nil == value {
return -1
}
if nil == other {
return 1
}
if nil != value.Block && nil != other.Block {
return strings.Compare(value.Block.Content, other.Block.Content)
}
if nil != value.Text && nil != other.Text {
return strings.Compare(value.Text.Content, other.Text.Content)
}
if nil != value.Number && nil != other.Number {
if value.Number.Content > other.Number.Content {
return 1
} else if value.Number.Content < other.Number.Content {
return -1
} else {
return 0
}
}
if nil != value.Date && nil != other.Date {
if value.Date.Content > other.Date.Content {
return 1
} else if value.Date.Content < other.Date.Content {
return -1
} else {
return 0
}
}
if nil != value.Select && nil != other.Select {
return strings.Compare(value.Select.Content, other.Select.Content)
}
if nil != value.MSelect && nil != other.MSelect {
var v1 string
for _, v := range value.MSelect {
v1 += v.Content
}
var v2 string
for _, v := range other.MSelect {
v2 += v.Content
}
return strings.Compare(v1, v2)
}
return 0
}
func NewCellBlock(blockID, blockContent string) *Cell {
return &Cell{
ID: ast.NewNodeID(),