mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 18:24:21 +01:00
♻️ Refactor av data structure
This commit is contained in:
parent
caf074185d
commit
39b28cbc98
4 changed files with 137 additions and 83 deletions
|
|
@ -42,7 +42,7 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
|
|||
}
|
||||
|
||||
if 1 > len(attrView.Views) {
|
||||
err = errors.New("no view")
|
||||
err = av.ErrViewNotFound
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -69,6 +69,108 @@ func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.Attrib
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewName(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewName(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewFilters(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewFilters(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewSorts(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewSorts(operation)
|
||||
if nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewName(operation *Operation) (err error) {
|
||||
avID := operation.ID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
attrView.Name = operation.Data.(string)
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(attrView)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, attrView); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewFilters(operation *Operation) (err error) {
|
||||
avID := operation.ID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
return
|
||||
}
|
||||
|
||||
operationData := operation.Data.([]interface{})
|
||||
data, err := gulu.JSON.MarshalJSON(operationData)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &view.Filters); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func setAttributeViewSorts(operation *Operation) (err error) {
|
||||
avID := operation.ID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
view := attrView.GetView(operation.ViewID)
|
||||
if nil == view {
|
||||
err = av.ErrViewNotFound
|
||||
return
|
||||
}
|
||||
|
||||
operationData := operation.Data.([]interface{})
|
||||
data, err := gulu.JSON.MarshalJSON(operationData)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &view.Sorts); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO 下面的方法要重写
|
||||
|
||||
func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *av.Table, err error) {
|
||||
ret = &av.Table{
|
||||
Spec: attrView.Spec,
|
||||
|
|
@ -144,7 +246,6 @@ func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
sql.RebuildAttributeViewQueue(view)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -172,10 +273,6 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr)
|
|||
|
||||
avs = append(avs, av)
|
||||
}
|
||||
|
||||
for _, av := range avs {
|
||||
sql.RebuildAttributeViewQueue(av)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -195,10 +292,6 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
|
|||
|
||||
avs = append(avs, av)
|
||||
}
|
||||
|
||||
for _, av := range avs {
|
||||
sql.RebuildAttributeViewQueue(av)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package model
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
|
@ -34,6 +33,7 @@ import (
|
|||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -217,6 +217,13 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
ret = tx.doAddFlashcards(op)
|
||||
case "removeFlashcards":
|
||||
ret = tx.doRemoveFlashcards(op)
|
||||
case "setAttrViewName":
|
||||
ret = tx.doSetAttrViewName(op)
|
||||
case "setAttrViewFilters":
|
||||
ret = tx.doSetAttrViewFilters(op)
|
||||
case "setAttrViewSorts":
|
||||
ret = tx.doSetAttrViewSorts(op)
|
||||
// TODO 下面的方法要重写
|
||||
case "insertAttrViewBlock":
|
||||
ret = tx.doInsertAttrViewBlock(op)
|
||||
case "removeAttrViewBlock":
|
||||
|
|
@ -1046,6 +1053,8 @@ type Operation struct {
|
|||
|
||||
DeckID string `json:"deckID"` // 用于添加/删除闪卡
|
||||
|
||||
AvID string `json:"avID"` // 属性视图 ID
|
||||
ViewID string `json:"viewID"` // 属性视图的视图 ID
|
||||
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中
|
||||
Name string `json:"name"` // 用于属性视图列名
|
||||
Typ string `json:"type"` // 用于属性视图列类型
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue