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

This commit is contained in:
Daniel 2024-03-03 16:58:37 +08:00
parent e487897b54
commit ce58bccd63
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
3 changed files with 26 additions and 5 deletions

View File

@ -91,10 +91,11 @@ func (value *Value) Compare(other *Value) int {
}
if !value.IsEdited() {
if other.IsEdited() {
return 1
}
if !other.IsEdited() {
return int(value.CreatedAt - other.CreatedAt)
} else if !other.IsEdited() {
return -1
}

View File

@ -184,8 +184,12 @@ func (value *Value) Clone() (ret *Value) {
}
func (value *Value) IsEdited() bool {
if 1709454120000 > value.CreatedAt {
// 说明是旧数据,认为都是编辑过的
return true
}
if value.CreatedAt == value.UpdatedAt {
// 说明是刚刚创建的块
return false
}
return true

View File

@ -976,7 +976,23 @@ func FillAttributeViewTableCellNilValue(tableCell *av.TableCell, rowID, colID st
}
func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ av.KeyType) (ret *av.Value) {
if "" == valueID {
valueID = ast.NewNodeID()
}
ret = &av.Value{ID: valueID, KeyID: keyID, BlockID: blockID, Type: typ}
createdStr := valueID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
ret.CreatedAt = created.UnixMilli()
} else {
ret.CreatedAt = time.Now().UnixMilli()
}
if 0 == ret.UpdatedAt {
ret.UpdatedAt = ret.CreatedAt
}
switch typ {
case av.KeyTypeText:
ret.Text = &av.ValueText{}