mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
🎨 支持基于文档复习闪卡 https://github.com/siyuan-note/siyuan/issues/7057
This commit is contained in:
parent
83777a14ed
commit
7dd6d1654d
3 changed files with 92 additions and 0 deletions
|
|
@ -27,6 +27,25 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getTreeRiffCards(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rootID := arg["rootID"].(string)
|
||||||
|
page := int(arg["page"].(float64))
|
||||||
|
blockIDs, total, pageCount := model.GetTreeFlashcards(rootID, page)
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"blocks": blockIDs,
|
||||||
|
"total": total,
|
||||||
|
"pageCount": pageCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getRiffCards(c *gin.Context) {
|
func getRiffCards(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -314,6 +314,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/riff/getTreeRiffDueCards", model.CheckAuth, getTreeRiffDueCards)
|
ginServer.Handle("POST", "/api/riff/getTreeRiffDueCards", model.CheckAuth, getTreeRiffDueCards)
|
||||||
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
ginServer.Handle("POST", "/api/riff/reviewRiffCard", model.CheckAuth, reviewRiffCard)
|
||||||
ginServer.Handle("POST", "/api/riff/getRiffCards", model.CheckAuth, getRiffCards)
|
ginServer.Handle("POST", "/api/riff/getRiffCards", model.CheckAuth, getRiffCards)
|
||||||
|
ginServer.Handle("POST", "/api/riff/getTreeRiffCards", model.CheckAuth, getTreeRiffCards)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
ginServer.Handle("POST", "/api/notification/pushMsg", model.CheckAuth, pushMsg)
|
||||||
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
ginServer.Handle("POST", "/api/notification/pushErrMsg", model.CheckAuth, pushErrMsg)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,76 @@ import (
|
||||||
var Decks = map[string]*riff.Deck{}
|
var Decks = map[string]*riff.Deck{}
|
||||||
var deckLock = sync.Mutex{}
|
var deckLock = sync.Mutex{}
|
||||||
|
|
||||||
|
func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
|
blocks = []*Block{}
|
||||||
|
|
||||||
|
tree, err := loadTreeByBlockID(rootID)
|
||||||
|
if nil != err {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
treeBlockIDs := map[string]bool{}
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering || !n.IsBlock() {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
treeBlockIDs[n.ID] = true
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
|
||||||
|
var allBlockIDs []string
|
||||||
|
const pageSize = 20
|
||||||
|
deck := Decks[builtinDeckID]
|
||||||
|
if nil == deck {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for bID, _ := range deck.BlockCard {
|
||||||
|
if _, ok := treeBlockIDs[bID]; !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
allBlockIDs = append(allBlockIDs, bID)
|
||||||
|
}
|
||||||
|
|
||||||
|
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
|
||||||
|
sort.Strings(allBlockIDs)
|
||||||
|
|
||||||
|
start := (page - 1) * pageSize
|
||||||
|
end := page * pageSize
|
||||||
|
if start > len(allBlockIDs) {
|
||||||
|
start = len(allBlockIDs)
|
||||||
|
}
|
||||||
|
if end > len(allBlockIDs) {
|
||||||
|
end = len(allBlockIDs)
|
||||||
|
}
|
||||||
|
blockIDs := allBlockIDs[start:end]
|
||||||
|
total = len(allBlockIDs)
|
||||||
|
pageCount = int(math.Ceil(float64(total) / float64(pageSize)))
|
||||||
|
if 1 > len(blockIDs) {
|
||||||
|
blocks = []*Block{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlBlocks := sql.GetBlocks(blockIDs)
|
||||||
|
blocks = fromSQLBlocks(&sqlBlocks, "", 36)
|
||||||
|
if 1 > len(blocks) {
|
||||||
|
blocks = []*Block{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, b := range blocks {
|
||||||
|
if nil == b {
|
||||||
|
blocks[i] = &Block{
|
||||||
|
ID: blockIDs[i],
|
||||||
|
Content: Conf.Language(180),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount int) {
|
func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
blocks = []*Block{}
|
blocks = []*Block{}
|
||||||
var allBlockIDs []string
|
var allBlockIDs []string
|
||||||
|
|
@ -62,7 +132,9 @@ func GetFlashcards(deckID string, page int) (blocks []*Block, total, pageCount i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
|
||||||
sort.Strings(allBlockIDs)
|
sort.Strings(allBlockIDs)
|
||||||
|
|
||||||
start := (page - 1) * pageSize
|
start := (page - 1) * pageSize
|
||||||
end := page * pageSize
|
end := page * pageSize
|
||||||
if start > len(allBlockIDs) {
|
if start > len(allBlockIDs) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue