🎨 Supports searching database blocks by the view title https://github.com/siyuan-note/siyuan/issues/9348
This commit is contained in:
parent
cf154dcaa1
commit
d38311c48c
5 changed files with 40 additions and 28 deletions
|
@ -493,3 +493,7 @@ var (
|
|||
ErrViewNotFound = errors.New("view not found")
|
||||
ErrKeyNotFound = errors.New("key not found")
|
||||
)
|
||||
|
||||
const (
|
||||
NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id
|
||||
)
|
||||
|
|
|
@ -70,7 +70,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||
|
||||
ret = []*BlockAttributeViewKeys{}
|
||||
attrs := GetBlockAttrs(blockID)
|
||||
avs := attrs[NodeAttrNameAvs]
|
||||
avs := attrs[av.NodeAttrNameAvs]
|
||||
if "" == avs {
|
||||
return
|
||||
}
|
||||
|
@ -352,16 +352,13 @@ func setAttributeViewName(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
attrView.Name = operation.Data.(string)
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(attrView)
|
||||
view, err := attrView.GetView()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, attrView); nil != err {
|
||||
return
|
||||
}
|
||||
attrView.Name = operation.Data.(string)
|
||||
view.Name = operation.Data.(string)
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
|
@ -554,13 +551,13 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre
|
|||
if !operation.IsDetached {
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
if "" == attrs[NodeAttrNameAvs] {
|
||||
attrs[NodeAttrNameAvs] = operation.AvID
|
||||
if "" == attrs[av.NodeAttrNameAvs] {
|
||||
attrs[av.NodeAttrNameAvs] = operation.AvID
|
||||
} else {
|
||||
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
|
||||
avIDs := strings.Split(attrs[av.NodeAttrNameAvs], ",")
|
||||
avIDs = append(avIDs, operation.AvID)
|
||||
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
}
|
||||
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
|
@ -628,15 +625,15 @@ func (tx *Transaction) removeAttributeViewBlock(operation *Operation) (err error
|
|||
node.RemoveIALAttr("custom-hidden")
|
||||
}
|
||||
|
||||
if avs := attrs[NodeAttrNameAvs]; "" != avs {
|
||||
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
|
||||
avIDs := strings.Split(avs, ",")
|
||||
avIDs = gulu.Str.RemoveElem(avIDs, operation.AvID)
|
||||
if 0 == len(avIDs) {
|
||||
delete(attrs, NodeAttrNameAvs)
|
||||
node.RemoveIALAttr(NodeAttrNameAvs)
|
||||
delete(attrs, av.NodeAttrNameAvs)
|
||||
node.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||
} else {
|
||||
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
node.SetIALAttr(NodeAttrNameAvs, strings.Join(avIDs, ","))
|
||||
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
node.SetIALAttr(av.NodeAttrNameAvs, strings.Join(avIDs, ","))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1160,17 +1157,17 @@ func bindBlockAv(tx *Transaction, avID, blockID string) {
|
|||
}
|
||||
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
if "" == attrs[NodeAttrNameAvs] {
|
||||
attrs[NodeAttrNameAvs] = avID
|
||||
if "" == attrs[av.NodeAttrNameAvs] {
|
||||
attrs[av.NodeAttrNameAvs] = avID
|
||||
} else {
|
||||
avIDs := strings.Split(attrs[NodeAttrNameAvs], ",")
|
||||
avIDs := strings.Split(attrs[av.NodeAttrNameAvs], ",")
|
||||
if gulu.Str.Contains(avID, avIDs) {
|
||||
return
|
||||
}
|
||||
|
||||
avIDs = append(avIDs, avID)
|
||||
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||
attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||
}
|
||||
|
||||
if nil != tx {
|
||||
|
@ -1346,7 +1343,3 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
|||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id
|
||||
)
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
|
@ -154,7 +155,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
// 重新指向数据库属性值
|
||||
ial := parse.IAL2Map(n.KramdownIAL)
|
||||
for k, _ := range ial {
|
||||
if strings.HasPrefix(k, NodeAttrNameAvs) {
|
||||
if strings.HasPrefix(k, av.NodeAttrNameAvs) {
|
||||
avBlockIDs[oldNodeID] = newNodeID
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +258,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
|
||||
ial := parse.IAL2Map(n.KramdownIAL)
|
||||
for k, v := range ial {
|
||||
if strings.HasPrefix(k, NodeAttrNameAvs) {
|
||||
if strings.HasPrefix(k, av.NodeAttrNameAvs) {
|
||||
newKey, newVal := k, v
|
||||
for oldAvID, newAvID := range avIDs {
|
||||
newKey = strings.ReplaceAll(newKey, oldAvID, newAvID)
|
||||
|
|
|
@ -714,7 +714,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
func syncDelete2AttributeView(node *ast.Node) {
|
||||
avs := node.IALAttr(NodeAttrNameAvs)
|
||||
avs := node.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
return
|
||||
}
|
||||
|
@ -1233,7 +1233,7 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
|
|||
|
||||
// 2. 更新属性视图主键内容
|
||||
for _, updatedDefNode := range updatedDefNodes {
|
||||
avs := updatedDefNode.IALAttr(NodeAttrNameAvs)
|
||||
avs := updatedDefNode.IALAttr(av.NodeAttrNameAvs)
|
||||
if "" == avs {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package treenode
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
@ -139,6 +140,19 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
|
||||
if ast.NodeDocument == node.Type {
|
||||
return node.IALAttr("title")
|
||||
} else if ast.NodeAttributeView == node.Type {
|
||||
if "" != node.AttributeViewID {
|
||||
attrView, err := av.ParseAttributeView(node.AttributeViewID)
|
||||
if nil == err {
|
||||
buf := bytes.Buffer{}
|
||||
for _, v := range attrView.Views {
|
||||
buf.WriteString(v.Name)
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
|
|
Loading…
Add table
Reference in a new issue