Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-06-10 17:44:35 +08:00
commit e5541921df
2 changed files with 26 additions and 18 deletions

View file

@ -35,6 +35,7 @@ import (
type AttributeView struct {
Spec int `json:"spec"`
ID string `json:"id"` // 属性视图 ID
Name string `json:"name"` // 属性视图名称
Columns []*Column `json:"columns"` // 表格列名
Rows []*Row `json:"rows"` // 表格行记录
@ -55,6 +56,7 @@ func NewAttributeView(id string) *AttributeView {
return &AttributeView{
Spec: 0,
ID: id,
Name: "Table",
Columns: []*Column{{ID: ast.NewNodeID(), Name: "Block", Type: ColumnTypeBlock}},
Rows: []*Row{},
Type: AttributeViewTypeTable,
@ -72,16 +74,6 @@ func (av *AttributeView) GetColumnNames() (ret []string) {
return
}
func (av *AttributeView) InsertColumn(index int, column *Column) {
if 0 > index || len(av.Columns) == index {
av.Columns = append(av.Columns, column)
return
}
av.Columns = append(av.Columns[:index+1], av.Columns[index:]...)
av.Columns[index] = column
}
type AttributeViewFilter struct {
Column string `json:"column"`
Operator FilterOperator `json:"operator"`

View file

@ -36,6 +36,8 @@ func RenderAttributeView(avID string) (ret *av.AttributeView, err error) {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return
}
// TODO render value
return
}
@ -80,7 +82,7 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
c.Value = parseCellData(operation.Data, av.ColumnType(operation.Typ))
attrs := parse.IAL2Map(node.KramdownIAL)
attrs["av"+c.ID] = c.Value
attrs[NodeAttrNamePrefixAvCol+c.ID] = c.Value
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
return
}
@ -154,7 +156,7 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
}
func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) {
err := addAttributeViewColumn(operation.Name, operation.Typ, -1, operation.ParentID)
err := addAttributeViewColumn(operation.Name, operation.Typ, operation.ParentID)
if nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
}
@ -169,15 +171,20 @@ func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr)
return
}
func addAttributeViewColumn(name string, typ string, columnIndex int, avID string) (err error) {
func addAttributeViewColumn(name string, typ string, avID string) (err error) {
attrView, err := av.ParseAttributeView(avID)
if nil != err {
return
}
switch av.ColumnType(typ) {
colType := av.ColumnType(typ)
switch colType {
case av.ColumnTypeText:
attrView.InsertColumn(columnIndex, &av.Column{ID: "av" + ast.NewNodeID(), Name: name, Type: av.ColumnTypeText})
col := &av.Column{ID: "av" + ast.NewNodeID(), Name: name, Type: colType}
attrView.Columns = append(attrView.Columns, col)
for _, row := range attrView.Rows {
row.Cells = append(row.Cells, &av.Cell{ID: ast.NewNodeID()})
}
default:
msg := fmt.Sprintf("invalid column type [%s]", typ)
logging.LogErrorf(msg)
@ -195,9 +202,16 @@ func removeAttributeViewColumn(columnID string, avID string) (err error) {
return
}
for i, column := range attrView.Columns[1:] {
for i, column := range attrView.Columns {
if column.ID == columnID {
attrView.Columns = append(attrView.Columns[:i], attrView.Columns[i+1:]...)
for _, row := range attrView.Rows {
if len(row.Cells) <= i {
continue
}
row.Cells = append(row.Cells[:i], row.Cells[i+1:]...)
}
break
}
}
@ -265,8 +279,8 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transacti
if 1 < len(ret.Columns) {
attrs := parse.IAL2Map(node.KramdownIAL)
for _, col := range ret.Columns[1:] {
attrs["av"+col.ID] = "" // 将列作为属性添加到块中
row.Cells = append(row.Cells, &av.Cell{ID: ast.NewNodeID(), Value: ""})
attrs[NodeAttrNamePrefixAvCol+col.ID] = "" // 将列作为属性添加到块中
row.Cells = append(row.Cells, &av.Cell{ID: ast.NewNodeID()})
}
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
@ -286,3 +300,5 @@ func parseCellData(data interface{}, colType av.ColumnType) string {
}
return ""
}
const NodeAttrNamePrefixAvCol = "av-col-"