🎨 Show count in spaced repetition tree filter floating window https://github.com/siyuan-note/siyuan/issues/8202

This commit is contained in:
Liang Ding 2023-05-08 22:17:52 +08:00
parent c2dba92f4d
commit 883c08810e
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 48 additions and 47 deletions

View file

@ -55,6 +55,7 @@ type Box struct {
NewFlashcardCount int `json:"newFlashcardCount"` NewFlashcardCount int `json:"newFlashcardCount"`
DueFlashcardCount int `json:"dueFlashcardCount"` DueFlashcardCount int `json:"dueFlashcardCount"`
FlashcardCount int `json:"flashcardCount"`
historyGenerated int64 // 最近一次历史生成时间 historyGenerated int64 // 最近一次历史生成时间
} }

View file

@ -48,25 +48,27 @@ import (
) )
type File struct { type File struct {
Path string `json:"path"` Path string `json:"path"`
Name string `json:"name"` // 标题,即 ial["title"] Name string `json:"name"` // 标题,即 ial["title"]
Icon string `json:"icon"` Icon string `json:"icon"`
Name1 string `json:"name1"` // 命名,即 ial["name"] Name1 string `json:"name1"` // 命名,即 ial["name"]
Alias string `json:"alias"` Alias string `json:"alias"`
Memo string `json:"memo"` Memo string `json:"memo"`
Bookmark string `json:"bookmark"` Bookmark string `json:"bookmark"`
ID string `json:"id"` ID string `json:"id"`
Count int `json:"count"` Count int `json:"count"`
Size uint64 `json:"size"` Size uint64 `json:"size"`
HSize string `json:"hSize"` HSize string `json:"hSize"`
Mtime int64 `json:"mtime"` Mtime int64 `json:"mtime"`
CTime int64 `json:"ctime"` CTime int64 `json:"ctime"`
HMtime string `json:"hMtime"` HMtime string `json:"hMtime"`
HCtime string `json:"hCtime"` HCtime string `json:"hCtime"`
Sort int `json:"sort"` Sort int `json:"sort"`
SubFileCount int `json:"subFileCount"` SubFileCount int `json:"subFileCount"`
NewFlashcardCount int `json:"newFlashcardCount"`
DueFlashcardCount int `json:"dueFlashcardCount"` NewFlashcardCount int `json:"newFlashcardCount"`
DueFlashcardCount int `json:"dueFlashcardCount"`
FlashcardCount int `json:"flashcardCount"`
} }
func (box *Box) docFromFileInfo(fileInfo *FileInfo, ial map[string]string) (ret *File) { func (box *Box) docFromFileInfo(fileInfo *FileInfo, ial map[string]string) (ret *File) {
@ -164,9 +166,9 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
for _, box := range boxes { for _, box := range boxes {
if strings.Contains(box.Name, keyword) { if strings.Contains(box.Name, keyword) {
if flashcard { if flashcard {
newFlashcardCount, dueFlashcardCount, containFlashcard := countBoxFlashcard(box.ID) newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
if containFlashcard { 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)}) 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)})
} }
} else { } else {
ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
@ -185,9 +187,9 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
} else { } else {
for _, box := range boxes { for _, box := range boxes {
if flashcard { if flashcard {
newFlashcardCount, dueFlashcardCount, containFlashcard := countBoxFlashcard(box.ID) newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
if containFlashcard { 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)}) 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)})
} }
} else { } else {
ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon}) ret = append(ret, map[string]string{"path": "/", "hPath": box.Name + "/", "box": box.ID, "boxIcon": box.Icon})
@ -202,9 +204,9 @@ func SearchDocsByKeyword(keyword string, flashcard bool) (ret []map[string]strin
} }
hPath := b.Name + rootBlock.HPath hPath := b.Name + rootBlock.HPath
if flashcard { if flashcard {
newFlashcardCount, dueFlashcardCount, containFlashcard := countTreeFlashcard(rootBlock.ID) newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootBlock.ID)
if containFlashcard { 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)}) 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)})
} }
} else { } else {
ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon}) ret = append(ret, map[string]string{"path": rootBlock.Path, "hPath": hPath, "box": rootBlock.Box, "boxIcon": b.Icon})
@ -291,10 +293,11 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
if flashcard { if flashcard {
rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy") rootID := strings.TrimSuffix(filepath.Base(parentDocPath), ".sy")
newFlashcardCount, dueFlashcardCount, containFlashcard := countTreeFlashcard(rootID) newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID)
if containFlashcard { if 0 < flashcardCount {
doc.NewFlashcardCount = newFlashcardCount doc.NewFlashcardCount = newFlashcardCount
doc.DueFlashcardCount = dueFlashcardCount doc.DueFlashcardCount = dueFlashcardCount
doc.FlashcardCount = flashcardCount
docs = append(docs, doc) docs = append(docs, doc)
} }
} else { } else {
@ -314,10 +317,11 @@ func ListDocTree(boxID, path string, sortMode int, flashcard bool, maxListCount
if flashcard { if flashcard {
rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy") rootID := strings.TrimSuffix(filepath.Base(file.path), ".sy")
newFlashcardCount, dueFlashcardCount, containFlashcard := countTreeFlashcard(rootID) newFlashcardCount, dueFlashcardCount, flashcardCount := countTreeFlashcard(rootID)
if containFlashcard { if 0 < flashcardCount {
doc.NewFlashcardCount = newFlashcardCount doc.NewFlashcardCount = newFlashcardCount
doc.DueFlashcardCount = dueFlashcardCount doc.DueFlashcardCount = dueFlashcardCount
doc.FlashcardCount = flashcardCount
docs = append(docs, doc) docs = append(docs, doc)
} }
} else { } else {

View file

@ -45,17 +45,18 @@ func GetFlashcardNotebooks() (ret []*Box) {
boxes := Conf.GetOpenedBoxes() boxes := Conf.GetOpenedBoxes()
for _, box := range boxes { for _, box := range boxes {
newFlashcardCount, dueFlashcardCount, containFlashcard := countBoxFlashcard(box.ID) newFlashcardCount, dueFlashcardCount, flashcardCount := countBoxFlashcard(box.ID)
if containFlashcard { if 0 < flashcardCount {
box.NewFlashcardCount = newFlashcardCount box.NewFlashcardCount = newFlashcardCount
box.DueFlashcardCount = dueFlashcardCount box.DueFlashcardCount = dueFlashcardCount
box.FlashcardCount = flashcardCount
ret = append(ret, box) ret = append(ret, box)
} }
} }
return return
} }
func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount int, containFlashcard bool) { func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
deck := Decks[builtinDeckID] deck := Decks[builtinDeckID]
if nil == deck { if nil == deck {
return return
@ -63,14 +64,12 @@ func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount int
deckBlockIDs := deck.GetBlockIDs() deckBlockIDs := deck.GetBlockIDs()
blockIDs := getTreeSubTreeChildBlocks(rootID) blockIDs := getTreeSubTreeChildBlocks(rootID)
containFlashcard = false
for _, blockID := range deckBlockIDs { for _, blockID := range deckBlockIDs {
if gulu.Str.Contains(blockID, blockIDs) { if gulu.Str.Contains(blockID, blockIDs) {
containFlashcard = true flashcardCount++
break
} }
} }
if !containFlashcard { if 1 > flashcardCount {
return return
} }
@ -81,7 +80,7 @@ func countTreeFlashcard(rootID string) (newFlashcardCount, dueFlashcardCount int
return return
} }
func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount int, containFlashcard bool) { func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount, flashcardCount int) {
deck := Decks[builtinDeckID] deck := Decks[builtinDeckID]
if nil == deck { if nil == deck {
return return
@ -93,7 +92,6 @@ func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount int,
return return
} }
containFlashcard = false
for _, entry := range entries { for _, entry := range entries {
if entry.IsDir() { if entry.IsDir() {
continue continue
@ -104,12 +102,10 @@ func countBoxFlashcard(boxID string) (newFlashcardCount, dueFlashcardCount int,
} }
rootID := strings.TrimSuffix(entry.Name(), ".sy") rootID := strings.TrimSuffix(entry.Name(), ".sy")
treeNewFlashcardCount, treeDueFlashcardCount, treeContainFlashcard := countTreeFlashcard(rootID) treeNewFlashcardCount, treeDueFlashcardCount, treeFlashcardCount := countTreeFlashcard(rootID)
if treeContainFlashcard { flashcardCount += treeFlashcardCount
containFlashcard = true newFlashcardCount += treeNewFlashcardCount
newFlashcardCount += treeNewFlashcardCount dueFlashcardCount += treeDueFlashcardCount
dueFlashcardCount += treeDueFlashcardCount
}
} }
return return
} }