mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 23:31:21 +08:00
🎨 Add internal kernel API /api/block/foldBlock
and /api/block/unfoldBlock
https://github.com/siyuan-note/siyuan/issues/9962
This commit is contained in:
parent
b3d51ed94f
commit
9403eef8b7
@ -29,6 +29,126 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func unfoldBlock(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)
|
||||||
|
if util.InvalidIDPattern(id, ret) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bt := treenode.GetBlockTree(id)
|
||||||
|
if nil == bt {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "block tree not found [id=" + id + "]"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if bt.Type == "d" {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "document can not be unfolded"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var transactions []*model.Transaction
|
||||||
|
if "h" == bt.Type {
|
||||||
|
transactions = []*model.Transaction{
|
||||||
|
{
|
||||||
|
DoOperations: []*model.Operation{
|
||||||
|
{
|
||||||
|
Action: "unfoldHeading",
|
||||||
|
ID: id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"unfold": "1"})
|
||||||
|
transactions = []*model.Transaction{
|
||||||
|
{
|
||||||
|
DoOperations: []*model.Operation{
|
||||||
|
{
|
||||||
|
Action: "setAttrs",
|
||||||
|
ID: id,
|
||||||
|
Data: string(data),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.PerformTransactions(&transactions)
|
||||||
|
model.WaitForWritingFiles()
|
||||||
|
|
||||||
|
broadcastTransactions(transactions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func foldBlock(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)
|
||||||
|
if util.InvalidIDPattern(id, ret) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bt := treenode.GetBlockTree(id)
|
||||||
|
if nil == bt {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "block tree not found [id=" + id + "]"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if bt.Type == "d" {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = "document can not be folded"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var transactions []*model.Transaction
|
||||||
|
if "h" == bt.Type {
|
||||||
|
transactions = []*model.Transaction{
|
||||||
|
{
|
||||||
|
DoOperations: []*model.Operation{
|
||||||
|
{
|
||||||
|
Action: "foldHeading",
|
||||||
|
ID: id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data, _ := gulu.JSON.MarshalJSON(map[string]interface{}{"fold": "1"})
|
||||||
|
transactions = []*model.Transaction{
|
||||||
|
{
|
||||||
|
DoOperations: []*model.Operation{
|
||||||
|
{
|
||||||
|
Action: "setAttrs",
|
||||||
|
ID: id,
|
||||||
|
Data: string(data),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.PerformTransactions(&transactions)
|
||||||
|
model.WaitForWritingFiles()
|
||||||
|
|
||||||
|
broadcastTransactions(transactions)
|
||||||
|
}
|
||||||
|
|
||||||
func moveBlock(c *gin.Context) {
|
func moveBlock(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
@ -181,6 +181,8 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock)
|
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, model.CheckReadonly, updateBlock)
|
||||||
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock)
|
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, model.CheckReadonly, deleteBlock)
|
||||||
ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock)
|
ginServer.Handle("POST", "/api/block/moveBlock", model.CheckAuth, model.CheckReadonly, moveBlock)
|
||||||
|
ginServer.Handle("POST", "/api/block/foldBlock", model.CheckAuth, model.CheckReadonly, foldBlock)
|
||||||
|
ginServer.Handle("POST", "/api/block/unfoldBlock", model.CheckAuth, model.CheckReadonly, unfoldBlock)
|
||||||
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, model.CheckReadonly, setBlockReminder)
|
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, model.CheckReadonly, setBlockReminder)
|
||||||
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
|
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
|
||||||
ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction)
|
ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction)
|
||||||
|
Loading…
Reference in New Issue
Block a user