From 32e538d0db7fe11ff71a7e85bf8df26a0282c050 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 29 Mar 2021 15:52:02 +0200 Subject: [PATCH] Add note reps column --- qt/aqt/table.py | 1 + rslib/backend.proto | 1 + rslib/src/backend/search/mod.rs | 1 + rslib/src/browser_rows.rs | 1 + rslib/src/config/mod.rs | 1 + rslib/src/search/mod.rs | 9 ++++++--- rslib/src/search/note_reps_order.sql | 10 ++++++++++ 7 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 rslib/src/search/note_reps_order.sql diff --git a/qt/aqt/table.py b/qt/aqt/table.py index 9fba51acd..56d625d41 100644 --- a/qt/aqt/table.py +++ b/qt/aqt/table.py @@ -725,6 +725,7 @@ class NoteState(ItemState): ("noteEase", tr.browsing_average_ease()), ("noteFld", tr.browsing_sort_field()), ("noteMod", tr.search_note_modified()), + ("noteReps", tr.scheduling_reviews()), ("noteTags", tr.editing_tags()), ] self._columns.sort(key=itemgetter(1)) diff --git a/rslib/backend.proto b/rslib/backend.proto index 25e2a4ed0..f4168ccad 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -812,6 +812,7 @@ message SortOrder { NOTE_EASE = 2; NOTE_MOD = 3; NOTE_FIELD = 4; + NOTE_REPS = 15; NOTE_TAGS = 5; NOTETYPE = 6; CARD_MOD = 7; diff --git a/rslib/src/backend/search/mod.rs b/rslib/src/backend/search/mod.rs index d88d2f9ce..6112eb886 100644 --- a/rslib/src/backend/search/mod.rs +++ b/rslib/src/backend/search/mod.rs @@ -102,6 +102,7 @@ impl From for SortKind { SortKindProto::NoteEase => SortKind::NoteEase, SortKindProto::NoteMod => SortKind::NoteMod, SortKindProto::NoteField => SortKind::NoteField, + SortKindProto::NoteReps => SortKind::NoteReps, SortKindProto::NoteTags => SortKind::NoteTags, SortKindProto::Notetype => SortKind::Notetype, SortKindProto::CardMod => SortKind::CardMod, diff --git a/rslib/src/browser_rows.rs b/rslib/src/browser_rows.rs index ae46b74b7..ec4a6e8b8 100644 --- a/rslib/src/browser_rows.rs +++ b/rslib/src/browser_rows.rs @@ -429,6 +429,7 @@ impl RowContext for NoteRowContext<'_> { "noteEase" => self.note_ease_str(), "noteFld" => self.note_field_str(), "noteMod" => self.note.mtime.date_string(), + "noteReps" => self.cards.iter().map(|c| c.reps).sum::().to_string(), "noteTags" => self.note.tags.join(" "), _ => "".to_string(), }) diff --git a/rslib/src/config/mod.rs b/rslib/src/config/mod.rs index 722d0104f..a56cf41e1 100644 --- a/rslib/src/config/mod.rs +++ b/rslib/src/config/mod.rs @@ -278,6 +278,7 @@ pub enum SortKind { NoteMod, #[serde(rename = "noteFld")] NoteField, + NoteReps, #[serde(rename = "note")] Notetype, NoteTags, diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 2b54e285c..5e10e2929 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -94,6 +94,7 @@ impl SortKind { | SortKind::NoteMod | SortKind::NoteField | SortKind::Notetype + | SortKind::NoteReps | SortKind::NoteTags => RequiredTable::Notes, SortKind::CardTemplate => RequiredTable::CardsAndNotes, SortKind::CardMod @@ -250,11 +251,12 @@ fn card_order_from_sortkind(kind: SortKind) -> Cow<'static, str> { fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> { match kind { - SortKind::NoteCards => "(select pos from sort_order where nid = n.id) asc".into(), + SortKind::NoteCards | SortKind::NoteEase | SortKind::NoteReps => { + "(select pos from sort_order where nid = n.id) asc".into() + } SortKind::NoteCreation => "n.id asc".into(), - SortKind::NoteEase => "(select pos from sort_order where nid = n.id) asc".into(), - SortKind::NoteMod => "n.mod asc".into(), SortKind::NoteField => "n.sfld collate nocase asc".into(), + SortKind::NoteMod => "n.mod asc".into(), SortKind::NoteTags => "n.tags asc".into(), SortKind::Notetype => "(select pos from sort_order where ntid = n.mid) asc".into(), _ => "".into(), @@ -269,6 +271,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind) -> Result<()> { CardTemplate => include_str!("template_order.sql"), NoteCards => include_str!("note_cards_order.sql"), NoteEase => include_str!("note_ease_order.sql"), + NoteReps => include_str!("note_reps_order.sql"), _ => return Ok(()), }; diff --git a/rslib/src/search/note_reps_order.sql b/rslib/src/search/note_reps_order.sql new file mode 100644 index 000000000..833fdeb65 --- /dev/null +++ b/rslib/src/search/note_reps_order.sql @@ -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(reps); \ No newline at end of file