mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
74d10b7e97
commit
d954602379
2 changed files with 112 additions and 144 deletions
|
|
@ -750,149 +750,117 @@ func updateAttributeViewColumnOptions(operation *Operation) (err error) {
|
||||||
return
|
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 {
|
||||||
// return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
// }
|
}
|
||||||
// return
|
return
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func removeAttributeViewColumnOption(operation *Operation) (err error) {
|
|
||||||
// avID := operation.ParentID
|
|
||||||
// attrView, err := av.ParseAttributeView(avID)
|
|
||||||
// if nil != err {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// optName := operation.Data.(string)
|
|
||||||
//
|
|
||||||
// key := attrView.GetKey(operation.ID)
|
|
||||||
// key.
|
|
||||||
//
|
|
||||||
// for _, row := range attrView.Rows {
|
|
||||||
// for i, cell := range row.Cells {
|
|
||||||
// if colIndex != i {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if nil != cell.Value {
|
|
||||||
// if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {
|
|
||||||
// if optName == cell.Value.MSelect[0].Content {
|
|
||||||
// cell.Value = nil
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// } else if nil != cell.Value.MSelect {
|
|
||||||
// for j, opt := range cell.Value.MSelect {
|
|
||||||
// if optName == opt.Content {
|
|
||||||
// cell.Value.MSelect = append(cell.Value.MSelect[:j], cell.Value.MSelect[j+1:]...)
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// err = av.SaveAttributeView(attrView)
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
||||||
// TODO 下面的方法要重写
|
func removeAttributeViewColumnOption(operation *Operation) (err error) {
|
||||||
|
avID := operation.ParentID
|
||||||
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//func (tx *Transaction) doUpdateAttrViewColOption(operation *Operation) (ret *TxErr) {
|
optName := operation.Data.(string)
|
||||||
// err := updateAttributeViewColumnOption(operation)
|
|
||||||
// if nil != err {
|
|
||||||
// return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
key, err := attrView.GetKey(operation.ID)
|
||||||
//func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
if nil != err {
|
||||||
// avID := operation.ParentID
|
return
|
||||||
// attrView, err := av.ParseAttributeView(avID)
|
}
|
||||||
// if nil != err {
|
|
||||||
// return
|
for i, opt := range key.Options {
|
||||||
// }
|
if optName == opt.Name {
|
||||||
//
|
key.Options = append(key.Options[:i], key.Options[i+1:]...)
|
||||||
// colID := operation.ID
|
break
|
||||||
// data := operation.Data.(map[string]interface{})
|
}
|
||||||
//
|
}
|
||||||
// oldName := data["oldName"].(string)
|
|
||||||
// newName := data["newName"].(string)
|
for _, keyValues := range attrView.KeyValues {
|
||||||
// newColor := data["newColor"].(string)
|
if keyValues.Key.ID != operation.ID {
|
||||||
//
|
continue
|
||||||
// var colIndex int
|
}
|
||||||
// for i, col := range attrView.Columns {
|
|
||||||
// if col.ID != colID {
|
for _, value := range keyValues.Values {
|
||||||
// continue
|
if nil == value || nil == value.MSelect {
|
||||||
// }
|
continue
|
||||||
//
|
}
|
||||||
// colIndex = i
|
|
||||||
// existOpt := false
|
for i, opt := range value.MSelect {
|
||||||
// for j, opt := range col.Options {
|
if optName == opt.Content {
|
||||||
// if opt.Name == newName {
|
value.MSelect = append(value.MSelect[:i], value.MSelect[i+1:]...)
|
||||||
// existOpt = true
|
break
|
||||||
// col.Options = append(col.Options[:j], col.Options[j+1:]...)
|
}
|
||||||
// break
|
}
|
||||||
// }
|
}
|
||||||
// }
|
break
|
||||||
// if !existOpt {
|
}
|
||||||
// for _, opt := range col.Options {
|
|
||||||
// if opt.Name != oldName {
|
err = av.SaveAttributeView(attrView)
|
||||||
// continue
|
return
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// opt.Name = newName
|
func (tx *Transaction) doUpdateAttrViewColOption(operation *Operation) (ret *TxErr) {
|
||||||
// opt.Color = newColor
|
err := updateAttributeViewColumnOption(operation)
|
||||||
// break
|
if nil != err {
|
||||||
// }
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||||
// }
|
}
|
||||||
// break
|
return
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, row := range attrView.Rows {
|
func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
||||||
// for i, cell := range row.Cells {
|
avID := operation.ParentID
|
||||||
// if colIndex != i || nil == cell.Value {
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
// continue
|
if nil != err {
|
||||||
// }
|
return
|
||||||
//
|
}
|
||||||
// if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {
|
|
||||||
// if oldName == cell.Value.MSelect[0].Content {
|
key, err := attrView.GetKey(operation.ID)
|
||||||
// cell.Value.MSelect[0].Content = newName
|
if nil != err {
|
||||||
// cell.Value.MSelect[0].Color = newColor
|
return
|
||||||
// break
|
}
|
||||||
// }
|
|
||||||
// } else if nil != cell.Value.MSelect {
|
data := operation.Data.(map[string]interface{})
|
||||||
// existInMSelect := false
|
|
||||||
// for j, opt := range cell.Value.MSelect {
|
oldName := data["oldName"].(string)
|
||||||
// if opt.Content == newName {
|
newName := data["newName"].(string)
|
||||||
// existInMSelect = true
|
newColor := data["newColor"].(string)
|
||||||
// cell.Value.MSelect = append(cell.Value.MSelect[:j], cell.Value.MSelect[j+1:]...)
|
|
||||||
// break
|
for i, opt := range key.Options {
|
||||||
// }
|
if oldName == opt.Name {
|
||||||
// }
|
key.Options[i].Name = newName
|
||||||
// if !existInMSelect {
|
key.Options[i].Color = newColor
|
||||||
// for j, opt := range cell.Value.MSelect {
|
break
|
||||||
// if oldName == opt.Content {
|
}
|
||||||
// cell.Value.MSelect[j].Content = newName
|
}
|
||||||
// cell.Value.MSelect[j].Color = newColor
|
|
||||||
// break
|
for _, keyValues := range attrView.KeyValues {
|
||||||
// }
|
if keyValues.Key.ID != operation.ID {
|
||||||
// }
|
continue
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// break
|
for _, value := range keyValues.Values {
|
||||||
// }
|
if nil == value || nil == value.MSelect {
|
||||||
// }
|
continue
|
||||||
//
|
}
|
||||||
// err = av.SaveAttributeView(attrView)
|
|
||||||
// return
|
for i, opt := range value.MSelect {
|
||||||
//}
|
if oldName == opt.Content {
|
||||||
//
|
value.MSelect[i].Content = newName
|
||||||
|
value.MSelect[i].Color = newColor
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
err = av.SaveAttributeView(attrView)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NodeAttrNameAVs = "custom-avs"
|
NodeAttrNameAVs = "custom-avs"
|
||||||
|
|
|
||||||
|
|
@ -247,10 +247,10 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
||||||
ret = tx.doUpdateAttrViewCell(op)
|
ret = tx.doUpdateAttrViewCell(op)
|
||||||
case "updateAttrViewColOptions":
|
case "updateAttrViewColOptions":
|
||||||
ret = tx.doUpdateAttrViewColOptions(op)
|
ret = tx.doUpdateAttrViewColOptions(op)
|
||||||
//case "removeAttrViewColOption":
|
case "removeAttrViewColOption":
|
||||||
//ret = tx.doRemoveAttrViewColOption(op)
|
ret = tx.doRemoveAttrViewColOption(op)
|
||||||
//case "updateAttrViewColOption":
|
case "updateAttrViewColOption":
|
||||||
// ret = tx.doUpdateAttrViewColOption(op)
|
ret = tx.doUpdateAttrViewColOption(op)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != ret {
|
if nil != ret {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue