diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-09-09 11:54:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 11:54:40 -0400 |
commit | 2aa86cc5f8cda022076f7fa047f17fdcca4a0f5e (patch) | |
tree | d89d3776d46e76fc818b3ac4ba420d38c024002e /ext/bg/js/backend.js | |
parent | b687870a55eae43a71ea3adc41be0ab341a8721f (diff) |
Anki API refactor (#790)
* Add function guiBrowseNote
* Assign default server as null
* Use get/set properties for server/enabled
* Refactor option values
* Refactor createNote/Data functions to not use options format directly
* Use createNote for testing
* Add errors
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r-- | ext/bg/js/backend.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index e9f3fbec..832dbc3a 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -471,7 +471,7 @@ class Backend { ); } - const note = await this._ankiNoteBuilder.createNote(definition, mode, context, options, templates); + const note = await this._createNote(definition, mode, context, options, templates); return this._anki.addNote(note); } @@ -484,7 +484,7 @@ class Backend { const notePromises = []; for (const definition of definitions) { for (const mode of modes) { - const notePromise = this._ankiNoteBuilder.createNote(definition, mode, context, options, templates); + const notePromise = this._createNote(definition, mode, context, options, templates); notePromises.push(notePromise); } } @@ -524,7 +524,7 @@ class Backend { } async _onApiNoteView({noteId}) { - return await this._anki.guiBrowse(`nid:${noteId}`); + return await this._anki.guiBrowseNote(noteId); } async _onApiTemplateRender({template, data, marker}) { @@ -1023,8 +1023,8 @@ class Backend { const options = this.getOptions({current: true}); this._updateBadge(); - this._anki.setServer(options.anki.server); - this._anki.setEnabled(options.anki.enable); + this._anki.server = options.anki.server; + this._anki.enabled = options.anki.enable; if (options.parsing.enableMecabParser) { this._mecab.startListener(); @@ -1609,4 +1609,21 @@ class Backend { reader.readAsDataURL(file); }); } + + async _createNote(definition, mode, context, options, templates) { + const {general: {resultOutputMode, compactGlossaries}, anki: ankiOptions} = options; + const {tags, duplicateScope} = ankiOptions; + const modeOptions = (mode === 'kanji') ? ankiOptions.kanji : ankiOptions.terms; + return await this._ankiNoteBuilder.createNote({ + definition, + mode, + context, + templates, + tags, + duplicateScope, + resultOutputMode, + compactGlossaries, + modeOptions + }); + } } |