🎨 Spaced repetition interface supports review by document selection https://github.com/siyuan-note/siyuan/issues/7954
This commit is contained in:
parent
6fc15a3b6a
commit
0ebdd49f8a
2 changed files with 59 additions and 8 deletions
|
@ -27,6 +27,16 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func getRiffCardNotebooks(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
notebooks := model.GetFlashcardNotebooks()
|
||||
ret.Data = map[string]interface{}{
|
||||
"notebooks": notebooks,
|
||||
}
|
||||
}
|
||||
|
||||
func getNotebookRiffCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -38,8 +38,53 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
var Decks = map[string]*riff.Deck{}
|
||||
var deckLock = sync.Mutex{}
|
||||
func GetFlashcardNotebooks() (ret []*Box) {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
deckBlockIDs := deck.GetBlockIDs()
|
||||
|
||||
boxes := Conf.GetOpenedBoxes()
|
||||
for _, box := range boxes {
|
||||
if isNotebookContainFlashcard(box.ID, deckBlockIDs) {
|
||||
ret = append(ret, box)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func isNotebookContainFlashcard(boxID string, deckBlockIDs []string) (ret bool) {
|
||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
||||
if nil != err {
|
||||
logging.LogErrorf("read dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(entry.Name(), ".sy") {
|
||||
continue
|
||||
}
|
||||
|
||||
rootID := strings.TrimSuffix(entry.Name(), ".sy")
|
||||
blockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
for _, blockID := range deckBlockIDs {
|
||||
if gulu.Str.Contains(blockID, blockIDs) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
Decks = map[string]*riff.Deck{}
|
||||
deckLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, pageCount int) {
|
||||
blocks = []*Block{}
|
||||
|
@ -66,9 +111,7 @@ func GetNotebookFlashcards(boxID string, page int) (blocks []*Block, total, page
|
|||
var treeBlockIDs []string
|
||||
for _, rootID := range rootIDs {
|
||||
blockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
for _, blockID := range blockIDs {
|
||||
treeBlockIDs = append(treeBlockIDs, blockID)
|
||||
}
|
||||
treeBlockIDs = append(treeBlockIDs, blockIDs...)
|
||||
}
|
||||
treeBlockIDs = gulu.Str.RemoveDuplicatedElem(treeBlockIDs)
|
||||
|
||||
|
@ -307,9 +350,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
|||
var treeBlockIDs []string
|
||||
for _, rootID := range rootIDs {
|
||||
blockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
for _, blockID := range blockIDs {
|
||||
treeBlockIDs = append(treeBlockIDs, blockID)
|
||||
}
|
||||
treeBlockIDs = append(treeBlockIDs, blockIDs...)
|
||||
}
|
||||
treeBlockIDs = gulu.Str.RemoveDuplicatedElem(treeBlockIDs)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue