mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
🎨 Supports multiple views for the database https://github.com/siyuan-note/siyuan/issues/9751
This commit is contained in:
parent
33585ae173
commit
ee9844c379
3 changed files with 66 additions and 50 deletions
|
|
@ -294,7 +294,7 @@ func RenderAttributeView(avID, viewID string) (viewable av.Viewable, attrView *a
|
|||
|
||||
func renderAttributeView(attrView *av.AttributeView, viewID string) (viewable av.Viewable, err error) {
|
||||
if 1 > len(attrView.Views) {
|
||||
view, _ := av.NewView()
|
||||
view, _ := av.NewView(ast.NewNodeID())
|
||||
attrView.Views = append(attrView.Views, view)
|
||||
attrView.ViewID = view.ID
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
|
|
@ -633,6 +633,56 @@ func getRowBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: avID}
|
||||
}
|
||||
|
||||
viewID := operation.ID
|
||||
for i, view := range attrView.Views {
|
||||
if viewID == view.ID {
|
||||
attrView.Views = append(attrView.Views[:i], attrView.Views[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: avID}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||
}
|
||||
|
||||
bKey := attrView.GetBlockKey()
|
||||
if nil == bKey {
|
||||
logging.LogErrorf("get block key failed: %s", avID)
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||
}
|
||||
|
||||
view, _ := av.NewView(bKey.ID)
|
||||
view.ID = operation.ID
|
||||
attrView.Views = append(attrView.Views, view)
|
||||
attrView.ViewID = view.ID
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrWriteAttributeView, msg: err.Error(), id: avID}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doSetAttrViewName(operation *Operation) (ret *TxErr) {
|
||||
err := setAttributeViewName(operation)
|
||||
if nil != err {
|
||||
|
|
|
|||
|
|
@ -261,50 +261,6 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doRemoveAttrViewView(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: avID}
|
||||
}
|
||||
|
||||
viewID := operation.ID
|
||||
for i, view := range attrView.Views {
|
||||
if viewID == view.ID {
|
||||
attrView.Views = append(attrView.Views[:i], attrView.Views[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: avID}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
avID := operation.AvID
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: avID}
|
||||
}
|
||||
|
||||
view, _ := av.NewView()
|
||||
view.ID = operation.ID
|
||||
attrView.Views = append(attrView.Views, view)
|
||||
attrView.ViewID = view.ID
|
||||
if err = av.SaveAttributeView(attrView); nil != err {
|
||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: avID}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
||||
var err error
|
||||
id := operation.ID
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue