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
ff539bab03
commit
d0662b5fde
2 changed files with 19 additions and 13 deletions
|
@ -220,6 +220,21 @@ func (view *View) GetGroup(groupID string) *View {
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetGroupKey 获取分组视图的分组字段。
|
||||
func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
|
||||
if nil == view.Group || "" == view.Group.Field {
|
||||
return
|
||||
}
|
||||
|
||||
for _, kv := range attrView.KeyValues {
|
||||
if kv.Key.ID == view.Group.Field {
|
||||
ret = kv.Key
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GroupCalc 描述了分组计算规则和结果的结构。
|
||||
type GroupCalc struct {
|
||||
Field string `json:"field"` // 字段 ID
|
||||
|
|
|
@ -3063,7 +3063,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
|
|||
}
|
||||
|
||||
// 如果存在分组条件,则将分组条件应用到新添加的块上
|
||||
groupKey := getViewGroupKey(view, attrView)
|
||||
groupKey := view.GetGroupKey(attrView)
|
||||
if nil != view && nil != groupKey {
|
||||
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
|
||||
if groupView := view.GetGroup(groupID); nil != groupView {
|
||||
|
@ -3868,6 +3868,7 @@ func updateAttributeViewColTemplate(operation *Operation) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
regenAttrViewViewGroups(attrView, operation.ID)
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
@ -4524,7 +4525,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
|
|||
|
||||
func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
|
||||
for _, view := range attrView.Views {
|
||||
groupKey := getViewGroupKey(view, attrView)
|
||||
groupKey := view.GetGroupKey(attrView)
|
||||
if nil == groupKey {
|
||||
continue
|
||||
}
|
||||
|
@ -4549,17 +4550,6 @@ func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
|
|||
}
|
||||
}
|
||||
|
||||
func getViewGroupKey(view *av.View, attrView *av.AttributeView) *av.Key {
|
||||
if nil == view.Group {
|
||||
return nil
|
||||
}
|
||||
if "" == view.Group.Field {
|
||||
return nil
|
||||
}
|
||||
ret, _ := attrView.GetKey(view.Group.Field)
|
||||
return ret
|
||||
}
|
||||
|
||||
func unbindBlockAv(tx *Transaction, avID, blockID string) {
|
||||
node, tree, err := getNodeByBlockID(tx, blockID)
|
||||
if err != nil {
|
||||
|
@ -4753,6 +4743,7 @@ func removeAttributeViewColumnOption(operation *Operation) (err error) {
|
|||
break
|
||||
}
|
||||
|
||||
regenAttrViewViewGroups(attrView, operation.ID)
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue