mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
93b5ca14c4
2 changed files with 35 additions and 16 deletions
|
|
@ -582,6 +582,19 @@ func (av *AttributeView) ExistBoundBlock(nodeID string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (av *AttributeView) GetBlockValueByBoundID(nodeID string) *Value {
|
||||||
|
for _, kv := range av.KeyValues {
|
||||||
|
if KeyTypeBlock == kv.Key.Type {
|
||||||
|
for _, v := range kv.Values {
|
||||||
|
if v.Block.ID == nodeID {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (av *AttributeView) GetValue(keyID, itemID string) (ret *Value) {
|
func (av *AttributeView) GetValue(keyID, itemID string) (ret *Value) {
|
||||||
for _, kv := range av.KeyValues {
|
for _, kv := range av.KeyValues {
|
||||||
if kv.Key.ID == keyID {
|
if kv.Key.ID == keyID {
|
||||||
|
|
|
||||||
|
|
@ -1267,11 +1267,11 @@ type BlockAttributeViewKeys struct {
|
||||||
KeyValues []*av.KeyValues `json:"keyValues"`
|
KeyValues []*av.KeyValues `json:"keyValues"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
||||||
waitForSyncingStorages()
|
waitForSyncingStorages()
|
||||||
|
|
||||||
ret = []*BlockAttributeViewKeys{}
|
ret = []*BlockAttributeViewKeys{}
|
||||||
attrs := sql.GetBlockAttrs(blockID)
|
attrs := sql.GetBlockAttrs(nodeID)
|
||||||
avs := attrs[av.NodeAttrNameAvs]
|
avs := attrs[av.NodeAttrNameAvs]
|
||||||
if "" == avs {
|
if "" == avs {
|
||||||
return
|
return
|
||||||
|
|
@ -1289,13 +1289,19 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
attrViewCache[avID] = attrView
|
attrViewCache[avID] = attrView
|
||||||
}
|
}
|
||||||
|
|
||||||
if !attrView.ExistBoundBlock(blockID) {
|
if !attrView.ExistBoundBlock(nodeID) {
|
||||||
// 比如剪切后粘贴,块 ID 会变,但是属性还在块上,这里做一次数据订正
|
// 比如剪切后粘贴,块 ID 会变,但是属性还在块上,这里做一次数据订正
|
||||||
// Auto verify the database name when clicking the block superscript icon https://github.com/siyuan-note/siyuan/issues/10861
|
// Auto verify the database name when clicking the block superscript icon https://github.com/siyuan-note/siyuan/issues/10861
|
||||||
unbindBlockAv(nil, avID, blockID)
|
unbindBlockAv(nil, avID, nodeID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
blockVal := attrView.GetBlockValueByBoundID(nodeID)
|
||||||
|
if nil == blockVal {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
itemID := blockVal.BlockID
|
||||||
var keyValues []*av.KeyValues
|
var keyValues []*av.KeyValues
|
||||||
for _, kv := range attrView.KeyValues {
|
for _, kv := range attrView.KeyValues {
|
||||||
if av.KeyTypeLineNumber == kv.Key.Type {
|
if av.KeyTypeLineNumber == kv.Key.Type {
|
||||||
|
|
@ -1306,20 +1312,20 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
|
|
||||||
kValues := &av.KeyValues{Key: kv.Key}
|
kValues := &av.KeyValues{Key: kv.Key}
|
||||||
for _, v := range kv.Values {
|
for _, v := range kv.Values {
|
||||||
if v.BlockID == blockID {
|
if v.BlockID == itemID {
|
||||||
kValues.Values = append(kValues.Values, v)
|
kValues.Values = append(kValues.Values, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch kValues.Key.Type {
|
switch kValues.Key.Type {
|
||||||
case av.KeyTypeRollup:
|
case av.KeyTypeRollup:
|
||||||
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeRollup, Rollup: &av.ValueRollup{Contents: []*av.Value{}}})
|
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeRollup, Rollup: &av.ValueRollup{Contents: []*av.Value{}}})
|
||||||
case av.KeyTypeTemplate:
|
case av.KeyTypeTemplate:
|
||||||
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: ""}})
|
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: ""}})
|
||||||
case av.KeyTypeCreated:
|
case av.KeyTypeCreated:
|
||||||
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeCreated})
|
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeCreated})
|
||||||
case av.KeyTypeUpdated:
|
case av.KeyTypeUpdated:
|
||||||
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeUpdated})
|
kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeUpdated})
|
||||||
case av.KeyTypeNumber:
|
case av.KeyTypeNumber:
|
||||||
for _, v := range kValues.Values {
|
for _, v := range kValues.Values {
|
||||||
if nil != v.Number {
|
if nil != v.Number {
|
||||||
|
|
@ -1336,7 +1342,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
keyValues = append(keyValues, kValues)
|
keyValues = append(keyValues, kValues)
|
||||||
} else {
|
} else {
|
||||||
// 如果没有值,那么就补一个默认值
|
// 如果没有值,那么就补一个默认值
|
||||||
kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))
|
kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, itemID, kv.Key.Type))
|
||||||
keyValues = append(keyValues, kValues)
|
keyValues = append(keyValues, kValues)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1347,7 +1353,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
switch kv.Key.Type {
|
switch kv.Key.Type {
|
||||||
case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
|
case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049
|
||||||
if nil != kv.Values[0].Block {
|
if nil != kv.Values[0].Block {
|
||||||
ial := sql.GetBlockAttrs(blockID)
|
ial := sql.GetBlockAttrs(nodeID)
|
||||||
if v := ial[av.NodeAttrViewStaticText+"-"+attrView.ID]; "" != v {
|
if v := ial[av.NodeAttrViewStaticText+"-"+attrView.ID]; "" != v {
|
||||||
kv.Values[0].Block.Content = v
|
kv.Values[0].Block.Content = v
|
||||||
}
|
}
|
||||||
|
|
@ -1419,7 +1425,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
kv.Values[0].Relation.Contents = append(kv.Values[0].Relation.Contents, blocks[bID])
|
kv.Values[0].Relation.Contents = append(kv.Values[0].Relation.Contents, blocks[bID])
|
||||||
}
|
}
|
||||||
case av.KeyTypeCreated:
|
case av.KeyTypeCreated:
|
||||||
createdStr := blockID[:len("20060102150405")]
|
createdStr := nodeID[:len("20060102150405")]
|
||||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||||
if nil == parseErr {
|
if nil == parseErr {
|
||||||
kv.Values[0].Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone)
|
kv.Values[0].Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone)
|
||||||
|
|
@ -1429,7 +1435,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
|
kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
|
||||||
}
|
}
|
||||||
case av.KeyTypeUpdated:
|
case av.KeyTypeUpdated:
|
||||||
ial := sql.GetBlockAttrs(blockID)
|
ial := sql.GetBlockAttrs(nodeID)
|
||||||
updatedStr := ial["updated"]
|
updatedStr := ial["updated"]
|
||||||
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
|
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
|
||||||
if nil == parseErr {
|
if nil == parseErr {
|
||||||
|
|
@ -1457,7 +1463,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == kv.Values[0].Template {
|
if nil == kv.Values[0].Template {
|
||||||
kv.Values[0] = av.GetAttributeViewDefaultValue(kv.Values[0].ID, kv.Key.ID, blockID, kv.Key.Type)
|
kv.Values[0] = av.GetAttributeViewDefaultValue(kv.Values[0].ID, kv.Key.ID, nodeID, kv.Key.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
var renderErr error
|
var renderErr error
|
||||||
|
|
@ -1503,9 +1509,9 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 1 > len(blockIDs) {
|
if 1 > len(blockIDs) {
|
||||||
tree, _ := LoadTreeByBlockID(blockID)
|
tree, _ := LoadTreeByBlockID(nodeID)
|
||||||
if nil != tree {
|
if nil != tree {
|
||||||
node := treenode.GetNodeInTree(tree, blockID)
|
node := treenode.GetNodeInTree(tree, nodeID)
|
||||||
if nil != node {
|
if nil != node {
|
||||||
if removeErr := removeNodeAvID(node, avID, nil, tree); nil != removeErr {
|
if removeErr := removeNodeAvID(node, avID, nil, tree); nil != removeErr {
|
||||||
logging.LogErrorf("remove node avID [%s] failed: %s", avID, removeErr)
|
logging.LogErrorf("remove node avID [%s] failed: %s", avID, removeErr)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue