An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Database gallery view https://github.com/siyuan-note/siyuan/issues/10414
Daniel05d1085633d7
diff --git a/kernel/sql/av.go b/kernel/sql/av.goindex 214458e7b0..8ea1619042 100644--- a/kernel/sql/av.go+++ b/kernel/sql/av.go@@ -25,6 +25,7 @@ import ("github.com/siyuan-note/logging""github.com/siyuan-note/siyuan/kernel/av""github.com/siyuan-note/siyuan/kernel/filesys"+ "github.com/siyuan-note/siyuan/kernel/treenode""github.com/siyuan-note/siyuan/kernel/util")@@ -173,6 +174,54 @@ func RenderTemplateField(ial map[string]string, keyValues []*av.KeyValues, tplCoreturn}+func generateAttrViewItems(attrView *av.AttributeView) (ret map[string][]*av.KeyValues) {+ ret = map[string][]*av.KeyValues{}+ for _, keyValues := range attrView.KeyValues {+ for _, val := range keyValues.Values {+ values := ret[val.BlockID]+ if nil == values {+ values = []*av.KeyValues{{Key: keyValues.Key, Values: []*av.Value{val}}}+ } else {+ values = append(values, &av.KeyValues{Key: keyValues.Key, Values: []*av.Value{val}})+ }+ ret[val.BlockID] = values+ }+ }+ return+}++func filterNotFoundAttrViewItems(keyValuesMap *map[string][]*av.KeyValues) {+ var notFound []string+ var toCheckBlockIDs []string+ for blockID, keyValues := range *keyValuesMap {+ blockValue := getBlockValue(keyValues)+ if nil == blockValue {+ notFound = append(notFound, blockID)+ continue+ }++ if blockValue.IsDetached {+ continue+ }++ if nil != blockValue.Block && "" == blockValue.Block.ID {+ notFound = append(notFound, blockID)+ continue+ }++ toCheckBlockIDs = append(toCheckBlockIDs, blockID)+ }+ checkRet := treenode.ExistBlockTrees(toCheckBlockIDs)+ for blockID, exist := range checkRet {+ if !exist {+ notFound = append(notFound, blockID)+ }+ }+ for _, blockID := range notFound {+ delete(*keyValuesMap, blockID)+ }+}+func fillAttributeViewNilValue(value *av.Value, typ av.KeyType) {value.Type = typswitch typ {diff --git a/kernel/sql/av_gallery.go b/kernel/sql/av_gallery.goindex ddc057d83e..e8167355bd 100644--- a/kernel/sql/av_gallery.go+++ b/kernel/sql/av_gallery.go@@ -64,50 +64,8 @@ func RenderAttributeViewGallery(attrView *av.AttributeView, view *av.View, query})}- // 生成卡片- cardsValues := map[string][]*av.KeyValues{}- for _, keyValues := range attrView.KeyValues {- for _, val := range keyValues.Values {- values := cardsValues[val.BlockID]- if nil == values {- values = []*av.KeyValues{{Key: keyValues.Key, Values: []*av.Value{val}}}- } else {- values = append(values, &av.KeyValues{Key: keyValues.Key, Values: []*av.Value{val}})- }- cardsValues[val.BlockID] = values- }- }-- // 过滤掉不存在的卡片- var notFound []string- var toCheckBlockIDs []string- for blockID, keyValues := range cardsValues {- blockValue := getBlockValue(keyValues)- if nil == blockValue {- notFound = append(notFound, blockID)- continue- }-- if blockValue.IsDetached {- continue- }-- if nil != blockValue.Block && "" == blockValue.Block.ID {- notFound = append(notFound, blockID)- continue- }-- toCheckBlockIDs = append(toCheckBlockIDs, blockID)- }- checkRet := treenode.ExistBlockTrees(toCheckBlockIDs)- for blockID, exist := range checkRet {- if !exist {- notFound = append(notFound, blockID)- }- }- for _, blockID := range notFound {- delete(cardsValues, blockID)- }+ cardsValues := generateAttrViewItems(attrView) // 生成卡片+ filterNotFoundAttrViewItems(&cardsValues) // 过滤掉不存在的卡片// 生成卡片字段值for cardID, cardValues := range cardsValues {diff --git a/kernel/sql/av_table.go b/kernel/sql/av_table.goindex e1423fb002..56f9741d0e 100644--- a/kernel/sql/av_table.go+++ b/kernel/sql/av_table.go@@ -22,7 +22,6 @@ import ("github.com/88250/lute/ast""github.com/siyuan-note/siyuan/kernel/av"- "github.com/siyuan-note/siyuan/kernel/treenode""github.com/siyuan-note/siyuan/kernel/util")@@ -72,50 +71,8 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s})}- // 生成行- rowsValues := map[string][]*av.KeyValues{}- for _, keyValues := range attrView.KeyValues {- for _, val := range keyValues.Values {- values := rowsValues[val.BlockID]- if nil == values {- values = []*av.KeyValues{{Key: keyValues.Key, Values: []*av.Value{val}}}- } else {- values = append(values, &av.KeyValues{Key: keyValues.Key, Values: []*av.Value{val}})- }- rowsValues[val.BlockID] = values- }- }-- // 过滤掉不存在的行- var notFound []string- var toCheckBlockIDs []string- for blockID, keyValues := range rowsValues {- blockValue := getBlockValue(keyValues)- if nil == blockValue {- notFound = append(notFound, blockID)- continue- }-- if blockValue.IsDetached {- continue- }-- if nil != blockValue.Block && "" == blockValue.Block.ID {- notFound = append(notFound, blockID)- continue- }-- toCheckBlockIDs = append(toCheckBlockIDs, blockID)- }- checkRet := treenode.ExistBlockTrees(toCheckBlockIDs)- for blockID, exist := range checkRet {- if !exist {- notFound = append(notFound, blockID)- }- }- for _, blockID := range notFound {- delete(rowsValues, blockID)- }+ rowsValues := generateAttrViewItems(attrView) // 生成行+ filterNotFoundAttrViewItems(&rowsValues) // 过滤掉不存在的行// 生成行单元格for rowID, rowValues := range rowsValues {