🎨 Rows non-bound in the database support Add to Database https://github.com/siyuan-note/siyuan/issues/11093

This commit is contained in:
Daniel 2024-04-20 22:37:39 +08:00
parent 01072dde42
commit 26cfc586f0
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 11 additions and 30 deletions

View file

@ -118,28 +118,17 @@ func addAttributeViewValues(c *gin.Context) {
if nil != arg["previousID"] { if nil != arg["previousID"] {
previousID = arg["previousID"].(string) previousID = arg["previousID"].(string)
} }
isDetached := arg["isDetached"].(bool)
ignoreFillFilter := true ignoreFillFilter := true
if nil != arg["ignoreFillFilter"] { if nil != arg["ignoreFillFilter"] {
ignoreFillFilter = arg["ignoreFillFilter"].(bool) ignoreFillFilter = arg["ignoreFillFilter"].(bool)
} }
var srcs []map[string]interface{} var srcs []map[string]interface{}
if nil != arg["srcIDs"] { for _, v := range arg["srcs"].([]interface{}) {
var srcIDs []string src := v.(map[string]interface{})
for _, v := range arg["srcIDs"].([]interface{}) { srcs = append(srcs, src)
srcIDs = append(srcIDs, v.(string))
}
for _, srcID := range srcIDs {
src := map[string]interface{}{
"id": srcID,
}
srcs = append(srcs, src)
}
} else {
srcs = arg["srcs"].([]map[string]interface{})
} }
err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, previousID, isDetached, ignoreFillFilter) err := model.AddAttributeViewBlock(nil, srcs, avID, blockID, previousID, ignoreFillFilter)
if nil != err { if nil != err {
ret.Code = -1 ret.Code = -1
ret.Msg = err.Error() ret.Msg = err.Error()

View file

@ -2165,25 +2165,17 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) {
} }
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) { func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
var srcs []map[string]interface{} err := AddAttributeViewBlock(tx, operation.Srcs, operation.AvID, operation.BlockID, operation.PreviousID, operation.IgnoreFillFilterVal)
if 0 < len(operation.Srcs) {
srcs = operation.Srcs
} else {
for _, srcID := range operation.SrcIDs {
srcs = append(srcs, map[string]interface{}{"id": srcID})
}
}
err := AddAttributeViewBlock(tx, srcs, operation.AvID, operation.BlockID, operation.PreviousID, operation.IsDetached, operation.IgnoreFillFilterVal)
if nil != err { if nil != err {
return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()} return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: err.Error()}
} }
return return
} }
func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, blockID, previousBlockID string, isDetached, ignoreFillFilter bool) (err error) { func AddAttributeViewBlock(tx *Transaction, srcs []map[string]interface{}, avID, blockID, previousBlockID string, ignoreFillFilter bool) (err error) {
for _, src := range srcs { for _, src := range srcs {
srcID := src["id"].(string) srcID := src["id"].(string)
isDetached := src["isDetached"].(bool)
var tree *parse.Tree var tree *parse.Tree
if !isDetached { if !isDetached {
var loadErr error var loadErr error
@ -3166,12 +3158,12 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
// 将游离行绑定到新建的块上 // 将游离行绑定到新建的块上
bindBlockAv(tx, avID, rowID) bindBlockAv(tx, avID, rowID)
} }
} else { // 之前绑定了块 } else { // 之前绑定了块
if isUpdatingBlockKey { // 正在更新主键 if isUpdatingBlockKey { // 正在更新主键
if val.IsDetached { // 现在是游离行 if val.IsDetached { // 现在是游离行
// 将绑定的块从属性视图中移除 // 将绑定的块从属性视图中移除
unbindBlockAv(tx, avID, rowID) unbindBlockAv(tx, avID, rowID)
} else { // 现在绑定了块 } else { // 现在绑定了块
if oldBoundBlockID != val.BlockID { // 之前绑定的块和现在绑定的块不一样 if oldBoundBlockID != val.BlockID { // 之前绑定的块和现在绑定的块不一样
// 换绑块 // 换绑块
unbindBlockAv(tx, avID, oldBoundBlockID) unbindBlockAv(tx, avID, oldBoundBlockID)

View file

@ -1263,8 +1263,8 @@ type Operation struct {
DeckID string `json:"deckID"` // 用于添加/删除闪卡 DeckID string `json:"deckID"` // 用于添加/删除闪卡
AvID string `json:"avID"` // 属性视图 ID AvID string `json:"avID"` // 属性视图 ID
SrcIDs []string `json:"srcIDs"` // 用于将块拖拽到属性视图中 SrcIDs []string `json:"srcIDs"` // 用于从属性视图中删除行
Srcs []map[string]interface{} `json:"srcs"` // 属性视图中多选 添加到数据库 Srcs []map[string]interface{} `json:"srcs"` // 用于添加属性视图行(包括绑定块){id, content, isDetached}
IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中 IsDetached bool `json:"isDetached"` // 用于标识是否未绑定块,仅存在于属性视图中
IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值 IgnoreFillFilterVal bool `json:"ignoreFillFilter"` // 用于标识是否忽略填充筛选值
Name string `json:"name"` // 属性视图列名 Name string `json:"name"` // 属性视图列名