mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Update av
This commit is contained in:
parent
ef362685cb
commit
18390572b5
3 changed files with 74 additions and 21 deletions
|
|
@ -19,24 +19,24 @@ package av
|
|||
import (
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Cell struct {
|
||||
ID string `json:"id"`
|
||||
Value *Value `json:"value"`
|
||||
ValueType ColumnType `json:"valueType"`
|
||||
RenderValue interface{} `json:"renderValue"`
|
||||
Color string `json:"color"`
|
||||
BgColor string `json:"bgColor"`
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
Block string `json:"block"`
|
||||
Text string `json:"text"`
|
||||
Number float64 `json:"number"`
|
||||
Date string `json:"date"`
|
||||
Select string `json:"select"`
|
||||
MSelect []string `json:"mSelect"`
|
||||
Block *ValueBlock `json:"block"`
|
||||
Text *ValueText `json:"text"`
|
||||
Number *ValueNumber `json:"number"`
|
||||
Date *ValueDate `json:"date"`
|
||||
Select *ValueSelect `json:"select"`
|
||||
MSelect []*ValueSelect `json:"mSelect"`
|
||||
}
|
||||
|
||||
func (value *Value) ToJSONString() string {
|
||||
|
|
@ -50,9 +50,8 @@ func (value *Value) ToJSONString() string {
|
|||
func NewCellBlock(blockID, blockContent string) *Cell {
|
||||
return &Cell{
|
||||
ID: ast.NewNodeID(),
|
||||
Value: &Value{Block: blockID},
|
||||
Value: &Value{Block: &ValueBlock{ID: blockID, Content: blockContent}},
|
||||
ValueType: ColumnTypeBlock,
|
||||
RenderValue: &RenderValueBlock{ID: blockID, Content: blockContent},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +62,23 @@ func NewCell(valueType ColumnType) *Cell {
|
|||
}
|
||||
}
|
||||
|
||||
type RenderValueBlock struct {
|
||||
type ValueBlock struct {
|
||||
ID string `json:"id"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type ValueText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type ValueNumber struct {
|
||||
Content float64 `json:"content"`
|
||||
}
|
||||
|
||||
type ValueDate struct {
|
||||
Content time.Time `json:"content"`
|
||||
}
|
||||
|
||||
type ValueSelect struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
|||
continue
|
||||
}
|
||||
|
||||
blockID = row.Cells[0].Value.Block
|
||||
blockID = row.Cells[0].Value.Block.ID
|
||||
for _, cell := range row.Cells[1:] {
|
||||
if cell.ID == operation.ID {
|
||||
c = cell
|
||||
|
|
@ -121,7 +121,6 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
c.RenderValue = operation.Data
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
attrs[NodeAttrNamePrefixAvCol+avID+"-"+c.ID] = c.Value.ToJSONString()
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
|
|
@ -229,6 +228,14 @@ func (tx *Transaction) doSortAttrViewColumn(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSortAttrViewRow(operation *Operation) (ret *TxErr) {
|
||||
err := sortAttributeViewRow(operation.ID, operation.PreviousID, operation.ParentID)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewColumn(name string, typ string, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
|
|
@ -340,6 +347,35 @@ func sortAttributeViewColumn(columnID, previousColumnID, avID string) (err error
|
|||
return
|
||||
}
|
||||
|
||||
func sortAttributeViewRow(rowID, previousRowID, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
var row *av.Row
|
||||
var index, previousIndex int
|
||||
for i, r := range attrView.Rows {
|
||||
if r.ID == rowID {
|
||||
row = r
|
||||
index = i
|
||||
break
|
||||
}
|
||||
if r.ID == previousRowID {
|
||||
previousIndex = i
|
||||
}
|
||||
}
|
||||
if nil == row {
|
||||
return
|
||||
}
|
||||
|
||||
attrView.Rows = append(attrView.Rows[:index], attrView.Rows[index+1:]...)
|
||||
attrView.Rows = append(attrView.Rows[:previousIndex], append([]*av.Row{row}, attrView.Rows[previousIndex:]...)...)
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (ret *av.AttributeView, err error) {
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
|
|
@ -353,7 +389,7 @@ func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (ret *av.A
|
|||
}
|
||||
|
||||
for i, row := range ret.Rows {
|
||||
if row.Cells[0].Value.Block == blockID {
|
||||
if row.Cells[0].Value.Block.ID == blockID {
|
||||
// 从行中移除,但是不移除属性
|
||||
ret.Rows = append(ret.Rows[:i], ret.Rows[i+1:]...)
|
||||
break
|
||||
|
|
@ -389,7 +425,7 @@ func addAttributeViewBlock(blockID, previousRowID, avID string, tree *parse.Tree
|
|||
|
||||
// 不允许重复添加相同的块到属性视图中
|
||||
for _, row := range ret.Rows {
|
||||
if row.Cells[0].Value.Block == blockID {
|
||||
if row.Cells[0].Value.Block.ID == blockID {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doSortAttrViewColumn(op)
|
||||
case "updateAttrViewCell":
|
||||
ret = tx.doUpdateAttrViewCell(op)
|
||||
case "sortAttrViewRow":
|
||||
ret = tx.doSortAttrViewRow(op)
|
||||
}
|
||||
|
||||
if nil != ret {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue