🎨 书签面板添加 删除
按钮用于删除书签组 https://github.com/siyuan-note/siyuan/issues/5155
This commit is contained in:
parent
72225ff73c
commit
34be74d74f
3 changed files with 65 additions and 0 deletions
|
@ -32,6 +32,24 @@ func getBookmark(c *gin.Context) {
|
|||
ret.Data = model.BuildBookmark()
|
||||
}
|
||||
|
||||
func removeBookmark(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
bookmark := arg["bookmark"].(string)
|
||||
if err := model.RemoveBookmark(bookmark); nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func renameBookmark(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -103,6 +103,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/outline/getDocOutline", model.CheckAuth, getDocOutline)
|
||||
ginServer.Handle("POST", "/api/bookmark/getBookmark", model.CheckAuth, getBookmark)
|
||||
ginServer.Handle("POST", "/api/bookmark/renameBookmark", model.CheckAuth, renameBookmark)
|
||||
ginServer.Handle("POST", "/api/bookmark/removeBookmark", model.CheckAuth, removeBookmark)
|
||||
ginServer.Handle("POST", "/api/tag/getTag", model.CheckAuth, getTag)
|
||||
ginServer.Handle("POST", "/api/tag/renameTag", model.CheckAuth, renameTag)
|
||||
ginServer.Handle("POST", "/api/tag/removeTag", model.CheckAuth, removeTag)
|
||||
|
|
|
@ -27,6 +27,52 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func RemoveBookmark(bookmark string) (err error) {
|
||||
util.PushEndlessProgress(Conf.Language(116))
|
||||
|
||||
bookmarks := sql.QueryBookmarkBlocksByKeyword(bookmark)
|
||||
treeBlocks := map[string][]string{}
|
||||
for _, tag := range bookmarks {
|
||||
if blocks, ok := treeBlocks[tag.RootID]; !ok {
|
||||
treeBlocks[tag.RootID] = []string{tag.ID}
|
||||
} else {
|
||||
treeBlocks[tag.RootID] = append(blocks, tag.ID)
|
||||
}
|
||||
}
|
||||
|
||||
for treeID, blocks := range treeBlocks {
|
||||
util.PushEndlessProgress("[" + treeID + "]")
|
||||
tree, e := loadTreeByBlockID(treeID)
|
||||
if nil != e {
|
||||
util.PushClearProgress()
|
||||
return e
|
||||
}
|
||||
|
||||
for _, blockID := range blocks {
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
continue
|
||||
}
|
||||
|
||||
if bookmarkAttrVal := node.IALAttr("bookmark"); bookmarkAttrVal == bookmark {
|
||||
node.RemoveIALAttr("bookmark")
|
||||
}
|
||||
}
|
||||
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), tree.Root.IALAttr("title")))
|
||||
if err = writeJSONQueue(tree); nil != err {
|
||||
util.ClearPushProgress(100)
|
||||
return
|
||||
}
|
||||
util.RandomSleep(50, 150)
|
||||
}
|
||||
|
||||
util.PushEndlessProgress(Conf.Language(113))
|
||||
sql.WaitForWritingDatabase()
|
||||
util.ReloadUI()
|
||||
return
|
||||
}
|
||||
|
||||
func RenameBookmark(oldBookmark, newBookmark string) (err error) {
|
||||
if treenode.ContainsMarker(newBookmark) {
|
||||
return errors.New(Conf.Language(112))
|
||||
|
|
Loading…
Add table
Reference in a new issue