summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-03 19:40:12 -0500
committerGitHub <noreply@github.com>2021-01-03 19:40:12 -0500
commit8c92c1cbc246001e27a1e31e53c2ce992bf72fbd (patch)
treeb92f99cccde03485f07669d172c85b8c78085d3e /ext/bg/js
parent63971776a5db6ad0d3a68361f64a74aa9e78aff5 (diff)
Refactor anki note generation (#1202)
* Create _injectAnkiNoteMedia function * Remove unused code path * Simplify modeOptions
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/anki-note-builder.js27
-rw-r--r--ext/bg/js/settings/anki-templates-controller.js10
2 files changed, 15 insertions, 22 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 71ef5b25..ae608bed 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -26,42 +26,35 @@ class AnkiNoteBuilder {
}
async createNote({
- anki=null,
definition,
mode,
context,
templates,
+ deckName,
+ modelName,
+ fields,
tags=[],
checkForDuplicates=true,
duplicateScope='collection',
resultOutputMode='split',
glossaryLayoutMode='default',
compactTags=false,
- modeOptions: {fields, deck, model},
- audioDetails=null,
- screenshotDetails=null,
- clipboardDetails=null,
errors=null
}) {
- if (anki !== null) {
- await this._injectMedia(anki, definition, fields, mode, audioDetails, screenshotDetails, clipboardDetails);
- }
-
let duplicateScopeDeckName = null;
let duplicateScopeCheckChildren = false;
if (duplicateScope === 'deck-root') {
duplicateScope = 'deck';
- duplicateScopeDeckName = this.getRootDeckName(deck);
+ duplicateScopeDeckName = this.getRootDeckName(deckName);
duplicateScopeCheckChildren = true;
}
- const fieldEntries = Object.entries(fields);
const noteFields = {};
const note = {
fields: noteFields,
tags,
- deckName: deck,
- modelName: model,
+ deckName,
+ modelName,
options: {
allowDuplicate: !checkForDuplicates,
duplicateScope,
@@ -74,14 +67,14 @@ class AnkiNoteBuilder {
const data = this._createNoteData(definition, mode, context, resultOutputMode, glossaryLayoutMode, compactTags);
const formattedFieldValuePromises = [];
- for (const [, fieldValue] of fieldEntries) {
+ for (const [, fieldValue] of fields) {
const formattedFieldValuePromise = this._formatField(fieldValue, data, templates, errors);
formattedFieldValuePromises.push(formattedFieldValuePromise);
}
const formattedFieldValues = await Promise.all(formattedFieldValuePromises);
- for (let i = 0, ii = fieldEntries.length; i < ii; ++i) {
- const fieldName = fieldEntries[i][0];
+ for (let i = 0, ii = fields.length; i < ii; ++i) {
+ const fieldName = fields[i][0];
const formattedFieldValue = formattedFieldValues[i];
noteFields[fieldName] = formattedFieldValue;
}
@@ -91,7 +84,7 @@ class AnkiNoteBuilder {
containsMarker(fields, marker) {
marker = `{${marker}}`;
- for (const fieldValue of Object.values(fields)) {
+ for (const [, fieldValue] of fields) {
if (fieldValue.includes(marker)) {
return true;
}
diff --git a/ext/bg/js/settings/anki-templates-controller.js b/ext/bg/js/settings/anki-templates-controller.js
index 5e40b7db..72f1a175 100644
--- a/ext/bg/js/settings/anki-templates-controller.js
+++ b/ext/bg/js/settings/anki-templates-controller.js
@@ -189,14 +189,14 @@ class AnkiTemplatesController {
mode,
context,
templates,
+ deckName: '',
+ modelName: '',
+ fields: [
+ ['field', field]
+ ],
resultOutputMode,
glossaryLayoutMode,
compactTags,
- modeOptions: {
- fields: {field},
- deck: '',
- model: ''
- },
errors: exceptions
});
result = note.fields.field;