Add deck column for notes mode
This commit is contained in:
parent
c6ebb9b441
commit
2350cd6e91
@ -23,7 +23,8 @@ const CARD_COLUMNS: [browser_table::Column; 15] = [
|
|||||||
browser_table::Column::Notetype,
|
browser_table::Column::Notetype,
|
||||||
];
|
];
|
||||||
|
|
||||||
const NOTE_COLUMNS: [browser_table::Column; 11] = [
|
const NOTE_COLUMNS: [browser_table::Column; 12] = [
|
||||||
|
browser_table::Column::CardDeck,
|
||||||
browser_table::Column::NoteCards,
|
browser_table::Column::NoteCards,
|
||||||
browser_table::Column::NoteCreation,
|
browser_table::Column::NoteCreation,
|
||||||
browser_table::Column::NoteDue,
|
browser_table::Column::NoteDue,
|
||||||
|
@ -395,6 +395,12 @@ impl RowContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deck_str(&mut self) -> String {
|
fn deck_str(&mut self) -> String {
|
||||||
|
if self.notes_mode {
|
||||||
|
let decks = self.cards.iter().map(|c| c.deck_id).unique().count();
|
||||||
|
if decks > 1 {
|
||||||
|
return format!("({})", decks);
|
||||||
|
}
|
||||||
|
}
|
||||||
let deck_name = self.deck.human_name();
|
let deck_name = self.deck.human_name();
|
||||||
if let Some(original_deck) = &self.original_deck {
|
if let Some(original_deck) = &self.original_deck {
|
||||||
format!("{} ({})", &deck_name, &original_deck.human_name())
|
format!("{} ({})", &deck_name, &original_deck.human_name())
|
||||||
|
@ -145,7 +145,7 @@ impl Collection {
|
|||||||
SortMode::NoOrder => (),
|
SortMode::NoOrder => (),
|
||||||
SortMode::FromConfig => unreachable!(),
|
SortMode::FromConfig => unreachable!(),
|
||||||
SortMode::Builtin { kind, reverse } => {
|
SortMode::Builtin { kind, reverse } => {
|
||||||
prepare_sort(self, kind)?;
|
prepare_sort(self, kind, items)?;
|
||||||
sql.push_str(" order by ");
|
sql.push_str(" order by ");
|
||||||
write_order(sql, items, kind, reverse)?;
|
write_order(sql, items, kind, reverse)?;
|
||||||
}
|
}
|
||||||
@ -255,7 +255,8 @@ 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::CardDeck
|
||||||
|
| SortKind::NoteCards
|
||||||
| SortKind::NoteDue
|
| SortKind::NoteDue
|
||||||
| SortKind::NoteEase
|
| SortKind::NoteEase
|
||||||
| SortKind::NoteInterval
|
| SortKind::NoteInterval
|
||||||
@ -270,10 +271,17 @@ fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prepare_sort(col: &mut Collection, kind: SortKind) -> Result<()> {
|
fn prepare_sort(col: &mut Collection, kind: SortKind, items: SearchItems) -> Result<()> {
|
||||||
use SortKind::*;
|
use SortKind::*;
|
||||||
|
let notes_mode = items == SearchItems::Notes;
|
||||||
let sql = match kind {
|
let sql = match kind {
|
||||||
CardDeck => include_str!("deck_order.sql"),
|
CardDeck => {
|
||||||
|
if notes_mode {
|
||||||
|
include_str!("note_decks_order.sql")
|
||||||
|
} else {
|
||||||
|
include_str!("deck_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"),
|
||||||
NoteDue => include_str!("note_due_order.sql"),
|
NoteDue => include_str!("note_due_order.sql"),
|
||||||
|
18
rslib/src/search/note_decks_order.sql
Normal file
18
rslib/src/search/note_decks_order.sql
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
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
|
||||||
|
JOIN (
|
||||||
|
SELECT id,
|
||||||
|
row_number() OVER(
|
||||||
|
ORDER BY name
|
||||||
|
) AS pos
|
||||||
|
FROM decks
|
||||||
|
) decks ON cards.did = decks.id
|
||||||
|
GROUP BY nid
|
||||||
|
ORDER BY COUNT(DISTINCT did),
|
||||||
|
decks.pos;
|
Loading…
Reference in New Issue
Block a user