mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
tidy up Rust imports
rustfmt can do this automatically, but only when run with a nightly toolchain, so it needs to be manually done for now - see rslib/rusfmt.toml
This commit is contained in:
parent
262b50445c
commit
64ebc32b3d
128 changed files with 649 additions and 524 deletions
|
@ -1,8 +1,7 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::{env, fmt::Write, path::PathBuf};
|
||||||
use std::{env, fmt::Write};
|
|
||||||
|
|
||||||
struct CustomGenerator {}
|
struct CustomGenerator {}
|
||||||
|
|
||||||
|
|
4
rslib/rustfmt.toml
Normal file
4
rslib/rustfmt.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# this is not supported on stable Rust, and is ignored by the Bazel rules; it is only
|
||||||
|
# useful for manual invocation with 'cargo +nightly fmt'
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
group_imports = "StdExternalCrate"
|
|
@ -1,8 +1,7 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::adding::DeckAndNotetype;
|
use crate::{adding::DeckAndNotetype, backend_proto::DeckAndNotetype as DeckAndNotetypeProto};
|
||||||
use crate::backend_proto::DeckAndNotetype as DeckAndNotetypeProto;
|
|
||||||
|
|
||||||
impl From<DeckAndNotetype> for DeckAndNotetypeProto {
|
impl From<DeckAndNotetype> for DeckAndNotetypeProto {
|
||||||
fn from(s: DeckAndNotetype) -> Self {
|
fn from(s: DeckAndNotetype) -> Self {
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
use crate::prelude::*;
|
pub(super) use crate::backend_proto::cards_service::Service as CardsService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::cards_service::Service as CardsService;
|
|
||||||
|
|
||||||
impl CardsService for Backend {
|
impl CardsService for Backend {
|
||||||
fn get_card(&self, input: pb::CardId) -> Result<pb::Card> {
|
fn get_card(&self, input: pb::CardId) -> Result<pb::Card> {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::cardrendering_service::Service as CardRenderingService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
latex::{extract_latex, extract_latex_expanding_clozes, ExtractedLatex},
|
latex::{extract_latex, extract_latex_expanding_clozes, ExtractedLatex},
|
||||||
|
@ -11,7 +12,6 @@ use crate::{
|
||||||
template::RenderedNode,
|
template::RenderedNode,
|
||||||
text::{extract_av_tags, sanitize_html_no_images, strip_av_tags, AvTag},
|
text::{extract_av_tags, sanitize_html_no_images, strip_av_tags, AvTag},
|
||||||
};
|
};
|
||||||
pub(super) use pb::cardrendering_service::Service as CardRenderingService;
|
|
||||||
|
|
||||||
impl CardRenderingService for Backend {
|
impl CardRenderingService for Backend {
|
||||||
fn extract_av_tags(&self, input: pb::ExtractAvTagsIn) -> Result<pb::ExtractAvTagsOut> {
|
fn extract_av_tags(&self, input: pb::ExtractAvTagsIn) -> Result<pb::ExtractAvTagsOut> {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use slog::error;
|
||||||
|
|
||||||
use super::{progress::Progress, Backend};
|
use super::{progress::Progress, Backend};
|
||||||
|
pub(super) use crate::backend_proto::collection_service::Service as CollectionService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::progress::progress_to_proto,
|
backend::progress::progress_to_proto,
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
@ -9,8 +12,6 @@ use crate::{
|
||||||
log::{self, default_logger},
|
log::{self, default_logger},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::collection_service::Service as CollectionService;
|
|
||||||
use slog::error;
|
|
||||||
|
|
||||||
impl CollectionService for Backend {
|
impl CollectionService for Backend {
|
||||||
fn latest_progress(&self, _input: pb::Empty) -> Result<pb::Progress> {
|
fn latest_progress(&self, _input: pb::Empty) -> Result<pb::Progress> {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::config_service::Service as ConfigService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
backend_proto::config::{bool::Key as BoolKeyProto, string::Key as StringKeyProto},
|
||||||
config::{BoolKey, StringKey},
|
config::{BoolKey, StringKey},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use pb::config::bool::Key as BoolKeyProto;
|
|
||||||
use pb::config::string::Key as StringKeyProto;
|
|
||||||
pub(super) use pb::config_service::Service as ConfigService;
|
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
impl From<BoolKeyProto> for BoolKey {
|
impl From<BoolKeyProto> for BoolKey {
|
||||||
fn from(k: BoolKeyProto) -> Self {
|
fn from(k: BoolKeyProto) -> Self {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::{prelude::*, storage::SqliteStorage};
|
|
||||||
use rusqlite::{
|
use rusqlite::{
|
||||||
types::{FromSql, FromSqlError, ToSql, ToSqlOutput, ValueRef},
|
types::{FromSql, FromSqlError, ToSql, ToSqlOutput, ValueRef},
|
||||||
OptionalExtension,
|
OptionalExtension,
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{prelude::*, storage::SqliteStorage};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(tag = "kind", rename_all = "lowercase")]
|
#[serde(tag = "kind", rename_all = "lowercase")]
|
||||||
pub(super) enum DbRequest {
|
pub(super) enum DbRequest {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::deckconfig_service::Service as DeckConfigService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
deckconf::{DeckConf, DeckConfSchema11, UpdateDeckConfigsIn},
|
deckconf::{DeckConf, DeckConfSchema11, UpdateDeckConfigsIn},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::deckconfig_service::Service as DeckConfigService;
|
|
||||||
|
|
||||||
impl DeckConfigService for Backend {
|
impl DeckConfigService for Backend {
|
||||||
fn add_or_update_deck_config_legacy(
|
fn add_or_update_deck_config_legacy(
|
||||||
|
|
|
@ -4,13 +4,13 @@
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::decks_service::Service as DecksService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{self as pb},
|
backend_proto::{self as pb},
|
||||||
decks::{DeckSchema11, FilteredSearchOrder},
|
decks::{DeckSchema11, FilteredSearchOrder},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::filtered::FilteredDeckForUpdate,
|
scheduler::filtered::FilteredDeckForUpdate,
|
||||||
};
|
};
|
||||||
pub(super) use pb::decks_service::Service as DecksService;
|
|
||||||
|
|
||||||
impl DecksService for Backend {
|
impl DecksService for Backend {
|
||||||
fn add_deck_legacy(&self, input: pb::Json) -> Result<pb::OpChangesWithId> {
|
fn add_deck_legacy(&self, input: pb::Json) -> Result<pb::OpChangesWithId> {
|
||||||
|
|
|
@ -3,12 +3,11 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
backend_proto::backend_error::Kind,
|
||||||
error::{AnkiError, SyncErrorKind},
|
error::{AnkiError, SyncErrorKind},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use pb::backend_error::Kind;
|
|
||||||
|
|
||||||
impl AnkiError {
|
impl AnkiError {
|
||||||
pub(super) fn into_protobuf(self, tr: &I18n) -> pb::BackendError {
|
pub(super) fn into_protobuf(self, tr: &I18n) -> pb::BackendError {
|
||||||
let localized = self.localized_description(tr);
|
let localized = self.localized_description(tr);
|
||||||
|
|
|
@ -3,14 +3,15 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use fluent::{FluentArgs, FluentValue};
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::i18n_service::Service as I18nService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::timespan::{answer_button_time, time_span},
|
scheduler::timespan::{answer_button_time, time_span},
|
||||||
};
|
};
|
||||||
use fluent::{FluentArgs, FluentValue};
|
|
||||||
pub(super) use pb::i18n_service::Service as I18nService;
|
|
||||||
|
|
||||||
impl I18nService for Backend {
|
impl I18nService for Backend {
|
||||||
fn translate_string(&self, input: pb::TranslateStringIn) -> Result<pb::String> {
|
fn translate_string(&self, input: pb::TranslateStringIn) -> Result<pb::String> {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{progress::Progress, Backend};
|
use super::{progress::Progress, Backend};
|
||||||
|
pub(super) use crate::backend_proto::media_service::Service as MediaService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
media::{check::MediaChecker, MediaManager},
|
media::{check::MediaChecker, MediaManager},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::media_service::Service as MediaService;
|
|
||||||
|
|
||||||
impl MediaService for Backend {
|
impl MediaService for Backend {
|
||||||
// media
|
// media
|
||||||
|
|
|
@ -26,6 +26,16 @@ mod stats;
|
||||||
mod sync;
|
mod sync;
|
||||||
mod tags;
|
mod tags;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
result,
|
||||||
|
sync::{Arc, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
use progress::AbortHandleSlot;
|
||||||
|
use prost::Message;
|
||||||
|
use tokio::runtime::{self, Runtime};
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
card::CardsService,
|
card::CardsService,
|
||||||
cardrendering::CardRenderingService,
|
cardrendering::CardRenderingService,
|
||||||
|
@ -44,7 +54,6 @@ use self::{
|
||||||
sync::{SyncService, SyncState},
|
sync::{SyncService, SyncState},
|
||||||
tags::TagsService,
|
tags::TagsService,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::dbproxy::db_command_bytes,
|
backend::dbproxy::db_command_bytes,
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
@ -52,14 +61,6 @@ use crate::{
|
||||||
error::{AnkiError, Result},
|
error::{AnkiError, Result},
|
||||||
i18n::I18n,
|
i18n::I18n,
|
||||||
};
|
};
|
||||||
use once_cell::sync::OnceCell;
|
|
||||||
use progress::AbortHandleSlot;
|
|
||||||
use prost::Message;
|
|
||||||
use std::{
|
|
||||||
result,
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
use tokio::runtime::{self, Runtime};
|
|
||||||
|
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
col: Arc<Mutex<Option<Collection>>>,
|
col: Arc<Mutex<Option<Collection>>>,
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::notes_service::Service as NotesService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{self as pb},
|
backend_proto::{self as pb},
|
||||||
cloze::add_cloze_numbers_in_string,
|
cloze::add_cloze_numbers_in_string,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::notes_service::Service as NotesService;
|
|
||||||
|
|
||||||
impl NotesService for Backend {
|
impl NotesService for Backend {
|
||||||
fn new_note(&self, input: pb::NotetypeId) -> Result<pb::Note> {
|
fn new_note(&self, input: pb::NotetypeId) -> Result<pb::Note> {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::notetypes_service::Service as NotetypesService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
notetype::{all_stock_notetypes, Notetype, NotetypeSchema11},
|
notetype::{all_stock_notetypes, Notetype, NotetypeSchema11},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
pub(super) use pb::notetypes_service::Service as NotetypesService;
|
|
||||||
|
|
||||||
impl NotetypesService for Backend {
|
impl NotetypesService for Backend {
|
||||||
fn add_or_update_notetype(&self, input: pb::AddOrUpdateNotetypeIn) -> Result<pb::NotetypeId> {
|
fn add_or_update_notetype(&self, input: pb::AddOrUpdateNotetypeIn) -> Result<pb::NotetypeId> {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use futures::future::AbortHandle;
|
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use futures::future::AbortHandle;
|
||||||
|
|
||||||
|
use super::Backend;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
dbcheck::DatabaseCheckProgress,
|
dbcheck::DatabaseCheckProgress,
|
||||||
|
@ -12,8 +14,6 @@ use crate::{
|
||||||
sync::{FullSyncProgress, NormalSyncProgress, SyncStage},
|
sync::{FullSyncProgress, NormalSyncProgress, SyncStage},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::Backend;
|
|
||||||
|
|
||||||
pub(super) struct ThrottlingProgressHandler {
|
pub(super) struct ThrottlingProgressHandler {
|
||||||
pub state: Arc<Mutex<ProgressState>>,
|
pub state: Arc<Mutex<ProgressState>>,
|
||||||
pub last_update: coarsetime::Instant,
|
pub last_update: coarsetime::Instant,
|
||||||
|
|
|
@ -5,6 +5,7 @@ mod answering;
|
||||||
mod states;
|
mod states;
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::scheduling_service::Service as SchedulingService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{self as pb},
|
backend_proto::{self as pb},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -14,7 +15,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
stats::studied_today,
|
stats::studied_today,
|
||||||
};
|
};
|
||||||
pub(super) use pb::scheduling_service::Service as SchedulingService;
|
|
||||||
|
|
||||||
impl SchedulingService for Backend {
|
impl SchedulingService for Backend {
|
||||||
/// This behaves like _updateCutoff() in older code - it also unburies at the start of
|
/// This behaves like _updateCutoff() in older code - it also unburies at the start of
|
||||||
|
|
|
@ -7,6 +7,7 @@ mod search_node;
|
||||||
use std::{convert::TryInto, str::FromStr, sync::Arc};
|
use std::{convert::TryInto, str::FromStr, sync::Arc};
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::search_service::Service as SearchService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
backend_proto::sort_order::Value as SortOrderProto,
|
backend_proto::sort_order::Value as SortOrderProto,
|
||||||
|
@ -14,7 +15,6 @@ use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
search::{concatenate_searches, replace_search_node, write_nodes, Node, SortMode},
|
search::{concatenate_searches, replace_search_node, write_nodes, Node, SortMode},
|
||||||
};
|
};
|
||||||
pub(super) use pb::search_service::Service as SearchService;
|
|
||||||
|
|
||||||
impl SearchService for Backend {
|
impl SearchService for Backend {
|
||||||
fn build_search_string(&self, input: pb::SearchNode) -> Result<pb::String> {
|
fn build_search_string(&self, input: pb::SearchNode) -> Result<pb::String> {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use itertools::Itertools;
|
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
@ -18,9 +19,7 @@ impl TryFrom<pb::SearchNode> for Node {
|
||||||
type Error = AnkiError;
|
type Error = AnkiError;
|
||||||
|
|
||||||
fn try_from(msg: pb::SearchNode) -> std::result::Result<Self, Self::Error> {
|
fn try_from(msg: pb::SearchNode) -> std::result::Result<Self, Self::Error> {
|
||||||
use pb::search_node::group::Joiner;
|
use pb::search_node::{group::Joiner, Filter, Flag};
|
||||||
use pb::search_node::Filter;
|
|
||||||
use pb::search_node::Flag;
|
|
||||||
Ok(if let Some(filter) = msg.filter {
|
Ok(if let Some(filter) = msg.filter {
|
||||||
match filter {
|
match filter {
|
||||||
Filter::Tag(s) => Node::Search(SearchNode::Tag(escape_anki_wildcards(&s))),
|
Filter::Tag(s) => Node::Search(SearchNode::Tag(escape_anki_wildcards(&s))),
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::Backend;
|
use super::Backend;
|
||||||
|
pub(super) use crate::backend_proto::stats_service::Service as StatsService;
|
||||||
use crate::{backend_proto as pb, prelude::*};
|
use crate::{backend_proto as pb, prelude::*};
|
||||||
pub(super) use pb::stats_service::Service as StatsService;
|
|
||||||
|
|
||||||
impl StatsService for Backend {
|
impl StatsService for Backend {
|
||||||
fn card_stats(&self, input: pb::CardId) -> Result<pb::String> {
|
fn card_stats(&self, input: pb::CardId) -> Result<pb::String> {
|
||||||
|
|
|
@ -8,6 +8,8 @@ use std::sync::Arc;
|
||||||
use futures::future::{AbortHandle, AbortRegistration, Abortable};
|
use futures::future::{AbortHandle, AbortRegistration, Abortable};
|
||||||
use slog::warn;
|
use slog::warn;
|
||||||
|
|
||||||
|
use super::{progress::AbortHandleSlot, Backend};
|
||||||
|
pub(super) use crate::backend_proto::sync_service::Service as SyncService;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
collection::open_collection,
|
collection::open_collection,
|
||||||
|
@ -19,9 +21,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{progress::AbortHandleSlot, Backend};
|
|
||||||
pub(super) use pb::sync_service::Service as SyncService;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(super) struct SyncState {
|
pub(super) struct SyncState {
|
||||||
remote_sync_status: RemoteSyncStatus,
|
remote_sync_status: RemoteSyncStatus,
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use std::{path::PathBuf, sync::MutexGuard};
|
use std::{path::PathBuf, sync::MutexGuard};
|
||||||
|
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
use crate::backend::{Backend, BackendState};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
backend::{Backend, BackendState},
|
||||||
error::SyncErrorKind,
|
error::SyncErrorKind,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
sync::{
|
sync::{
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{notes::to_note_ids, Backend};
|
use super::{notes::to_note_ids, Backend};
|
||||||
|
pub(super) use crate::backend_proto::tags_service::Service as TagsService;
|
||||||
use crate::{backend_proto as pb, prelude::*};
|
use crate::{backend_proto as pb, prelude::*};
|
||||||
pub(super) use pb::tags_service::Service as TagsService;
|
|
||||||
|
|
||||||
impl TagsService for Backend {
|
impl TagsService for Backend {
|
||||||
fn clear_unused_tags(&self, _input: pb::Empty) -> Result<pb::OpChangesWithCount> {
|
fn clear_unused_tags(&self, _input: pb::Empty) -> Result<pb::OpChangesWithCount> {
|
||||||
|
|
|
@ -6,14 +6,14 @@ use std::sync::Arc;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
|
use strum::{Display, EnumIter, EnumString, IntoEnumIterator};
|
||||||
|
|
||||||
use crate::error::{AnkiError, Result};
|
|
||||||
use crate::i18n::I18n;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
card::{Card, CardId, CardQueue, CardType},
|
card::{Card, CardId, CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
config::BoolKey,
|
config::BoolKey,
|
||||||
decks::{Deck, DeckId},
|
decks::{Deck, DeckId},
|
||||||
|
error::{AnkiError, Result},
|
||||||
|
i18n::I18n,
|
||||||
notes::{Note, NoteId},
|
notes::{Note, NoteId},
|
||||||
notetype::{CardTemplate, Notetype, NotetypeKind},
|
notetype::{CardTemplate, Notetype, NotetypeKind},
|
||||||
scheduler::{timespan::time_span, timing::SchedTimingToday},
|
scheduler::{timespan::time_span, timing::SchedTimingToday},
|
||||||
|
|
|
@ -3,18 +3,24 @@
|
||||||
|
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
use crate::error::{AnkiError, FilteredDeckError, Result};
|
use std::collections::HashSet;
|
||||||
use crate::notes::NoteId;
|
|
||||||
use crate::{
|
|
||||||
collection::Collection, config::SchedulerVersion, prelude::*, timestamp::TimestampSecs,
|
|
||||||
types::Usn,
|
|
||||||
};
|
|
||||||
use crate::{define_newtype, ops::StateChanges};
|
|
||||||
|
|
||||||
use crate::{deckconf::DeckConf, decks::DeckId};
|
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use std::collections::HashSet;
|
|
||||||
|
use crate::{
|
||||||
|
collection::Collection,
|
||||||
|
config::SchedulerVersion,
|
||||||
|
deckconf::DeckConf,
|
||||||
|
decks::DeckId,
|
||||||
|
define_newtype,
|
||||||
|
error::{AnkiError, FilteredDeckError, Result},
|
||||||
|
notes::NoteId,
|
||||||
|
ops::StateChanges,
|
||||||
|
prelude::*,
|
||||||
|
timestamp::TimestampSecs,
|
||||||
|
types::Usn,
|
||||||
|
};
|
||||||
|
|
||||||
define_newtype!(CardId, i64);
|
define_newtype!(CardId, i64);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::latex::contains_latex;
|
use std::{borrow::Cow, collections::HashSet};
|
||||||
use crate::template::RenderContext;
|
|
||||||
use crate::text::strip_html_preserving_entities;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Captures;
|
use regex::{Captures, Regex};
|
||||||
use regex::Regex;
|
|
||||||
use std::borrow::Cow;
|
use crate::{latex::contains_latex, template::RenderContext, text::strip_html_preserving_entities};
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CLOZE: Regex = Regex::new(
|
static ref CLOZE: Regex = Regex::new(
|
||||||
|
@ -182,9 +180,10 @@ pub(crate) fn cloze_only_filter<'a>(text: &'a str, context: &RenderContext) -> C
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::text::strip_html;
|
use crate::text::strip_html;
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cloze() {
|
fn cloze() {
|
||||||
|
|
|
@ -5,18 +5,20 @@ pub(crate) mod timestamps;
|
||||||
mod transact;
|
mod transact;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
use crate::i18n::I18n;
|
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
||||||
use crate::types::Usn;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
browser_table,
|
browser_table,
|
||||||
decks::{Deck, DeckId},
|
decks::{Deck, DeckId},
|
||||||
|
error::Result,
|
||||||
|
i18n::I18n,
|
||||||
|
log::Logger,
|
||||||
notetype::{Notetype, NotetypeId},
|
notetype::{Notetype, NotetypeId},
|
||||||
|
scheduler::{queue::CardQueues, SchedulerInfo},
|
||||||
storage::SqliteStorage,
|
storage::SqliteStorage,
|
||||||
|
types::Usn,
|
||||||
undo::UndoManager,
|
undo::UndoManager,
|
||||||
};
|
};
|
||||||
use crate::{error::Result, scheduler::queue::CardQueues};
|
|
||||||
use crate::{log::Logger, scheduler::SchedulerInfo};
|
|
||||||
use std::{collections::HashMap, path::PathBuf, sync::Arc};
|
|
||||||
|
|
||||||
pub fn open_collection<P: Into<PathBuf>>(
|
pub fn open_collection<P: Into<PathBuf>>(
|
||||||
path: P,
|
path: P,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use serde_aux::field_attributes::deserialize_bool_from_anything;
|
use serde_aux::field_attributes::deserialize_bool_from_anything;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
||||||
#[strum(serialize_all = "camelCase")]
|
#[strum(serialize_all = "camelCase")]
|
||||||
pub enum BoolKey {
|
pub enum BoolKey {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Auxillary deck state, stored in the config table.
|
/// Auxillary deck state, stored in the config table.
|
||||||
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
||||||
#[strum(serialize_all = "camelCase")]
|
#[strum(serialize_all = "camelCase")]
|
||||||
|
|
|
@ -8,13 +8,14 @@ pub(crate) mod schema11;
|
||||||
mod string;
|
mod string;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
pub use self::{bool::BoolKey, string::StringKey};
|
|
||||||
use crate::prelude::*;
|
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use slog::warn;
|
use slog::warn;
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
|
pub use self::{bool::BoolKey, string::StringKey};
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Only used when updating/undoing.
|
/// Only used when updating/undoing.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ConfigEntry {
|
pub(crate) struct ConfigEntry {
|
||||||
|
@ -263,8 +264,7 @@ pub(crate) enum Weekday {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::collection::open_test_collection;
|
use crate::{collection::open_test_collection, decks::DeckId};
|
||||||
use crate::decks::DeckId;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults() {
|
fn defaults() {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
use super::ConfigKey;
|
use super::ConfigKey;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use strum::IntoStaticStr;
|
|
||||||
|
|
||||||
/// Notetype config packed into a collection config key. This may change
|
/// Notetype config packed into a collection config key. This may change
|
||||||
/// frequently, and we want to avoid the potentially expensive notetype
|
/// frequently, and we want to avoid the potentially expensive notetype
|
||||||
/// write/sync.
|
/// write/sync.
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
||||||
#[strum(serialize_all = "camelCase")]
|
#[strum(serialize_all = "camelCase")]
|
||||||
pub enum StringKey {
|
pub enum StringKey {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{collections::HashSet, sync::Arc};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
use slog::debug;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
|
@ -13,9 +18,6 @@ use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
timestamp::{TimestampMillis, TimestampSecs},
|
timestamp::{TimestampMillis, TimestampSecs},
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
|
||||||
use slog::debug;
|
|
||||||
use std::{collections::HashSet, sync::Arc};
|
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq)]
|
#[derive(Debug, Default, PartialEq)]
|
||||||
pub struct CheckDatabaseOutput {
|
pub struct CheckDatabaseOutput {
|
||||||
|
|
|
@ -5,13 +5,12 @@ mod schema11;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
mod update;
|
mod update;
|
||||||
|
|
||||||
pub use {
|
pub use schema11::{DeckConfSchema11, NewCardOrderSchema11};
|
||||||
crate::backend_proto::{
|
pub use update::UpdateDeckConfigsIn;
|
||||||
deck_config::config::{LeechAction, NewCardOrder, ReviewCardOrder, ReviewMix},
|
|
||||||
deck_config::Config as DeckConfigInner,
|
pub use crate::backend_proto::deck_config::{
|
||||||
},
|
config::{LeechAction, NewCardOrder, ReviewCardOrder, ReviewMix},
|
||||||
schema11::{DeckConfSchema11, NewCardOrderSchema11},
|
Config as DeckConfigInner,
|
||||||
update::UpdateDeckConfigsIn,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Old deck config and cards table store 250% as 2500.
|
/// Old deck config and cards table store 250% as 2500.
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{DeckConf, DeckConfId, INITIAL_EASE_FACTOR_THOUSANDS};
|
use std::collections::HashMap;
|
||||||
use super::{DeckConfigInner, NewCardOrder};
|
|
||||||
use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn};
|
|
||||||
use serde_aux::field_attributes::deserialize_number_from_string;
|
use serde_aux::field_attributes::deserialize_number_from_string;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use serde_tuple::Serialize_tuple;
|
use serde_tuple::Serialize_tuple;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
use super::{DeckConf, DeckConfId, DeckConfigInner, NewCardOrder, INITIAL_EASE_FACTOR_THOUSANDS};
|
||||||
|
use crate::{serde::default_on_invalid, timestamp::TimestampSecs, types::Usn};
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use pb::deck_configs_for_update::{ConfigWithExtra, CurrentDeck};
|
use crate::{
|
||||||
|
backend_proto as pb,
|
||||||
use crate::{backend_proto as pb, prelude::*};
|
backend_proto::deck_configs_for_update::{ConfigWithExtra, CurrentDeck},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct UpdateDeckConfigsIn {
|
pub struct UpdateDeckConfigsIn {
|
||||||
pub target_deck_id: DeckId,
|
pub target_deck_id: DeckId,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
use crate::{backend_proto as pb, prelude::*};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::{backend_proto as pb, prelude::*};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct DueCounts {
|
pub(crate) struct DueCounts {
|
||||||
pub new: u32,
|
pub new: u32,
|
||||||
|
|
|
@ -13,22 +13,26 @@ mod stats;
|
||||||
mod tree;
|
mod tree;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub(crate) use counts::DueCounts;
|
||||||
|
pub(crate) use name::immediate_parent_name;
|
||||||
|
pub use name::NativeDeckName;
|
||||||
|
pub use schema11::DeckSchema11;
|
||||||
|
|
||||||
pub use crate::backend_proto::{
|
pub use crate::backend_proto::{
|
||||||
deck::filtered::{search_term::Order as FilteredSearchOrder, SearchTerm as FilteredSearchTerm},
|
deck::{
|
||||||
deck::kind_container::Kind as DeckKind,
|
filtered::{search_term::Order as FilteredSearchOrder, SearchTerm as FilteredSearchTerm},
|
||||||
deck::KindContainer as DeckKindContainer,
|
kind_container::Kind as DeckKind,
|
||||||
deck::{Common as DeckCommon, Filtered as FilteredDeck, Normal as NormalDeck},
|
Common as DeckCommon, Filtered as FilteredDeck, KindContainer as DeckKindContainer,
|
||||||
|
Normal as NormalDeck,
|
||||||
|
},
|
||||||
Deck as DeckProto,
|
Deck as DeckProto,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
define_newtype, error::FilteredDeckError, markdown::render_markdown, prelude::*,
|
define_newtype, error::FilteredDeckError, markdown::render_markdown, prelude::*,
|
||||||
text::sanitize_html_no_images,
|
text::sanitize_html_no_images,
|
||||||
};
|
};
|
||||||
pub(crate) use counts::DueCounts;
|
|
||||||
pub(crate) use name::immediate_parent_name;
|
|
||||||
pub use name::NativeDeckName;
|
|
||||||
pub use schema11::DeckSchema11;
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
define_newtype!(DeckId, i64);
|
define_newtype!(DeckId, i64);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
use crate::{prelude::*, text::normalize_to_nfc};
|
|
||||||
use itertools::Itertools;
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
use crate::{prelude::*, text::normalize_to_nfc};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct NativeDeckName(String);
|
pub struct NativeDeckName(String);
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
use serde_tuple::Serialize_tuple;
|
||||||
|
|
||||||
use super::{DeckCommon, FilteredDeck, FilteredSearchTerm, NormalDeck};
|
use super::{DeckCommon, FilteredDeck, FilteredSearchTerm, NormalDeck};
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
serde::{default_on_invalid, deserialize_bool_from_anything, deserialize_number_from_string},
|
serde::{default_on_invalid, deserialize_bool_from_anything, deserialize_number_from_string},
|
||||||
};
|
};
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
use serde_json::Value;
|
|
||||||
use serde_tuple::Serialize_tuple;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Serialize, PartialEq, Debug, Clone)]
|
#[derive(Serialize, PartialEq, Debug, Clone)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum DeckSchema11 {
|
pub enum DeckSchema11 {
|
||||||
|
@ -21,10 +22,11 @@ pub enum DeckSchema11 {
|
||||||
|
|
||||||
// serde doesn't support integer/bool enum tags, so we manually pick the correct variant
|
// serde doesn't support integer/bool enum tags, so we manually pick the correct variant
|
||||||
mod dynfix {
|
mod dynfix {
|
||||||
use super::{DeckSchema11, FilteredDeckSchema11, NormalDeckSchema11};
|
|
||||||
use serde::de::{self, Deserialize, Deserializer};
|
use serde::de::{self, Deserialize, Deserializer};
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
|
|
||||||
|
use super::{DeckSchema11, FilteredDeckSchema11, NormalDeckSchema11};
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for DeckSchema11 {
|
impl<'de> Deserialize<'de> for DeckSchema11 {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<DeckSchema11, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<DeckSchema11, D::Error>
|
||||||
where
|
where
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
iter::Peekable,
|
||||||
|
};
|
||||||
|
|
||||||
|
use serde_tuple::Serialize_tuple;
|
||||||
|
use unicase::UniCase;
|
||||||
|
|
||||||
use super::DueCounts;
|
use super::DueCounts;
|
||||||
pub use crate::backend_proto::set_deck_collapsed_in::Scope as DeckCollapseScope;
|
pub use crate::backend_proto::set_deck_collapsed_in::Scope as DeckCollapseScope;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::DeckTreeNode, config::SchedulerVersion, ops::OpOutput, prelude::*, undo::Op,
|
backend_proto::DeckTreeNode, config::SchedulerVersion, ops::OpOutput, prelude::*, undo::Op,
|
||||||
};
|
};
|
||||||
use serde_tuple::Serialize_tuple;
|
|
||||||
use std::{
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
iter::Peekable,
|
|
||||||
};
|
|
||||||
use unicase::UniCase;
|
|
||||||
|
|
||||||
fn deck_names_to_tree(names: Vec<(DeckId, String)>) -> DeckTreeNode {
|
fn deck_names_to_tree(names: Vec<(DeckId, String)>) -> DeckTreeNode {
|
||||||
let mut top = DeckTreeNode::default();
|
let mut top = DeckTreeNode::default();
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::str::Utf8Error;
|
||||||
|
|
||||||
use anki_i18n::I18n;
|
use anki_i18n::I18n;
|
||||||
use rusqlite::{types::FromSqlError, Error};
|
use rusqlite::{types::FromSqlError, Error};
|
||||||
use std::str::Utf8Error;
|
|
||||||
|
|
||||||
use super::AnkiError;
|
use super::AnkiError;
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,15 @@ mod filtered;
|
||||||
mod network;
|
mod network;
|
||||||
mod search;
|
mod search;
|
||||||
|
|
||||||
pub use {
|
use std::{fmt::Display, io};
|
||||||
db::{DbError, DbErrorKind},
|
|
||||||
filtered::FilteredDeckError,
|
pub use db::{DbError, DbErrorKind};
|
||||||
network::{NetworkError, NetworkErrorKind, SyncError, SyncErrorKind},
|
pub use filtered::FilteredDeckError;
|
||||||
search::{ParseError, SearchErrorKind},
|
pub use network::{NetworkError, NetworkErrorKind, SyncError, SyncErrorKind};
|
||||||
};
|
pub use search::{ParseError, SearchErrorKind};
|
||||||
|
use tempfile::PathPersistError;
|
||||||
|
|
||||||
use crate::i18n::I18n;
|
use crate::i18n::I18n;
|
||||||
use std::{fmt::Display, io};
|
|
||||||
use tempfile::PathPersistError;
|
|
||||||
|
|
||||||
pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::AnkiError;
|
|
||||||
|
|
||||||
use anki_i18n::I18n;
|
use anki_i18n::I18n;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
|
use super::AnkiError;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct NetworkError {
|
pub struct NetworkError {
|
||||||
pub info: String,
|
pub info: String,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::AnkiError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
use anki_i18n::I18n;
|
use anki_i18n::I18n;
|
||||||
use nom::error::{ErrorKind as NomErrorKind, ParseError as NomParseError};
|
use nom::error::{ErrorKind as NomErrorKind, ParseError as NomParseError};
|
||||||
use std::num::ParseIntError;
|
|
||||||
|
use super::AnkiError;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum ParseError<'a> {
|
pub enum ParseError<'a> {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
error::{AnkiError, Result},
|
error::{AnkiError, Result},
|
||||||
|
@ -8,8 +12,6 @@ use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
text::normalize_to_nfc,
|
text::normalize_to_nfc,
|
||||||
};
|
};
|
||||||
use regex::Regex;
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
pub struct FindReplaceContext {
|
pub struct FindReplaceContext {
|
||||||
nids: Vec<NoteId>,
|
nids: Vec<NoteId>,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::cloze::expand_clozes_to_reveal_latex;
|
use std::borrow::Cow;
|
||||||
use crate::media::files::sha1_of_data;
|
|
||||||
use crate::text::strip_html;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
use std::borrow::Cow;
|
|
||||||
|
use crate::{cloze::expand_clozes_to_reveal_latex, media::files::sha1_of_data, text::strip_html};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref LATEX: Regex = Regex::new(
|
static ref LATEX: Regex = Regex::new(
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{fs, fs::OpenOptions, io};
|
||||||
|
|
||||||
pub use slog::{debug, error, Logger};
|
pub use slog::{debug, error, Logger};
|
||||||
use slog::{slog_o, Drain};
|
use slog::{slog_o, Drain};
|
||||||
use slog_async::OverflowStrategy;
|
use slog_async::OverflowStrategy;
|
||||||
use std::fs::OpenOptions;
|
|
||||||
use std::{fs, io};
|
|
||||||
|
|
||||||
const LOG_ROTATE_BYTES: u64 = 50 * 1024 * 1024;
|
const LOG_ROTATE_BYTES: u64 = 50 * 1024 * 1024;
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::error::{AnkiError, Result};
|
use std::{collections::HashMap, path::Path, time};
|
||||||
use crate::log::{debug, Logger};
|
|
||||||
use crate::media::database::{MediaDatabaseContext, MediaEntry};
|
use crate::{
|
||||||
use crate::media::files::{
|
error::{AnkiError, Result},
|
||||||
filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT,
|
log::{debug, Logger},
|
||||||
NONSYNCABLE_FILENAME,
|
media::{
|
||||||
|
database::{MediaDatabaseContext, MediaEntry},
|
||||||
|
files::{
|
||||||
|
filename_if_normalized, mtime_as_i64, sha1_of_file, MEDIA_SYNC_FILESIZE_LIMIT,
|
||||||
|
NONSYNCABLE_FILENAME,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::time;
|
|
||||||
|
|
||||||
struct FilesystemEntry {
|
struct FilesystemEntry {
|
||||||
fname: String,
|
fname: String,
|
||||||
|
@ -243,16 +246,17 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::error::Result;
|
use std::{fs, path::Path, time, time::Duration};
|
||||||
use crate::media::changetracker::ChangeTracker;
|
|
||||||
use crate::media::database::MediaEntry;
|
|
||||||
use crate::media::files::sha1_of_data;
|
|
||||||
use crate::media::MediaManager;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::{fs, time};
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::Result,
|
||||||
|
media::{
|
||||||
|
changetracker::ChangeTracker, database::MediaEntry, files::sha1_of_data, MediaManager,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// helper
|
// helper
|
||||||
fn change_mtime(p: &Path) {
|
fn change_mtime(p: &Path) {
|
||||||
let mtime = p.metadata().unwrap().modified().unwrap();
|
let mtime = p.metadata().unwrap().modified().unwrap();
|
||||||
|
|
|
@ -1,23 +1,32 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::collection::Collection;
|
use std::{
|
||||||
use crate::error::{AnkiError, DbErrorKind, Result};
|
borrow::Cow,
|
||||||
use crate::latex::extract_latex_expanding_clozes;
|
collections::{HashMap, HashSet},
|
||||||
use crate::log::debug;
|
fs, io,
|
||||||
use crate::media::database::MediaDatabaseContext;
|
path::Path,
|
||||||
use crate::media::files::{
|
|
||||||
data_for_file, filename_if_normalized, normalize_nfc_filename, trash_folder,
|
|
||||||
MEDIA_SYNC_FILESIZE_LIMIT,
|
|
||||||
};
|
};
|
||||||
use crate::notes::Note;
|
|
||||||
use crate::text::{normalize_to_nfc, MediaRef};
|
|
||||||
use crate::{media::MediaManager, text::extract_media_refs};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use std::path::Path;
|
use crate::{
|
||||||
use std::{borrow::Cow, fs, io};
|
collection::Collection,
|
||||||
|
error::{AnkiError, DbErrorKind, Result},
|
||||||
|
latex::extract_latex_expanding_clozes,
|
||||||
|
log::debug,
|
||||||
|
media::{
|
||||||
|
database::MediaDatabaseContext,
|
||||||
|
files::{
|
||||||
|
data_for_file, filename_if_normalized, normalize_nfc_filename, trash_folder,
|
||||||
|
MEDIA_SYNC_FILESIZE_LIMIT,
|
||||||
|
},
|
||||||
|
MediaManager,
|
||||||
|
},
|
||||||
|
notes::Note,
|
||||||
|
text::{extract_media_refs, normalize_to_nfc, MediaRef},
|
||||||
|
};
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref REMOTE_FILENAME: Regex = Regex::new("(?i)^https?://").unwrap();
|
static ref REMOTE_FILENAME: Regex = Regex::new("(?i)^https?://").unwrap();
|
||||||
|
@ -506,18 +515,23 @@ pub(crate) mod test {
|
||||||
pub(crate) const MEDIACHECK_ANKI2: &[u8] =
|
pub(crate) const MEDIACHECK_ANKI2: &[u8] =
|
||||||
include_bytes!("../../tests/support/mediacheck.anki2");
|
include_bytes!("../../tests/support/mediacheck.anki2");
|
||||||
|
|
||||||
use super::normalize_and_maybe_rename_files;
|
use std::{collections::HashMap, fs, io, path::Path};
|
||||||
use crate::collection::{open_collection, Collection};
|
|
||||||
use crate::error::Result;
|
|
||||||
use crate::i18n::I18n;
|
|
||||||
use crate::log;
|
|
||||||
use crate::media::check::{MediaCheckOutput, MediaChecker};
|
|
||||||
use crate::media::files::trash_folder;
|
|
||||||
use crate::media::MediaManager;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::{collections::HashMap, fs, io};
|
|
||||||
use tempfile::{tempdir, TempDir};
|
use tempfile::{tempdir, TempDir};
|
||||||
|
|
||||||
|
use super::normalize_and_maybe_rename_files;
|
||||||
|
use crate::{
|
||||||
|
collection::{open_collection, Collection},
|
||||||
|
error::Result,
|
||||||
|
i18n::I18n,
|
||||||
|
log,
|
||||||
|
media::{
|
||||||
|
check::{MediaCheckOutput, MediaChecker},
|
||||||
|
files::trash_folder,
|
||||||
|
MediaManager,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
fn common_setup() -> Result<(TempDir, MediaManager, Collection)> {
|
fn common_setup() -> Result<(TempDir, MediaManager, Collection)> {
|
||||||
let dir = tempdir()?;
|
let dir = tempdir()?;
|
||||||
let media_dir = dir.path().join("media");
|
let media_dir = dir.path().join("media");
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::error::Result;
|
use std::{collections::HashMap, path::Path};
|
||||||
|
|
||||||
use rusqlite::{params, Connection, OptionalExtension, Row, Statement, NO_PARAMS};
|
use rusqlite::{params, Connection, OptionalExtension, Row, Statement, NO_PARAMS};
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::path::Path;
|
use crate::error::Result;
|
||||||
|
|
||||||
fn trace(s: &str) {
|
fn trace(s: &str) {
|
||||||
println!("sql: {}", s)
|
println!("sql: {}", s)
|
||||||
|
@ -251,12 +252,13 @@ fn row_to_entry(row: &Row) -> rusqlite::Result<MediaEntry> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::error::Result;
|
|
||||||
use crate::media::database::MediaEntry;
|
|
||||||
use crate::media::files::sha1_of_data;
|
|
||||||
use crate::media::MediaManager;
|
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::Result,
|
||||||
|
media::{database::MediaEntry, files::sha1_of_data, MediaManager},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn database() -> Result<()> {
|
fn database() -> Result<()> {
|
||||||
let db_file = NamedTempFile::new()?;
|
let db_file = NamedTempFile::new()?;
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::error::{AnkiError, Result};
|
use std::{
|
||||||
use crate::log::{debug, Logger};
|
borrow::Cow,
|
||||||
|
fs, io,
|
||||||
|
io::Read,
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
time,
|
||||||
|
};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use sha1::Sha1;
|
use sha1::Sha1;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::io::Read;
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
use std::{fs, io, time};
|
|
||||||
use unicode_normalization::{is_nfc, UnicodeNormalization};
|
use unicode_normalization::{is_nfc, UnicodeNormalization};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::{AnkiError, Result},
|
||||||
|
log::{debug, Logger},
|
||||||
|
};
|
||||||
|
|
||||||
/// The maximum length we allow a filename to be. When combined
|
/// The maximum length we allow a filename to be. When combined
|
||||||
/// with the rest of the path, the full path needs to be under ~240 chars
|
/// with the rest of the path, the full path needs to be under ~240 chars
|
||||||
/// on some platforms, and some filesystems like eCryptFS will increase
|
/// on some platforms, and some filesystems like eCryptFS will increase
|
||||||
|
@ -426,12 +433,14 @@ pub(super) fn data_for_file(media_folder: &Path, fname: &str) -> Result<Option<V
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use crate::media::files::{
|
use crate::media::files::{
|
||||||
add_data_to_folder_uniquely, add_hash_suffix_to_file_stem, normalize_filename,
|
add_data_to_folder_uniquely, add_hash_suffix_to_file_stem, normalize_filename,
|
||||||
remove_files, sha1_of_data, truncate_filename, MAX_FILENAME_LENGTH,
|
remove_files, sha1_of_data, truncate_filename, MAX_FILENAME_LENGTH,
|
||||||
};
|
};
|
||||||
use std::borrow::Cow;
|
|
||||||
use tempfile::tempdir;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn normalize() {
|
fn normalize() {
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::error::Result;
|
use std::{
|
||||||
use crate::media::database::{open_or_create, MediaDatabaseContext, MediaEntry};
|
borrow::Cow,
|
||||||
use crate::media::files::{add_data_to_folder_uniquely, mtime_as_i64, remove_files, sha1_of_data};
|
path::{Path, PathBuf},
|
||||||
use crate::media::sync::{MediaSyncProgress, MediaSyncer};
|
};
|
||||||
|
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::path::{Path, PathBuf};
|
use crate::{
|
||||||
|
error::Result,
|
||||||
|
media::{
|
||||||
|
database::{open_or_create, MediaDatabaseContext, MediaEntry},
|
||||||
|
files::{add_data_to_folder_uniquely, mtime_as_i64, remove_files, sha1_of_data},
|
||||||
|
sync::{MediaSyncProgress, MediaSyncer},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
pub mod changetracker;
|
pub mod changetracker;
|
||||||
pub mod check;
|
pub mod check;
|
||||||
|
|
|
@ -1,27 +1,37 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::error::{AnkiError, Result, SyncErrorKind};
|
use std::{
|
||||||
use crate::media::changetracker::ChangeTracker;
|
borrow::Cow,
|
||||||
use crate::media::database::{MediaDatabaseContext, MediaDatabaseMetadata, MediaEntry};
|
collections::HashMap,
|
||||||
use crate::media::files::{
|
io,
|
||||||
add_file_from_ankiweb, data_for_file, mtime_as_i64, normalize_filename, AddedFile,
|
io::{Read, Write},
|
||||||
|
path::Path,
|
||||||
|
time,
|
||||||
};
|
};
|
||||||
use crate::media::MediaManager;
|
|
||||||
use crate::{sync::Timeouts, version};
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use reqwest::{multipart, Client, Response};
|
use reqwest::{multipart, Client, Response};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use serde_tuple::Serialize_tuple;
|
use serde_tuple::Serialize_tuple;
|
||||||
use slog::{debug, Logger};
|
use slog::{debug, Logger};
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::Path;
|
|
||||||
use std::{io, time};
|
|
||||||
use time::Duration;
|
use time::Duration;
|
||||||
use version::sync_client_version;
|
use version::sync_client_version;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::{AnkiError, Result, SyncErrorKind},
|
||||||
|
media::{
|
||||||
|
changetracker::ChangeTracker,
|
||||||
|
database::{MediaDatabaseContext, MediaDatabaseMetadata, MediaEntry},
|
||||||
|
files::{
|
||||||
|
add_file_from_ankiweb, data_for_file, mtime_as_i64, normalize_filename, AddedFile,
|
||||||
|
},
|
||||||
|
MediaManager,
|
||||||
|
},
|
||||||
|
sync::Timeouts,
|
||||||
|
version,
|
||||||
|
};
|
||||||
|
|
||||||
static SYNC_MAX_FILES: usize = 25;
|
static SYNC_MAX_FILES: usize = 25;
|
||||||
static SYNC_MAX_BYTES: usize = (2.5 * 1024.0 * 1024.0) as usize;
|
static SYNC_MAX_BYTES: usize = (2.5 * 1024.0 * 1024.0) as usize;
|
||||||
static SYNC_SINGLE_FILE_MAX_BYTES: usize = 100 * 1024 * 1024;
|
static SYNC_SINGLE_FILE_MAX_BYTES: usize = 100 * 1024 * 1024;
|
||||||
|
@ -805,14 +815,17 @@ fn zip_files<'a>(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::error::Result;
|
|
||||||
use crate::media::sync::{
|
|
||||||
determine_required_change, LocalState, MediaSyncProgress, RequiredChange,
|
|
||||||
};
|
|
||||||
use crate::media::MediaManager;
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::Result,
|
||||||
|
media::{
|
||||||
|
sync::{determine_required_change, LocalState, MediaSyncProgress, RequiredChange},
|
||||||
|
MediaManager,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async fn test_sync(hkey: &str) -> Result<()> {
|
async fn test_sync(hkey: &str) -> Result<()> {
|
||||||
let dir = tempdir()?;
|
let dir = tempdir()?;
|
||||||
let media_dir = dir.path().join("media");
|
let media_dir = dir.path().join("media");
|
||||||
|
|
|
@ -3,28 +3,29 @@
|
||||||
|
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
convert::TryInto,
|
||||||
|
};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
use num_integer::Integer;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto as pb,
|
||||||
|
backend_proto::note_is_duplicate_or_empty_out::State as DuplicateState,
|
||||||
decks::DeckId,
|
decks::DeckId,
|
||||||
define_newtype,
|
define_newtype,
|
||||||
error::{AnkiError, Result},
|
error::{AnkiError, Result},
|
||||||
notetype::{CardGenContext, NoteField, Notetype, NotetypeId},
|
notetype::{CardGenContext, NoteField, Notetype, NotetypeId},
|
||||||
|
ops::StateChanges,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
template::field_is_empty,
|
template::field_is_empty,
|
||||||
text::{ensure_string_in_nfc, normalize_to_nfc, strip_html_preserving_media_filenames},
|
text::{ensure_string_in_nfc, normalize_to_nfc, strip_html_preserving_media_filenames},
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
use crate::{
|
|
||||||
backend_proto::note_is_duplicate_or_empty_out::State as DuplicateState, ops::StateChanges,
|
|
||||||
};
|
|
||||||
use itertools::Itertools;
|
|
||||||
use num_integer::Integer;
|
|
||||||
use std::{
|
|
||||||
borrow::Cow,
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
convert::TryInto,
|
|
||||||
};
|
|
||||||
|
|
||||||
define_newtype!(NoteId, i64);
|
define_newtype!(NoteId, i64);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::{prelude::*, undo::UndoableChange};
|
|
||||||
|
|
||||||
use super::NoteTags;
|
use super::NoteTags;
|
||||||
|
use crate::{prelude::*, undo::UndoableChange};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) enum UndoableNoteChange {
|
pub(crate) enum UndoableNoteChange {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||||
|
|
||||||
use super::Notetype;
|
use super::Notetype;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{Card, CardId},
|
card::{Card, CardId},
|
||||||
|
@ -14,9 +19,6 @@ use crate::{
|
||||||
template::ParsedTemplate,
|
template::ParsedTemplate,
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
|
||||||
use rand::{rngs::StdRng, Rng, SeedableRng};
|
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
|
|
||||||
/// Info about an existing card required when generating new cards
|
/// Info about an existing card required when generating new cards
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{collections::HashSet, fmt::Write};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
cardgen::group_generated_cards_by_note, CardGenContext, Notetype, NotetypeId, NotetypeKind,
|
cardgen::group_generated_cards_by_note, CardGenContext, Notetype, NotetypeId, NotetypeKind,
|
||||||
};
|
};
|
||||||
use crate::{card::CardId, collection::Collection, error::Result, notes::NoteId};
|
use crate::{card::CardId, collection::Collection, error::Result, notes::NoteId};
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::fmt::Write;
|
|
||||||
|
|
||||||
pub struct EmptyCardsForNote {
|
pub struct EmptyCardsForNote {
|
||||||
pub nid: NoteId,
|
pub nid: NoteId,
|
||||||
|
|
|
@ -10,24 +10,30 @@ mod schemachange;
|
||||||
mod stock;
|
mod stock;
|
||||||
mod templates;
|
mod templates;
|
||||||
|
|
||||||
pub use crate::backend_proto::{
|
use std::{
|
||||||
notetype::{
|
collections::{HashMap, HashSet},
|
||||||
config::card_requirement::Kind as CardRequirementKind,
|
sync::Arc,
|
||||||
config::CardRequirement,
|
|
||||||
config::Kind as NotetypeKind,
|
|
||||||
template::Config as CardTemplateConfig,
|
|
||||||
Config as NotetypeConfig, Template as CardTemplateProto,
|
|
||||||
{field::Config as NoteFieldConfig, Field as NoteFieldProto},
|
|
||||||
},
|
|
||||||
Notetype as NotetypeProto,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use cardgen::{AlreadyGeneratedCardInfo, CardGenContext};
|
pub(crate) use cardgen::{AlreadyGeneratedCardInfo, CardGenContext};
|
||||||
pub use fields::NoteField;
|
pub use fields::NoteField;
|
||||||
pub(crate) use render::RenderCardOutput;
|
pub(crate) use render::RenderCardOutput;
|
||||||
pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11};
|
pub use schema11::{CardTemplateSchema11, NoteFieldSchema11, NotetypeSchema11};
|
||||||
pub use stock::all_stock_notetypes;
|
pub use stock::all_stock_notetypes;
|
||||||
pub use templates::CardTemplate;
|
pub use templates::CardTemplate;
|
||||||
|
use unicase::UniCase;
|
||||||
|
|
||||||
|
pub use crate::backend_proto::{
|
||||||
|
notetype::{
|
||||||
|
config::{
|
||||||
|
card_requirement::Kind as CardRequirementKind, CardRequirement, Kind as NotetypeKind,
|
||||||
|
},
|
||||||
|
field::Config as NoteFieldConfig,
|
||||||
|
template::Config as CardTemplateConfig,
|
||||||
|
Config as NotetypeConfig, Field as NoteFieldProto, Template as CardTemplateProto,
|
||||||
|
},
|
||||||
|
Notetype as NotetypeProto,
|
||||||
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
decks::DeckId,
|
decks::DeckId,
|
||||||
|
@ -40,11 +46,6 @@ use crate::{
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
use std::{
|
|
||||||
collections::{HashMap, HashSet},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
use unicase::UniCase;
|
|
||||||
|
|
||||||
define_newtype!(NotetypeId, i64);
|
define_newtype!(NotetypeId, i64);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{borrow::Cow, collections::HashMap};
|
||||||
|
|
||||||
use super::{CardTemplate, Notetype, NotetypeKind};
|
use super::{CardTemplate, Notetype, NotetypeKind};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{Card, CardId},
|
card::{Card, CardId},
|
||||||
|
@ -10,7 +12,6 @@ use crate::{
|
||||||
notes::{Note, NoteId},
|
notes::{Note, NoteId},
|
||||||
template::{field_is_empty, render_card, ParsedTemplate, RenderedNode},
|
template::{field_is_empty, render_card, ParsedTemplate, RenderedNode},
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, collections::HashMap};
|
|
||||||
|
|
||||||
pub struct RenderCardOutput {
|
pub struct RenderCardOutput {
|
||||||
pub qnodes: Vec<RenderedNode>,
|
pub qnodes: Vec<RenderedNode>,
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
|
use serde_tuple::Serialize_tuple;
|
||||||
|
|
||||||
|
use super::{CardRequirementKind, NotetypeId};
|
||||||
use crate::{
|
use crate::{
|
||||||
decks::DeckId,
|
decks::DeckId,
|
||||||
notetype::{
|
notetype::{
|
||||||
|
@ -11,13 +19,6 @@ use crate::{
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
|
||||||
use serde_json::Value;
|
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
|
||||||
use serde_tuple::Serialize_tuple;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use super::{CardRequirementKind, NotetypeId};
|
|
||||||
|
|
||||||
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
|
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug, Clone)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use super::NotetypeKind;
|
use super::NotetypeKind;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
backend_proto::stock_notetype::Kind,
|
||||||
config::{ConfigEntry, ConfigKey},
|
config::{ConfigEntry, ConfigKey},
|
||||||
error::Result,
|
error::Result,
|
||||||
i18n::I18n,
|
i18n::I18n,
|
||||||
|
@ -11,8 +12,6 @@ use crate::{
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::backend_proto::stock_notetype::Kind;
|
|
||||||
|
|
||||||
impl SqliteStorage {
|
impl SqliteStorage {
|
||||||
pub(crate) fn add_stock_notetypes(&self, tr: &I18n) -> Result<()> {
|
pub(crate) fn add_stock_notetypes(&self, tr: &I18n) -> Result<()> {
|
||||||
for (idx, mut nt) in all_stock_notetypes(tr).into_iter().enumerate() {
|
for (idx, mut nt) in all_stock_notetypes(tr).into_iter().enumerate() {
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::{
|
backend_proto::{
|
||||||
preferences::scheduling::NewReviewMix as NewRevMixPB,
|
preferences::{scheduling::NewReviewMix as NewRevMixPB, Editing, Reviewing, Scheduling},
|
||||||
preferences::{Editing, Reviewing, Scheduling},
|
|
||||||
Preferences,
|
Preferences,
|
||||||
},
|
},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
pub use slog::{debug, Logger};
|
||||||
|
|
||||||
pub(crate) use crate::types::IntoNewtypeVec;
|
pub(crate) use crate::types::IntoNewtypeVec;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
card::{Card, CardId},
|
card::{Card, CardId},
|
||||||
|
@ -17,4 +19,3 @@ pub use crate::{
|
||||||
timestamp::{TimestampMillis, TimestampSecs},
|
timestamp::{TimestampMillis, TimestampSecs},
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
pub use slog::{debug, Logger};
|
|
||||||
|
|
|
@ -3,13 +3,17 @@
|
||||||
|
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
||||||
use crate::serde::{default_on_invalid, deserialize_int_from_number};
|
|
||||||
use crate::{define_newtype, prelude::*};
|
|
||||||
use num_enum::TryFromPrimitive;
|
use num_enum::TryFromPrimitive;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||||
use serde_tuple::Serialize_tuple;
|
use serde_tuple::Serialize_tuple;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
define_newtype,
|
||||||
|
prelude::*,
|
||||||
|
serde::{default_on_invalid, deserialize_int_from_number},
|
||||||
|
};
|
||||||
|
|
||||||
define_newtype!(RevlogId, i64);
|
define_newtype!(RevlogId, i64);
|
||||||
|
|
||||||
impl RevlogId {
|
impl RevlogId {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::CardStateUpdater;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardType,
|
card::CardType,
|
||||||
decks::DeckKind,
|
decks::DeckKind,
|
||||||
|
@ -10,8 +11,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::CardStateUpdater;
|
|
||||||
|
|
||||||
impl CardStateUpdater {
|
impl CardStateUpdater {
|
||||||
pub(crate) fn current_card_state(&self) -> CardState {
|
pub(crate) fn current_card_state(&self) -> CardState {
|
||||||
let due = match &self.deck.kind {
|
let due = match &self.deck.kind {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::{CardStateUpdater, RevlogEntryPartial};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::states::{CardState, IntervalKind, LearnState, NewState},
|
scheduler::states::{CardState, IntervalKind, LearnState, NewState},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CardStateUpdater, RevlogEntryPartial};
|
|
||||||
|
|
||||||
impl CardStateUpdater {
|
impl CardStateUpdater {
|
||||||
pub(super) fn apply_new_state(
|
pub(super) fn apply_new_state(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -9,14 +9,6 @@ mod review;
|
||||||
mod revlog;
|
mod revlog;
|
||||||
mod undo;
|
mod undo;
|
||||||
|
|
||||||
use crate::{
|
|
||||||
backend_proto,
|
|
||||||
card::CardQueue,
|
|
||||||
deckconf::{DeckConf, LeechAction},
|
|
||||||
decks::Deck,
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
|
|
||||||
use revlog::RevlogEntryPartial;
|
use revlog::RevlogEntryPartial;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -26,6 +18,13 @@ use super::{
|
||||||
timespan::answer_button_time_collapsible,
|
timespan::answer_button_time_collapsible,
|
||||||
timing::SchedTimingToday,
|
timing::SchedTimingToday,
|
||||||
};
|
};
|
||||||
|
use crate::{
|
||||||
|
backend_proto,
|
||||||
|
card::CardQueue,
|
||||||
|
deckconf::{DeckConf, LeechAction},
|
||||||
|
decks::Deck,
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum Rating {
|
pub enum Rating {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::{CardStateUpdater, RevlogEntryPartial};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardQueue,
|
card::CardQueue,
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
scheduler::states::{CardState, IntervalKind, PreviewState},
|
scheduler::states::{CardState, IntervalKind, PreviewState},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CardStateUpdater, RevlogEntryPartial};
|
|
||||||
|
|
||||||
impl CardStateUpdater {
|
impl CardStateUpdater {
|
||||||
// fixme: check learning card moved into preview
|
// fixme: check learning card moved into preview
|
||||||
// restores correctly in both learn and day-learn case
|
// restores correctly in both learn and day-learn case
|
||||||
|
@ -41,12 +40,11 @@ impl CardStateUpdater {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::collection::open_test_collection;
|
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardType,
|
card::CardType,
|
||||||
|
collection::open_test_collection,
|
||||||
|
prelude::*,
|
||||||
scheduler::{
|
scheduler::{
|
||||||
answering::{CardAnswer, Rating},
|
answering::{CardAnswer, Rating},
|
||||||
states::{CardState, FilteredState},
|
states::{CardState, FilteredState},
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::{CardStateUpdater, RevlogEntryPartial};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
scheduler::states::{CardState, IntervalKind, RelearnState},
|
scheduler::states::{CardState, IntervalKind, RelearnState},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CardStateUpdater, RevlogEntryPartial};
|
|
||||||
|
|
||||||
impl CardStateUpdater {
|
impl CardStateUpdater {
|
||||||
pub(super) fn apply_relearning_state(
|
pub(super) fn apply_relearning_state(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::{CardStateUpdater, RevlogEntryPartial};
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
scheduler::states::{CardState, ReviewState},
|
scheduler::states::{CardState, ReviewState},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CardStateUpdater, RevlogEntryPartial};
|
|
||||||
|
|
||||||
impl CardStateUpdater {
|
impl CardStateUpdater {
|
||||||
pub(super) fn apply_review_state(
|
pub(super) fn apply_review_state(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::timing::SchedTimingToday;
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto as pb,
|
backend_proto::{
|
||||||
|
bury_or_suspend_cards_in::Mode as BuryOrSuspendMode,
|
||||||
|
unbury_cards_in_current_deck_in::Mode as UnburyDeckMode,
|
||||||
|
},
|
||||||
card::{Card, CardId, CardQueue},
|
card::{Card, CardId, CardQueue},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
|
@ -11,12 +15,6 @@ use crate::{
|
||||||
search::SortMode,
|
search::SortMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::timing::SchedTimingToday;
|
|
||||||
use pb::{
|
|
||||||
bury_or_suspend_cards_in::Mode as BuryOrSuspendMode,
|
|
||||||
unbury_cards_in_current_deck_in::Mode as UnburyDeckMode,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
/// True if card was buried/suspended prior to the call.
|
/// True if card was buried/suspended prior to the call.
|
||||||
pub(crate) fn restore_queue_after_bury_or_suspend(&mut self) -> bool {
|
pub(crate) fn restore_queue_after_bury_or_suspend(&mut self) -> bool {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::backend_proto as pb;
|
use crate::{backend_proto as pb, prelude::*};
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct CongratsInfo {
|
pub(crate) struct CongratsInfo {
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use super::DeckFilterContext;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::DeckFilterContext;
|
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
pub(crate) fn restore_queue_from_type(&mut self) {
|
pub(crate) fn restore_queue_from_type(&mut self) {
|
||||||
self.queue = match self.ctype {
|
self.queue = match self.ctype {
|
||||||
|
|
|
@ -6,13 +6,14 @@ mod card;
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ConfigKey,
|
config::{ConfigKey, SchedulerVersion},
|
||||||
decks::{FilteredDeck, FilteredSearchTerm},
|
decks::{FilteredDeck, FilteredSearchTerm},
|
||||||
error::FilteredDeckError,
|
error::FilteredDeckError,
|
||||||
search::writer::{deck_search, normalize_search},
|
prelude::*,
|
||||||
};
|
search::{
|
||||||
use crate::{
|
writer::{deck_search, normalize_search},
|
||||||
config::SchedulerVersion, prelude::*, search::SortMode,
|
SortMode,
|
||||||
|
},
|
||||||
storage::card::filtered::order_and_limit_for_search,
|
storage::card::filtered::order_and_limit_for_search,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{Card, CardId, CardQueue, CardType},
|
card::{Card, CardId, CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
|
@ -11,8 +15,6 @@ use crate::{
|
||||||
search::SortMode,
|
search::SortMode,
|
||||||
types::Usn,
|
types::Usn,
|
||||||
};
|
};
|
||||||
use rand::seq::SliceRandom;
|
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
fn schedule_as_new(&mut self, position: u32) {
|
fn schedule_as_new(&mut self, position: u32) {
|
||||||
|
|
|
@ -11,13 +11,17 @@ use std::{
|
||||||
collections::{BinaryHeap, HashSet, VecDeque},
|
collections::{BinaryHeap, HashSet, VecDeque},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use intersperser::Intersperser;
|
||||||
|
use sized_chain::SizedChain;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
limits::{remaining_limits_capped_to_parents, RemainingLimits},
|
limits::{remaining_limits_capped_to_parents, RemainingLimits},
|
||||||
CardQueues, Counts, LearningQueueEntry, MainQueueEntry, MainQueueEntryKind,
|
CardQueues, Counts, LearningQueueEntry, MainQueueEntry, MainQueueEntryKind,
|
||||||
};
|
};
|
||||||
use crate::deckconf::{NewCardOrder, ReviewCardOrder, ReviewMix};
|
use crate::{
|
||||||
use crate::prelude::*;
|
deckconf::{NewCardOrder, ReviewCardOrder, ReviewMix},
|
||||||
use {intersperser::Intersperser, sized_chain::SizedChain};
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
/// Temporary holder for review cards that will be built into a queue.
|
/// Temporary holder for review cards that will be built into a queue.
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{DueCard, NewCard, NewCardOrder, QueueBuilder, ReviewCardOrder};
|
|
||||||
use fnv::FnvHasher;
|
|
||||||
use std::{cmp::Ordering, hash::Hasher};
|
use std::{cmp::Ordering, hash::Hasher};
|
||||||
|
|
||||||
|
use fnv::FnvHasher;
|
||||||
|
|
||||||
|
use super::{DueCard, NewCard, NewCardOrder, QueueBuilder, ReviewCardOrder};
|
||||||
|
|
||||||
impl QueueBuilder {
|
impl QueueBuilder {
|
||||||
pub(super) fn sort_new(&mut self) {
|
pub(super) fn sort_new(&mut self) {
|
||||||
match self.new_order {
|
match self.new_order {
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use super::{LearningQueueEntry, MainQueueEntry, MainQueueEntryKind};
|
use super::{LearningQueueEntry, MainQueueEntry, MainQueueEntryKind};
|
||||||
use crate::card::CardQueue;
|
use crate::{card::CardQueue, prelude::*};
|
||||||
use crate::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub(crate) enum QueueEntry {
|
pub(crate) enum QueueEntry {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::{Deck, DeckKind};
|
use super::{Deck, DeckKind};
|
||||||
use crate::deckconf::{DeckConf, DeckConfId};
|
use crate::deckconf::{DeckConf, DeckConfId};
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub(crate) struct RemainingLimits {
|
pub(crate) struct RemainingLimits {
|
||||||
|
|
|
@ -13,17 +13,14 @@ use std::{
|
||||||
collections::{BinaryHeap, VecDeque},
|
collections::{BinaryHeap, VecDeque},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{backend_proto as pb, prelude::*, timestamp::TimestampSecs};
|
|
||||||
pub(crate) use builder::{DueCard, NewCard};
|
pub(crate) use builder::{DueCard, NewCard};
|
||||||
pub(crate) use {
|
pub(crate) use entry::{QueueEntry, QueueEntryKind};
|
||||||
entry::{QueueEntry, QueueEntryKind},
|
pub(crate) use learning::LearningQueueEntry;
|
||||||
learning::LearningQueueEntry,
|
pub(crate) use main::{MainQueueEntry, MainQueueEntryKind};
|
||||||
main::{MainQueueEntry, MainQueueEntryKind},
|
|
||||||
};
|
|
||||||
|
|
||||||
use self::undo::QueueUpdate;
|
use self::undo::QueueUpdate;
|
||||||
|
|
||||||
use super::{states::NextCardStates, timing::SchedTimingToday};
|
use super::{states::NextCardStates, timing::SchedTimingToday};
|
||||||
|
use crate::{backend_proto as pb, prelude::*, timestamp::TimestampSecs};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct CardQueues {
|
pub(crate) struct CardQueues {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use rand::distributions::{Distribution, Uniform};
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{Card, CardId, CardQueue, CardType},
|
card::{Card, CardId, CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
|
@ -9,9 +13,6 @@ use crate::{
|
||||||
error::Result,
|
error::Result,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use rand::distributions::{Distribution, Uniform};
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
impl Card {
|
impl Card {
|
||||||
/// Make card due in `days_from_today`.
|
/// Make card due in `days_from_today`.
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
IntervalKind, NextCardStates, PreviewState, ReschedulingFilterState, ReviewState, StateContext,
|
IntervalKind, NextCardStates, PreviewState, ReschedulingFilterState, ReviewState, StateContext,
|
||||||
};
|
};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum FilteredState {
|
pub enum FilteredState {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{interval_kind::IntervalKind, CardState, NextCardStates, ReviewState, StateContext};
|
use super::{interval_kind::IntervalKind, CardState, NextCardStates, ReviewState, StateContext};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct LearnState {
|
pub struct LearnState {
|
||||||
|
|
|
@ -12,20 +12,19 @@ pub(crate) mod rescheduling_filter;
|
||||||
pub(crate) mod review;
|
pub(crate) mod review;
|
||||||
pub(crate) mod steps;
|
pub(crate) mod steps;
|
||||||
|
|
||||||
use rand::prelude::*;
|
pub use filtered::FilteredState;
|
||||||
use rand::rngs::StdRng;
|
|
||||||
|
|
||||||
pub use {
|
|
||||||
filtered::FilteredState, learning::LearnState, new::NewState, normal::NormalState,
|
|
||||||
preview_filter::PreviewState, relearning::RelearnState,
|
|
||||||
rescheduling_filter::ReschedulingFilterState, review::ReviewState,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) use interval_kind::IntervalKind;
|
pub(crate) use interval_kind::IntervalKind;
|
||||||
|
pub use learning::LearnState;
|
||||||
use crate::revlog::RevlogReviewKind;
|
pub use new::NewState;
|
||||||
|
pub use normal::NormalState;
|
||||||
|
pub use preview_filter::PreviewState;
|
||||||
|
use rand::{prelude::*, rngs::StdRng};
|
||||||
|
pub use relearning::RelearnState;
|
||||||
|
pub use rescheduling_filter::ReschedulingFilterState;
|
||||||
|
pub use review::ReviewState;
|
||||||
|
|
||||||
use self::steps::LearningSteps;
|
use self::steps::LearningSteps;
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum CardState {
|
pub enum CardState {
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::interval_kind::IntervalKind;
|
use super::interval_kind::IntervalKind;
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||||
pub struct NewState {
|
pub struct NewState {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
interval_kind::IntervalKind, LearnState, NewState, NextCardStates, RelearnState, ReviewState,
|
interval_kind::IntervalKind, LearnState, NewState, NextCardStates, RelearnState, ReviewState,
|
||||||
StateContext,
|
StateContext,
|
||||||
};
|
};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum NormalState {
|
pub enum NormalState {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
interval_kind::IntervalKind, CardState, LearnState, NextCardStates, ReviewState, StateContext,
|
interval_kind::IntervalKind, CardState, LearnState, NextCardStates, ReviewState, StateContext,
|
||||||
};
|
};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct RelearnState {
|
pub struct RelearnState {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
interval_kind::IntervalKind, normal::NormalState, CardState, NextCardStates, StateContext,
|
interval_kind::IntervalKind, normal::NormalState, CardState, NextCardStates, StateContext,
|
||||||
};
|
};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct ReschedulingFilterState {
|
pub struct ReschedulingFilterState {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::revlog::RevlogReviewKind;
|
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
interval_kind::IntervalKind, CardState, LearnState, NextCardStates, RelearnState, StateContext,
|
interval_kind::IntervalKind, CardState, LearnState, NextCardStates, RelearnState, StateContext,
|
||||||
};
|
};
|
||||||
|
use crate::revlog::RevlogReviewKind;
|
||||||
|
|
||||||
pub const INITIAL_EASE_FACTOR: f32 = 2.5;
|
pub const INITIAL_EASE_FACTOR: f32 = 2.5;
|
||||||
pub const MINIMUM_EASE_FACTOR: f32 = 1.3;
|
pub const MINIMUM_EASE_FACTOR: f32 = 1.3;
|
||||||
|
|
|
@ -166,8 +166,10 @@ impl Timespan {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::i18n::I18n;
|
use crate::{
|
||||||
use crate::scheduler::timespan::{answer_button_time, time_span, MONTH};
|
i18n::I18n,
|
||||||
|
scheduler::timespan::{answer_button_time, time_span, MONTH},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn answer_buttons() {
|
fn answer_buttons() {
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use chrono::{Date, Duration, FixedOffset, Local, TimeZone, Timelike};
|
use chrono::{Date, Duration, FixedOffset, Local, TimeZone, Timelike};
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub struct SchedTimingToday {
|
pub struct SchedTimingToday {
|
||||||
pub now: TimestampSecs,
|
pub now: TimestampSecs,
|
||||||
|
@ -192,9 +193,10 @@ pub(crate) fn sched_timing_today(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
|
||||||
use chrono::{FixedOffset, Local, TimeZone, Utc};
|
use chrono::{FixedOffset, Local, TimeZone, Utc};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
// static timezone for tests
|
// static timezone for tests
|
||||||
const AEST_MINS_WEST: i32 = -600;
|
const AEST_MINS_WEST: i32 = -600;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use super::timing::local_minutes_west_for_stamp;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
config::SchedulerVersion,
|
config::SchedulerVersion,
|
||||||
|
@ -10,8 +11,6 @@ use crate::{
|
||||||
search::SortMode,
|
search::SortMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::timing::local_minutes_west_for_stamp;
|
|
||||||
|
|
||||||
struct V1FilteredDeckInfo {
|
struct V1FilteredDeckInfo {
|
||||||
/// True if the filtered deck had rescheduling enabled.
|
/// True if the filtered deck had rescheduling enabled.
|
||||||
reschedule: bool,
|
reschedule: bool,
|
||||||
|
|
|
@ -5,19 +5,24 @@ mod parser;
|
||||||
mod sqlwriter;
|
mod sqlwriter;
|
||||||
pub(crate) mod writer;
|
pub(crate) mod writer;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub use parser::{
|
pub use parser::{
|
||||||
parse as parse_search, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind,
|
parse as parse_search, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind,
|
||||||
};
|
};
|
||||||
|
use rusqlite::types::FromSql;
|
||||||
|
use sqlwriter::{RequiredTable, SqlWriter};
|
||||||
pub use writer::{concatenate_searches, replace_search_node, write_nodes, BoolSeparator};
|
pub use writer::{concatenate_searches, replace_search_node, write_nodes, BoolSeparator};
|
||||||
|
|
||||||
use rusqlite::types::FromSql;
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
browser_table::Column, card::CardId, card::CardType, collection::Collection, error::Result,
|
browser_table::Column,
|
||||||
notes::NoteId, prelude::AnkiError, search::parser::parse,
|
card::{CardId, CardType},
|
||||||
|
collection::Collection,
|
||||||
|
error::Result,
|
||||||
|
notes::NoteId,
|
||||||
|
prelude::AnkiError,
|
||||||
|
search::parser::parse,
|
||||||
};
|
};
|
||||||
use sqlwriter::{RequiredTable, SqlWriter};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum ReturnItemType {
|
pub enum ReturnItemType {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::{
|
|
||||||
decks::DeckId,
|
|
||||||
error::{ParseError, Result, SearchErrorKind as FailKind},
|
|
||||||
notetype::NotetypeId,
|
|
||||||
};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
|
@ -18,6 +13,12 @@ use nom::{
|
||||||
};
|
};
|
||||||
use regex::{Captures, Regex};
|
use regex::{Captures, Regex};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
decks::DeckId,
|
||||||
|
error::{ParseError, Result, SearchErrorKind as FailKind},
|
||||||
|
notetype::NotetypeId,
|
||||||
|
};
|
||||||
|
|
||||||
type IResult<'a, O> = std::result::Result<(&'a str, O), nom::Err<ParseError<'a>>>;
|
type IResult<'a, O> = std::result::Result<(&'a str, O), nom::Err<ParseError<'a>>>;
|
||||||
type ParseResult<'a, O> = std::result::Result<O, nom::Err<ParseError<'a>>>;
|
type ParseResult<'a, O> = std::result::Result<O, nom::Err<ParseError<'a>>>;
|
||||||
|
|
||||||
|
@ -696,9 +697,8 @@ fn is_parser_escape(txt: &str) -> bool {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::error::SearchErrorKind;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::error::SearchErrorKind;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing() -> Result<()> {
|
fn parsing() -> Result<()> {
|
||||||
|
@ -858,9 +858,10 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors() {
|
fn errors() {
|
||||||
use crate::error::AnkiError;
|
|
||||||
use FailKind::*;
|
use FailKind::*;
|
||||||
|
|
||||||
|
use crate::error::AnkiError;
|
||||||
|
|
||||||
fn assert_err_kind(input: &str, kind: FailKind) {
|
fn assert_err_kind(input: &str, kind: FailKind) {
|
||||||
assert_eq!(parse(input), Err(AnkiError::SearchError(kind)));
|
assert_eq!(parse(input), Err(AnkiError::SearchError(kind)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::{borrow::Cow, fmt::Write};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
parser::{Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind},
|
parser::{Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind},
|
||||||
ReturnItemType,
|
ReturnItemType,
|
||||||
|
@ -19,7 +21,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
timestamp::TimestampSecs,
|
timestamp::TimestampSecs,
|
||||||
};
|
};
|
||||||
use std::{borrow::Cow, fmt::Write};
|
|
||||||
|
|
||||||
pub(crate) struct SqlWriter<'a> {
|
pub(crate) struct SqlWriter<'a> {
|
||||||
col: &'a mut Collection,
|
col: &'a mut Collection,
|
||||||
|
@ -575,16 +576,16 @@ impl SearchNode {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
use super::{super::parser::parse, *};
|
||||||
use crate::{
|
use crate::{
|
||||||
collection::{open_collection, Collection},
|
collection::{open_collection, Collection},
|
||||||
i18n::I18n,
|
i18n::I18n,
|
||||||
log,
|
log,
|
||||||
};
|
};
|
||||||
use std::{fs, path::PathBuf};
|
|
||||||
use tempfile::tempdir;
|
|
||||||
|
|
||||||
use super::super::parser::parse;
|
|
||||||
|
|
||||||
// shortcut
|
// shortcut
|
||||||
fn s(req: &mut Collection, search: &str) -> (String, Vec<String>) {
|
fn s(req: &mut Collection, search: &str) -> (String, Vec<String>) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
decks::DeckId as DeckIdType,
|
decks::DeckId as DeckIdType,
|
||||||
notetype::NotetypeId as NotetypeIdType,
|
notetype::NotetypeId as NotetypeIdType,
|
||||||
|
@ -8,7 +10,6 @@ use crate::{
|
||||||
search::parser::{parse, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind},
|
search::parser::{parse, Node, PropertyKind, RatingKind, SearchNode, StateKind, TemplateKind},
|
||||||
text::escape_anki_wildcards,
|
text::escape_anki_wildcards,
|
||||||
};
|
};
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum BoolSeparator {
|
pub enum BoolSeparator {
|
||||||
|
@ -191,8 +192,7 @@ pub(crate) fn normalize_search(input: &str) -> Result<String> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::error::Result;
|
use crate::{error::Result, search::parse_search as parse};
|
||||||
use crate::search::parse_search as parse;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn normalizing() {
|
fn normalizing() {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
use crate::timestamp::TimestampSecs;
|
|
||||||
use serde::{Deserialize as DeTrait, Deserializer};
|
use serde::{Deserialize as DeTrait, Deserializer};
|
||||||
pub(crate) use serde_aux::field_attributes::{
|
pub(crate) use serde_aux::field_attributes::{
|
||||||
deserialize_bool_from_anything, deserialize_number_from_string,
|
deserialize_bool_from_anything, deserialize_number_from_string,
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use crate::timestamp::TimestampSecs;
|
||||||
|
|
||||||
/// Note: if you wish to cover the case where a field is missing, make sure you also
|
/// Note: if you wish to cover the case where a field is missing, make sure you also
|
||||||
/// use the `serde(default)` flag.
|
/// use the `serde(default)` flag.
|
||||||
pub(crate) fn default_on_invalid<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
pub(crate) fn default_on_invalid<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
||||||
|
@ -68,9 +69,10 @@ impl FromI64 for TimestampSecs {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq)]
|
#[derive(Deserialize, Debug, PartialEq)]
|
||||||
struct MaybeInvalid {
|
struct MaybeInvalid {
|
||||||
#[serde(deserialize_with = "default_on_invalid", default)]
|
#[serde(deserialize_with = "default_on_invalid", default)]
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use askama::Template;
|
||||||
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::CardQueue,
|
card::CardQueue,
|
||||||
i18n::I18n,
|
i18n::I18n,
|
||||||
|
@ -8,8 +11,6 @@ use crate::{
|
||||||
revlog::{RevlogEntry, RevlogReviewKind},
|
revlog::{RevlogEntry, RevlogReviewKind},
|
||||||
scheduler::timespan::time_span,
|
scheduler::timespan::time_span,
|
||||||
};
|
};
|
||||||
use askama::Template;
|
|
||||||
use chrono::prelude::*;
|
|
||||||
|
|
||||||
struct CardStats {
|
struct CardStats {
|
||||||
added: TimestampSecs,
|
added: TimestampSecs,
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue