Browse Source

:bug: The selection options are inconsistent after pasting data into the database https://github.com/siyuan-note/siyuan/issues/11409

Daniel 1 năm trước cách đây
mục cha
commit
f7d23b41fd

+ 13 - 0
kernel/api/av.go

@@ -27,6 +27,19 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 )
 
 
+func getAttributeViewSelectOptions(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)
+	keyID := arg["keyID"].(string)
+	ret.Data = model.GetAttributeViewSelectOptions(avID, keyID)
+}
+
 func getMirrorDatabaseBlocks(c *gin.Context) {
 func getMirrorDatabaseBlocks(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)
 	defer c.JSON(http.StatusOK, ret)

+ 1 - 0
kernel/api/router.go

@@ -423,6 +423,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/av/getAttributeViewPrimaryKeyValues", model.CheckAuth, model.CheckReadonly, getAttributeViewPrimaryKeyValues)
 	ginServer.Handle("POST", "/api/av/getAttributeViewPrimaryKeyValues", model.CheckAuth, model.CheckReadonly, getAttributeViewPrimaryKeyValues)
 	ginServer.Handle("POST", "/api/av/setDatabaseBlockView", model.CheckAuth, model.CheckReadonly, setDatabaseBlockView)
 	ginServer.Handle("POST", "/api/av/setDatabaseBlockView", model.CheckAuth, model.CheckReadonly, setDatabaseBlockView)
 	ginServer.Handle("POST", "/api/av/getMirrorDatabaseBlocks", model.CheckAuth, model.CheckReadonly, getMirrorDatabaseBlocks)
 	ginServer.Handle("POST", "/api/av/getMirrorDatabaseBlocks", model.CheckAuth, model.CheckReadonly, getMirrorDatabaseBlocks)
+	ginServer.Handle("POST", "/api/av/getAttributeViewSelectOptions", model.CheckAuth, model.CheckReadonly, getAttributeViewSelectOptions)
 
 
 	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)

+ 24 - 0
kernel/model/attribute_view.go

@@ -41,6 +41,30 @@ import (
 	"github.com/xrash/smetrics"
 	"github.com/xrash/smetrics"
 )
 )
 
 
+func GetAttributeViewSelectOptions(avID string, keyID string) (ret []*av.SelectOption) {
+	ret = []*av.SelectOption{}
+
+	attrView, err := av.ParseAttributeView(avID)
+	if nil != err {
+		logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
+		return
+	}
+
+	key, _ := attrView.GetKey(keyID)
+	if nil == key {
+		return
+	}
+
+	if av.KeyTypeSelect != key.Type && av.KeyTypeMSelect != key.Type {
+		return
+	}
+
+	if 0 < len(key.Options) {
+		ret = key.Options
+	}
+	return ret
+}
+
 func SetDatabaseBlockView(blockID, viewID string) (err error) {
 func SetDatabaseBlockView(blockID, viewID string) (err error) {
 	node, tree, err := getNodeByBlockID(nil, blockID)
 	node, tree, err := getNodeByBlockID(nil, blockID)
 	if nil != err {
 	if nil != err {