Rename columns for future mode-independent use
This commit is contained in:
parent
7a0cb08ac2
commit
dd56dc6650
@ -522,7 +522,7 @@ class Collection:
|
||||
order="c.ivl asc, c.due desc".
|
||||
|
||||
If order is a BuiltinSort.Kind value, sort using that builtin sort, eg
|
||||
col.find_cards("", order=BuiltinSort.Kind.CARD_DUE)
|
||||
col.find_cards("", order=BuiltinSort.Kind.DUE)
|
||||
|
||||
The reverse argument only applies when a BuiltinSort.Kind is provided;
|
||||
otherwise the collection config defines whether reverse is set or not.
|
||||
|
@ -124,12 +124,8 @@ def test_findCards():
|
||||
col.set_config_bool(Config.Bool.BROWSER_SORT_BACKWARDS, True)
|
||||
col.flush()
|
||||
assert col.findCards("", order=True)[0] in latestCardIds
|
||||
assert (
|
||||
col.find_cards("", order=BuiltinSort.CARD_DUE, reverse=False)[0] == firstCardId
|
||||
)
|
||||
assert (
|
||||
col.find_cards("", order=BuiltinSort.CARD_DUE, reverse=True)[0] != firstCardId
|
||||
)
|
||||
assert col.find_cards("", order=BuiltinSort.DUE, reverse=False)[0] == firstCardId
|
||||
assert col.find_cards("", order=BuiltinSort.DUE, reverse=True)[0] != firstCardId
|
||||
# model
|
||||
assert len(col.findCards("note:basic")) == 3
|
||||
assert len(col.findCards("-note:basic")) == 2
|
||||
|
@ -802,21 +802,21 @@ message SortOrder {
|
||||
NOTE_CREATION = 1;
|
||||
NOTE_DUE = 2;
|
||||
NOTE_EASE = 3;
|
||||
NOTE_FIELD = 4;
|
||||
SORT_FIELD = 4;
|
||||
NOTE_INTERVAL = 5;
|
||||
NOTE_LAPSES = 6;
|
||||
NOTE_MOD = 7;
|
||||
NOTE_REPS = 8;
|
||||
NOTE_TAGS = 9;
|
||||
TAGS = 9;
|
||||
NOTETYPE = 10;
|
||||
CARD_MOD = 11;
|
||||
CARD_REPS = 12;
|
||||
CARD_DUE = 13;
|
||||
CARD_EASE = 14;
|
||||
CARD_LAPSES = 15;
|
||||
CARD_INTERVAL = 16;
|
||||
CARD_DECK = 17;
|
||||
CARD_TEMPLATE = 18;
|
||||
REPS = 12;
|
||||
DUE = 13;
|
||||
EASE = 14;
|
||||
LAPSES = 15;
|
||||
INTERVAL = 16;
|
||||
DECK = 17;
|
||||
CARDS = 18;
|
||||
}
|
||||
Kind kind = 1;
|
||||
bool reverse = 2;
|
||||
|
@ -8,34 +8,34 @@ use crate::{backend_proto as pb, browser_table, collection::Collection, i18n::I1
|
||||
const CARD_COLUMNS: [browser_table::Column; 15] = [
|
||||
browser_table::Column::Question,
|
||||
browser_table::Column::Answer,
|
||||
browser_table::Column::CardDeck,
|
||||
browser_table::Column::CardDue,
|
||||
browser_table::Column::CardEase,
|
||||
browser_table::Column::CardLapses,
|
||||
browser_table::Column::CardInterval,
|
||||
browser_table::Column::Deck,
|
||||
browser_table::Column::Due,
|
||||
browser_table::Column::Ease,
|
||||
browser_table::Column::Lapses,
|
||||
browser_table::Column::Interval,
|
||||
browser_table::Column::CardMod,
|
||||
browser_table::Column::CardReps,
|
||||
browser_table::Column::CardTemplate,
|
||||
browser_table::Column::Reps,
|
||||
browser_table::Column::Cards,
|
||||
browser_table::Column::NoteCreation,
|
||||
browser_table::Column::NoteField,
|
||||
browser_table::Column::SortField,
|
||||
browser_table::Column::NoteMod,
|
||||
browser_table::Column::NoteTags,
|
||||
browser_table::Column::Tags,
|
||||
browser_table::Column::Notetype,
|
||||
];
|
||||
|
||||
const NOTE_COLUMNS: [browser_table::Column; 13] = [
|
||||
browser_table::Column::CardDeck,
|
||||
browser_table::Column::Deck,
|
||||
browser_table::Column::CardMod,
|
||||
browser_table::Column::NoteCards,
|
||||
browser_table::Column::NoteCreation,
|
||||
browser_table::Column::NoteDue,
|
||||
browser_table::Column::NoteEase,
|
||||
browser_table::Column::NoteField,
|
||||
browser_table::Column::SortField,
|
||||
browser_table::Column::NoteInterval,
|
||||
browser_table::Column::NoteLapses,
|
||||
browser_table::Column::NoteMod,
|
||||
browser_table::Column::NoteReps,
|
||||
browser_table::Column::NoteTags,
|
||||
browser_table::Column::Tags,
|
||||
browser_table::Column::Notetype,
|
||||
];
|
||||
|
||||
@ -70,24 +70,24 @@ impl browser_table::Column {
|
||||
fn sorting(self) -> pb::browser_columns::Sorting {
|
||||
match self {
|
||||
Self::Question | Self::Answer | Self::Custom => pb::browser_columns::Sorting::None,
|
||||
Self::NoteField => pb::browser_columns::Sorting::Reversed,
|
||||
Self::SortField => pb::browser_columns::Sorting::Reversed,
|
||||
_ => pb::browser_columns::Sorting::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
fn uses_cell_font(self) -> bool {
|
||||
matches!(self, Self::Question | Self::Answer | Self::NoteField)
|
||||
matches!(self, Self::Question | Self::Answer | Self::SortField)
|
||||
}
|
||||
|
||||
fn alignment(self) -> pb::browser_columns::Alignment {
|
||||
match self {
|
||||
Self::Question
|
||||
| Self::Answer
|
||||
| Self::CardTemplate
|
||||
| Self::CardDeck
|
||||
| Self::NoteField
|
||||
| Self::Cards
|
||||
| Self::Deck
|
||||
| Self::SortField
|
||||
| Self::Notetype
|
||||
| Self::NoteTags => pb::browser_columns::Alignment::Start,
|
||||
| Self::Tags => pb::browser_columns::Alignment::Start,
|
||||
_ => pb::browser_columns::Alignment::Center,
|
||||
}
|
||||
}
|
||||
@ -97,24 +97,24 @@ impl browser_table::Column {
|
||||
Self::Custom => i18n.browsing_addon(),
|
||||
Self::Question => i18n.browsing_question(),
|
||||
Self::Answer => i18n.browsing_answer(),
|
||||
Self::CardDeck => i18n.decks_deck(),
|
||||
Self::CardDue => i18n.statistics_due_date(),
|
||||
Self::CardEase => i18n.browsing_ease(),
|
||||
Self::CardInterval => i18n.browsing_interval(),
|
||||
Self::CardLapses => i18n.scheduling_lapses(),
|
||||
Self::Deck => i18n.decks_deck(),
|
||||
Self::Due => i18n.statistics_due_date(),
|
||||
Self::Ease => i18n.browsing_ease(),
|
||||
Self::Interval => i18n.browsing_interval(),
|
||||
Self::Lapses => i18n.scheduling_lapses(),
|
||||
Self::CardMod => i18n.search_card_modified(),
|
||||
Self::CardReps => i18n.scheduling_reviews(),
|
||||
Self::CardTemplate => i18n.browsing_card(),
|
||||
Self::Reps => i18n.scheduling_reviews(),
|
||||
Self::Cards => i18n.browsing_card(),
|
||||
Self::NoteCards => i18n.editing_cards(),
|
||||
Self::NoteCreation => i18n.browsing_created(),
|
||||
Self::NoteDue => i18n.statistics_due_date(),
|
||||
Self::NoteEase => i18n.browsing_average_ease(),
|
||||
Self::NoteField => i18n.browsing_sort_field(),
|
||||
Self::SortField => i18n.browsing_sort_field(),
|
||||
Self::NoteInterval => i18n.browsing_average_interval(),
|
||||
Self::NoteMod => i18n.search_note_modified(),
|
||||
Self::NoteLapses => i18n.scheduling_lapses(),
|
||||
Self::NoteReps => i18n.scheduling_reviews(),
|
||||
Self::NoteTags => i18n.editing_tags(),
|
||||
Self::Tags => i18n.editing_tags(),
|
||||
Self::Notetype => i18n.browsing_note(),
|
||||
}
|
||||
.into()
|
||||
|
@ -122,18 +122,18 @@ impl From<SortKindProto> for SortKind {
|
||||
SortKindProto::NoteInterval => SortKind::NoteInterval,
|
||||
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
||||
SortKindProto::NoteMod => SortKind::NoteMod,
|
||||
SortKindProto::NoteField => SortKind::NoteField,
|
||||
SortKindProto::SortField => SortKind::SortField,
|
||||
SortKindProto::NoteReps => SortKind::NoteReps,
|
||||
SortKindProto::NoteTags => SortKind::NoteTags,
|
||||
SortKindProto::Tags => SortKind::Tags,
|
||||
SortKindProto::Notetype => SortKind::Notetype,
|
||||
SortKindProto::CardMod => SortKind::CardMod,
|
||||
SortKindProto::CardReps => SortKind::CardReps,
|
||||
SortKindProto::CardDue => SortKind::CardDue,
|
||||
SortKindProto::CardEase => SortKind::CardEase,
|
||||
SortKindProto::CardLapses => SortKind::CardLapses,
|
||||
SortKindProto::CardInterval => SortKind::CardInterval,
|
||||
SortKindProto::CardDeck => SortKind::CardDeck,
|
||||
SortKindProto::CardTemplate => SortKind::CardTemplate,
|
||||
SortKindProto::Reps => SortKind::Reps,
|
||||
SortKindProto::Due => SortKind::Due,
|
||||
SortKindProto::Ease => SortKind::Ease,
|
||||
SortKindProto::Lapses => SortKind::Lapses,
|
||||
SortKindProto::Interval => SortKind::Interval,
|
||||
SortKindProto::Deck => SortKind::Deck,
|
||||
SortKindProto::Cards => SortKind::Cards,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,30 +30,33 @@ pub enum Column {
|
||||
Custom,
|
||||
Question,
|
||||
Answer,
|
||||
#[strum(serialize = "deck")]
|
||||
CardDeck,
|
||||
CardDue,
|
||||
CardEase,
|
||||
CardLapses,
|
||||
Deck,
|
||||
#[strum(serialize = "cardDue")]
|
||||
Due,
|
||||
#[strum(serialize = "cardEase")]
|
||||
Ease,
|
||||
#[strum(serialize = "cardLapses")]
|
||||
Lapses,
|
||||
#[strum(serialize = "cardIvl")]
|
||||
CardInterval,
|
||||
Interval,
|
||||
CardMod,
|
||||
CardReps,
|
||||
#[strum(serialize = "cardReps")]
|
||||
Reps,
|
||||
#[strum(serialize = "template")]
|
||||
CardTemplate,
|
||||
Cards,
|
||||
NoteCards,
|
||||
#[strum(serialize = "noteCrt")]
|
||||
NoteCreation,
|
||||
NoteDue,
|
||||
NoteEase,
|
||||
#[strum(serialize = "noteFld")]
|
||||
NoteField,
|
||||
SortField,
|
||||
#[strum(serialize = "noteIvl")]
|
||||
NoteInterval,
|
||||
NoteLapses,
|
||||
NoteMod,
|
||||
NoteReps,
|
||||
NoteTags,
|
||||
Tags,
|
||||
#[strum(serialize = "note")]
|
||||
Notetype,
|
||||
}
|
||||
@ -291,22 +294,22 @@ impl RowContext {
|
||||
Ok(match column {
|
||||
Column::Question => self.question_str(),
|
||||
Column::Answer => self.answer_str(),
|
||||
Column::CardDeck => self.deck_str(),
|
||||
Column::CardDue | Column::NoteDue => self.due_str(),
|
||||
Column::CardEase | Column::NoteEase => self.ease_str(),
|
||||
Column::CardInterval | Column::NoteInterval => self.interval_str(),
|
||||
Column::CardLapses | Column::NoteLapses => {
|
||||
Column::Deck => self.deck_str(),
|
||||
Column::Due | Column::NoteDue => self.due_str(),
|
||||
Column::Ease | Column::NoteEase => self.ease_str(),
|
||||
Column::Interval | Column::NoteInterval => self.interval_str(),
|
||||
Column::Lapses | Column::NoteLapses => {
|
||||
self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string()
|
||||
}
|
||||
Column::CardMod => self.card_mod_str(),
|
||||
Column::CardReps | Column::NoteReps => {
|
||||
Column::Reps | Column::NoteReps => {
|
||||
self.cards.iter().map(|c| c.reps).sum::<u32>().to_string()
|
||||
}
|
||||
Column::CardTemplate | Column::NoteCards => self.cards_str()?,
|
||||
Column::Cards | Column::NoteCards => self.cards_str()?,
|
||||
Column::NoteCreation => self.note_creation_str(),
|
||||
Column::NoteField => self.note_field_str(),
|
||||
Column::SortField => self.note_field_str(),
|
||||
Column::NoteMod => self.note.mtime.date_string(),
|
||||
Column::NoteTags => self.note.tags.join(" "),
|
||||
Column::Tags => self.note.tags.join(" "),
|
||||
Column::Notetype => self.notetype.name.to_owned(),
|
||||
Column::Custom => "".to_string(),
|
||||
})
|
||||
@ -323,7 +326,7 @@ impl RowContext {
|
||||
|
||||
fn get_is_rtl(&self, column: Column) -> bool {
|
||||
match column {
|
||||
Column::NoteField => {
|
||||
Column::SortField => {
|
||||
let index = self.notetype.config.sort_field_idx as usize;
|
||||
self.notetype.fields[index].config.rtl
|
||||
}
|
||||
|
@ -282,22 +282,26 @@ pub enum SortKind {
|
||||
NoteLapses,
|
||||
NoteMod,
|
||||
#[serde(rename = "noteFld")]
|
||||
NoteField,
|
||||
SortField,
|
||||
NoteReps,
|
||||
#[serde(rename = "note")]
|
||||
Notetype,
|
||||
NoteTags,
|
||||
#[serde(rename = "noteTags")]
|
||||
Tags,
|
||||
CardMod,
|
||||
CardReps,
|
||||
CardDue,
|
||||
CardEase,
|
||||
CardLapses,
|
||||
#[serde(rename = "cardReps")]
|
||||
Reps,
|
||||
#[serde(rename = "cardDue")]
|
||||
Due,
|
||||
#[serde(rename = "cardEase")]
|
||||
Ease,
|
||||
#[serde(rename = "cardLapses")]
|
||||
Lapses,
|
||||
#[serde(rename = "cardIvl")]
|
||||
CardInterval,
|
||||
#[serde(rename = "deck")]
|
||||
CardDeck,
|
||||
Interval,
|
||||
Deck,
|
||||
#[serde(rename = "template")]
|
||||
CardTemplate,
|
||||
Cards,
|
||||
}
|
||||
|
||||
impl Default for SortKind {
|
||||
@ -338,7 +342,7 @@ mod test {
|
||||
fn defaults() {
|
||||
let col = open_test_collection();
|
||||
assert_eq!(col.get_current_deck_id(), DeckId(1));
|
||||
assert_eq!(col.get_browser_sort_kind(), SortKind::NoteField);
|
||||
assert_eq!(col.get_browser_sort_kind(), SortKind::SortField);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -92,21 +92,21 @@ impl SortKind {
|
||||
| SortKind::NoteCreation
|
||||
| SortKind::NoteDue
|
||||
| SortKind::NoteEase
|
||||
| SortKind::NoteField
|
||||
| SortKind::SortField
|
||||
| SortKind::NoteInterval
|
||||
| SortKind::NoteLapses
|
||||
| SortKind::NoteMod
|
||||
| SortKind::NoteReps
|
||||
| SortKind::NoteTags
|
||||
| SortKind::Tags
|
||||
| SortKind::Notetype => RequiredTable::Notes,
|
||||
SortKind::CardTemplate => RequiredTable::CardsAndNotes,
|
||||
SortKind::Cards => RequiredTable::CardsAndNotes,
|
||||
SortKind::CardMod
|
||||
| SortKind::CardReps
|
||||
| SortKind::CardDue
|
||||
| SortKind::CardEase
|
||||
| SortKind::CardLapses
|
||||
| SortKind::CardInterval
|
||||
| SortKind::CardDeck => RequiredTable::Cards,
|
||||
| SortKind::Reps
|
||||
| SortKind::Due
|
||||
| SortKind::Ease
|
||||
| SortKind::Lapses
|
||||
| SortKind::Interval
|
||||
| SortKind::Deck => RequiredTable::Cards,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -233,17 +233,17 @@ fn card_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
||||
match kind {
|
||||
SortKind::NoteCreation => "n.id asc, c.ord asc".into(),
|
||||
SortKind::NoteMod => "n.mod asc, c.ord asc".into(),
|
||||
SortKind::NoteField => "n.sfld collate nocase asc, c.ord asc".into(),
|
||||
SortKind::SortField => "n.sfld collate nocase asc, c.ord asc".into(),
|
||||
SortKind::CardMod => "c.mod asc".into(),
|
||||
SortKind::CardReps => "c.reps asc".into(),
|
||||
SortKind::CardDue => "c.type asc, c.due asc".into(),
|
||||
SortKind::CardEase => format!("c.type = {} asc, c.factor asc", CardType::New as i8).into(),
|
||||
SortKind::CardLapses => "c.lapses asc".into(),
|
||||
SortKind::CardInterval => "c.ivl asc".into(),
|
||||
SortKind::NoteTags => "n.tags asc".into(),
|
||||
SortKind::CardDeck => "(select pos from sort_order where did = c.did) asc".into(),
|
||||
SortKind::Reps => "c.reps asc".into(),
|
||||
SortKind::Due => "c.type asc, c.due asc".into(),
|
||||
SortKind::Ease => format!("c.type = {} asc, c.factor asc", CardType::New as i8).into(),
|
||||
SortKind::Lapses => "c.lapses asc".into(),
|
||||
SortKind::Interval => "c.ivl asc".into(),
|
||||
SortKind::Tags => "n.tags asc".into(),
|
||||
SortKind::Deck => "(select pos from sort_order where did = c.did) asc".into(),
|
||||
SortKind::Notetype => "(select pos from sort_order where ntid = n.mid) asc".into(),
|
||||
SortKind::CardTemplate => concat!(
|
||||
SortKind::Cards => concat!(
|
||||
"coalesce((select pos from sort_order where ntid = n.mid and ord = c.ord),",
|
||||
// need to fall back on ord 0 for cloze cards
|
||||
"(select pos from sort_order where ntid = n.mid and ord = 0)) asc"
|
||||
@ -255,7 +255,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::Deck
|
||||
| SortKind::CardMod
|
||||
| SortKind::NoteCards
|
||||
| SortKind::NoteDue
|
||||
@ -264,9 +264,9 @@ fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
||||
| SortKind::NoteLapses
|
||||
| SortKind::NoteReps => "(select pos from sort_order where nid = n.id) asc".into(),
|
||||
SortKind::NoteCreation => "n.id asc".into(),
|
||||
SortKind::NoteField => "n.sfld collate nocase asc".into(),
|
||||
SortKind::SortField => "n.sfld collate nocase asc".into(),
|
||||
SortKind::NoteMod => "n.mod asc".into(),
|
||||
SortKind::NoteTags => "n.tags asc".into(),
|
||||
SortKind::Tags => "n.tags asc".into(),
|
||||
SortKind::Notetype => "(select pos from sort_order where ntid = n.mid) asc".into(),
|
||||
_ => "".into(),
|
||||
}
|
||||
@ -276,7 +276,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind, items: SearchItems) -> Res
|
||||
use SortKind::*;
|
||||
let notes_mode = items == SearchItems::Notes;
|
||||
let sql = match kind {
|
||||
CardDeck => {
|
||||
Deck => {
|
||||
if notes_mode {
|
||||
include_str!("note_decks_order.sql")
|
||||
} else {
|
||||
@ -284,7 +284,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind, items: SearchItems) -> Res
|
||||
}
|
||||
}
|
||||
CardMod if notes_mode => include_str!("card_mod_order.sql"),
|
||||
CardTemplate => include_str!("template_order.sql"),
|
||||
Cards => include_str!("template_order.sql"),
|
||||
NoteCards => include_str!("note_cards_order.sql"),
|
||||
NoteDue => include_str!("note_due_order.sql"),
|
||||
NoteEase => include_str!("note_ease_order.sql"),
|
||||
|
Loading…
Reference in New Issue
Block a user