From 435af3a485c5938ca1ff808d456d786735a3ea18 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 26 Jun 2021 14:10:18 -0400 Subject: Improve what info is logged when debugging a definition (#1756) --- ext/js/display/display.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 26c1e06c..28659294 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -1073,7 +1073,7 @@ class Display extends EventDispatcher { try { this._updateAdderButtonsPromise = promise; - const modes = isTerms ? ['term-kanji', 'term-kana'] : ['kanji']; + const modes = this._getModes(isTerms); let states; try { const noteContext = this._getNoteContext(); @@ -1922,9 +1922,16 @@ class Display extends EventDispatcher { return typeof queryPostProcessor === 'function' ? queryPostProcessor(query) : query; } + _getModes(isTerms) { + return isTerms ? ['term-kanji', 'term-kana'] : ['kanji']; + } + async _logDictionaryEntryData(index) { if (index < 0 || index >= this._dictionaryEntries.length) { return; } const dictionaryEntry = this._dictionaryEntries[index]; + const result = {dictionaryEntry}; + + // Anki note data let ankiNoteData; let ankiNoteDataException; try { @@ -1943,10 +1950,32 @@ class Display extends EventDispatcher { } catch (e) { ankiNoteDataException = e; } - const result = {dictionaryEntry, ankiNoteData}; + result.ankiNoteData = ankiNoteData; if (typeof ankiNoteDataException !== 'undefined') { result.ankiNoteDataException = ankiNoteDataException; } + + // Anki notes + const ankiNotes = []; + const modes = this._getModes(dictionaryEntry.type === 'term'); + for (const mode of modes) { + let ankiNote; + let ankiNoteException; + const ankiNoteErrors = []; + try { + const noteContext = this._getNoteContext(); + ankiNote = await this._createNote(dictionaryEntry, mode, noteContext, false, ankiNoteErrors); + } catch (e) { + ankiNoteException = e; + } + const entry = {mode, ankiNote}; + if (typeof ankiNoteException !== 'undefined') { + entry.ankiNoteException = ankiNoteException; + } + ankiNotes.push(entry); + } + result.ankiNotes = ankiNotes; + console.log(result); } } -- cgit v1.2.3