🎨 Show count in spaced repetition tree filter floating window https://github.com/siyuan-note/siyuan/issues/8202
This commit is contained in:
parent
d7fcf3cbe1
commit
1c68ce46f9
2 changed files with 19 additions and 20 deletions
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/facette/natsort"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/riff"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
|
@ -148,11 +149,15 @@ func (box *Box) moveCorruptedData(filePath string) {
|
|||
func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]string) {
|
||||
ret = []map[string]string{}
|
||||
|
||||
var deck *riff.Deck
|
||||
var deckBlockIDs []string
|
||||
if flashcard {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
deckBlockIDs = deck.GetBlockIDs()
|
||||
}
|
||||
|
||||
openedBoxes := Conf.GetOpenedBoxes()
|
||||
|
@ -166,7 +171,7 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
|
|||
for _, box := range boxes {
|
||||
if strings.Contains(box.Name, keyword) {
|
||||
if flashcard {
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon, "newFlashcardCount": strconv.Itoa(newFlashcardCount), "dueFlashcardCount": strconv.Itoa(dueFlashcardCount), "flashcardCount": strconv.Itoa(flashcardCount)})
|
||||
}
|
||||
|
@ -187,7 +192,7 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
|
|||
} else {
|
||||
for _, box := range boxes {
|
||||
if flashcard {
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon, "newFlashcardCount": strconv.Itoa(newFlashcardCount), "dueFlashcardCount": strconv.Itoa(dueFlashcardCount), "flashcardCount": strconv.Itoa(flashcardCount)})
|
||||
}
|
||||
|
@ -204,7 +209,7 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
|
|||
}
|
||||
hPath := b.Name + rootBlock.HPath
|
||||
if flashcard {
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootBlock.ID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootBlock.ID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon, "newFlashcardCount": strconv.Itoa(newFlashcardCount), "dueFlashcardCount": strconv.Itoa(dueFlashcardCount), "flashcardCount": strconv.Itoa(flashcardCount)})
|
||||
}
|
||||
|
@ -234,11 +239,15 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
|
|||
|
||||
ret = []*File{}
|
||||
|
||||
var deck *riff.Deck
|
||||
var deckBlockIDs []string
|
||||
if flashcard {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
deckBlockIDs = deck.GetBlockIDs()
|
||||
}
|
||||
|
||||
box := Conf.Box(boxID)
|
||||
|
@ -293,7 +302,7 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
|
|||
|
||||
if flashcard {
|
||||
rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy")
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
doc.NewFlashcardCount = newFlashcardCount
|
||||
doc.DueFlashcardCount = dueFlashcardCount
|
||||
|
@ -317,7 +326,7 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
|
|||
|
||||
if flashcard {
|
||||
rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy")
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
doc.NewFlashcardCount = newFlashcardCount
|
||||
doc.DueFlashcardCount = dueFlashcardCount
|
||||
|
|
|
@ -43,9 +43,10 @@ func GetFlashcardNotebooks() (ret []*Box) {
|
|||
return
|
||||
}
|
||||
|
||||
deckBlockIDs := deck.GetBlockIDs()
|
||||
boxes := Conf.GetOpenedBoxes()
|
||||
for _, box := range boxes {
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
|
||||
newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID, deck, deckBlockIDs)
|
||||
if 0 < flashcardCount {
|
||||
box.NewFlashcardCount = newFlashcardCount
|
||||
box.DueFlashcardCount = dueFlashcardCount
|
||||
|
@ -56,13 +57,7 @@ func GetFlashcardNotebooks() (ret []*Box) {
|
|||
return
|
||||
}
|
||||
|
||||
func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
deckBlockIDs := deck.GetBlockIDs()
|
||||
func countTreeFlashcard(rootID string, deck *riff.Deck, deckBlockIDs []string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
||||
blockIDs := getTreeSubTreeChildBlocks(rootID)
|
||||
for _, blockID := range deckBlockIDs {
|
||||
if gulu.Str.Contains(blockID, blockIDs) {
|
||||
|
@ -80,12 +75,7 @@ func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount, fl
|
|||
return
|
||||
}
|
||||
|
||||
func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
||||
deck := Decks[builtinDeckID]
|
||||
if nil == deck {
|
||||
return
|
||||
}
|
||||
|
||||
func countBoxFlashcard(boxID string, deck *riff.Deck, deckBlockIDs []string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
|
||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
||||
if nil != err {
|
||||
logging.LogErrorf("read dir failed: %s", err)
|
||||
|
@ -102,7 +92,7 @@ func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount, flas
|
|||
}
|
||||
|
||||
rootID := strings.TrimSuffix(entry.Name(), ".sy")
|
||||
treeNewFlashcardCount, treeDueFlashcardCount, treeFlashcardCount := countTreeFlashcard(rootID)
|
||||
treeNewFlashcardCount, treeDueFlashcardCount, treeFlashcardCount := countTreeFlashcard(rootID, deck, deckBlockIDs)
|
||||
flashcardCount += treeFlashcardCount
|
||||
newFlashcardCount += treeNewFlashcardCount
|
||||
dueFlashcardCount += treeDueFlashcardCount
|
||||
|
|
Loading…
Add table
Reference in a new issue