From 2a168adb66a11e7e5eab3913bafbfe45d26f5e16 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 23 Mar 2021 23:55:28 +1000 Subject: [PATCH] move filter code into scheduler/ --- rslib/src/decks/filtered.rs | 38 ++++++++++++++++++++++ rslib/src/decks/mod.rs | 1 + rslib/src/lib.rs | 1 - rslib/src/{ => scheduler}/filtered.rs | 47 +++------------------------ rslib/src/scheduler/mod.rs | 1 + 5 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 rslib/src/decks/filtered.rs rename rslib/src/{ => scheduler}/filtered.rs (87%) diff --git a/rslib/src/decks/filtered.rs b/rslib/src/decks/filtered.rs new file mode 100644 index 000000000..0cb40bec2 --- /dev/null +++ b/rslib/src/decks/filtered.rs @@ -0,0 +1,38 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +pub use crate::backend_proto::{ + deck_kind::Kind as DeckKind, Deck as DeckProto, DeckCommon, DeckKind as DeckKindProto, + FilteredDeck, NormalDeck, +}; +use crate::decks::FilteredSearchTerm; +use crate::prelude::*; + +impl Deck { + pub fn new_filtered() -> Deck { + let mut filt = FilteredDeck::default(); + filt.search_terms.push(FilteredSearchTerm { + search: "".into(), + limit: 100, + order: 0, + }); + filt.preview_delay = 10; + filt.reschedule = true; + Deck { + id: DeckID(0), + name: "".into(), + mtime_secs: TimestampSecs(0), + usn: Usn(0), + common: DeckCommon { + study_collapsed: true, + browser_collapsed: true, + ..Default::default() + }, + kind: DeckKind::Filtered(filt), + } + } + + pub(crate) fn is_filtered(&self) -> bool { + matches!(self.kind, DeckKind::Filtered(_)) + } +} diff --git a/rslib/src/decks/mod.rs b/rslib/src/decks/mod.rs index 69b69bafe..d86a5a874 100644 --- a/rslib/src/decks/mod.rs +++ b/rslib/src/decks/mod.rs @@ -2,6 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html mod counts; +mod filtered; mod schema11; mod tree; pub(crate) mod undo; diff --git a/rslib/src/lib.rs b/rslib/src/lib.rs index 8994c8b7b..584607d62 100644 --- a/rslib/src/lib.rs +++ b/rslib/src/lib.rs @@ -15,7 +15,6 @@ pub mod dbcheck; pub mod deckconf; pub mod decks; pub mod err; -pub mod filtered; pub mod findreplace; mod fluent_proto; pub mod i18n; diff --git a/rslib/src/filtered.rs b/rslib/src/scheduler/filtered.rs similarity index 87% rename from rslib/src/filtered.rs rename to rslib/src/scheduler/filtered.rs index bc2a5047b..3fe178df9 100644 --- a/rslib/src/filtered.rs +++ b/rslib/src/scheduler/filtered.rs @@ -1,21 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -pub use crate::backend_proto::{ - deck_kind::Kind as DeckKind, Deck as DeckProto, DeckCommon, DeckKind as DeckKindProto, - FilteredDeck, NormalDeck, -}; -use crate::decks::{Deck, DeckID}; -use crate::decks::{FilteredSearchOrder, FilteredSearchTerm}; +use crate::decks::{FilteredDeck, FilteredSearchOrder, FilteredSearchTerm}; use crate::{ - card::{Card, CardID, CardQueue, CardType}, - collection::Collection, + card::{CardQueue, CardType}, config::SchedulerVersion, - err::Result, - prelude::AnkiError, + prelude::*, search::SortMode, - timestamp::TimestampSecs, - types::Usn, }; impl Card { @@ -131,35 +122,6 @@ impl Card { } } -impl Deck { - pub fn new_filtered() -> Deck { - let mut filt = FilteredDeck::default(); - filt.search_terms.push(FilteredSearchTerm { - search: "".into(), - limit: 100, - order: 0, - }); - filt.preview_delay = 10; - filt.reschedule = true; - Deck { - id: DeckID(0), - name: "".into(), - mtime_secs: TimestampSecs(0), - usn: Usn(0), - common: DeckCommon { - study_collapsed: true, - browser_collapsed: true, - ..Default::default() - }, - kind: DeckKind::Filtered(filt), - } - } - - pub(crate) fn is_filtered(&self) -> bool { - matches!(self.kind, DeckKind::Filtered(_)) - } -} - pub(crate) struct DeckFilterContext<'a> { pub target_deck: DeckID, pub config: &'a FilteredDeck, @@ -172,7 +134,8 @@ impl Collection { pub fn empty_filtered_deck(&mut self, did: DeckID) -> Result<()> { self.transact_no_undo(|col| col.return_all_cards_in_filtered_deck(did)) } - pub(super) fn return_all_cards_in_filtered_deck(&mut self, did: DeckID) -> Result<()> { + + pub(crate) fn return_all_cards_in_filtered_deck(&mut self, did: DeckID) -> Result<()> { let cids = self.storage.all_cards_in_single_deck(did)?; self.return_cards_to_home_deck(&cids) } diff --git a/rslib/src/scheduler/mod.rs b/rslib/src/scheduler/mod.rs index 01b1cda82..6a13d2390 100644 --- a/rslib/src/scheduler/mod.rs +++ b/rslib/src/scheduler/mod.rs @@ -6,6 +6,7 @@ use crate::{collection::Collection, config::SchedulerVersion, err::Result, prelu pub mod answering; pub mod bury_and_suspend; pub(crate) mod congrats; +mod filtered; mod learning; pub mod new; pub(crate) mod queue;