🎨 Database table view cell value adds createdAt and updatedAt fields https://github.com/siyuan-note/siyuan/issues/10492

Adding rows after setting the sort field in the database table view no longer fills in the default value https://github.com/siyuan-note/siyuan/issues/10486
This commit is contained in:
Daniel 2024-03-03 16:12:44 +08:00
parent 49031aaca7
commit 01744ae69e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 71 additions and 72 deletions

View file

@ -269,7 +269,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
}
}
if 0 == v.Block.Updated {
v.Block.Updated = now
v.Block.Updated = v.Block.Created
}
}
case KeyTypeNumber:
@ -302,6 +302,19 @@ func SaveAttributeView(av *AttributeView) (err error) {
}
}
}
// 补全值的创建时间和更新时间
createdStr := v.ID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
v.CreatedAt = created.UnixMilli()
} else {
v.CreatedAt = now
}
if 0 == v.UpdatedAt {
v.UpdatedAt = v.CreatedAt
}
}
}

View file

@ -84,12 +84,20 @@ const (
func (value *Value) Compare(other *Value) int {
if nil == value {
return -1
return 1
}
if nil == other {
return -1
}
if !value.IsEdited() {
return 1
}
if !other.IsEdited() {
return -1
}
switch value.Type {
case KeyTypeBlock:
if nil != value.Block && nil != other.Block {

View file

@ -37,6 +37,9 @@ type Value struct {
Type KeyType `json:"type,omitempty"`
IsDetached bool `json:"isDetached,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
Block *ValueBlock `json:"block,omitempty"`
Text *ValueText `json:"text,omitempty"`
Number *ValueNumber `json:"number,omitempty"`
@ -180,6 +183,14 @@ func (value *Value) Clone() (ret *Value) {
return
}
func (value *Value) IsEdited() bool {
if value.CreatedAt == value.UpdatedAt {
// 说明是刚刚创建的块
return false
}
return true
}
type ValueBlock struct {
ID string `json:"id"`
Content string `json:"content"`