mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
Restore and save last dupe resolution setting (#1930)
* Restore dupe resolution setting * Save dupe resolution setting * Push config logic into backend (dae)
This commit is contained in:
parent
dd0e56afb3
commit
b6a7760cb4
8 changed files with 51 additions and 5 deletions
|
|
@ -106,8 +106,8 @@ message MediaEntries {
|
||||||
message ImportCsvRequest {
|
message ImportCsvRequest {
|
||||||
enum DupeResolution {
|
enum DupeResolution {
|
||||||
UPDATE = 0;
|
UPDATE = 0;
|
||||||
ADD = 1;
|
IGNORE = 1;
|
||||||
IGNORE = 2;
|
ADD = 2;
|
||||||
// UPDATE_IF_NEWER = 3;
|
// UPDATE_IF_NEWER = 3;
|
||||||
}
|
}
|
||||||
string path = 1;
|
string path = 1;
|
||||||
|
|
@ -166,6 +166,7 @@ message CsvMetadata {
|
||||||
bool force_is_html = 12;
|
bool force_is_html = 12;
|
||||||
repeated generic.StringList preview = 13;
|
repeated generic.StringList preview = 13;
|
||||||
uint32 guid_column = 14;
|
uint32 guid_column = 14;
|
||||||
|
ImportCsvRequest.DupeResolution dupe_resolution = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ExportCardCsvRequest {
|
message ExportCardCsvRequest {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
mod bool;
|
mod bool;
|
||||||
mod deck;
|
mod deck;
|
||||||
mod notetype;
|
mod notetype;
|
||||||
|
mod number;
|
||||||
pub(crate) mod schema11;
|
pub(crate) mod schema11;
|
||||||
mod string;
|
mod string;
|
||||||
pub(crate) mod undo;
|
pub(crate) mod undo;
|
||||||
|
|
@ -14,7 +15,8 @@ use slog::warn;
|
||||||
use strum::IntoStaticStr;
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
bool::BoolKey, deck::DeckConfigKey, notetype::get_aux_notetype_config_key, string::StringKey,
|
bool::BoolKey, deck::DeckConfigKey, notetype::get_aux_notetype_config_key,
|
||||||
|
number::I32ConfigKey, string::StringKey,
|
||||||
};
|
};
|
||||||
use crate::{backend_proto::preferences::BackupLimits, prelude::*};
|
use crate::{backend_proto::preferences::BackupLimits, prelude::*};
|
||||||
|
|
||||||
|
|
|
||||||
27
rslib/src/config/number.rs
Normal file
27
rslib/src/config/number.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use strum::IntoStaticStr;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, IntoStaticStr)]
|
||||||
|
#[strum(serialize_all = "camelCase")]
|
||||||
|
pub enum I32ConfigKey {
|
||||||
|
CsvDuplicateResolution,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Collection {
|
||||||
|
pub fn get_config_i32(&self, key: I32ConfigKey) -> i32 {
|
||||||
|
#[allow(clippy::match_single_binding)]
|
||||||
|
self.get_config_optional(key).unwrap_or_else(|| match key {
|
||||||
|
_other => 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Collection {
|
||||||
|
pub(crate) fn set_config_i32_inner(&mut self, key: I32ConfigKey, value: i32) -> Result<bool> {
|
||||||
|
self.set_config(key, &value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -276,6 +276,7 @@ mod test {
|
||||||
field_columns: vec![1, 2],
|
field_columns: vec![1, 2],
|
||||||
})),
|
})),
|
||||||
preview: Vec::new(),
|
preview: Vec::new(),
|
||||||
|
dupe_resolution: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ use strum::IntoEnumIterator;
|
||||||
use super::import::build_csv_reader;
|
use super::import::build_csv_reader;
|
||||||
pub use crate::backend_proto::import_export::{
|
pub use crate::backend_proto::import_export::{
|
||||||
csv_metadata::{Deck as CsvDeck, Delimiter, MappedNotetype, Notetype as CsvNotetype},
|
csv_metadata::{Deck as CsvDeck, Delimiter, MappedNotetype, Notetype as CsvNotetype},
|
||||||
|
import_csv_request::DupeResolution,
|
||||||
CsvMetadata,
|
CsvMetadata,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
backend_proto::StringList,
|
backend_proto::StringList,
|
||||||
|
config::I32ConfigKey,
|
||||||
error::ImportError,
|
error::ImportError,
|
||||||
import_export::text::NameOrId,
|
import_export::text::NameOrId,
|
||||||
notetype::NoteField,
|
notetype::NoteField,
|
||||||
|
|
@ -48,7 +50,14 @@ impl Collection {
|
||||||
notetype_id: Option<NotetypeId>,
|
notetype_id: Option<NotetypeId>,
|
||||||
is_html: Option<bool>,
|
is_html: Option<bool>,
|
||||||
) -> Result<CsvMetadata> {
|
) -> Result<CsvMetadata> {
|
||||||
let mut metadata = CsvMetadata::default();
|
let dupe_resolution =
|
||||||
|
DupeResolution::from_i32(self.get_config_i32(I32ConfigKey::CsvDuplicateResolution))
|
||||||
|
.map(|r| r as i32)
|
||||||
|
.unwrap_or_default();
|
||||||
|
let mut metadata = CsvMetadata {
|
||||||
|
dupe_resolution,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let meta_len = self.parse_meta_lines(&mut reader, &mut metadata)? as u64;
|
let meta_len = self.parse_meta_lines(&mut reader, &mut metadata)? as u64;
|
||||||
maybe_set_fallback_delimiter(delimiter, &mut metadata, &mut reader, meta_len)?;
|
maybe_set_fallback_delimiter(delimiter, &mut metadata, &mut reader, meta_len)?;
|
||||||
let records = collect_preview_records(&mut metadata, reader)?;
|
let records = collect_preview_records(&mut metadata, reader)?;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use std::{
|
||||||
use super::NameOrId;
|
use super::NameOrId;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{CardQueue, CardType},
|
card::{CardQueue, CardType},
|
||||||
|
config::I32ConfigKey,
|
||||||
import_export::{
|
import_export::{
|
||||||
text::{
|
text::{
|
||||||
DupeResolution, ForeignCard, ForeignData, ForeignNote, ForeignNotetype, ForeignTemplate,
|
DupeResolution, ForeignCard, ForeignData, ForeignNote, ForeignNotetype, ForeignTemplate,
|
||||||
|
|
@ -31,6 +32,10 @@ impl ForeignData {
|
||||||
let mut progress = IncrementableProgress::new(progress_fn);
|
let mut progress = IncrementableProgress::new(progress_fn);
|
||||||
progress.call(ImportProgress::File)?;
|
progress.call(ImportProgress::File)?;
|
||||||
col.transact(Op::Import, |col| {
|
col.transact(Op::Import, |col| {
|
||||||
|
col.set_config_i32_inner(
|
||||||
|
I32ConfigKey::CsvDuplicateResolution,
|
||||||
|
self.dupe_resolution as i32,
|
||||||
|
)?;
|
||||||
let mut ctx = Context::new(&self, col)?;
|
let mut ctx = Context::new(&self, col)?;
|
||||||
ctx.import_foreign_notetypes(self.notetypes)?;
|
ctx.import_foreign_notetypes(self.notetypes)?;
|
||||||
ctx.import_foreign_notes(
|
ctx.import_foreign_notes(
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let path: string;
|
export let path: string;
|
||||||
export let notetypeNameIds: Notetypes.NotetypeNameId[];
|
export let notetypeNameIds: Notetypes.NotetypeNameId[];
|
||||||
export let deckNameIds: Decks.DeckNameId[];
|
export let deckNameIds: Decks.DeckNameId[];
|
||||||
|
export let dupeResolution: ImportExport.ImportCsvRequest.DupeResolution;
|
||||||
|
|
||||||
export let delimiter: ImportExport.CsvMetadata.Delimiter;
|
export let delimiter: ImportExport.CsvMetadata.Delimiter;
|
||||||
export let forceDelimiter: boolean;
|
export let forceDelimiter: boolean;
|
||||||
|
|
@ -47,7 +48,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let deckId: number | null;
|
export let deckId: number | null;
|
||||||
export let deckColumn: number | null;
|
export let deckColumn: number | null;
|
||||||
|
|
||||||
let dupeResolution: ImportExport.ImportCsvRequest.DupeResolution;
|
|
||||||
let lastNotetypeId = globalNotetype?.id;
|
let lastNotetypeId = globalNotetype?.id;
|
||||||
let lastDelimeter = delimiter;
|
let lastDelimeter = delimiter;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ export async function setupImportCsvPage(path: string): Promise<ImportCsvPage> {
|
||||||
path: path,
|
path: path,
|
||||||
deckNameIds: decks.entries,
|
deckNameIds: decks.entries,
|
||||||
notetypeNameIds: notetypes.entries,
|
notetypeNameIds: notetypes.entries,
|
||||||
|
dupeResolution: metadata.dupeResolution,
|
||||||
delimiter: metadata.delimiter,
|
delimiter: metadata.delimiter,
|
||||||
forceDelimiter: metadata.forceDelimiter,
|
forceDelimiter: metadata.forceDelimiter,
|
||||||
isHtml: metadata.isHtml,
|
isHtml: metadata.isHtml,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue