🎨 Update av

This commit is contained in:
Daniel 2023-06-10 16:42:07 +08:00
parent 5acd3aae08
commit b0dc75b3c4
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 19 additions and 15 deletions

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
}
@ -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
}
}