mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964
This commit is contained in:
parent
0816925e76
commit
f7d28dc1de
1 changed files with 30 additions and 29 deletions
|
@ -3038,15 +3038,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
|
||||||
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
|
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
|
||||||
if groupView := view.GetGroup(groupID); nil != groupView {
|
if groupView := view.GetGroup(groupID); nil != groupView {
|
||||||
if keyValues, _ := attrView.GetKeyValues(groupKey.ID); nil != keyValues {
|
if keyValues, _ := attrView.GetKeyValues(groupKey.ID); nil != keyValues {
|
||||||
var newValue *av.Value
|
newValue := getNewValueByNearItem(nearItem, groupKey, blockID)
|
||||||
if nil != nearItem {
|
|
||||||
defaultVal := nearItem.GetValue(groupKey.ID)
|
|
||||||
newValue = defaultVal.Clone()
|
|
||||||
}
|
|
||||||
if nil == newValue {
|
|
||||||
newValue = av.GetAttributeViewDefaultValue(ast.NewNodeID(), groupKey.ID, blockID, groupKey.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
if av.KeyTypeBlock == newValue.Type {
|
if av.KeyTypeBlock == newValue.Type {
|
||||||
// 如果是主键的话前面已经添加过了,这里仅修改内容
|
// 如果是主键的话前面已经添加过了,这里仅修改内容
|
||||||
blockValue.Block.Content = newValue.Block.Content
|
blockValue.Block.Content = newValue.Block.Content
|
||||||
|
@ -3079,6 +3071,17 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getNewValueByNearItem(nearItem av.Item, key *av.Key, blockID string) (ret *av.Value) {
|
||||||
|
if nil != nearItem {
|
||||||
|
defaultVal := nearItem.GetValue(key.ID)
|
||||||
|
ret = defaultVal.Clone()
|
||||||
|
}
|
||||||
|
if nil == ret {
|
||||||
|
ret = av.GetAttributeViewDefaultValue(ast.NewNodeID(), key.ID, blockID, key.Type)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func getNearItem(attrView *av.AttributeView, view, groupView *av.View, previousItemID string) (ret av.Item) {
|
func getNearItem(attrView *av.AttributeView, view, groupView *av.View, previousItemID string) (ret av.Item) {
|
||||||
viewable := sql.RenderGroupView(attrView, view, groupView)
|
viewable := sql.RenderGroupView(attrView, view, groupView)
|
||||||
av.Filter(viewable, attrView)
|
av.Filter(viewable, attrView)
|
||||||
|
@ -3566,33 +3569,31 @@ func sortAttributeViewRow(operation *Operation) (err error) {
|
||||||
}
|
}
|
||||||
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
|
groupView.GroupItemIDs = append(groupView.GroupItemIDs[:idx], groupView.GroupItemIDs[idx+1:]...)
|
||||||
|
|
||||||
targetGroupView := groupView
|
if operation.GroupID != operation.TargetGroupID { // 跨分组排序
|
||||||
if operation.GroupID != operation.TargetGroupID { // 跨分组拖拽
|
if targetGroupView := view.GetGroup(operation.TargetGroupID); nil != targetGroupView {
|
||||||
targetGroupView = view.GetGroup(operation.TargetGroupID)
|
groupKey := view.GetGroupKey(attrView)
|
||||||
}
|
nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID)
|
||||||
if nil != targetGroupView {
|
newValue := getNewValueByNearItem(nearItem, groupKey, operation.ID)
|
||||||
groupKey := view.GetGroupKey(attrView)
|
val := attrView.GetValue(groupKey.ID, operation.ID)
|
||||||
nearItem := getNearItem(attrView, view, targetGroupView, operation.PreviousID)
|
newValueRaw := newValue.GetValByType(groupKey.Type)
|
||||||
var newValue *av.Value
|
val.SetValByType(groupKey.Type, newValueRaw)
|
||||||
if nil != nearItem {
|
|
||||||
defaultVal := nearItem.GetValue(view.Group.Field)
|
|
||||||
newValue = defaultVal.Clone()
|
|
||||||
}
|
|
||||||
if nil == newValue {
|
|
||||||
newValue = av.GetAttributeViewDefaultValue(ast.NewNodeID(), groupKey.ID, operation.ID, groupKey.Type)
|
|
||||||
|
|
||||||
|
for i, r := range targetGroupView.GroupItemIDs {
|
||||||
|
if r == operation.PreviousID {
|
||||||
|
previousIndex = i + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
|
||||||
}
|
}
|
||||||
val := attrView.GetValue(groupKey.ID, operation.ID)
|
} else { // 同分组内排序
|
||||||
newValueRaw := newValue.GetValByType(groupKey.Type)
|
for i, r := range groupView.GroupItemIDs {
|
||||||
val.SetValByType(groupKey.Type, newValueRaw)
|
|
||||||
|
|
||||||
for i, r := range targetGroupView.GroupItemIDs {
|
|
||||||
if r == operation.PreviousID {
|
if r == operation.PreviousID {
|
||||||
previousIndex = i + 1
|
previousIndex = i + 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
|
groupView.GroupItemIDs = util.InsertElem(groupView.GroupItemIDs, previousIndex, itemID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue