🎨 Add Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9958

This commit is contained in:
Daniel 2024-01-01 01:08:55 +08:00
parent 4fcc7f1b4c
commit 99218f400b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
6 changed files with 35 additions and 10 deletions

View file

@ -66,7 +66,7 @@ func SetBlockReminder(id string, timed string) (err error) {
if ast.NodeDocument != node.Type && node.IsContainerBlock() { if ast.NodeDocument != node.Type && node.IsContainerBlock() {
node = treenode.FirstLeafBlock(node) node = treenode.FirstLeafBlock(node)
} }
content := treenode.NodeStaticContent(node, nil, false, false) content := treenode.NodeStaticContent(node, nil, false, false, false)
content = gulu.Str.SubStr(content, 128) content = gulu.Str.SubStr(content, 128)
err = SetCloudBlockReminder(id, content, timedMills) err = SetCloudBlockReminder(id, content, timedMills)
if nil != err { if nil != err {

View file

@ -93,7 +93,7 @@ func renderOutline(heading *ast.Node, luteEngine *lute.Lute) (ret string) {
} }
func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) { func renderBlockText(node *ast.Node, excludeTypes []string) (ret string) {
ret = treenode.NodeStaticContent(node, excludeTypes, false, false) ret = treenode.NodeStaticContent(node, excludeTypes, false, false, false)
ret = strings.TrimSpace(ret) ret = strings.TrimSpace(ret)
ret = strings.ReplaceAll(ret, "\n", "") ret = strings.ReplaceAll(ret, "\n", "")
ret = util.EscapeHTML(ret) ret = util.EscapeHTML(ret)
@ -156,7 +156,7 @@ func renderBlockContentByNodes(nodes []*ast.Node) string {
buf := bytes.Buffer{} buf := bytes.Buffer{}
for _, n := range subNodes { for _, n := range subNodes {
buf.WriteString(treenode.NodeStaticContent(n, nil, false, false)) buf.WriteString(treenode.NodeStaticContent(n, nil, false, false, false))
} }
return buf.String() return buf.String()
} }

View file

@ -51,7 +51,7 @@ func getBlockVirtualRefKeywords(root *ast.Node) (ret []string) {
return ast.WalkContinue return ast.WalkContinue
} }
content := treenode.NodeStaticContent(n, nil, false, false) content := treenode.NodeStaticContent(n, nil, false, false, false)
buf.WriteString(content) buf.WriteString(content)
return ast.WalkContinue return ast.WalkContinue
}) })

View file

@ -109,7 +109,7 @@ func indexNode(tx *sql.Tx, id string) (err error) {
return return
} }
content := treenode.NodeStaticContent(node, nil, true, indexAssetPath) content := treenode.NodeStaticContent(node, nil, true, indexAssetPath, true)
stmt := "UPDATE blocks SET content = ? WHERE id = ?" stmt := "UPDATE blocks SET content = ? WHERE id = ?"
if err = execStmtTx(tx, stmt, content, id); nil != err { if err = execStmtTx(tx, stmt, content, id); nil != err {
tx.Rollback() tx.Rollback()

View file

@ -801,13 +801,13 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
if !treenode.IsNodeOCRed(n) { if !treenode.IsNodeOCRed(n) {
util.PushNodeOCRQueue(n) util.PushNodeOCRQueue(n)
} }
content = treenode.NodeStaticContent(n, nil, true, indexAssetPath) content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true)
fc := treenode.FirstLeafBlock(n) fc := treenode.FirstLeafBlock(n)
if !treenode.IsNodeOCRed(fc) { if !treenode.IsNodeOCRed(fc) {
util.PushNodeOCRQueue(fc) util.PushNodeOCRQueue(fc)
} }
fcontent = treenode.NodeStaticContent(fc, nil, true, false) fcontent = treenode.NodeStaticContent(fc, nil, true, false, true)
parentID = n.Parent.ID parentID = n.Parent.ID
// 将标题块作为父节点 // 将标题块作为父节点
@ -820,7 +820,7 @@ func buildBlockFromNode(n *ast.Node, tree *parse.Tree) (block *Block, attributes
if !treenode.IsNodeOCRed(n) { if !treenode.IsNodeOCRed(n) {
util.PushNodeOCRQueue(n) util.PushNodeOCRQueue(n)
} }
content = treenode.NodeStaticContent(n, nil, true, indexAssetPath) content = treenode.NodeStaticContent(n, nil, true, indexAssetPath, true)
parentID = n.Parent.ID parentID = n.Parent.ID
// 将标题块作为父节点 // 将标题块作为父节点

View file

@ -168,7 +168,7 @@ func IsNodeOCRed(node *ast.Node) (ret bool) {
return return
} }
func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath bool) string { func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATitleURL, includeAssetPath, fullAttrView bool) string {
if nil == node { if nil == node {
return "" return ""
} }
@ -178,7 +178,11 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
} }
if ast.NodeAttributeView == node.Type { if ast.NodeAttributeView == node.Type {
return getAttributeViewContent(node.AttributeViewID) if fullAttrView {
return getAttributeViewContent(node.AttributeViewID)
}
return getAttributeViewName(node.AttributeViewID)
} }
buf := bytes.Buffer{} buf := bytes.Buffer{}
@ -528,6 +532,27 @@ func GetAttributeViewName(avID string) (name string) {
return return
} }
func getAttributeViewName(avID string) (name string) {
if "" == avID {
return
}
attrView, err := av.ParseAttributeView(avID)
if nil != err {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return
}
buf := bytes.Buffer{}
for _, v := range attrView.Views {
buf.WriteString(v.Name)
buf.WriteByte(' ')
}
name = strings.TrimSpace(buf.String())
return
}
func getAttributeViewContent(avID string) (content string) { func getAttributeViewContent(avID string) (content string) {
if "" == avID { if "" == avID {
return return