mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
This commit is contained in:
parent
a0f6a6f117
commit
dcae07d2e4
2 changed files with 35 additions and 18 deletions
|
|
@ -1217,7 +1217,8 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
|
||||||
view = attrView.Views[0]
|
view = attrView.Views[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 做一些数据兼容和订正处理,保存的时候也会做 av.SaveAttributeView()
|
// 做一些数据兼容和订正处理
|
||||||
|
checkViewInstance(attrView, view)
|
||||||
upgradeAttributeViewSpec(attrView)
|
upgradeAttributeViewSpec(attrView)
|
||||||
|
|
||||||
switch view.LayoutType {
|
switch view.LayoutType {
|
||||||
|
|
@ -1964,31 +1965,37 @@ func (tx *Transaction) doDuplicateAttrViewView(operation *Operation) (ret *TxErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
||||||
var err error
|
err := addAttrViewView(operation.AvID, operation.ID, operation.BlockID, operation.Layout)
|
||||||
avID := operation.AvID
|
if nil != err {
|
||||||
|
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAttrViewView(avID, viewID, blockID string, layout av.LayoutType) (err error) {
|
||||||
attrView, err := av.ParseAttributeView(avID)
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if 1 > len(attrView.Views) {
|
if 1 > len(attrView.Views) {
|
||||||
logging.LogErrorf("no view in attribute view [%s]", avID)
|
logging.LogErrorf("no view in attribute view [%s]", avID)
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
firstView := attrView.Views[0]
|
firstView := attrView.Views[0]
|
||||||
if nil == firstView {
|
if nil == firstView {
|
||||||
logging.LogErrorf("get first view failed: %s", avID)
|
logging.LogErrorf("get first view failed: %s", avID)
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if "" == operation.Layout {
|
if "" == layout {
|
||||||
operation.Layout = av.LayoutTypeTable
|
layout = av.LayoutTypeTable
|
||||||
}
|
}
|
||||||
|
|
||||||
var view *av.View
|
var view *av.View
|
||||||
switch operation.Layout {
|
switch layout {
|
||||||
case av.LayoutTypeTable:
|
case av.LayoutTypeTable:
|
||||||
view = av.NewTableView()
|
view = av.NewTableView()
|
||||||
switch firstView.LayoutType {
|
switch firstView.LayoutType {
|
||||||
|
|
@ -2027,32 +2034,32 @@ func (tx *Transaction) doAddAttrViewView(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
err = av.ErrWrongLayoutType
|
err = av.ErrWrongLayoutType
|
||||||
logging.LogErrorf("wrong layout type [%s] for attribute view [%s]", operation.Layout, avID)
|
logging.LogErrorf("wrong layout type [%s] for attribute view [%s]", layout, avID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view.ID = operation.ID
|
attrView.ViewID = viewID
|
||||||
|
view.ID = viewID
|
||||||
attrView.Views = append(attrView.Views, view)
|
attrView.Views = append(attrView.Views, view)
|
||||||
attrView.ViewID = view.ID
|
|
||||||
|
|
||||||
node, tree, _ := getNodeByBlockID(nil, operation.BlockID)
|
node, tree, _ := getNodeByBlockID(nil, blockID)
|
||||||
if nil == node {
|
if nil == node {
|
||||||
logging.LogErrorf("get node by block ID [%s] failed", operation.BlockID)
|
logging.LogErrorf("get node by block ID [%s] failed", blockID)
|
||||||
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
node.AttributeViewType = string(view.LayoutType)
|
node.AttributeViewType = string(view.LayoutType)
|
||||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
attrs[av.NodeAttrView] = operation.ID
|
attrs[av.NodeAttrView] = viewID
|
||||||
err = setNodeAttrs(node, tree, attrs)
|
err = setNodeAttrs(node, tree, attrs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogWarnf("set node [%s] attrs failed: %s", operation.BlockID, err)
|
logging.LogWarnf("set node [%s] attrs failed: %s", blockID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = av.SaveAttributeView(attrView); err != nil {
|
if err = av.SaveAttributeView(attrView); err != nil {
|
||||||
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
logging.LogErrorf("save attribute view [%s] failed: %s", avID, err)
|
||||||
return &TxErr{code: TxErrWriteAttributeView, msg: err.Error(), id: avID}
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,16 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkViewInstance(attrView *av.AttributeView, view *av.View) {
|
||||||
|
if av.LayoutTypeGallery == view.LayoutType && nil == view.Gallery {
|
||||||
|
// 切换为画廊视图时可能没有初始化画廊实例 https://github.com/siyuan-note/siyuan/issues/15122
|
||||||
|
if nil != view.Table {
|
||||||
|
view.LayoutType = av.LayoutTypeTable
|
||||||
|
av.SaveAttributeView(attrView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func upgradeAttributeViewSpec(attrView *av.AttributeView) {
|
func upgradeAttributeViewSpec(attrView *av.AttributeView) {
|
||||||
currentSpec := attrView.Spec
|
currentSpec := attrView.Spec
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue