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)
|
notebookID := arg["notebook"].(string)
|
||||||
reviewedCardIDs := getReviewedCards(arg)
|
reviewedCardIDs := getReviewedCards(arg)
|
||||||
cards, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
|
cards, unreviewedCount, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = cards
|
ret.Data = map[string]interface{}{
|
||||||
|
"cards": cards,
|
||||||
|
"unreviewedCount": unreviewedCount,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTreeRiffDueCards(c *gin.Context) {
|
func getTreeRiffDueCards(c *gin.Context) {
|
||||||
|
|
@ -156,14 +159,17 @@ func getTreeRiffDueCards(c *gin.Context) {
|
||||||
|
|
||||||
rootID := arg["rootID"].(string)
|
rootID := arg["rootID"].(string)
|
||||||
reviewedCardIDs := getReviewedCards(arg)
|
reviewedCardIDs := getReviewedCards(arg)
|
||||||
cards, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
|
cards, unreviewedCount, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = cards
|
ret.Data = map[string]interface{}{
|
||||||
|
"cards": cards,
|
||||||
|
"unreviewedCount": unreviewedCount,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRiffDueCards(c *gin.Context) {
|
func getRiffDueCards(c *gin.Context) {
|
||||||
|
|
@ -177,14 +183,17 @@ func getRiffDueCards(c *gin.Context) {
|
||||||
|
|
||||||
deckID := arg["deckID"].(string)
|
deckID := arg["deckID"].(string)
|
||||||
reviewedCardIDs := getReviewedCards(arg)
|
reviewedCardIDs := getReviewedCards(arg)
|
||||||
cards, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
|
cards, unreviewedCount, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.Data = cards
|
ret.Data = map[string]interface{}{
|
||||||
|
"cards": cards,
|
||||||
|
"unreviewedCount": unreviewedCount,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getReviewedCards(arg map[string]interface{}) (ret []string) {
|
func getReviewedCards(arg map[string]interface{}) (ret []string) {
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dueCards := getDueFlashcards(deckID, reviewedCardIDs)
|
dueCards, _ := getDueFlashcards(deckID, reviewedCardIDs)
|
||||||
if 1 > len(dueCards) {
|
if 1 > len(dueCards) {
|
||||||
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
|
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
|
||||||
reviewCardCache = map[string]riff.Card{}
|
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()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
||||||
|
|
@ -320,7 +320,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cards := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
cards, unreviewdCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
blockID := card.BlockID()
|
blockID := card.BlockID()
|
||||||
|
|
@ -329,10 +329,11 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
ret = []*Flashcard{}
|
ret = []*Flashcard{}
|
||||||
}
|
}
|
||||||
|
unreviewedCount = unreviewdCnt
|
||||||
return
|
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()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
||||||
|
|
@ -347,7 +348,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
|
||||||
}
|
}
|
||||||
|
|
||||||
treeBlockIDs := getTreeSubTreeChildBlocks(rootID)
|
treeBlockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||||
cards := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
blockID := card.BlockID()
|
blockID := card.BlockID()
|
||||||
|
|
@ -356,6 +357,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
ret = []*Flashcard{}
|
ret = []*Flashcard{}
|
||||||
}
|
}
|
||||||
|
unreviewedCount = unreviewedCnt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -395,7 +397,7 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs []string) {
|
||||||
return
|
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()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
||||||
|
|
@ -405,22 +407,22 @@ func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard
|
||||||
}
|
}
|
||||||
|
|
||||||
if "" == deckID {
|
if "" == deckID {
|
||||||
ret = getAllDueFlashcards(reviewedCardIDs)
|
ret, unreviewedCount = getAllDueFlashcards(reviewedCardIDs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = getDueFlashcards(deckID, reviewedCardIDs)
|
ret, unreviewedCount = getDueFlashcards(deckID, reviewedCardIDs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard) {
|
func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int) {
|
||||||
deck := Decks[deckID]
|
deck := Decks[deckID]
|
||||||
if nil == deck {
|
if nil == deck {
|
||||||
logging.LogWarnf("deck not found [%s]", deckID)
|
logging.LogWarnf("deck not found [%s]", deckID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cards := getDeckDueCards(deck, reviewedCardIDs, nil)
|
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
blockID := card.BlockID()
|
blockID := card.BlockID()
|
||||||
|
|
@ -434,13 +436,14 @@ func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
ret = []*Flashcard{}
|
ret = []*Flashcard{}
|
||||||
}
|
}
|
||||||
|
unreviewedCount = unreviewedCnt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard) {
|
func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for _, deck := range Decks {
|
for _, deck := range Decks {
|
||||||
cards := getDeckDueCards(deck, reviewedCardIDs, nil)
|
cards, unreviewedCnt := getDeckDueCards(deck, reviewedCardIDs, nil)
|
||||||
for _, card := range cards {
|
for _, card := range cards {
|
||||||
blockID := card.BlockID()
|
blockID := card.BlockID()
|
||||||
if nil == treenode.GetBlockTree(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))
|
ret = append(ret, newFlashcard(card, blockID, deck.ID, now))
|
||||||
|
unreviewedCount += unreviewedCnt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
|
|
@ -817,10 +821,27 @@ func getDeckIDs() (deckIDs []string) {
|
||||||
return
|
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{}
|
ret = []riff.Card{}
|
||||||
dues := deck.Dues()
|
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
|
newCount := 0
|
||||||
reviewCount := 0
|
reviewCount := 0
|
||||||
for _, c := range dues {
|
for _, c := range dues {
|
||||||
|
|
@ -828,10 +849,6 @@ func getDeckDueCards(deck *riff.Deck, reviewedCardIDs, blockIDs []string) (ret [
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 < len(blockIDs) && !gulu.Str.Contains(c.BlockID(), blockIDs) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fsrsCard := c.Impl().(*fsrs.Card)
|
fsrsCard := c.Impl().(*fsrs.Card)
|
||||||
if fsrs.New == fsrsCard.State {
|
if fsrs.New == fsrsCard.State {
|
||||||
newCount++
|
newCount++
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue