mirror of
https://github.com/ankitects/anki.git
synced 2025-12-13 06:46:55 -05: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()),
|
("note", tr.browsing_note()),
|
||||||
("noteCards", tr.editing_cards()),
|
("noteCards", tr.editing_cards()),
|
||||||
("noteCrt", tr.browsing_created()),
|
("noteCrt", tr.browsing_created()),
|
||||||
|
("noteDue", tr.statistics_due_date()),
|
||||||
("noteEase", tr.browsing_average_ease()),
|
("noteEase", tr.browsing_average_ease()),
|
||||||
("noteFld", tr.browsing_sort_field()),
|
("noteFld", tr.browsing_sort_field()),
|
||||||
("noteLapses", tr.scheduling_lapses()),
|
("noteLapses", tr.scheduling_lapses()),
|
||||||
|
|
|
||||||
|
|
@ -811,6 +811,7 @@ message SortOrder {
|
||||||
enum Kind {
|
enum Kind {
|
||||||
NOTE_CARDS = 0;
|
NOTE_CARDS = 0;
|
||||||
NOTE_CREATION = 1;
|
NOTE_CREATION = 1;
|
||||||
|
NOTE_DUE = 17;
|
||||||
NOTE_EASE = 2;
|
NOTE_EASE = 2;
|
||||||
NOTE_FIELD = 3;
|
NOTE_FIELD = 3;
|
||||||
NOTE_LAPSES = 4;
|
NOTE_LAPSES = 4;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ impl From<String> for browser_table::Column {
|
||||||
"template" => browser_table::Column::CardTemplate,
|
"template" => browser_table::Column::CardTemplate,
|
||||||
"noteCards" => browser_table::Column::NoteCards,
|
"noteCards" => browser_table::Column::NoteCards,
|
||||||
"noteCrt" => browser_table::Column::NoteCreation,
|
"noteCrt" => browser_table::Column::NoteCreation,
|
||||||
|
"noteDue" => browser_table::Column::NoteDue,
|
||||||
"noteEase" => browser_table::Column::NoteEase,
|
"noteEase" => browser_table::Column::NoteEase,
|
||||||
"noteFld" => browser_table::Column::NoteField,
|
"noteFld" => browser_table::Column::NoteField,
|
||||||
"noteLapses" => browser_table::Column::NoteLapses,
|
"noteLapses" => browser_table::Column::NoteLapses,
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ impl From<SortKindProto> for SortKind {
|
||||||
match kind {
|
match kind {
|
||||||
SortKindProto::NoteCards => SortKind::NoteCards,
|
SortKindProto::NoteCards => SortKind::NoteCards,
|
||||||
SortKindProto::NoteCreation => SortKind::NoteCreation,
|
SortKindProto::NoteCreation => SortKind::NoteCreation,
|
||||||
|
SortKindProto::NoteDue => SortKind::NoteDue,
|
||||||
SortKindProto::NoteEase => SortKind::NoteEase,
|
SortKindProto::NoteEase => SortKind::NoteEase,
|
||||||
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
SortKindProto::NoteLapses => SortKind::NoteLapses,
|
||||||
SortKindProto::NoteMod => SortKind::NoteMod,
|
SortKindProto::NoteMod => SortKind::NoteMod,
|
||||||
|
|
|
||||||
|
|
@ -24,26 +24,27 @@ use crate::{
|
||||||
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy)]
|
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Column {
|
pub enum Column {
|
||||||
Custom = 0,
|
Custom,
|
||||||
Question = 1,
|
Question,
|
||||||
Answer = 2,
|
Answer,
|
||||||
CardDeck = 3,
|
CardDeck,
|
||||||
CardDue = 4,
|
CardDue,
|
||||||
CardEase = 5,
|
CardEase,
|
||||||
CardLapses = 6,
|
CardLapses,
|
||||||
CardInterval = 7,
|
CardInterval,
|
||||||
CardMod = 8,
|
CardMod,
|
||||||
CardReps = 9,
|
CardReps,
|
||||||
CardTemplate = 10,
|
CardTemplate,
|
||||||
NoteCards = 11,
|
NoteCards,
|
||||||
NoteCreation = 12,
|
NoteCreation,
|
||||||
NoteEase = 13,
|
NoteDue,
|
||||||
NoteField = 14,
|
NoteEase,
|
||||||
NoteLapses = 15,
|
NoteField,
|
||||||
NoteMod = 16,
|
NoteLapses,
|
||||||
NoteReps = 17,
|
NoteMod,
|
||||||
NoteTags = 18,
|
NoteReps,
|
||||||
Notetype = 19,
|
NoteTags,
|
||||||
|
Notetype,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
|
@ -147,6 +148,7 @@ struct NoteRowContext<'a> {
|
||||||
notetype: Arc<Notetype>,
|
notetype: Arc<Notetype>,
|
||||||
cards: Vec<Card>,
|
cards: Vec<Card>,
|
||||||
tr: &'a I18n,
|
tr: &'a I18n,
|
||||||
|
timing: SchedTimingToday,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn card_render_required(columns: &[Column]) -> bool {
|
fn card_render_required(columns: &[Column]) -> bool {
|
||||||
|
|
@ -453,12 +455,14 @@ impl<'a> NoteRowContext<'a> {
|
||||||
.get_notetype(note.notetype_id)?
|
.get_notetype(note.notetype_id)?
|
||||||
.ok_or(AnkiError::NotFound)?;
|
.ok_or(AnkiError::NotFound)?;
|
||||||
let cards = col.storage.all_cards_of_note(note.id)?;
|
let cards = col.storage.all_cards_of_note(note.id)?;
|
||||||
|
let timing = col.timing_today()?;
|
||||||
|
|
||||||
Ok(NoteRowContext {
|
Ok(NoteRowContext {
|
||||||
note,
|
note,
|
||||||
notetype,
|
notetype,
|
||||||
cards,
|
cards,
|
||||||
tr: &col.tr,
|
tr: &col.tr,
|
||||||
|
timing,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,6 +479,18 @@ impl<'a> NoteRowContext<'a> {
|
||||||
format!("{}%", ease / 10)
|
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<'_> {
|
impl RowContext for NoteRowContext<'_> {
|
||||||
|
|
@ -482,6 +498,7 @@ impl RowContext for NoteRowContext<'_> {
|
||||||
Ok(match column {
|
Ok(match column {
|
||||||
Column::NoteCards => self.cards.len().to_string(),
|
Column::NoteCards => self.cards.len().to_string(),
|
||||||
Column::NoteCreation => self.note_creation_str(),
|
Column::NoteCreation => self.note_creation_str(),
|
||||||
|
Column::NoteDue => self.note_due_str(),
|
||||||
Column::NoteEase => self.note_ease_str(),
|
Column::NoteEase => self.note_ease_str(),
|
||||||
Column::NoteField => self.note_field_str(),
|
Column::NoteField => self.note_field_str(),
|
||||||
Column::NoteLapses => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
|
Column::NoteLapses => self.cards.iter().map(|c| c.lapses).sum::<u32>().to_string(),
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,7 @@ pub enum SortKind {
|
||||||
NoteCards,
|
NoteCards,
|
||||||
#[serde(rename = "noteCrt")]
|
#[serde(rename = "noteCrt")]
|
||||||
NoteCreation,
|
NoteCreation,
|
||||||
|
NoteDue,
|
||||||
NoteEase,
|
NoteEase,
|
||||||
NoteLapses,
|
NoteLapses,
|
||||||
NoteMod,
|
NoteMod,
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ impl SortKind {
|
||||||
match self {
|
match self {
|
||||||
SortKind::NoteCards
|
SortKind::NoteCards
|
||||||
| SortKind::NoteCreation
|
| SortKind::NoteCreation
|
||||||
|
| SortKind::NoteDue
|
||||||
| SortKind::NoteEase
|
| SortKind::NoteEase
|
||||||
| SortKind::NoteField
|
| SortKind::NoteField
|
||||||
| SortKind::NoteLapses
|
| 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> {
|
fn note_order_from_sortkind(kind: SortKind) -> Cow<'static, str> {
|
||||||
match kind {
|
match kind {
|
||||||
SortKind::NoteCards | SortKind::NoteEase | SortKind::NoteLapses | SortKind::NoteReps => {
|
SortKind::NoteCards
|
||||||
"(select pos from sort_order where nid = n.id) asc".into()
|
| 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::NoteCreation => "n.id asc".into(),
|
||||||
SortKind::NoteField => "n.sfld collate nocase asc".into(),
|
SortKind::NoteField => "n.sfld collate nocase asc".into(),
|
||||||
SortKind::NoteMod => "n.mod 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"),
|
CardDeck => 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"),
|
||||||
NoteEase => include_str!("note_ease_order.sql"),
|
NoteEase => include_str!("note_ease_order.sql"),
|
||||||
NoteLapses => include_str!("note_lapses_order.sql"),
|
NoteLapses => include_str!("note_lapses_order.sql"),
|
||||||
NoteReps => include_str!("note_reps_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