From 4692a48ef3a72c27d5273de754697a9aa433d5db Mon Sep 17 00:00:00 2001 From: RumovZ Date: Thu, 8 Apr 2021 20:14:10 +0200 Subject: [PATCH] Add card mod column for notes mode --- rslib/src/backend/search/browser_table.rs | 3 ++- rslib/src/browser_table.rs | 11 ++++++++++- rslib/src/search/card_mod_order.sql | 10 ++++++++++ rslib/src/search/mod.rs | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 rslib/src/search/card_mod_order.sql diff --git a/rslib/src/backend/search/browser_table.rs b/rslib/src/backend/search/browser_table.rs index aed7c04b0..49f34bad3 100644 --- a/rslib/src/backend/search/browser_table.rs +++ b/rslib/src/backend/search/browser_table.rs @@ -23,8 +23,9 @@ const CARD_COLUMNS: [browser_table::Column; 15] = [ browser_table::Column::Notetype, ]; -const NOTE_COLUMNS: [browser_table::Column; 12] = [ +const NOTE_COLUMNS: [browser_table::Column; 13] = [ browser_table::Column::CardDeck, + browser_table::Column::CardMod, browser_table::Column::NoteCards, browser_table::Column::NoteCreation, browser_table::Column::NoteDue, diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index 9c69bdacf..be278d699 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -296,7 +296,7 @@ impl RowContext { Column::CardEase => self.card_ease_str(), Column::CardInterval => self.card_interval_str(), Column::CardLapses => self.cards[0].lapses.to_string(), - Column::CardMod => self.cards[0].mtime.date_string(), + Column::CardMod => self.card_mod_str(), Column::CardReps => self.cards[0].reps.to_string(), Column::CardTemplate => self.template_str()?, Column::NoteCreation => self.note_creation_str(), @@ -394,6 +394,15 @@ impl RowContext { } } + fn card_mod_str(&self) -> String { + self.cards + .iter() + .map(|c| c.mtime) + .max() + .unwrap() + .date_string() + } + fn deck_str(&mut self) -> String { if self.notes_mode { let decks = self.cards.iter().map(|c| c.deck_id).unique().count(); diff --git a/rslib/src/search/card_mod_order.sql b/rslib/src/search/card_mod_order.sql new file mode 100644 index 000000000..efbaf70e3 --- /dev/null +++ b/rslib/src/search/card_mod_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 MAX(mod); \ No newline at end of file diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index a1c6d8f7e..53634f84e 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -256,6 +256,7 @@ fn card_order_from_sortkind(kind: SortKind) -> Cow<'static, str> { fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> { match kind { SortKind::CardDeck + | SortKind::CardMod | SortKind::NoteCards | SortKind::NoteDue | SortKind::NoteEase @@ -282,6 +283,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind, items: SearchItems) -> Res include_str!("deck_order.sql") } } + CardMod if notes_mode => include_str!("card_mod_order.sql"), CardTemplate => include_str!("template_order.sql"), NoteCards => include_str!("note_cards_order.sql"), NoteDue => include_str!("note_due_order.sql"),