mirror of
https://github.com/ankitects/anki.git
synced 2025-12-12 22:36:55 -05:00
Fix misleading warning when changing notetype from/to cloze (#2744)
This commit is contained in:
parent
dfe0370a2a
commit
bba67fdab4
5 changed files with 9 additions and 6 deletions
|
|
@ -210,6 +210,7 @@ message ChangeNotetypeRequest {
|
||||||
int64 new_notetype_id = 5;
|
int64 new_notetype_id = 5;
|
||||||
int64 current_schema = 6;
|
int64 current_schema = 6;
|
||||||
string old_notetype_name = 7;
|
string old_notetype_name = 7;
|
||||||
|
bool is_cloze = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ChangeNotetypeInfo {
|
message ChangeNotetypeInfo {
|
||||||
|
|
|
||||||
|
|
@ -422,11 +422,8 @@ and notes.mid = ? and cards.ord = ?""",
|
||||||
self.col.mod_schema(check=True)
|
self.col.mod_schema(check=True)
|
||||||
assert fmap
|
assert fmap
|
||||||
field_map = self._convert_legacy_map(fmap, len(newModel["flds"]))
|
field_map = self._convert_legacy_map(fmap, len(newModel["flds"]))
|
||||||
if (
|
is_cloze = newModel["type"] == MODEL_CLOZE or notetype["type"] == MODEL_CLOZE
|
||||||
not cmap
|
if not cmap or is_cloze:
|
||||||
or newModel["type"] == MODEL_CLOZE
|
|
||||||
or notetype["type"] == MODEL_CLOZE
|
|
||||||
):
|
|
||||||
template_map = []
|
template_map = []
|
||||||
else:
|
else:
|
||||||
template_map = self._convert_legacy_map(cmap, len(newModel["tmpls"]))
|
template_map = self._convert_legacy_map(cmap, len(newModel["tmpls"]))
|
||||||
|
|
@ -439,6 +436,7 @@ and notes.mid = ? and cards.ord = ?""",
|
||||||
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"),
|
||||||
|
is_cloze=is_cloze,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _convert_legacy_map(
|
def _convert_legacy_map(
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,7 @@ impl From<ChangeNotetypeInput> for anki_proto::notetypes::ChangeNotetypeRequest
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|idx| idx.map(|v| v as i32).unwrap_or(-1))
|
.map(|idx| idx.map(|v| v as i32).unwrap_or(-1))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
is_cloze: i.new_templates.is_none(),
|
||||||
new_templates: i
|
new_templates: i
|
||||||
.new_templates
|
.new_templates
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
? tr.changeNotetypeFields()
|
? tr.changeNotetypeFields()
|
||||||
: tr.changeNotetypeTemplates();
|
: tr.changeNotetypeTemplates();
|
||||||
|
|
||||||
$: unused = $info.unusedItems(ctx);
|
$: unused =
|
||||||
|
$info.isCloze && ctx === MapContext.Template ? [] : $info.unusedItems(ctx);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<StickyContainer
|
<StickyContainer
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,13 @@ export class ChangeNotetypeInfoWrapper {
|
||||||
fields: (number | null)[];
|
fields: (number | null)[];
|
||||||
templates?: (number | null)[];
|
templates?: (number | null)[];
|
||||||
oldNotetypeName: string;
|
oldNotetypeName: string;
|
||||||
|
isCloze: boolean;
|
||||||
readonly info: ChangeNotetypeInfo;
|
readonly info: ChangeNotetypeInfo;
|
||||||
|
|
||||||
constructor(info: ChangeNotetypeInfo) {
|
constructor(info: ChangeNotetypeInfo) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
const templates = info.input?.newTemplates ?? [];
|
const templates = info.input?.newTemplates ?? [];
|
||||||
|
this.isCloze = info.input?.isCloze ?? false;
|
||||||
if (templates.length > 0) {
|
if (templates.length > 0) {
|
||||||
this.templates = negativeOneToNull(templates);
|
this.templates = negativeOneToNull(templates);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue