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