mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-30 13:28:48 +01:00
🎨 Add template type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8766
This commit is contained in:
parent
dbdddd7ff3
commit
b833087cb6
4 changed files with 36 additions and 4 deletions
|
|
@ -79,6 +79,7 @@ type Key struct {
|
|||
|
||||
Options []*KeySelectOption `json:"options,omitempty"` // 选项列表
|
||||
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
||||
Template string `json:"template"` // 模板内容
|
||||
}
|
||||
|
||||
func NewKey(id, name string, keyType KeyType) *Key {
|
||||
|
|
@ -350,7 +351,6 @@ type ValueAsset struct {
|
|||
}
|
||||
|
||||
type ValueTemplate struct {
|
||||
Content string `json:"content"`
|
||||
RenderedContent string `json:"renderedContent"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -396,6 +396,7 @@ type TableColumn struct {
|
|||
|
||||
Options []*KeySelectOption `json:"options,omitempty"` // 选项列表
|
||||
NumberFormat NumberFormat `json:"numberFormat"` // 列数字格式化
|
||||
Template string `json:"template"` // 模板内容
|
||||
}
|
||||
|
||||
type TableRow struct {
|
||||
|
|
|
|||
|
|
@ -235,16 +235,16 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
|
|||
render := func(blockID string) string {
|
||||
funcMap := sprig.TxtFuncMap()
|
||||
goTpl := template.New("").Delims(".action{", "}")
|
||||
tpl, tplErr := goTpl.Funcs(funcMap).Parse(tableCell.Value.Template.Content)
|
||||
tpl, tplErr := goTpl.Funcs(funcMap).Parse(col.Template)
|
||||
if nil != tplErr {
|
||||
logging.LogWarnf("parse template [%s] failed: %s", tableCell.Value.Template.Content, tplErr)
|
||||
logging.LogWarnf("parse template [%s] failed: %s", col.Template, tplErr)
|
||||
return ""
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
ial := GetBlockAttrs(blockID)
|
||||
if err = tpl.Execute(buf, ial); nil != err {
|
||||
logging.LogWarnf("execute template [%s] failed: %s", tableCell.Value.Template.Content, err)
|
||||
logging.LogWarnf("execute template [%s] failed: %s", col.Template, err)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
|
@ -827,6 +827,35 @@ func addAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColTemplate(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColTemplate(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColTemplate(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
colType := av.KeyType(operation.Typ)
|
||||
switch colType {
|
||||
case av.KeyTypeTemplate:
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
if keyValues.Key.ID == operation.ID && av.KeyTypeTemplate == keyValues.Key.Type {
|
||||
keyValues.Key.Template = operation.Data.(string)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColNumberFormat(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColNumberFormat(operation)
|
||||
if nil != err {
|
||||
|
|
|
|||
|
|
@ -262,6 +262,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doUpdateAttrViewColNumberFormat(op)
|
||||
case "replaceAttrViewBlock":
|
||||
ret = tx.doReplaceAttrViewBlock(op)
|
||||
case "updateAttrViewColTemplate":
|
||||
ret = tx.doUpdateAttrViewColTemplate(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue