mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Show count in spaced repetition tree filter floating window https://github.com/siyuan-note/siyuan/issues/8202
This commit is contained in:
parent
ba5449a0b4
commit
2678dfc827
2 changed files with 34 additions and 18 deletions
|
|
@ -76,27 +76,20 @@ func countTreeFlashcard(rootID string, deck *riff.Deck, deckBlockIDs []string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func countBoxFlashcard(boxID string, deck *riff.Deck, deckBlockIDs []string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
func countBoxFlashcard(boxID string, deck *riff.Deck, deckBlockIDs []string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
||||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
blockIDs := getBoxBlocks(boxID)
|
||||||
if nil != err {
|
for _, blockID := range deckBlockIDs {
|
||||||
logging.LogErrorf("read dir failed: %s", err)
|
if gulu.Str.Contains(blockID, blockIDs) {
|
||||||
|
flashcardCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if 1 > flashcardCount {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range entries {
|
newFlashCards := deck.GetNewCardsByBlockIDs(blockIDs)
|
||||||
if entry.IsDir() {
|
newFlashcardCount = len(newFlashCards)
|
||||||
continue
|
newDueFlashcards := deck.GetDueCardsByBlockIDs(blockIDs)
|
||||||
}
|
dueFlashcardCount = len(newDueFlashcards)
|
||||||
|
|
||||||
if !strings.HasSuffix(entry.Name(), ".sy") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
rootID := strings.TrimSuffix(entry.Name(), ".sy")
|
|
||||||
treeNewFlashcardCount, treeDueFlashcardCount, treeFlashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
|
|
||||||
flashcardCount += treeFlashcardCount
|
|
||||||
newFlashcardCount += treeNewFlashcardCount
|
|
||||||
dueFlashcardCount += treeDueFlashcardCount
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -421,6 +414,14 @@ func getTreeSubTreeChildBlocks(rootID string) (treeBlockIDs []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBoxBlocks(boxID string) (blockIDs []string) {
|
||||||
|
bts := treenode.GetBlockTreesByBoxID(boxID)
|
||||||
|
for _, bt := range bts {
|
||||||
|
blockIDs = append(blockIDs, bt.ID)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int, err error) {
|
func GetDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard, unreviewedCount int, err error) {
|
||||||
deckLock.Lock()
|
deckLock.Lock()
|
||||||
defer deckLock.Unlock()
|
defer deckLock.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,21 @@ func RemoveBlockTreesByPathPrefix(pathPrefix string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBlockTreesByBoxID(boxID string) (ret []*BlockTree) {
|
||||||
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
|
slice := value.(*btSlice)
|
||||||
|
slice.m.Lock()
|
||||||
|
for _, b := range slice.data {
|
||||||
|
if b.BoxID == boxID {
|
||||||
|
ret = append(ret, b)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slice.m.Unlock()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func RemoveBlockTreesByBoxID(boxID string) (ids []string) {
|
func RemoveBlockTreesByBoxID(boxID string) (ids []string) {
|
||||||
blockTrees.Range(func(key, value interface{}) bool {
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
slice := value.(*btSlice)
|
slice := value.(*btSlice)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue