mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-18 18:10:43 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
cf8b9a534a
@ -31,6 +31,29 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getHeadingLevelTransaction(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)
|
||||||
|
level := int(arg["level"].(float64))
|
||||||
|
|
||||||
|
transaction, err := model.GetHeadingLevelTransaction(id, level)
|
||||||
|
if nil != err {
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Data = transaction
|
||||||
|
}
|
||||||
|
|
||||||
func setBlockReminder(c *gin.Context) {
|
func setBlockReminder(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
@ -147,6 +147,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, updateBlock)
|
ginServer.Handle("POST", "/api/block/updateBlock", model.CheckAuth, updateBlock)
|
||||||
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, deleteBlock)
|
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, deleteBlock)
|
||||||
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, setBlockReminder)
|
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, setBlockReminder)
|
||||||
|
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
|
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
|
||||||
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, putFile)
|
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, putFile)
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/88250/lute"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/html"
|
"github.com/88250/lute/html"
|
||||||
"github.com/88250/lute/lex"
|
"github.com/88250/lute/lex"
|
||||||
@ -32,6 +33,62 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetHeadingLevelTransaction(id string, level int) (transaction *Transaction, err error) {
|
||||||
|
tree, err := loadTreeByBlockID(id)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
node := treenode.GetNodeInTree(tree, id)
|
||||||
|
if nil == node {
|
||||||
|
err = errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ast.NodeHeading != node.Type {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hLevel := node.HeadingLevel
|
||||||
|
if hLevel == level {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := level - hLevel
|
||||||
|
var children, childrenHeadings []*ast.Node
|
||||||
|
children = append(children, node)
|
||||||
|
children = append(children, treenode.HeadingChildren(node)...)
|
||||||
|
for _, c := range children {
|
||||||
|
if ast.NodeHeading == c.Type {
|
||||||
|
childrenHeadings = append(childrenHeadings, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction = &Transaction{}
|
||||||
|
luteEngine := NewLute()
|
||||||
|
for _, c := range childrenHeadings {
|
||||||
|
op := &Operation{}
|
||||||
|
op.ID = c.ID
|
||||||
|
op.Action = "update"
|
||||||
|
op.Data = lute.RenderNodeBlockDOM(c, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||||
|
transaction.UndoOperations = append(transaction.UndoOperations, op)
|
||||||
|
|
||||||
|
c.HeadingLevel += diff
|
||||||
|
if 6 < c.HeadingLevel {
|
||||||
|
c.HeadingLevel = 6
|
||||||
|
} else if 1 > c.HeadingLevel {
|
||||||
|
c.HeadingLevel = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
op = &Operation{}
|
||||||
|
op.ID = c.ID
|
||||||
|
op.Action = "update"
|
||||||
|
op.Data = lute.RenderNodeBlockDOM(c, luteEngine.ParseOptions, luteEngine.RenderOptions)
|
||||||
|
transaction.DoOperations = append(transaction.DoOperations, op)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func SetBlockReminder(id string, timed string) (err error) {
|
func SetBlockReminder(id string, timed string) (err error) {
|
||||||
if !IsSubscriber() {
|
if !IsSubscriber() {
|
||||||
if "ios" == util.Container {
|
if "ios" == util.Container {
|
||||||
|
Loading…
Reference in New Issue
Block a user