Переглянути джерело

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 2 роки тому
батько
коміт
ac24220257
3 змінених файлів з 27 додано та 9 видалено
  1. 2 1
      kernel/go.mod
  2. 2 2
      kernel/go.sum
  3. 23 6
      kernel/model/flashcard.go

+ 2 - 1
kernel/go.mod

@@ -45,7 +45,7 @@ require (
 	github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
 	github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8
 	github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a
-	github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945
+	github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b
 	github.com/steambap/captcha v1.4.1
 	github.com/studio-b12/gowebdav v0.0.0-20221109171924-60ec5ad56012
 	github.com/vmihailenco/msgpack/v5 v5.3.5
@@ -134,6 +134,7 @@ require (
 replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5
 
 //replace github.com/siyuan-note/dejavu => D:\88250\dejavu
+//replace github.com/siyuan-note/riff => D:\88250\riff
 //replace github.com/siyuan-note/httpclient => D:\88250\httpclient
 //replace github.com/siyuan-note/filelock => D:\88250\filelock
 //replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute

+ 2 - 2
kernel/go.sum

@@ -385,8 +385,8 @@ github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8 h1:cv0U38yu
 github.com/siyuan-note/httpclient v0.0.0-20221213030227-fa8d21fd9cf8/go.mod h1:aLj3LQVz2iuA3AUfkqk1UvPhqafRpthAVtjV1+ZAq+U=
 github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a h1:b9VJCE8IccYjsadwNBI11he+Wn25hI9lCma4uYoIYEM=
 github.com/siyuan-note/logging v0.0.0-20221031125421-9b7234d79d8a/go.mod h1:t1zRGxK13L/9ZFoGyTD39IbFCbee3CsypDj4b5dt4qM=
-github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945 h1:ED7QFLeOu5/PpXK1v0ax82MJrhpgPrxkq6UEhIEOnFA=
-github.com/siyuan-note/riff v0.0.0-20221223145438-041dea8f7945/go.mod h1:WnNt0JPjfXp2fjAgbF9rS5W7JC2W0YVcaVmLXIeYF8A=
+github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b h1:JDpKOdiyocNsgKFfrF3mB7UoBJz4qcHBUKBig78kVjc=
+github.com/siyuan-note/riff v0.0.0-20221228031102-17d458a1217b/go.mod h1:WnNt0JPjfXp2fjAgbF9rS5W7JC2W0YVcaVmLXIeYF8A=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v1.6.7 h1:I6tZjLXD2Q1kjvNbIzB1wvQBsXmKXiVrhpRE8ZjP5jY=

+ 23 - 6
kernel/model/flashcard.go

@@ -28,6 +28,7 @@ import (
 	"github.com/88250/lute"
 	"github.com/88250/lute/ast"
 	"github.com/88250/lute/parse"
+	"github.com/dustin/go-humanize"
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/riff"
 	"github.com/siyuan-note/siyuan/kernel/cache"
@@ -78,8 +79,9 @@ func ReviewFlashcard(deckID string, blockID string, rating riff.Rating) (err err
 }
 
 type Flashcard struct {
-	DeckID  string `json:"deckID"`
-	BlockID string `json:"blockID"`
+	DeckID   string                 `json:"deckID"`
+	BlockID  string                 `json:"blockID"`
+	NextDues map[riff.Rating]string `json:"nextDues"`
 }
 
 func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
@@ -97,15 +99,23 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
 
 	deck := Decks[deckID]
 	cards := deck.Dues()
+	now := time.Now()
 	for _, card := range cards {
 		blockID := card.BlockID()
 
 		if nil == treenode.GetBlockTree(blockID) {
 			continue
 		}
+
+		nextDues := map[riff.Rating]string{}
+		for rating, due := range card.NextDues() {
+			nextDues[rating] = strings.TrimSpace(humanize.RelTime(due, now, "", ""))
+		}
+
 		ret = append(ret, &Flashcard{
-			DeckID:  deckID,
-			BlockID: blockID,
+			DeckID:   deckID,
+			BlockID:  blockID,
+			NextDues: nextDues,
 		})
 	}
 	if 1 > len(ret) {
@@ -116,6 +126,7 @@ func GetDueFlashcards(deckID string) (ret []*Flashcard, err error) {
 
 func getAllDueFlashcards() (ret []*Flashcard, err error) {
 	blockIDs := map[string]bool{}
+	now := time.Now()
 	for _, deck := range Decks {
 		cards := deck.Dues()
 		for _, card := range cards {
@@ -128,9 +139,15 @@ func getAllDueFlashcards() (ret []*Flashcard, err error) {
 				continue
 			}
 
+			nextDues := map[riff.Rating]string{}
+			for rating, due := range card.NextDues() {
+				nextDues[rating] = strings.TrimSpace(humanize.RelTime(due, now, "", ""))
+			}
+
 			ret = append(ret, &Flashcard{
-				DeckID:  deck.ID,
-				BlockID: blockID,
+				DeckID:   deck.ID,
+				BlockID:  blockID,
+				NextDues: nextDues,
 			})
 			blockIDs[blockID] = true
 		}