mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-27 03:48:48 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
ad77e4d7f3
commit
ff239c1211
3 changed files with 60 additions and 55 deletions
|
|
@ -123,9 +123,8 @@ func setAttributeViewFilters(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -158,9 +157,8 @@ func setAttributeViewSorts(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -316,9 +314,8 @@ func setAttributeViewColWidth(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -347,9 +344,8 @@ func setAttributeViewColWrap(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -378,9 +374,8 @@ func setAttributeViewColHidden(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -495,9 +490,8 @@ func addAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
view, err := attrView.GetView(operation.ViewID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -522,6 +516,51 @@ func addAttributeViewColumn(operation *Operation) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColumn(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColumn(operation *Operation) (err error) {
|
||||
attrView, err := av.ParseAttributeView(operation.AvID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
colType := av.ColumnType(operation.Typ)
|
||||
switch colType {
|
||||
case av.ColumnTypeText, av.ColumnTypeNumber, av.ColumnTypeDate, av.ColumnTypeSelect, av.ColumnTypeMSelect:
|
||||
for _, col := range attrView.Columns {
|
||||
if col.ID == operation.ID {
|
||||
col.Name = operation.Name
|
||||
col.Type = colType
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, view := range attrView.Views {
|
||||
for _, col := range view.Table.Columns {
|
||||
if col.ID == operation.ID {
|
||||
col.Name = operation.Name
|
||||
col.Type = colType
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
msg := fmt.Sprintf("invalid column type [%s]", operation.Typ)
|
||||
logging.LogErrorf(msg)
|
||||
err = errors.New(msg)
|
||||
return
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO 下面的方法要重写
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
||||
|
|
@ -613,14 +652,6 @@ func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *Tx
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doUpdateAttrViewColumn(operation *Operation) (ret *TxErr) {
|
||||
err := updateAttributeViewColumn(operation.ID, operation.Name, operation.Typ, operation.ParentID)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr) {
|
||||
err := removeAttributeViewColumn(operation.ID, operation.ParentID)
|
||||
if nil != err {
|
||||
|
|
@ -637,33 +668,6 @@ func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColumn(id, name string, typ string, avID string) (err error) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
colType := av.ColumnType(typ)
|
||||
switch colType {
|
||||
case av.ColumnTypeText, av.ColumnTypeNumber, av.ColumnTypeDate, av.ColumnTypeSelect, av.ColumnTypeMSelect:
|
||||
for _, col := range attrView.Columns {
|
||||
if col.ID == id {
|
||||
col.Name = name
|
||||
col.Type = colType
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
msg := fmt.Sprintf("invalid column type [%s]", typ)
|
||||
logging.LogErrorf(msg)
|
||||
err = errors.New(msg)
|
||||
return
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func updateAttributeViewColumnOption(operation *Operation) (err error) {
|
||||
avID := operation.ParentID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue