mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 14:03:07 +08:00
This commit is contained in:
parent
504032f285
commit
86fbb759ed
@ -17,6 +17,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/88250/lute/parse"
|
||||||
"github.com/siyuan-note/siyuan/kernel/av"
|
"github.com/siyuan-note/siyuan/kernel/av"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
@ -45,11 +46,18 @@ func AddBlockToAttributeView(blockID, avID string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
var row []av.Cell
|
var row []av.Cell
|
||||||
row = append(row, av.NewCellBlock(block.ID))
|
row = append(row, av.NewCellBlock(block.ID))
|
||||||
|
if 1 < len(attrView.Columns) {
|
||||||
for _, col := range attrView.Columns[1:] {
|
for _, col := range attrView.Columns[1:] {
|
||||||
// TODO 为块添加列对应的属性
|
colName := col.Name()
|
||||||
_ = col
|
attrs[colName] = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = setNodeAttrs(node, tree, attrs); nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attrView.Rows = append(attrView.Rows, row)
|
attrView.Rows = append(attrView.Rows, row)
|
||||||
|
@ -19,13 +19,13 @@ package model
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/88250/lute/parse"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
"github.com/88250/lute/lex"
|
"github.com/88250/lute/lex"
|
||||||
"github.com/88250/lute/parse"
|
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
@ -105,12 +105,17 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||||||
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
return errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = setNodeAttrs(node, tree, nameValues)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
|
|
||||||
for name := range nameValues {
|
for name := range nameValues {
|
||||||
for i := 0; i < len(name); i++ {
|
for i := 0; i < len(name); i++ {
|
||||||
if !lex.IsASCIILetterNumHyphen(name[i]) {
|
if !lex.IsASCIILetterNumHyphen(name[i]) {
|
||||||
return errors.New(fmt.Sprintf(Conf.Language(25), id))
|
return errors.New(fmt.Sprintf(Conf.Language(25), node.ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,10 +140,10 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IncSync()
|
IncSync()
|
||||||
cache.PutBlockIAL(id, parse.IAL2Map(node.KramdownIAL))
|
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||||
|
|
||||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: id}
|
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: node.ID}
|
||||||
trans := []*Transaction{{
|
trans := []*Transaction{{
|
||||||
DoOperations: []*Operation{doOp},
|
DoOperations: []*Operation{doOp},
|
||||||
UndoOperations: []*Operation{},
|
UndoOperations: []*Operation{},
|
||||||
|
Loading…
Reference in New Issue
Block a user