mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
Handle card due dates and original due/did
This commit is contained in:
parent
a528106af0
commit
126a92c239
2 changed files with 49 additions and 10 deletions
|
@ -26,6 +26,7 @@ pub(super) struct ExchangeData {
|
||||||
pub(super) revlog: Vec<RevlogEntry>,
|
pub(super) revlog: Vec<RevlogEntry>,
|
||||||
pub(super) deck_configs: Vec<DeckConfig>,
|
pub(super) deck_configs: Vec<DeckConfig>,
|
||||||
pub(super) media_paths: HashSet<PathBuf>,
|
pub(super) media_paths: HashSet<PathBuf>,
|
||||||
|
pub(super) days_elapsed: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExchangeData {
|
impl ExchangeData {
|
||||||
|
@ -35,6 +36,7 @@ impl ExchangeData {
|
||||||
search: impl TryIntoSearch,
|
search: impl TryIntoSearch,
|
||||||
with_scheduling: bool,
|
with_scheduling: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
self.days_elapsed = col.timing_today()?.days_elapsed;
|
||||||
self.notes = col.gather_notes(search)?;
|
self.notes = col.gather_notes(search)?;
|
||||||
self.cards = col.gather_cards()?;
|
self.cards = col.gather_cards()?;
|
||||||
self.decks = col.gather_decks()?;
|
self.decks = col.gather_decks()?;
|
||||||
|
|
|
@ -15,7 +15,9 @@ use tempfile::NamedTempFile;
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
card::{CardQueue, CardType},
|
||||||
collection::CollectionBuilder,
|
collection::CollectionBuilder,
|
||||||
|
config::SchedulerVersion,
|
||||||
decks::NormalDeck,
|
decks::NormalDeck,
|
||||||
import_export::{
|
import_export::{
|
||||||
gather::ExchangeData,
|
gather::ExchangeData,
|
||||||
|
@ -396,23 +398,28 @@ impl<'a> Context<'a> {
|
||||||
|
|
||||||
fn import_cards(&mut self) -> Result<()> {
|
fn import_cards(&mut self) -> Result<()> {
|
||||||
let existing = self.target_col.storage.all_cards_as_nid_and_ord()?;
|
let existing = self.target_col.storage.all_cards_as_nid_and_ord()?;
|
||||||
|
let collection_delta = self.collection_delta()?;
|
||||||
|
let version = self.target_col.scheduler_info()?.version;
|
||||||
for mut card in mem::take(&mut self.data.cards) {
|
for mut card in mem::take(&mut self.data.cards) {
|
||||||
if self.conflicting_notes.contains(&card.note_id) {
|
if !self.conflicting_notes.contains(&card.note_id) {
|
||||||
continue;
|
self.remap_note_id(&mut card);
|
||||||
}
|
if !existing.contains(&(card.note_id, card.template_idx)) {
|
||||||
self.remap_note_id(&mut card);
|
self.remap_deck_id(&mut card);
|
||||||
if existing.contains(&(card.note_id, card.template_idx)) {
|
card.shift_collection_relative_dates(collection_delta);
|
||||||
|
card.maybe_remove_from_filtered_deck(version);
|
||||||
|
self.add_card(&mut card)?;
|
||||||
|
}
|
||||||
// TODO: maybe update
|
// TODO: maybe update
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
self.remap_deck_id(&mut card);
|
|
||||||
// TODO: adjust collection-relative due times
|
|
||||||
// TODO: remove cards from filtered decks
|
|
||||||
self.add_card(&mut card)?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The number of days the source collection is ahead of the target collection.
|
||||||
|
fn collection_delta(&mut self) -> Result<i32> {
|
||||||
|
Ok(self.data.days_elapsed as i32 - self.target_col.timing_today()?.days_elapsed as i32)
|
||||||
|
}
|
||||||
|
|
||||||
fn add_card(&mut self, card: &mut Card) -> Result<()> {
|
fn add_card(&mut self, card: &mut Card) -> Result<()> {
|
||||||
card.usn = self.usn;
|
card.usn = self.usn;
|
||||||
if self.target_col.add_card_if_unique_undoable(card)? {
|
if self.target_col.add_card_if_unique_undoable(card)? {
|
||||||
|
@ -497,3 +504,33 @@ impl Notetype {
|
||||||
hasher.digest().bytes()
|
hasher.digest().bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Card {
|
||||||
|
/// `delta` is the number days the card's source collection is ahead of the
|
||||||
|
/// target collection.
|
||||||
|
fn shift_collection_relative_dates(&mut self, delta: i32) {
|
||||||
|
if self.due_in_days_since_collection_creation() {
|
||||||
|
self.due -= delta;
|
||||||
|
}
|
||||||
|
if self.original_due_in_days_since_collection_creation() && self.original_due != 0 {
|
||||||
|
self.original_due -= delta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn due_in_days_since_collection_creation(&self) -> bool {
|
||||||
|
matches!(self.queue, CardQueue::Review | CardQueue::DayLearn)
|
||||||
|
|| self.ctype == CardType::Review
|
||||||
|
}
|
||||||
|
|
||||||
|
fn original_due_in_days_since_collection_creation(&self) -> bool {
|
||||||
|
self.ctype == CardType::Review
|
||||||
|
}
|
||||||
|
|
||||||
|
fn maybe_remove_from_filtered_deck(&mut self, version: SchedulerVersion) {
|
||||||
|
if self.is_filtered() {
|
||||||
|
// instead of moving between decks, the deck is converted to a regular one
|
||||||
|
self.original_deck_id = self.deck_id;
|
||||||
|
self.remove_from_filtered_deck_restoring_queue(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue