mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-02-28 05:32:52 +00:00
🎨 Add some database related internal kernel APIs https://github.com/siyuan-note/siyuan/issues/10201
This commit is contained in:
@@ -26,6 +26,61 @@ import (
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func addAttributeViewValues(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, _ := util.JsonArg(c, ret)
|
||||
if nil == arg {
|
||||
return
|
||||
}
|
||||
|
||||
avID := arg["avID"].(string)
|
||||
var srcIDs []string
|
||||
for _, v := range arg["srcIDs"].([]interface{}) {
|
||||
srcIDs = append(srcIDs, v.(string))
|
||||
}
|
||||
var previousID string
|
||||
if nil != arg["previousID"] {
|
||||
previousID = arg["previousID"].(string)
|
||||
}
|
||||
isDetached := arg["isDetached"].(bool)
|
||||
|
||||
err := model.AddAttributeViewBlock(nil, srcIDs, avID, previousID, isDetached)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func removeAttributeViewValues(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, _ := util.JsonArg(c, ret)
|
||||
if nil == arg {
|
||||
return
|
||||
}
|
||||
|
||||
avID := arg["avID"].(string)
|
||||
var srcIDs []string
|
||||
for _, v := range arg["srcIDs"].([]interface{}) {
|
||||
srcIDs = append(srcIDs, v.(string))
|
||||
}
|
||||
|
||||
err := model.RemoveAttributeViewBlock(srcIDs, avID)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func addAttributeViewCol(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
@@ -48,6 +103,8 @@ func addAttributeViewCol(c *gin.Context) {
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func removeAttributeViewCol(c *gin.Context) {
|
||||
@@ -68,6 +125,8 @@ func removeAttributeViewCol(c *gin.Context) {
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func sortAttributeViewCol(c *gin.Context) {
|
||||
@@ -89,6 +148,8 @@ func sortAttributeViewCol(c *gin.Context) {
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func getAttributeViewFilterSort(c *gin.Context) {
|
||||
@@ -357,6 +418,11 @@ func setAttributeViewBlockAttr(c *gin.Context) {
|
||||
cellID := arg["cellID"].(string)
|
||||
value := arg["value"].(interface{})
|
||||
blockAttributeViewKeys := model.UpdateAttributeViewCell(nil, avID, keyID, rowID, cellID, value)
|
||||
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
|
||||
ret.Data = blockAttributeViewKeys
|
||||
|
||||
pushRefreshAttrView(avID)
|
||||
}
|
||||
|
||||
func pushRefreshAttrView(avID string) {
|
||||
util.BroadcastByType("protyle", "refreshAttributeView", 0, "", map[string]interface{}{"id": avID})
|
||||
}
|
||||
|
||||
@@ -401,6 +401,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("POST", "/api/av/addAttributeViewKey", model.CheckAuth, model.CheckReadonly, addAttributeViewCol)
|
||||
ginServer.Handle("POST", "/api/av/removeAttributeViewKey", model.CheckAuth, model.CheckReadonly, removeAttributeViewCol)
|
||||
ginServer.Handle("POST", "/api/av/sortAttributeViewKey", model.CheckAuth, model.CheckReadonly, sortAttributeViewCol)
|
||||
ginServer.Handle("POST", "/api/av/addAttributeViewValues", model.CheckAuth, model.CheckReadonly, addAttributeViewValues)
|
||||
ginServer.Handle("POST", "/api/av/removeAttributeViewValues", model.CheckAuth, model.CheckReadonly, removeAttributeViewValues)
|
||||
|
||||
ginServer.Handle("POST", "/api/ai/chatGPT", model.CheckAuth, chatGPT)
|
||||
ginServer.Handle("POST", "/api/ai/chatGPTWithAction", model.CheckAuth, chatGPTWithAction)
|
||||
|
||||
Reference in New Issue
Block a user