Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve av https://github.com/siyuan-note/siyuan/issues/15555

Danieldc39e18fc133
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 9e2b0ac0e1..2cd073775e 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -630,6 +630,20 @@ func (av *AttributeView) GetBlockKeyValues() (ret *KeyValues) {
return
}
+func (av *AttributeView) GetBlockValue(itemID string) (ret *Value) {
+ for _, kv := range av.KeyValues {
+ if KeyTypeBlock == kv.Key.Type && 0 < len(kv.Values) {
+ for _, v := range kv.Values {
+ if v.BlockID == itemID {
+ ret = v
+ return
+ }
+ }
+ }
+ }
+ return
+}
+
func (av *AttributeView) GetKeyValues(keyID string) (ret *KeyValues, err error) {
for _, kv := range av.KeyValues {
if kv.Key.ID == keyID {
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 162c932246..0ba2421591 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -1648,6 +1648,11 @@ func genAttrViewGroups(view *av.View, attrView *av.AttributeView) {
return
}
+ var relationDestAv *av.AttributeView
+ if av.KeyTypeRelation == groupKey.Type && nil != groupKey.Relation {
+ relationDestAv, _ = av.ParseAttributeView(groupKey.Relation.AvID)
+ }
+
var rangeStart, rangeEnd float64
switch group.Method {
case av.GroupMethodValue:
@@ -1695,11 +1700,20 @@ func genAttrViewGroups(view *av.View, attrView *av.AttributeView) {
var groupVal string
switch group.Method {
case av.GroupMethodValue:
- if av.KeyTypeMSelect == groupKey.Type {
+ if av.KeyTypeSelect == groupKey.Type || av.KeyTypeMSelect == groupKey.Type {
for _, s := range value.MSelect {
groupItemsMap[s.Content] = append(groupItemsMap[s.Content], item)
}
continue
+ } else if av.KeyTypeRelation == groupKey.Type {
+ if nil == relationDestAv {
+ continue
+ }
+
+ for _, bID := range value.Relation.BlockIDs {
+ groupItemsMap[bID] = append(groupItemsMap[bID], item)
+ }
+ continue
}
groupVal = value.String(false)
@@ -1801,6 +1815,16 @@ func genAttrViewGroups(view *av.View, attrView *av.AttributeView) {
v.GroupVal.Type = av.KeyTypeSelect
v.GroupVal.MSelect = []*av.ValueSelect{{Content: opt.Name, Color: opt.Color}}
}
+ } else if av.KeyTypeRelation == groupKey.Type {
+ if relationDestAv != nil && groupValueDefault != groupValue {
+ v.GroupVal.Text = nil
+ v.GroupVal.Type = av.KeyTypeRelation
+ v.GroupVal.Relation = &av.ValueRelation{BlockIDs: []string{groupValue}}
+
+ if destBlock := relationDestAv.GetBlockValue(groupValue); nil != destBlock {
+ v.GroupVal.Relation.Contents = []*av.Value{destBlock}
+ }
+ }
}
v.GroupSort = -1
view.Groups = append(view.Groups, v)
@@ -3556,7 +3580,7 @@ func sortAttributeViewRow(operation *Operation) (err error) {
}
targetGroupView.GroupItemIDs = util.InsertElem(targetGroupView.GroupItemIDs, previousIndex, itemID)
- if av.KeyTypeMSelect == groupKey.Type {
+ if av.KeyTypeMSelect == groupKey.Type || av.KeyTypeRelation == groupKey.Type {
// 跨多选分组时一个项目可能会同时存在于多个分组中,需要重新生成分组
regenAttrViewGroups(attrView, "force")
}