mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
🎨 Update av
This commit is contained in:
parent
5acd3aae08
commit
b0dc75b3c4
2 changed files with 19 additions and 15 deletions
|
|
@ -72,16 +72,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"`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue