Add note lapses column

This commit is contained in:
RumovZ 2021-03-29 16:06:15 +02:00
parent 32e538d0db
commit 4933b922f7
7 changed files with 35 additions and 18 deletions

View file

@ -724,6 +724,7 @@ class NoteState(ItemState):
("noteCrt", tr.browsing_created()), ("noteCrt", tr.browsing_created()),
("noteEase", tr.browsing_average_ease()), ("noteEase", tr.browsing_average_ease()),
("noteFld", tr.browsing_sort_field()), ("noteFld", tr.browsing_sort_field()),
("noteLapses", tr.scheduling_lapses()),
("noteMod", tr.search_note_modified()), ("noteMod", tr.search_note_modified()),
("noteReps", tr.scheduling_reviews()), ("noteReps", tr.scheduling_reviews()),
("noteTags", tr.editing_tags()), ("noteTags", tr.editing_tags()),

View file

@ -810,19 +810,20 @@ message SortOrder {
NOTE_CARDS = 0; NOTE_CARDS = 0;
NOTE_CREATION = 1; NOTE_CREATION = 1;
NOTE_EASE = 2; NOTE_EASE = 2;
NOTE_MOD = 3; NOTE_FIELD = 3;
NOTE_FIELD = 4; NOTE_LAPSES = 4;
NOTE_REPS = 15; NOTE_MOD = 5;
NOTE_TAGS = 5; NOTE_REPS = 6;
NOTETYPE = 6; NOTE_TAGS = 7;
CARD_MOD = 7; NOTETYPE = 8;
CARD_REPS = 8; CARD_MOD = 9;
CARD_DUE = 9; CARD_REPS = 10;
CARD_EASE = 10; CARD_DUE = 11;
CARD_LAPSES = 11; CARD_EASE = 12;
CARD_INTERVAL = 12; CARD_LAPSES = 13;
CARD_DECK = 13; CARD_INTERVAL = 14;
CARD_TEMPLATE = 14; CARD_DECK = 15;
CARD_TEMPLATE = 16;
} }
Kind kind = 1; Kind kind = 1;
bool reverse = 2; bool reverse = 2;

View file

@ -100,6 +100,7 @@ impl From<SortKindProto> for SortKind {
SortKindProto::NoteCards => SortKind::NoteCards, SortKindProto::NoteCards => SortKind::NoteCards,
SortKindProto::NoteCreation => SortKind::NoteCreation, SortKindProto::NoteCreation => SortKind::NoteCreation,
SortKindProto::NoteEase => SortKind::NoteEase, SortKindProto::NoteEase => SortKind::NoteEase,
SortKindProto::NoteLapses => SortKind::NoteLapses,
SortKindProto::NoteMod => SortKind::NoteMod, SortKindProto::NoteMod => SortKind::NoteMod,
SortKindProto::NoteField => SortKind::NoteField, SortKindProto::NoteField => SortKind::NoteField,
SortKindProto::NoteReps => SortKind::NoteReps, SortKindProto::NoteReps => SortKind::NoteReps,

View file

@ -428,6 +428,7 @@ impl RowContext for NoteRowContext<'_> {
"noteCrt" => self.note_creation_str(), "noteCrt" => self.note_creation_str(),
"noteEase" => self.note_ease_str(), "noteEase" => self.note_ease_str(),
"noteFld" => self.note_field_str(), "noteFld" => self.note_field_str(),
"noteLapses" => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
"noteMod" => self.note.mtime.date_string(), "noteMod" => self.note.mtime.date_string(),
"noteReps" => self.cards.iter().map(|c| c.reps).sum::<u32>().to_string(), "noteReps" => self.cards.iter().map(|c| c.reps).sum::<u32>().to_string(),
"noteTags" => self.note.tags.join(" "), "noteTags" => self.note.tags.join(" "),

View file

@ -275,6 +275,7 @@ pub enum SortKind {
#[serde(rename = "noteCrt")] #[serde(rename = "noteCrt")]
NoteCreation, NoteCreation,
NoteEase, NoteEase,
NoteLapses,
NoteMod, NoteMod,
#[serde(rename = "noteFld")] #[serde(rename = "noteFld")]
NoteField, NoteField,

View file

@ -91,11 +91,12 @@ impl SortKind {
SortKind::NoteCards SortKind::NoteCards
| SortKind::NoteCreation | SortKind::NoteCreation
| SortKind::NoteEase | SortKind::NoteEase
| SortKind::NoteMod
| SortKind::NoteField | SortKind::NoteField
| SortKind::Notetype | SortKind::NoteLapses
| SortKind::NoteMod
| SortKind::NoteReps | SortKind::NoteReps
| SortKind::NoteTags => RequiredTable::Notes, | SortKind::NoteTags
| SortKind::Notetype => RequiredTable::Notes,
SortKind::CardTemplate => RequiredTable::CardsAndNotes, SortKind::CardTemplate => RequiredTable::CardsAndNotes,
SortKind::CardMod SortKind::CardMod
| SortKind::CardReps | SortKind::CardReps
@ -251,7 +252,7 @@ fn card_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> { fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
match kind { match kind {
SortKind::NoteCards | SortKind::NoteEase | SortKind::NoteReps => { SortKind::NoteCards | SortKind::NoteEase | SortKind::NoteLapses | SortKind::NoteReps => {
"(select pos from sort_order where nid = n.id) asc".into() "(select pos from sort_order where nid = n.id) asc".into()
} }
SortKind::NoteCreation => "n.id asc".into(), SortKind::NoteCreation => "n.id asc".into(),
@ -267,11 +268,12 @@ fn prepare_sort(col: &mut Collection, kind: SortKind) -> Result<()> {
use SortKind::*; use SortKind::*;
let sql = match kind { let sql = match kind {
CardDeck => include_str!("deck_order.sql"), CardDeck => include_str!("deck_order.sql"),
Notetype => include_str!("notetype_order.sql"),
CardTemplate => include_str!("template_order.sql"), CardTemplate => include_str!("template_order.sql"),
NoteCards => include_str!("note_cards_order.sql"), NoteCards => include_str!("note_cards_order.sql"),
NoteEase => include_str!("note_ease_order.sql"), NoteEase => include_str!("note_ease_order.sql"),
NoteLapses => include_str!("note_lapses_order.sql"),
NoteReps => include_str!("note_reps_order.sql"), NoteReps => include_str!("note_reps_order.sql"),
Notetype => include_str!("notetype_order.sql"),
_ => return Ok(()), _ => return Ok(()),
}; };

View file

@ -0,0 +1,10 @@
DROP TABLE IF EXISTS sort_order;
CREATE TEMPORARY TABLE sort_order (
pos integer PRIMARY KEY,
nid integer NOT NULL UNIQUE
);
INSERT INTO sort_order (nid)
SELECT nid
FROM cards
GROUP BY nid
ORDER BY SUM(lapses);