mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🧑💻 Add internal kernel API /api/av/getAttributeViewBoundBlockIDs and getAttributeViewItemIDs https://github.com/siyuan-note/siyuan/issues/15708
This commit is contained in:
parent
3c8c096d83
commit
ab66716178
3 changed files with 82 additions and 0 deletions
|
|
@ -27,6 +27,44 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getAttributeViewItemIDsByBoundIDs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
avID := arg["avID"].(string)
|
||||
blockIDsArg := arg["blockIDs"].([]interface{})
|
||||
var blockIDs []string
|
||||
for _, v := range blockIDsArg {
|
||||
blockIDs = append(blockIDs, v.(string))
|
||||
}
|
||||
|
||||
ret.Data = model.GetAttributeViewItemIDs(avID, blockIDs)
|
||||
}
|
||||
|
||||
func getAttributeViewBoundBlockIDsByItemIDs(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
avID := arg["avID"].(string)
|
||||
itemIDsArg := arg["itemIDs"].([]interface{})
|
||||
var itemIDs []string
|
||||
for _, v := range itemIDsArg {
|
||||
itemIDs = append(itemIDs, v.(string))
|
||||
}
|
||||
|
||||
ret.Data = model.GetAttributeViewBoundBlockIDs(avID, itemIDs)
|
||||
}
|
||||
|
||||
// getAttributeViewAddingBlockDefaultValues 用于获取添加块时的默认值。
|
||||
// 存在过滤或分组条件时,添加块时需要填充默认值到过滤字段或分组字段中,前端需要调用该接口来获取这些默认值以便填充。
|
||||
func getAttributeViewAddingBlockDefaultValues(c *gin.Context) {
|
||||
|
|
|
|||
|
|
@ -465,6 +465,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/av/setAttrViewGroup", model.CheckAuth, setAttrViewGroup)
|
||||
ginServer.Handle("POST", "/api/av/batchReplaceAttributeViewBlocks", model.CheckAuth, batchReplaceAttributeViewBlocks)
|
||||
ginServer.Handle("POST", "/api/av/getAttributeViewAddingBlockDefaultValues", model.CheckAuth, getAttributeViewAddingBlockDefaultValues)
|
||||
ginServer.Handle("POST", "/api/av/getAttributeViewBoundBlockIDsByItemIDs", model.CheckAuth, getAttributeViewBoundBlockIDsByItemIDs)
|
||||
ginServer.Handle("POST", "/api/av/getAttributeViewItemIDsByBoundIDs", model.CheckAuth, getAttributeViewItemIDsByBoundIDs)
|
||||
|
||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckAdminRole, chatGPT)
|
||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckAdminRole, chatGPTWithAction)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,48 @@ import (
|
|||
"github.com/xrash/smetrics"
|
||||
)
|
||||
|
||||
func GetAttributeViewItemIDs(avID string, blockIDs []string) (ret map[string]string) {
|
||||
ret = map[string]string{}
|
||||
for _, blockID := range blockIDs {
|
||||
ret[blockID] = ""
|
||||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
blockKv := attrView.GetBlockKeyValues()
|
||||
for _, b := range blockKv.Values {
|
||||
if _, ok := ret[b.Block.ID]; ok {
|
||||
ret[b.Block.ID] = b.BlockID
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetAttributeViewBoundBlockIDs(avID string, itemIDs []string) (ret map[string]string) {
|
||||
ret = map[string]string{}
|
||||
for _, itemID := range itemIDs {
|
||||
ret[itemID] = ""
|
||||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
blockKv := attrView.GetBlockKeyValues()
|
||||
for _, b := range blockKv.Values {
|
||||
if _, ok := ret[b.BlockID]; ok {
|
||||
ret[b.BlockID] = b.Block.ID
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetAttrViewAddingBlockDefaultValues(avID, viewID, groupID, previousBlockID, addingBlockID string) (ret map[string]*av.Value) {
|
||||
ret = map[string]*av.Value{}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue