mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Add multi-select type column to Attribute View https://github.com/siyuan-note/siyuan/issues/8695
This commit is contained in:
parent
f6f5e6e2d3
commit
da62a0ad8f
2 changed files with 74 additions and 0 deletions
|
|
@ -167,6 +167,14 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Transaction) doUpdateAttrViewColOption(operation *Operation) (ret *TxErr) {
|
||||||
|
err := updateAttributeViewColumnOption(operation)
|
||||||
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doRemoveAttrViewColOption(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doRemoveAttrViewColOption(operation *Operation) (ret *TxErr) {
|
||||||
err := removeAttributeViewColumnOption(operation)
|
err := removeAttributeViewColumnOption(operation)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -307,6 +315,70 @@ func updateAttributeViewColumn(id, name string, typ string, avID string) (err er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
||||||
|
avID := operation.ParentID
|
||||||
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
colID := operation.ID
|
||||||
|
data := operation.Data.(map[string]interface{})
|
||||||
|
|
||||||
|
var oldName, newName string
|
||||||
|
if nil == data["newName"] {
|
||||||
|
oldName = data["oldName"].(string)
|
||||||
|
newName = data["newName"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
var colIndex int
|
||||||
|
for i, col := range attrView.Columns {
|
||||||
|
if col.ID != colID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
colIndex = i
|
||||||
|
|
||||||
|
for _, opt := range col.Options {
|
||||||
|
if opt.Name != oldName {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
opt.Name = newName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, row := range attrView.Rows {
|
||||||
|
for k, cell := range row.Cells {
|
||||||
|
if colIndex != k {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil != cell.Value {
|
||||||
|
if nil != cell.Value.Select {
|
||||||
|
if oldName == cell.Value.Select.Content {
|
||||||
|
cell.Value.Select.Content = newName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else if nil != cell.Value.MSelect {
|
||||||
|
for j, opt := range cell.Value.MSelect {
|
||||||
|
if oldName == opt.Content {
|
||||||
|
cell.Value.MSelect[j].Content = newName
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func removeAttributeViewColumnOption(operation *Operation) (err error) {
|
func removeAttributeViewColumnOption(operation *Operation) (err error) {
|
||||||
avID := operation.ParentID
|
avID := operation.ParentID
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doUpdateAttrViewColOptions(op)
|
ret = tx.doUpdateAttrViewColOptions(op)
|
||||||
case "removeAttrViewColOption":
|
case "removeAttrViewColOption":
|
||||||
ret = tx.doRemoveAttrViewColOption(op)
|
ret = tx.doRemoveAttrViewColOption(op)
|
||||||
|
case "updateAttrViewColOption":
|
||||||
|
ret = tx.doUpdateAttrViewColOption(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != ret {
|
if nil != ret {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue