Add card mod column for notes mode

This commit is contained in:
RumovZ 2021-04-08 20:14:10 +02:00
parent 2350cd6e91
commit 4692a48ef3
4 changed files with 24 additions and 2 deletions

View File

@ -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,

View File

@ -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();

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 MAX(mod);

View File

@ -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"),