mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 When the current spaced repetition is completed, supports choose whether to continue https://github.com/siyuan-note/siyuan/issues/7943
This commit is contained in:
parent
71369fd71d
commit
fc8a4c8466
2 changed files with 49 additions and 23 deletions
|
|
@ -135,14 +135,17 @@ func getNotebookRiffDueCards(c *gin.Context) {
|
|||
|
||||
notebookID := arg["notebook"].(string)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
|
||||
cards, unreviewedCount, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = cards
|
||||
ret.Data = map[string]interface{}{
|
||||
"cards": cards,
|
||||
"unreviewedCount": unreviewedCount,
|
||||
}
|
||||
}
|
||||
|
||||
func getTreeRiffDueCards(c *gin.Context) {
|
||||
|
|
@ -156,14 +159,17 @@ func getTreeRiffDueCards(c *gin.Context) {
|
|||
|
||||
rootID := arg["rootID"].(string)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
|
||||
cards, unreviewedCount, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = cards
|
||||
ret.Data = map[string]interface{}{
|
||||
"cards": cards,
|
||||
"unreviewedCount": unreviewedCount,
|
||||
}
|
||||
}
|
||||
|
||||
func getRiffDueCards(c *gin.Context) {
|
||||
|
|
@ -177,14 +183,17 @@ func getRiffDueCards(c *gin.Context) {
|
|||
|
||||
deckID := arg["deckID"].(string)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
|
||||
cards, unreviewedCount, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = cards
|
||||
ret.Data = map[string]interface{}{
|
||||
"cards": cards,
|
||||
"unreviewedCount": unreviewedCount,
|
||||
}
|
||||
}
|
||||
|
||||
func getReviewedCards(arg map[string]interface{}) (ret []string) {
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs
|
|||
return
|
||||
}
|
||||
|
||||
dueCards := getDueFlashcards(deckID, reviewedCardIDs)
|
||||
dueCards, _ := getDueFlashcards(deckID, reviewedCardIDs)
|
||||
if 1 > len(dueCards) {
|
||||
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
|
||||
reviewCardCache = map[string]riff.Card{}
|
||||
|
|
@ -277,7 +277,7 @@ func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashc
|
|||
}
|
||||
}
|
||||
|
||||
func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
|
|
@ -320,7 +320,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
|||
return
|
||||
}
|
||||
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||
cards, unreviewdCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
|
|
@ -329,10 +329,11 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
|||
if 1 > len(ret) {
|
||||
ret = []*Flashcard{}
|
||||
}
|
||||
unreviewedCount = unreviewdCnt
|
||||
return
|
||||
}
|
||||
|
||||
func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
|
|
@ -347,7 +348,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
|
|||
}
|
||||
|
||||
treeBlockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
|
|
@ -356,6 +357,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
|
|||
if 1 > len(ret) {
|
||||
ret = []*Flashcard{}
|
||||
}
|
||||
unreviewedCount = unreviewedCnt
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +397,7 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
|
|
@ -405,22 +407,22 @@ func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard
|
|||
}
|
||||
|
||||
if "" == deckID {
|
||||
ret = getAllDueFlashcards(reviewedCardIDs)
|
||||
ret, unreviewedCount = getAllDueFlashcards(reviewedCardIDs)
|
||||
return
|
||||
}
|
||||
|
||||
ret = getDueFlashcards(deckID, reviewedCardIDs)
|
||||
ret, unreviewedCount = getDueFlashcards(deckID, reviewedCardIDs)
|
||||
return
|
||||
}
|
||||
|
||||
func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard) {
|
||||
func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int) {
|
||||
deck := Decks[deckID]
|
||||
if nil == deck {
|
||||
logging.LogWarnf("deck not found [%s]", deckID)
|
||||
return
|
||||
}
|
||||
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
|
|
@ -434,13 +436,14 @@ func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard
|
|||
if 1 > len(ret) {
|
||||
ret = []*Flashcard{}
|
||||
}
|
||||
unreviewedCount = unreviewedCnt
|
||||
return
|
||||
}
|
||||
|
||||
func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard) {
|
||||
func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int) {
|
||||
now := time.Now()
|
||||
for _, deck := range Decks {
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
if nil == treenode.GetBlockTree(blockID) {
|
||||
|
|
@ -448,6 +451,7 @@ func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard) {
|
|||
}
|
||||
|
||||
ret = append(ret, newFlashcard(card, blockID, deck.ID, now))
|
||||
unreviewedCount += unreviewedCnt
|
||||
}
|
||||
}
|
||||
if 1 > len(ret) {
|
||||
|
|
@ -817,10 +821,27 @@ func getDeckIDs() (deckIDs []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string) (ret []riff.Card) {
|
||||
func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string) (ret []riff.Card, unreviewedCount int) {
|
||||
ret = []riff.Card{}
|
||||
dues := deck.Dues()
|
||||
|
||||
var tmp []riff.Card
|
||||
for _, c := range dues {
|
||||
if 0 < len(blockIDs) && !gulu.Str.Contains(c.BlockID(), blockIDs) {
|
||||
continue
|
||||
}
|
||||
tmp = append(tmp, c)
|
||||
|
||||
if 0 < len(reviewedCardIDs) {
|
||||
if !gulu.Str.Contains(c.ID(), reviewedCardIDs) {
|
||||
unreviewedCount++
|
||||
}
|
||||
} else {
|
||||
unreviewedCount++
|
||||
}
|
||||
}
|
||||
dues = tmp
|
||||
|
||||
newCount := 0
|
||||
reviewCount := 0
|
||||
for _, c := range dues {
|
||||
|
|
@ -828,10 +849,6 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string) (ret [
|
|||
continue
|
||||
}
|
||||
|
||||
if 0 < len(blockIDs) && !gulu.Str.Contains(c.BlockID(), blockIDs) {
|
||||
continue
|
||||
}
|
||||
|
||||
fsrsCard := c.Impl().(*fsrs.Card)
|
||||
if fsrs.New == fsrsCard.State {
|
||||
newCount++
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue