mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 15:17:12 -05:00
Enable access to old notetype name
This commit is contained in:
parent
8b3d964866
commit
d273ea2923
6 changed files with 19 additions and 2 deletions
|
|
@ -167,6 +167,7 @@ message ChangeNotetypeRequest {
|
|||
int64 old_notetype_id = 4;
|
||||
int64 new_notetype_id = 5;
|
||||
int64 current_schema = 6;
|
||||
string old_notetype_name = 7;
|
||||
}
|
||||
|
||||
message ChangeNotetypeInfo {
|
||||
|
|
@ -175,4 +176,5 @@ message ChangeNotetypeInfo {
|
|||
repeated string new_field_names = 3;
|
||||
repeated string new_template_names = 4;
|
||||
ChangeNotetypeRequest input = 5;
|
||||
string old_notetype_name = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -415,6 +415,7 @@ and notes.mid = ? and cards.ord = ?""",
|
|||
note_ids=nids,
|
||||
new_fields=field_map,
|
||||
new_templates=template_map,
|
||||
old_notetype_name=notetype["name"],
|
||||
old_notetype_id=notetype["id"],
|
||||
new_notetype_id=newModel["id"],
|
||||
current_schema=self.col.db.scalar("select scm from col"),
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ impl From<pb::Notetype> for Notetype {
|
|||
impl From<NotetypeChangeInfo> for pb::ChangeNotetypeInfo {
|
||||
fn from(i: NotetypeChangeInfo) -> Self {
|
||||
pb::ChangeNotetypeInfo {
|
||||
old_notetype_name: i.old_notetype_name,
|
||||
old_field_names: i.old_field_names,
|
||||
old_template_names: i.old_template_names,
|
||||
new_field_names: i.new_field_names,
|
||||
|
|
@ -204,6 +205,7 @@ impl From<pb::ChangeNotetypeRequest> for ChangeNotetypeInput {
|
|||
ChangeNotetypeInput {
|
||||
current_schema: i.current_schema.into(),
|
||||
note_ids: i.note_ids.into_newtype(NoteId),
|
||||
old_notetype_name: i.old_notetype_name.into(),
|
||||
old_notetype_id: i.old_notetype_id.into(),
|
||||
new_notetype_id: i.new_notetype_id.into(),
|
||||
new_fields: i
|
||||
|
|
@ -232,6 +234,7 @@ impl From<ChangeNotetypeInput> for pb::ChangeNotetypeRequest {
|
|||
pb::ChangeNotetypeRequest {
|
||||
current_schema: i.current_schema.into(),
|
||||
note_ids: i.note_ids.into_iter().map(Into::into).collect(),
|
||||
old_notetype_name: i.old_notetype_name.into(),
|
||||
old_notetype_id: i.old_notetype_id.into(),
|
||||
new_notetype_id: i.new_notetype_id.into(),
|
||||
new_fields: i
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
pub struct ChangeNotetypeInput {
|
||||
pub current_schema: TimestampMillis,
|
||||
pub note_ids: Vec<NoteId>,
|
||||
pub old_notetype_name: String,
|
||||
pub old_notetype_id: NotetypeId,
|
||||
pub new_notetype_id: NotetypeId,
|
||||
pub new_fields: Vec<Option<usize>>,
|
||||
|
|
@ -25,6 +26,7 @@ pub struct ChangeNotetypeInput {
|
|||
#[derive(Debug)]
|
||||
pub struct NotetypeChangeInfo {
|
||||
pub input: ChangeNotetypeInput,
|
||||
pub old_notetype_name: String,
|
||||
pub old_field_names: Vec<String>,
|
||||
pub old_template_names: Vec<String>,
|
||||
pub new_field_names: Vec<String>,
|
||||
|
|
@ -77,18 +79,20 @@ impl Collection {
|
|||
.ok_or(AnkiError::NotFound)?;
|
||||
|
||||
let current_schema = self.storage.get_collection_timestamps()?.schema_change;
|
||||
let old_notetype_name = &old_notetype.name.to_string();
|
||||
let new_fields = default_field_map(&old_notetype, &new_notetype);
|
||||
let new_templates = default_template_map(&old_notetype, &new_notetype);
|
||||
|
||||
Ok(NotetypeChangeInfo {
|
||||
input: ChangeNotetypeInput {
|
||||
current_schema,
|
||||
note_ids: vec![],
|
||||
old_notetype_name: old_notetype_name.to_string(),
|
||||
old_notetype_id,
|
||||
new_notetype_id,
|
||||
new_fields,
|
||||
new_templates,
|
||||
},
|
||||
old_notetype_name: old_notetype_name.to_string(),
|
||||
old_field_names: old_notetype.fields.iter().map(|f| f.name.clone()).collect(),
|
||||
old_template_names: old_notetype
|
||||
.templates
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ const exampleInfoDifferent = {
|
|||
oldNotetypeId: "1623289129847",
|
||||
newNotetypeId: "1623289129849",
|
||||
currentSchema: "1623302002316",
|
||||
oldNotetypeName: "Basic",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ const exampleInfoSame = {
|
|||
oldNotetypeId: "1623289129847",
|
||||
newNotetypeId: "1623289129847",
|
||||
currentSchema: "1623302002316",
|
||||
oldNotetypeName: "Basic",
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export function negativeOneToNull(list: number[]): (number | null)[] {
|
|||
export class ChangeNotetypeInfoWrapper {
|
||||
fields: (number | null)[];
|
||||
templates?: (number | null)[];
|
||||
oldNotetypeName: String;
|
||||
readonly info: Notetypes.ChangeNotetypeInfo;
|
||||
|
||||
constructor(info: Notetypes.ChangeNotetypeInfo) {
|
||||
|
|
@ -54,6 +55,7 @@ export class ChangeNotetypeInfoWrapper {
|
|||
this.templates = negativeOneToNull(templates);
|
||||
}
|
||||
this.fields = negativeOneToNull(info.input!.newFields!);
|
||||
this.oldNotetypeName = info.oldNotetypeName;
|
||||
}
|
||||
|
||||
/// A list with an entry for each field/template in the new notetype, with
|
||||
|
|
@ -82,6 +84,10 @@ export class ChangeNotetypeInfoWrapper {
|
|||
: this.info.oldFieldNames;
|
||||
}
|
||||
|
||||
getOldNotetypeName(): string {
|
||||
return this.info.oldNotetypeName;
|
||||
}
|
||||
|
||||
getNewName(ctx: MapContext, idx: number): string {
|
||||
return (
|
||||
ctx == MapContext.Template
|
||||
|
|
@ -97,7 +103,6 @@ export class ChangeNotetypeInfoWrapper {
|
|||
(idx) => !usedEntries.has(idx),
|
||||
);
|
||||
const unusedNames = unusedIdxs.map((idx) => oldNames[idx]);
|
||||
unusedNames.sort();
|
||||
return unusedNames;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue