mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 19:41:31 +08:00
🎨 Add Relation and Rollup column to database table view https://github.com/siyuan-note/siyuan/issues/9888
This commit is contained in:
parent
87096f9671
commit
62e92c0e6b
@ -26,6 +26,35 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func searchAttributeView(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, _ := util.JsonArg(c, ret)
|
||||||
|
if nil == arg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
keyword := arg["keyword"].(string)
|
||||||
|
page := 1
|
||||||
|
pageArg := arg["page"]
|
||||||
|
if nil != pageArg {
|
||||||
|
page = int(pageArg.(float64))
|
||||||
|
}
|
||||||
|
|
||||||
|
pageSize := 10
|
||||||
|
pageSizeArg := arg["pageSize"]
|
||||||
|
if nil != pageSizeArg {
|
||||||
|
pageSize = int(pageSizeArg.(float64))
|
||||||
|
}
|
||||||
|
|
||||||
|
results, total := model.SearchAttributeView(keyword, page, pageSize)
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"results": results,
|
||||||
|
"total": total,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func renderSnapshotAttributeView(c *gin.Context) {
|
func renderSnapshotAttributeView(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
@ -386,6 +386,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/av/renderSnapshotAttributeView", model.CheckAuth, renderSnapshotAttributeView)
|
ginServer.Handle("POST", "/api/av/renderSnapshotAttributeView", model.CheckAuth, renderSnapshotAttributeView)
|
||||||
ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys)
|
ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys)
|
||||||
ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttr", model.CheckAuth, model.CheckReadonly, setAttributeViewBlockAttr)
|
ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttr", model.CheckAuth, model.CheckReadonly, setAttributeViewBlockAttr)
|
||||||
|
ginServer.Handle("POST", "/api/av/searchAttributeView", model.CheckAuth, model.CheckReadonly, searchAttributeView)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
||||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)
|
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)
|
||||||
|
@ -37,6 +37,63 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type SearchAttributeViewResult struct {
|
||||||
|
AvID string `json:"avID"`
|
||||||
|
AvName string `json:"avName"`
|
||||||
|
BlockID string `json:"blockID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func SearchAttributeView(keyword string, page int, pageSize int) (ret []*SearchAttributeViewResult, pageCount int) {
|
||||||
|
waitForSyncingStorages()
|
||||||
|
|
||||||
|
ret = []*SearchAttributeViewResult{}
|
||||||
|
blocks, _, _, pageCount := FullTextSearchBlock(keyword, nil, nil, map[string]bool{"databaseBlock": true}, 0, 7, 0, page, pageSize)
|
||||||
|
trees := map[string]*parse.Tree{}
|
||||||
|
for _, block := range blocks {
|
||||||
|
tree := trees[block.RootID]
|
||||||
|
if nil == tree {
|
||||||
|
tree, _ = loadTreeByBlockID(block.ID)
|
||||||
|
if nil != tree {
|
||||||
|
trees[block.RootID] = tree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if nil == tree {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
node := treenode.GetNodeInTree(tree, block.ID)
|
||||||
|
if nil == node {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if "" == node.AttributeViewID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
avID := node.AttributeViewID
|
||||||
|
attrView, _ := av.ParseAttributeView(avID)
|
||||||
|
if nil == attrView {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
exist := false
|
||||||
|
for _, result := range ret {
|
||||||
|
if result.AvID == avID {
|
||||||
|
exist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !exist {
|
||||||
|
ret = append(ret, &SearchAttributeViewResult{
|
||||||
|
AvID: avID,
|
||||||
|
AvName: attrView.Name,
|
||||||
|
BlockID: block.ID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type BlockAttributeViewKeys struct {
|
type BlockAttributeViewKeys struct {
|
||||||
AvID string `json:"avID"`
|
AvID string `json:"avID"`
|
||||||
AvName string `json:"avName"`
|
AvName string `json:"avName"`
|
||||||
|
Loading…
Reference in New Issue
Block a user