mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🎨 Better display of attribute view fields in block attribute panel https://github.com/siyuan-note/siyuan/issues/8765
This commit is contained in:
parent
53c9036738
commit
14c270c238
3 changed files with 71 additions and 0 deletions
|
|
@ -62,3 +62,17 @@ func renderAttributeView(c *gin.Context) {
|
||||||
"view": view,
|
"view": view,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getAttributeViewKeys(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := arg["id"].(string)
|
||||||
|
blockAttributeViewKeys := model.GetBlockAttributeViewKeys(id)
|
||||||
|
ret.Data = blockAttributeViewKeys
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("GET", "/snippets/*filepath", serveSnippets)
|
ginServer.Handle("GET", "/snippets/*filepath", serveSnippets)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView)
|
ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView)
|
||||||
|
ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckReadonly, chatGPT)
|
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, model.CheckReadonly, chatGPT)
|
||||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckReadonly, chatGPTWithAction)
|
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, model.CheckReadonly, chatGPTWithAction)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,62 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type BlockAttributeViewKeys struct {
|
||||||
|
AvID string `json:"avID"`
|
||||||
|
AvName string `json:"avName"`
|
||||||
|
KeyValues []*av.KeyValues `json:"keyValues"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
||||||
|
waitForSyncingStorages()
|
||||||
|
|
||||||
|
ret = []*BlockAttributeViewKeys{}
|
||||||
|
attrs := GetBlockAttrs(blockID)
|
||||||
|
avs := attrs[NodeAttrNameAvs]
|
||||||
|
if "" == avs {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
avIDs := strings.Split(avs, ",")
|
||||||
|
for _, avID := range avIDs {
|
||||||
|
attrView, err := av.ParseAttributeView(avID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if 1 > len(attrView.Views) {
|
||||||
|
err = av.ErrViewNotFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var keyValues []*av.KeyValues
|
||||||
|
for _, kv := range attrView.KeyValues {
|
||||||
|
if av.KeyTypeBlock == kv.Key.Type {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
kValues := &av.KeyValues{Key: kv.Key}
|
||||||
|
for _, v := range kv.Values {
|
||||||
|
if v.BlockID == blockID {
|
||||||
|
kValues.Values = append(kValues.Values, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if 0 < len(kValues.Values) {
|
||||||
|
keyValues = append(keyValues, kValues)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = append(ret, &BlockAttributeViewKeys{
|
||||||
|
AvID: avID,
|
||||||
|
AvName: attrView.Name,
|
||||||
|
KeyValues: keyValues,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
func RenderAttributeView(avID string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||||
waitForSyncingStorages()
|
waitForSyncingStorages()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue