Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-10-10 17:08:48 +08:00
commit 97724993a4
6 changed files with 71 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -66,6 +66,28 @@ func getHeadingChildrenDOM(c *gin.Context) {
ret.Data = dom
}
func getHeadingDeleteTransaction(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)
transaction, err := model.GetHeadingDeleteTransaction(id)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()
ret.Data = map[string]interface{}{"closeTimeout": 7000}
return
}
ret.Data = transaction
}
func getHeadingLevelTransaction(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -148,6 +148,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/block/deleteBlock", model.CheckAuth, deleteBlock)
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, setBlockReminder)
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction)
ginServer.Handle("POST", "/api/block/getHeadingChildrenDOM", model.CheckAuth, getHeadingChildrenDOM)
ginServer.Handle("POST", "/api/block/swapBlockRef", model.CheckAuth, swapBlockRef)

View file

@ -6,7 +6,7 @@ require (
github.com/88250/clipboard v0.1.5
github.com/88250/css v0.1.2
github.com/88250/gulu v1.2.3-0.20221007162906-ded80d955178
github.com/88250/lute v1.7.5-0.20221009142747-5ce252ca53b5
github.com/88250/lute v1.7.5-0.20221010035631-282b765b5a5d
github.com/88250/pdfcpu v0.3.13
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ConradIrwin/font v0.0.0-20210318200717-ce8d41cc0732

View file

@ -17,12 +17,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20221007162906-ded80d955178 h1:+Mvo3MW8qYoXNhLx3bDBmEimPGdemLT87kyxq4cW7tE=
github.com/88250/gulu v1.2.3-0.20221007162906-ded80d955178/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
github.com/88250/lute v1.7.5-0.20221008160844-7c08042d00c2 h1:5+MyUHPJJG8lBF5Dlc3N+VNGLhnYs86Dr6OB9uWZ9B8=
github.com/88250/lute v1.7.5-0.20221008160844-7c08042d00c2/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221009114359-9f634b044e42 h1:zEQrrv4Og3jVEfGARW98LJD2Jv2TD3iAH04pGhmHX0c=
github.com/88250/lute v1.7.5-0.20221009114359-9f634b044e42/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221009142747-5ce252ca53b5 h1:nWiD6AuZh6bZwMLezEtPn1ppGSmIIx4Z+hZ7Ly5xiME=
github.com/88250/lute v1.7.5-0.20221009142747-5ce252ca53b5/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/lute v1.7.5-0.20221010035631-282b765b5a5d h1:PqBjpCgoy/G2ILM1lbLdtWMV9zq0mmZKpfeaFcG0lfo=
github.com/88250/lute v1.7.5-0.20221010035631-282b765b5a5d/go.mod h1:cEoBGi0zArPqAsp0MdG9SKinvH/xxZZWXU7sRx8vHSA=
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=
github.com/88250/pdfcpu v0.3.13/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -209,6 +209,49 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
return
}
func GetHeadingDeleteTransaction(id string) (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
}
var nodes []*ast.Node
nodes = append(nodes, node)
nodes = append(nodes, treenode.HeadingChildren(node)...)
transaction = &Transaction{}
luteEngine := NewLute()
for _, n := range nodes {
op := &Operation{}
op.ID = n.ID
op.Action = "delete"
transaction.DoOperations = append(transaction.DoOperations, op)
op = &Operation{}
op.ID = n.ID
if nil != n.Parent {
op.ParentID = n.Parent.ID
}
if nil != n.Parent {
op.PreviousID = n.Previous.ID
}
op.Action = "insert"
op.Data = lute.RenderNodeBlockDOM(n, luteEngine.ParseOptions, luteEngine.RenderOptions)
transaction.UndoOperations = append(transaction.UndoOperations, op)
}
return
}
func GetHeadingChildrenDOM(id string) (ret string) {
tree, err := loadTreeByBlockID(id)
if nil != err {