🎨 属性视图增减行列 https://github.com/siyuan-note/siyuan/issues/7521 https://github.com/siyuan-note/siyuan/issues/7522
This commit is contained in:
parent
ba7927344c
commit
96cd0fd3d1
3 changed files with 12 additions and 6 deletions
|
@ -54,7 +54,7 @@ func NewAttributeView(id string) *AttributeView {
|
|||
return &AttributeView{
|
||||
Spec: 0,
|
||||
ID: id,
|
||||
Columns: []*Column{&Column{ID: ast.NewNodeID(), Name: "Block", Type: ColumnTypeBlock}},
|
||||
Columns: []*Column{{ID: ast.NewNodeID(), Name: "Block", Type: ColumnTypeBlock}},
|
||||
Rows: []*Row{},
|
||||
Type: AttributeViewTypeTable,
|
||||
Projections: []string{},
|
||||
|
|
|
@ -81,7 +81,7 @@ func AddAttributeViewColumn(name string, typ string, columnIndex int, avID strin
|
|||
|
||||
switch av.ColumnType(typ) {
|
||||
case av.ColumnTypeText:
|
||||
attrView.InsertColumn(columnIndex, &av.Column{ID: ast.NewNodeID(), Name: name, Type: av.ColumnTypeText})
|
||||
attrView.InsertColumn(columnIndex, &av.Column{ID: "av" + ast.NewNodeID(), Name: name, Type: av.ColumnTypeText})
|
||||
default:
|
||||
msg := fmt.Sprintf("invalid column type [%s]", typ)
|
||||
logging.LogErrorf(msg)
|
||||
|
@ -107,6 +107,7 @@ func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transa
|
|||
|
||||
for i, row := range attrView.Rows {
|
||||
if row.Cells[0].Value == blockID {
|
||||
// 从行中移除,但是不移除属性
|
||||
attrView.Rows = append(attrView.Rows[:i], attrView.Rows[i+1:]...)
|
||||
break
|
||||
}
|
||||
|
@ -150,11 +151,9 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transacti
|
|||
row.Cells = append(row.Cells, &av.Cell{ID: ast.NewNodeID(), Value: blockID})
|
||||
if 1 < len(attrView.Columns) {
|
||||
// 将列作为属性添加到块中
|
||||
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
for _, col := range attrView.Columns[1:] {
|
||||
colName := col.Name
|
||||
attrs[colName] = ""
|
||||
attrs["av"+col.ID] = ""
|
||||
}
|
||||
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
|
|
|
@ -19,13 +19,14 @@ package model
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/88250/lute/parse"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/lex"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
@ -166,6 +167,12 @@ func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrs map[s
|
|||
}
|
||||
|
||||
for name, value := range nameValues {
|
||||
if strings.HasPrefix(name, "av") {
|
||||
// 属性视图设置的属性值可以为空
|
||||
node.SetIALAttr(name, value)
|
||||
continue
|
||||
}
|
||||
|
||||
if "" == value {
|
||||
node.RemoveIALAttr(name)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue