|
@@ -18,6 +18,7 @@ package model
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
+ "fmt"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"sort"
|
|
@@ -398,7 +399,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|
|
keyValues = append(keyValues, kValues)
|
|
|
} else {
|
|
|
// 如果没有值,那么就补一个默认值
|
|
|
- kValues.Values = append(kValues.Values, treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))
|
|
|
+ kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))
|
|
|
keyValues = append(keyValues, kValues)
|
|
|
}
|
|
|
}
|
|
@@ -426,7 +427,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|
|
destVal := destAv.GetValue(kv.Key.Rollup.KeyID, bID)
|
|
|
if nil == destVal {
|
|
|
if destAv.ExistBlock(bID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
|
|
|
- destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type)
|
|
|
+ destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.Rollup.KeyID, bID, destKey.Type)
|
|
|
}
|
|
|
if nil == destVal {
|
|
|
continue
|
|
@@ -499,6 +500,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|
|
//}
|
|
|
|
|
|
// 渲染模板
|
|
|
+ var renderTemplateErr error
|
|
|
for _, kv := range keyValues {
|
|
|
switch kv.Key.Type {
|
|
|
case av.KeyTypeTemplate:
|
|
@@ -509,10 +511,17 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|
|
ial = GetBlockAttrsWithoutWaitWriting(block.BlockID)
|
|
|
}
|
|
|
|
|
|
- kv.Values[0].Template.Content = renderTemplateCol(ial, flashcard, keyValues, kv.Key.Template)
|
|
|
+ var renderErr error
|
|
|
+ kv.Values[0].Template.Content, renderErr = renderTemplateCol(ial, flashcard, keyValues, kv.Key.Template)
|
|
|
+ if nil != renderErr {
|
|
|
+ renderTemplateErr = renderErr
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if nil != renderTemplateErr {
|
|
|
+ util.PushErrMsg(fmt.Sprintf(Conf.Language(44), util.EscapeHTML(renderTemplateErr.Error())), 30000)
|
|
|
+ }
|
|
|
|
|
|
// Attribute Panel - Database sort attributes by view column order https://github.com/siyuan-note/siyuan/issues/9319
|
|
|
viewID := attrs[av.NodeAttrView]
|
|
@@ -839,7 +848,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues []*av.KeyValues, tplContent string) string {
|
|
|
+func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues []*av.KeyValues, tplContent string) (ret string, err error) {
|
|
|
if "" == ial["id"] {
|
|
|
block := getRowBlockValue(rowValues)
|
|
|
if nil != block && nil != block.Block {
|
|
@@ -857,10 +866,10 @@ func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues []
|
|
|
tplFuncMap := util.BuiltInTemplateFuncs()
|
|
|
SQLTemplateFuncs(&tplFuncMap)
|
|
|
goTpl = goTpl.Funcs(tplFuncMap)
|
|
|
- tpl, tplErr := goTpl.Parse(tplContent)
|
|
|
- if nil != tplErr {
|
|
|
- logging.LogWarnf("parse template [%s] failed: %s", tplContent, tplErr)
|
|
|
- return ""
|
|
|
+ tpl, err := goTpl.Parse(tplContent)
|
|
|
+ if nil != err {
|
|
|
+ logging.LogWarnf("parse template [%s] failed: %s", tplContent, err)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
@@ -943,10 +952,12 @@ func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues []
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if err := tpl.Execute(buf, dataModel); nil != err {
|
|
|
+ if err = tpl.Execute(buf, dataModel); nil != err {
|
|
|
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
|
|
|
+ return
|
|
|
}
|
|
|
- return buf.String()
|
|
|
+ ret = buf.String()
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query string) (ret *av.Table, err error) {
|
|
@@ -1118,7 +1129,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|
|
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
|
|
|
if nil == destVal {
|
|
|
if destAv.ExistBlock(blockID) { // 数据库中存在行但是列值不存在是数据未初始化,这里补一个默认值
|
|
|
- destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
|
|
+ destVal = av.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
|
|
|
}
|
|
|
if nil == destVal {
|
|
|
continue
|
|
@@ -1219,6 +1230,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
+ var renderTemplateErr error
|
|
|
for _, row := range ret.Rows {
|
|
|
for _, cell := range row.Cells {
|
|
|
switch cell.ValueType {
|
|
@@ -1229,11 +1241,17 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|
|
if nil != block && !block.IsDetached {
|
|
|
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
|
|
|
}
|
|
|
- content := renderTemplateCol(ial, flashcards[row.ID], keyValues, cell.Value.Template.Content)
|
|
|
+ content, renderErr := renderTemplateCol(ial, flashcards[row.ID], keyValues, cell.Value.Template.Content)
|
|
|
cell.Value.Template.Content = content
|
|
|
+ if nil != renderErr {
|
|
|
+ renderTemplateErr = renderErr
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if nil != renderTemplateErr {
|
|
|
+ util.PushErrMsg(fmt.Sprintf(Conf.Language(44), util.EscapeHTML(renderTemplateErr.Error())), 30000)
|
|
|
+ }
|
|
|
|
|
|
// 根据搜索条件过滤
|
|
|
query = strings.TrimSpace(query)
|