🎨 Update av

This commit is contained in:
Daniel 2023-06-10 15:00:04 +08:00
parent bf96331cf6
commit 54799578d7
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 70 additions and 5 deletions

View file

@ -202,6 +202,5 @@ func RebuildAttributeViewTable(tx *sql.Tx, av *AttributeView) (err error) {
return
}
}
return
}

View file

@ -17,8 +17,9 @@
package av
type Cell struct {
ID string `json:"id"`
Value string `json:"value"`
Color string `json:"color"`
BgColor string `json:"bgColor"`
ID string `json:"id"`
Value string `json:"value"`
RenderValue interface{} `json:"renderValue"`
Color string `json:"color"`
BgColor string `json:"bgColor"`
}

View file

@ -39,6 +39,60 @@ func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
return
}
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
avID := operation.ParentID
view, err := av.ParseAttributeView(avID)
if nil != err {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return &TxErr{code: TxErrCodeBlockNotFound, id: avID, msg: err.Error()}
}
var c *av.Cell
var blockID string
for _, row := range view.Rows {
if row.ID != operation.RowID {
continue
}
blockID = row.Cells[0].Value
for _, cell := range row.Cells[1:] {
if cell.ID == operation.ID {
c = cell
break
}
}
break
}
if nil == c {
return
}
tree, err := tx.loadTree(blockID)
if nil != err {
return
}
node := treenode.GetNodeInTree(tree, blockID)
if nil == node {
return
}
c.Value = parseCellData(operation.Data, av.ColumnType(operation.Typ))
attrs := parse.IAL2Map(node.KramdownIAL)
attrs["av"+c.ID] = c.Value
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
return
}
if err = av.SaveAttributeView(view); nil != err {
return
}
sql.RebuildAttributeViewQueue(view)
return
}
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
firstSrcID := operation.SrcIDs[0]
tree, err := tx.loadTree(firstSrcID)
@ -224,3 +278,11 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transacti
err = av.SaveAttributeView(ret)
return
}
func parseCellData(data interface{}, colType av.ColumnType) string {
switch colType {
case av.ColumnTypeText:
return data.(string)
}
return ""
}

View file

@ -224,6 +224,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doAddAttrViewColumn(op)
case "removeAttrViewCol":
ret = tx.doRemoveAttrViewColumn(op)
case "updateAttrViewCell":
ret = tx.doUpdateAttrViewCell(op)
}
if nil != ret {
@ -1026,6 +1028,7 @@ type Operation struct {
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
Name string `json:"name"` // 用于属性视图列名
Typ string `json:"type"` // 用于属性视图列类型
RowID string `json:"rowID"` // 用于属性视图行 ID
discard bool // 用于标识是否在事务合并中丢弃
}