mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-03 03:49:11 +08:00
🎨 闪卡支持设置复习上限 https://github.com/siyuan-note/siyuan/issues/7703
This commit is contained in:
parent
f569df8efd
commit
e6218a61b5
@ -196,7 +196,7 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||
deckID: blocks[index].deckID,
|
||||
cardID: blocks[index].cardID,
|
||||
rating: parseInt(type),
|
||||
reviewedCardIDs: blocks
|
||||
reviewedCards: blocks
|
||||
}, () => {
|
||||
/// #if MOBILE
|
||||
if (type !== "-3" &&
|
||||
@ -213,7 +213,7 @@ export const openCardByData = (cardsData: ICard[], html = "") => {
|
||||
rootID: titleElement.getAttribute("data-id"),
|
||||
deckID: selectElement?.value,
|
||||
notebook: titleElement.getAttribute("data-notebookid"),
|
||||
reviewedCardIDs: blocks
|
||||
reviewedCards: blocks
|
||||
}, (treeCards) => {
|
||||
index = 0;
|
||||
blocks = treeCards.data;
|
||||
|
@ -96,7 +96,8 @@ func reviewRiffCard(c *gin.Context) {
|
||||
deckID := arg["deckID"].(string)
|
||||
cardID := arg["cardID"].(string)
|
||||
rating := int(arg["rating"].(float64))
|
||||
err := model.ReviewFlashcard(deckID, cardID, riff.Rating(rating))
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
err := model.ReviewFlashcard(deckID, cardID, riff.Rating(rating), reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -133,7 +134,8 @@ func getNotebookRiffDueCards(c *gin.Context) {
|
||||
}
|
||||
|
||||
notebookID := arg["notebook"].(string)
|
||||
cards, err := model.GetNotebookDueFlashcards(notebookID)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetNotebookDueFlashcards(notebookID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -153,7 +155,8 @@ func getTreeRiffDueCards(c *gin.Context) {
|
||||
}
|
||||
|
||||
rootID := arg["rootID"].(string)
|
||||
cards, err := model.GetTreeDueFlashcards(rootID)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetTreeDueFlashcards(rootID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -173,7 +176,8 @@ func getRiffDueCards(c *gin.Context) {
|
||||
}
|
||||
|
||||
deckID := arg["deckID"].(string)
|
||||
cards, err := model.GetDueFlashcards(deckID)
|
||||
reviewedCardIDs := getReviewedCards(arg)
|
||||
cards, err := model.GetDueFlashcards(deckID, reviewedCardIDs)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@ -183,6 +187,20 @@ func getRiffDueCards(c *gin.Context) {
|
||||
ret.Data = cards
|
||||
}
|
||||
|
||||
func getReviewedCards(arg map[string]interface{}) (ret []string) {
|
||||
if nil == arg["reviewedCards"] {
|
||||
return
|
||||
}
|
||||
|
||||
reviewedCardsArg := arg["reviewedCards"].([]interface{})
|
||||
for _, card := range reviewedCardsArg {
|
||||
c := card.(map[string]interface{})
|
||||
cardID := c["cardID"].(string)
|
||||
ret = append(ret, cardID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func removeRiffCards(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
@ -190,7 +190,7 @@ var (
|
||||
skipCardCache = map[string]riff.Card{}
|
||||
)
|
||||
|
||||
func ReviewFlashcard(deckID, cardID string, rating riff.Rating) (err error) {
|
||||
func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs []string) (err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
@ -224,7 +224,7 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
dueCards := getDueFlashcards(deckID)
|
||||
dueCards := getDueFlashcards(deckID, reviewedCardIDs)
|
||||
if 1 > len(dueCards) {
|
||||
// 该卡包中没有待复习的卡片了,说明最后一张卡片已经复习完了,清空撤销缓存和跳过缓存
|
||||
reviewCardCache = map[string]riff.Card{}
|
||||
@ -273,7 +273,7 @@ func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashc
|
||||
}
|
||||
}
|
||||
|
||||
func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) {
|
||||
func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
@ -315,7 +315,7 @@ func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
cards := getDeckDueCards(deck)
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
@ -331,7 +331,7 @@ func GetNotebookDueFlashcards(boxID string) (ret []*Flashcard, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {
|
||||
func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
@ -346,7 +346,7 @@ func GetTreeDueFlashcards(rootID string) (ret []*Flashcard, err error) {
|
||||
}
|
||||
|
||||
treeBlockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
cards := getDeckDueCards(deck)
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
@ -400,7 +400,7 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs map[string]bool) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
|
||||
func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, err error) {
|
||||
deckLock.Lock()
|
||||
defer deckLock.Unlock()
|
||||
|
||||
@ -410,22 +410,22 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
|
||||
}
|
||||
|
||||
if "" == deckID {
|
||||
ret = getAllDueFlashcards()
|
||||
ret = getAllDueFlashcards(reviewedCardIDs)
|
||||
return
|
||||
}
|
||||
|
||||
ret = getDueFlashcards(deckID)
|
||||
ret = getDueFlashcards(deckID, reviewedCardIDs)
|
||||
return
|
||||
}
|
||||
|
||||
func getDueFlashcards(deckID string) (ret []*Flashcard) {
|
||||
func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard) {
|
||||
deck := Decks[deckID]
|
||||
if nil == deck {
|
||||
logging.LogWarnf("deck not found [%s]", deckID)
|
||||
return
|
||||
}
|
||||
|
||||
cards := getDeckDueCards(deck)
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs)
|
||||
now := time.Now()
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
@ -442,10 +442,10 @@ func getDueFlashcards(deckID string) (ret []*Flashcard) {
|
||||
return
|
||||
}
|
||||
|
||||
func getAllDueFlashcards() (ret []*Flashcard) {
|
||||
func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard) {
|
||||
now := time.Now()
|
||||
for _, deck := range Decks {
|
||||
cards := getDeckDueCards(deck)
|
||||
cards := getDeckDueCards(deck, reviewedCardIDs)
|
||||
for _, card := range cards {
|
||||
blockID := card.BlockID()
|
||||
if nil == treenode.GetBlockTree(blockID) {
|
||||
@ -894,7 +894,7 @@ func getDeckIDs() (deckIDs []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func getDeckDueCards(deck *riff.Deck) (ret []riff.Card) {
|
||||
func getDeckDueCards(deck *riff.Deck, reviewedCardIDs []string) (ret []riff.Card) {
|
||||
ret = []riff.Card{}
|
||||
dues := deck.Dues()
|
||||
|
||||
@ -918,6 +918,10 @@ func getDeckDueCards(deck *riff.Deck) (ret []riff.Card) {
|
||||
}
|
||||
}
|
||||
|
||||
if !gulu.Str.Contains(c.ID(), reviewedCardIDs) {
|
||||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, c)
|
||||
}
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user