mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 19:59:08 +08:00
🎨 闪卡
菜单加入管理子项 https://github.com/siyuan-note/siyuan/issues/7503
This commit is contained in:
parent
b57010d449
commit
880ed3d6f9
@ -27,6 +27,25 @@ import (
|
|||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getNotebookRiffCards(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
arg, ok := util.JsonArg(c, ret)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
notebookID := arg["id"].(string)
|
||||||
|
page := int(arg["page"].(float64))
|
||||||
|
blockIDs, total, pageCount := model.GetNotebookFlashcards(notebookID, page)
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"blocks": blockIDs,
|
||||||
|
"total": total,
|
||||||
|
"pageCount": pageCount,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getTreeRiffCards(c *gin.Context) {
|
func getTreeRiffCards(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
@ -316,6 +316,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||||||
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/riff/getTreeRiffCards", model.CheckAuth, getTreeRiffCards)
|
||||||
|
ginServer.Handle("POST", "/api/riff/getNotebookRiffCards", model.CheckAuth, getNotebookRiffCards)
|
||||||
|
|
||||||
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,55 @@ import (
|
|||||||
var Decks = map[string]*riff.Deck{}
|
var Decks = map[string]*riff.Deck{}
|
||||||
var deckLock = sync.Mutex{}
|
var deckLock = sync.Mutex{}
|
||||||
|
|
||||||
|
func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
|
blocks = []*Block{}
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("read dir failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var rootIDs []string
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasSuffix(entry.Name(), ".sy") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
rootIDs = append(rootIDs, strings.TrimSuffix(entry.Name(), ".sy"))
|
||||||
|
}
|
||||||
|
|
||||||
|
treeBlockIDs := map[string]bool{}
|
||||||
|
for _, rootID := range rootIDs {
|
||||||
|
blockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||||
|
for blockID, _ := range blockIDs {
|
||||||
|
treeBlockIDs[blockID] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deck := Decks[builtinDeckID]
|
||||||
|
if nil == deck {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var allBlockIDs []string
|
||||||
|
deckBlockIDs := deck.GetBlockIDs()
|
||||||
|
for _, blockID := range deckBlockIDs {
|
||||||
|
if treeBlockIDs[blockID] {
|
||||||
|
allBlockIDs = append(allBlockIDs, blockID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allBlockIDs = gulu.Str.RemoveDuplicatedElem(allBlockIDs)
|
||||||
|
cards := deck.GetCardsByBlockIDs(allBlockIDs)
|
||||||
|
|
||||||
|
blocks, total, pageCount = getCardsBlocks(cards, page)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {
|
func GetTreeFlashcards(rootID string, page int) (blocks []*Block, total, pageCount int) {
|
||||||
blocks = []*Block{}
|
blocks = []*Block{}
|
||||||
deck := Decks[builtinDeckID]
|
deck := Decks[builtinDeckID]
|
||||||
@ -263,7 +312,6 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {
|
|||||||
|
|
||||||
deck := Decks[builtinDeckID]
|
deck := Decks[builtinDeckID]
|
||||||
if nil == deck {
|
if nil == deck {
|
||||||
logging.LogWarnf("builtin deck not found")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user