mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Add note due column
This commit is contained in:
parent
e9c14a763c
commit
1ad91a5312
8 changed files with 65 additions and 23 deletions
|
@ -717,6 +717,7 @@ class NoteState(ItemState):
|
|||
("note", tr.browsing_note()),
|
||||
("noteCards", tr.editing_cards()),
|
||||
("noteCrt", tr.browsing_created()),
|
||||
("noteDue", tr.statistics_due_date()),
|
||||
("noteEase", tr.browsing_average_ease()),
|
||||
("noteFld", tr.browsing_sort_field()),
|
||||
("noteLapses", tr.scheduling_lapses()),
|
||||
|
|
|
@ -811,6 +811,7 @@ message SortOrder {
|
|||
enum Kind {
|
||||
NOTE_CARDS = 0;
|
||||
NOTE_CREATION = 1;
|
||||
NOTE_DUE = 17;
|
||||
NOTE_EASE = 2;
|
||||
NOTE_FIELD = 3;
|
||||
NOTE_LAPSES = 4;
|
||||
|
|
|
@ -24,6 +24,7 @@ impl From<String> for browser_table::Column {
|
|||
"template" => browser_table::Column::CardTemplate,
|
||||
"noteCards" => browser_table::Column::NoteCards,
|
||||
"noteCrt" => browser_table::Column::NoteCreation,
|
||||
"noteDue" => browser_table::Column::NoteDue,
|
||||
"noteEase" => browser_table::Column::NoteEase,
|
||||
"noteFld" => browser_table::Column::NoteField,
|
||||
"noteLapses" => browser_table::Column::NoteLapses,
|
||||
|
|
|
@ -109,6 +109,7 @@ impl From<SortKindProto> for SortKind {
|
|||
match kind {
|
||||
SortKindProto::NoteCards => SortKind::NoteCards,
|
||||
SortKindProto::NoteCreation => SortKind::NoteCreation,
|
||||
SortKindProto::NoteDue => SortKind::NoteDue,
|
||||
SortKindProto::NoteEase => SortKind::NoteEase,
|
||||
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
||||
SortKindProto::NoteMod => SortKind::NoteMod,
|
||||
|
|
|
@ -24,26 +24,27 @@ use crate::{
|
|||
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy)]
|
||||
#[repr(u8)]
|
||||
pub enum Column {
|
||||
Custom = 0,
|
||||
Question = 1,
|
||||
Answer = 2,
|
||||
CardDeck = 3,
|
||||
CardDue = 4,
|
||||
CardEase = 5,
|
||||
CardLapses = 6,
|
||||
CardInterval = 7,
|
||||
CardMod = 8,
|
||||
CardReps = 9,
|
||||
CardTemplate = 10,
|
||||
NoteCards = 11,
|
||||
NoteCreation = 12,
|
||||
NoteEase = 13,
|
||||
NoteField = 14,
|
||||
NoteLapses = 15,
|
||||
NoteMod = 16,
|
||||
NoteReps = 17,
|
||||
NoteTags = 18,
|
||||
Notetype = 19,
|
||||
Custom,
|
||||
Question,
|
||||
Answer,
|
||||
CardDeck,
|
||||
CardDue,
|
||||
CardEase,
|
||||
CardLapses,
|
||||
CardInterval,
|
||||
CardMod,
|
||||
CardReps,
|
||||
CardTemplate,
|
||||
NoteCards,
|
||||
NoteCreation,
|
||||
NoteDue,
|
||||
NoteEase,
|
||||
NoteField,
|
||||
NoteLapses,
|
||||
NoteMod,
|
||||
NoteReps,
|
||||
NoteTags,
|
||||
Notetype,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
|
@ -147,6 +148,7 @@ struct NoteRowContext<'a> {
|
|||
notetype: Arc<Notetype>,
|
||||
cards: Vec<Card>,
|
||||
tr: &'a I18n,
|
||||
timing: SchedTimingToday,
|
||||
}
|
||||
|
||||
fn card_render_required(columns: &[Column]) -> bool {
|
||||
|
@ -453,12 +455,14 @@ impl<'a> NoteRowContext<'a> {
|
|||
.get_notetype(note.notetype_id)?
|
||||
.ok_or(AnkiError::NotFound)?;
|
||||
let cards = col.storage.all_cards_of_note(note.id)?;
|
||||
let timing = col.timing_today()?;
|
||||
|
||||
Ok(NoteRowContext {
|
||||
note,
|
||||
notetype,
|
||||
cards,
|
||||
tr: &col.tr,
|
||||
timing,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -475,6 +479,18 @@ impl<'a> NoteRowContext<'a> {
|
|||
format!("{}%", ease / 10)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the due date of the next due card that is not in a filtered deck, new, suspended or
|
||||
/// buried or the empty string if there is no such card.
|
||||
fn note_due_str(&self) -> String {
|
||||
self.cards
|
||||
.iter()
|
||||
.filter(|c| !(c.is_filtered_deck() || c.is_new_type_or_queue() || c.is_undue_queue()))
|
||||
.filter_map(|c| c.due_time(&self.timing))
|
||||
.min()
|
||||
.map(|time| time.date_string())
|
||||
.unwrap_or_else(|| "".into())
|
||||
}
|
||||
}
|
||||
|
||||
impl RowContext for NoteRowContext<'_> {
|
||||
|
@ -482,6 +498,7 @@ impl RowContext for NoteRowContext<'_> {
|
|||
Ok(match column {
|
||||
Column::NoteCards => self.cards.len().to_string(),
|
||||
Column::NoteCreation => self.note_creation_str(),
|
||||
Column::NoteDue => self.note_due_str(),
|
||||
Column::NoteEase => self.note_ease_str(),
|
||||
Column::NoteField => self.note_field_str(),
|
||||
Column::NoteLapses => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
|
||||
|
|
|
@ -271,6 +271,7 @@ pub enum SortKind {
|
|||
NoteCards,
|
||||
#[serde(rename = "noteCrt")]
|
||||
NoteCreation,
|
||||
NoteDue,
|
||||
NoteEase,
|
||||
NoteLapses,
|
||||
NoteMod,
|
||||
|
|
|
@ -90,6 +90,7 @@ impl SortKind {
|
|||
match self {
|
||||
SortKind::NoteCards
|
||||
| SortKind::NoteCreation
|
||||
| SortKind::NoteDue
|
||||
| SortKind::NoteEase
|
||||
| SortKind::NoteField
|
||||
| SortKind::NoteLapses
|
||||
|
@ -252,9 +253,11 @@ fn card_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
|||
|
||||
fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
||||
match kind {
|
||||
SortKind::NoteCards | SortKind::NoteEase | SortKind::NoteLapses | SortKind::NoteReps => {
|
||||
"(select pos from sort_order where nid = n.id) asc".into()
|
||||
}
|
||||
SortKind::NoteCards
|
||||
| SortKind::NoteDue
|
||||
| SortKind::NoteEase
|
||||
| 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::NoteMod => "n.mod asc".into(),
|
||||
|
@ -270,6 +273,7 @@ fn prepare_sort(col: &mut Collection, kind: SortKind) -> Result<()> {
|
|||
CardDeck => include_str!("deck_order.sql"),
|
||||
CardTemplate => 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"),
|
||||
NoteLapses => include_str!("note_lapses_order.sql"),
|
||||
NoteReps => include_str!("note_reps_order.sql"),
|
||||
|
|
16
rslib/src/search/note_due_order.sql
Normal file
16
rslib/src/search/note_due_order.sql
Normal file
|
@ -0,0 +1,16 @@
|
|||
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
|
||||
WHERE (
|
||||
odid = 0
|
||||
AND type != 0
|
||||
AND queue > 0
|
||||
)
|
||||
GROUP BY nid
|
||||
ORDER BY MIN(type),
|
||||
MIN(due);
|
Loading…
Reference in a new issue