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

This commit is contained in:
Vanessa 2024-03-09 11:08:21 +08:00
commit 8b1f42acea
3 changed files with 52 additions and 12 deletions

View file

@ -433,7 +433,22 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
}
}
}
// 再处理模板列
// 获取闪卡信息
// TODO 目前看来使用场景不多,暂时不实现了 https://github.com/siyuan-note/siyuan/issues/10502#issuecomment-1986703280
var flashcard *Flashcard
//deck := Decks[builtinDeckID]
//if nil != deck {
// blockIDs := []string{blockID}
// cards := deck.GetCardsByBlockIDs(blockIDs)
// now := time.Now()
// if 0 < len(cards) {
// flashcard = newFlashcard(cards[0], builtinDeckID, now)
// }
//}
// 渲染模板
for _, kv := range keyValues {
switch kv.Key.Type {
case av.KeyTypeTemplate:
@ -441,9 +456,10 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
ial := map[string]string{}
block := getRowBlockValue(keyValues)
if nil != block && !block.IsDetached {
ial = GetBlockAttrsWithoutWaitWriting(blockID)
ial = GetBlockAttrsWithoutWaitWriting(block.ID)
}
kv.Values[0].Template.Content = renderTemplateCol(ial, kv.Key.Template, keyValues)
kv.Values[0].Template.Content = renderTemplateCol(ial, flashcard, keyValues, kv.Key.Template)
}
}
}
@ -798,7 +814,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID string, page, pageSi
return
}
func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
func renderTemplateCol(ial map[string]string, flashcard *Flashcard, rowValues []*av.KeyValues, tplContent string) string {
if "" == ial["id"] {
block := getRowBlockValue(rowValues)
if nil != block && nil != block.Block {
@ -847,6 +863,11 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
dataModel["updated"] = time.Now()
}
}
if nil != flashcard {
dataModel["flashcard"] = flashcard
}
for _, rowValue := range rowValues {
if 0 < len(rowValue.Values) {
v := rowValue.Values[0]
@ -859,6 +880,7 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
}
}
}
if err := tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
}
@ -1113,6 +1135,22 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
// 最后单独渲染模板列,这样模板列就可以使用汇总、关联、创建时间和更新时间列的值了
// Database table view template columns support reading relation, rollup, created and updated columns https://github.com/siyuan-note/siyuan/issues/10442
// 获取闪卡信息
flashcards := map[string]*Flashcard{}
deck := Decks[builtinDeckID]
if nil != deck {
var blockIDs []string
for _, row := range ret.Rows {
blockIDs = append(blockIDs, row.ID)
}
cards := deck.GetCardsByBlockIDs(blockIDs)
now := time.Now()
for _, card := range cards {
flashcards[card.BlockID()] = newFlashcard(card, builtinDeckID, now)
}
}
for _, row := range ret.Rows {
for _, cell := range row.Cells {
switch cell.ValueType {
@ -1123,7 +1161,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
if nil != block && !block.IsDetached {
ial = GetBlockAttrsWithoutWaitWriting(row.ID)
}
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
content := renderTemplateCol(ial, flashcards[row.ID], keyValues, cell.Value.Template.Content)
cell.Value.Template.Content = content
}
}

View file

@ -513,7 +513,7 @@ type Flashcard struct {
NextDues map[riff.Rating]string `json:"nextDues"`
}
func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashcard {
func newFlashcard(card riff.Card, deckID string, now time.Time) *Flashcard {
nextDues := map[riff.Rating]string{}
for rating, due := range card.NextDues() {
nextDues[rating] = strings.TrimSpace(util.HumanizeDiffTime(due, now, Conf.Lang))
@ -522,7 +522,7 @@ func newFlashcard(card riff.Card, blockID, deckID string, now time.Time) *Flashc
return &Flashcard{
DeckID: deckID,
CardID: card.ID(),
BlockID: blockID,
BlockID: card.BlockID(),
Lapses: card.GetLapses(),
Reps: card.GetReps(),
State: card.GetState(),
@ -572,7 +572,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
cards, unreviewedCnt, unreviewedNewCardCnt, unreviewedOldCardCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs, Conf.Flashcard.NewCardLimit, Conf.Flashcard.ReviewCardLimit, Conf.Flashcard.ReviewMode)
now := time.Now()
for _, card := range cards {
ret = append(ret, newFlashcard(card, card.BlockID(), builtinDeckID, now))
ret = append(ret, newFlashcard(card, builtinDeckID, now))
}
if 1 > len(ret) {
ret = []*Flashcard{}
@ -617,7 +617,7 @@ func GetTreeDueFlashcards(rootID string, reviewedCardIDs []string) (ret []*Flash
cards, unreviewedCnt, unreviewedNewCardCnt, unreviewedOldCardCnt := getDeckDueCards(deck, reviewedCardIDs, treeBlockIDs, newCardLimit, reviewCardLimit, Conf.Flashcard.ReviewMode)
now := time.Now()
for _, card := range cards {
ret = append(ret, newFlashcard(card, card.BlockID(), builtinDeckID, now))
ret = append(ret, newFlashcard(card, builtinDeckID, now))
}
if 1 > len(ret) {
ret = []*Flashcard{}
@ -688,7 +688,7 @@ func getDueFlashcards(deckID string, reviewedCardIDs []string) (ret []*Flashcard
cards, unreviewedCnt, unreviewedNewCardCnt, unreviewedOldCardCnt := getDeckDueCards(deck, reviewedCardIDs, nil, Conf.Flashcard.NewCardLimit, Conf.Flashcard.ReviewCardLimit, Conf.Flashcard.ReviewMode)
now := time.Now()
for _, card := range cards {
ret = append(ret, newFlashcard(card, card.BlockID(), deckID, now))
ret = append(ret, newFlashcard(card, deckID, now))
}
if 1 > len(ret) {
ret = []*Flashcard{}
@ -707,7 +707,7 @@ func getAllDueFlashcards(reviewedCardIDs []string) (ret []*Flashcard, unreviewed
unreviewedNewCardCount += unreviewedNewCardCnt
unreviewedOldCardCount += unreviewedOldCardCnt
for _, card := range cards {
ret = append(ret, newFlashcard(card, card.BlockID(), deck.ID, now))
ret = append(ret, newFlashcard(card, deck.ID, now))
}
}
if 1 > len(ret) {

View file

@ -896,7 +896,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
ial = map[string]string{}
}
}
content := renderTemplateCol(ial, cell.Value.Template.Content, keyValues)
content := renderTemplateCol(ial, keyValues, cell.Value.Template.Content)
cell.Value.Template.Content = content
}
}
@ -1028,7 +1028,7 @@ func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ av.KeyType
return
}
func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av.KeyValues) string {
func renderTemplateCol(ial map[string]string, rowValues []*av.KeyValues, tplContent string) string {
if "" == ial["id"] {
block := getRowBlockValue(rowValues)
ial["id"] = block.Block.ID
@ -1073,6 +1073,7 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
dataModel["updated"] = time.Now()
}
}
for _, rowValue := range rowValues {
if 0 < len(rowValue.Values) {
v := rowValue.Values[0]
@ -1085,6 +1086,7 @@ func renderTemplateCol(ial map[string]string, tplContent string, rowValues []*av
}
}
}
if err := tpl.Execute(buf, dataModel); nil != err {
logging.LogWarnf("execute template [%s] failed: %s", tplContent, err)
}