mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve av https://github.com/siyuan-note/siyuan/issues/14511
This commit is contained in:
parent
aaf1d9896a
commit
de8eb72393
6 changed files with 35 additions and 36 deletions
|
|
@ -120,15 +120,11 @@ func upgradeSpec1(av *AttributeView) {
|
||||||
for _, v := range kv.Values {
|
for _, v := range kv.Values {
|
||||||
if 0 == v.Block.Created {
|
if 0 == v.Block.Created {
|
||||||
logging.LogWarnf("block [%s] created time is empty", v.BlockID)
|
logging.LogWarnf("block [%s] created time is empty", v.BlockID)
|
||||||
if "" == v.Block.ID {
|
if "" == v.BlockID {
|
||||||
v.Block.ID = v.BlockID
|
v.BlockID = ast.NewNodeID()
|
||||||
if "" == v.Block.ID {
|
|
||||||
v.Block.ID = ast.NewNodeID()
|
|
||||||
v.BlockID = v.Block.ID
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createdStr := v.Block.ID[:len("20060102150405")]
|
createdStr := v.BlockID[:len("20060102150405")]
|
||||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||||
if nil == parseErr {
|
if nil == parseErr {
|
||||||
v.Block.Created = created.UnixMilli()
|
v.Block.Created = created.UnixMilli()
|
||||||
|
|
|
||||||
|
|
@ -865,21 +865,21 @@ func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *V
|
||||||
case KeyTypeBlock:
|
case KeyTypeBlock:
|
||||||
switch filter.Operator {
|
switch filter.Operator {
|
||||||
case FilterOperatorIsEqual:
|
case FilterOperatorIsEqual:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorIsNotEqual:
|
case FilterOperatorIsNotEqual:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorContains:
|
case FilterOperatorContains:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorDoesNotContain:
|
case FilterOperatorDoesNotContain:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorStartsWith:
|
case FilterOperatorStartsWith:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorEndsWith:
|
case FilterOperatorEndsWith:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: filter.Value.Block.Content, Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorIsEmpty:
|
case FilterOperatorIsEmpty:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
case FilterOperatorIsNotEmpty:
|
case FilterOperatorIsNotEmpty:
|
||||||
ret.Block = &ValueBlock{ID: addingBlockID, Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
ret.Block = &ValueBlock{Content: "", Created: ret.CreatedAt, Updated: ret.UpdatedAt}
|
||||||
}
|
}
|
||||||
case KeyTypeText:
|
case KeyTypeText:
|
||||||
switch filter.Operator {
|
switch filter.Operator {
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ func (value *Value) GetValByType(typ KeyType) (ret interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValueBlock struct {
|
type ValueBlock struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"` // 绑定的块 ID,非绑定块时为空
|
||||||
Icon string `json:"icon"`
|
Icon string `json:"icon"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
|
|
|
||||||
|
|
@ -847,9 +847,9 @@ func AppendAttributeViewDetachedBlocksWithValues(avID string, blocksValues [][]*
|
||||||
v.BlockID = blockID
|
v.BlockID = blockID
|
||||||
v.Type = keyValues.Key.Type
|
v.Type = keyValues.Key.Type
|
||||||
if av.KeyTypeBlock == v.Type {
|
if av.KeyTypeBlock == v.Type {
|
||||||
v.Block.ID = blockID
|
|
||||||
v.Block.Created = now
|
v.Block.Created = now
|
||||||
v.Block.Updated = now
|
v.Block.Updated = now
|
||||||
|
v.Block.ID = "" // 非绑定块 ID 置空
|
||||||
}
|
}
|
||||||
v.IsDetached = true
|
v.IsDetached = true
|
||||||
v.CreatedAt = now
|
v.CreatedAt = now
|
||||||
|
|
@ -1829,7 +1829,7 @@ func unbindAttributeViewBlock(operation *Operation, tx *Transaction) (err error)
|
||||||
value.BlockID = operation.NextID
|
value.BlockID = operation.NextID
|
||||||
value.IsDetached = true
|
value.IsDetached = true
|
||||||
if nil != value.Block {
|
if nil != value.Block {
|
||||||
value.Block.ID = operation.NextID
|
value.Block.ID = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
avIDs := replaceRelationAvValues(operation.AvID, operation.ID, operation.NextID)
|
avIDs := replaceRelationAvValues(operation.AvID, operation.ID, operation.NextID)
|
||||||
|
|
@ -2877,7 +2877,11 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
|
||||||
IsDetached: isDetached,
|
IsDetached: isDetached,
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
Block: &av.ValueBlock{ID: addingBlockID, Icon: blockIcon, Content: addingBlockContent, Created: now, Updated: now}}
|
Block: &av.ValueBlock{Icon: blockIcon, Content: addingBlockContent, Created: now, Updated: now}}
|
||||||
|
if !isDetached {
|
||||||
|
blockValue.Block.ID = addingBlockID
|
||||||
|
}
|
||||||
|
|
||||||
blockValues.Values = append(blockValues.Values, blockValue)
|
blockValues.Values = append(blockValues.Values, blockValue)
|
||||||
|
|
||||||
view, err := getAttrViewViewByBlockID(attrView, blockID)
|
view, err := getAttrViewViewByBlockID(attrView, blockID)
|
||||||
|
|
@ -4065,12 +4069,14 @@ func replaceAttributeViewBlock0(attrView *av.AttributeView, oldBlockID, newBlock
|
||||||
|
|
||||||
value.BlockID = newBlockID
|
value.BlockID = newBlockID
|
||||||
if av.KeyTypeBlock == value.Type && nil != value.Block {
|
if av.KeyTypeBlock == value.Type && nil != value.Block {
|
||||||
value.Block.ID = newBlockID
|
|
||||||
value.IsDetached = isDetached
|
value.IsDetached = isDetached
|
||||||
if !isDetached {
|
if !isDetached {
|
||||||
|
value.Block.ID = newBlockID
|
||||||
icon, content := getNodeAvBlockText(node)
|
icon, content := getNodeAvBlockText(node)
|
||||||
content = util.UnescapeHTML(content)
|
content = util.UnescapeHTML(content)
|
||||||
value.Block.Icon, value.Block.Content = icon, content
|
value.Block.Icon, value.Block.Content = icon, content
|
||||||
|
} else {
|
||||||
|
value.Block.ID = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4196,7 +4202,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
|
||||||
for _, kv := range attrView.KeyValues {
|
for _, kv := range attrView.KeyValues {
|
||||||
if av.KeyTypeBlock == kv.Key.Type {
|
if av.KeyTypeBlock == kv.Key.Type {
|
||||||
for _, v := range kv.Values {
|
for _, v := range kv.Values {
|
||||||
if blockID == v.Block.ID {
|
if blockID == v.BlockID {
|
||||||
blockVal = v
|
blockVal = v
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -4314,14 +4320,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
|
||||||
|
|
||||||
if !val.IsDetached { // 现在绑定了块
|
if !val.IsDetached { // 现在绑定了块
|
||||||
// 将游离行绑定到新建的块上
|
// 将游离行绑定到新建的块上
|
||||||
|
bindBlockAv(tx, avID, val.Block.ID)
|
||||||
if val.Block.ID != blockID {
|
|
||||||
// 从其他库拷贝主键值后会出现该情况
|
|
||||||
blockID = val.Block.ID
|
|
||||||
val.BlockID = blockID
|
|
||||||
}
|
|
||||||
|
|
||||||
bindBlockAv(tx, avID, blockID)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 之前绑定了块
|
// 之前绑定了块
|
||||||
|
|
|
||||||
|
|
@ -73,15 +73,14 @@ func checkAttrView(attrView *av.AttributeView, view *av.View) {
|
||||||
if v.Type != kv.Key.Type {
|
if v.Type != kv.Key.Type {
|
||||||
v.Type = kv.Key.Type
|
v.Type = kv.Key.Type
|
||||||
if av.KeyTypeBlock == v.Type && nil == v.Block {
|
if av.KeyTypeBlock == v.Type && nil == v.Block {
|
||||||
v.Block = &av.ValueBlock{ID: v.BlockID}
|
v.Block = &av.ValueBlock{}
|
||||||
if nil != v.Text {
|
if nil != v.Text {
|
||||||
v.Block.Content = v.Text.Content
|
v.Block.Content = v.Text.Content
|
||||||
}
|
}
|
||||||
if "" == v.Block.ID {
|
if "" == v.BlockID {
|
||||||
v.Block.ID = ast.NewNodeID()
|
v.BlockID = ast.NewNodeID()
|
||||||
v.BlockID = v.Block.ID
|
|
||||||
}
|
}
|
||||||
createdStr := v.Block.ID[:len("20060102150405")]
|
createdStr := v.BlockID[:len("20060102150405")]
|
||||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||||
if nil == parseErr {
|
if nil == parseErr {
|
||||||
v.Block.Created = created.UnixMilli()
|
v.Block.Created = created.UnixMilli()
|
||||||
|
|
|
||||||
|
|
@ -91,8 +91,13 @@ func renderView(attrView *av.AttributeView, view *av.View, query string, depth *
|
||||||
func RenderTemplateField(ial map[string]string, keyValues []*av.KeyValues, tplContent string) (ret string, err error) {
|
func RenderTemplateField(ial map[string]string, keyValues []*av.KeyValues, tplContent string) (ret string, err error) {
|
||||||
if "" == ial["id"] {
|
if "" == ial["id"] {
|
||||||
block := getBlockValue(keyValues)
|
block := getBlockValue(keyValues)
|
||||||
if nil != block && nil != block.Block {
|
if nil != block {
|
||||||
ial["id"] = block.Block.ID
|
if nil != block.Block {
|
||||||
|
ial["id"] = block.Block.ID
|
||||||
|
}
|
||||||
|
if "" == ial["id"] {
|
||||||
|
ial["id"] = block.BlockID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if "" == ial["updated"] {
|
if "" == ial["updated"] {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue