From d57c5530b7ad56a7cc89782b4d186d8fddb55d86 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 1 Jul 2017 18:27:49 -0700 Subject: view added notes --- ext/bg/js/anki-connect.js | 16 ++++++++++------ ext/bg/js/anki-null.js | 4 ++++ ext/bg/js/display-window.js | 4 ++++ ext/bg/js/templates.js | 12 ++++++------ ext/bg/js/yomichan.js | 8 ++++++++ 5 files changed, 32 insertions(+), 12 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/anki-connect.js b/ext/bg/js/anki-connect.js index 9759c8f5..173feefd 100644 --- a/ext/bg/js/anki-connect.js +++ b/ext/bg/js/anki-connect.js @@ -26,7 +26,7 @@ class AnkiConnect { } addNote(note) { - return this.checkVersion().then(() => this.ankiInvoke('addNote', {note}, null)); + return this.checkVersion().then(() => this.ankiInvoke('addNote', {note})); } canAddNotes(notes) { @@ -34,15 +34,19 @@ class AnkiConnect { } getDeckNames() { - return this.checkVersion().then(() => this.ankiInvoke('deckNames', {}, null)); + return this.checkVersion().then(() => this.ankiInvoke('deckNames', {})); } getModelNames() { - return this.checkVersion().then(() => this.ankiInvoke('modelNames', {}, null)); + return this.checkVersion().then(() => this.ankiInvoke('modelNames', {})); } getModelFieldNames(modelName) { - return this.checkVersion().then(() => this.ankiInvoke('modelFieldNames', {modelName}, null)); + return this.checkVersion().then(() => this.ankiInvoke('modelFieldNames', {modelName})); + } + + guiBrowse(query) { + return this.checkVersion().then(() => this.ankiInvoke('guiBrowse', {query})); } checkVersion() { @@ -60,13 +64,13 @@ class AnkiConnect { ankiInvoke(action, params, pool) { return new Promise((resolve, reject) => { - if (pool !== null && this.asyncPools.hasOwnProperty(pool)) { + if (pool && this.asyncPools.hasOwnProperty(pool)) { this.asyncPools[pool].abort(); } const xhr = new XMLHttpRequest(); xhr.addEventListener('loadend', () => { - if (pool !== null) { + if (pool) { delete this.asyncPools[pool]; } diff --git a/ext/bg/js/anki-null.js b/ext/bg/js/anki-null.js index 99dc2f30..8dad6915 100644 --- a/ext/bg/js/anki-null.js +++ b/ext/bg/js/anki-null.js @@ -37,4 +37,8 @@ class AnkiNull { getModelFieldNames(modelName) { return Promise.resolve([]); } + + guiBrowse(query) { + return Promise.resolve([]); + } } diff --git a/ext/bg/js/display-window.js b/ext/bg/js/display-window.js index ae97cd36..64e56f72 100644 --- a/ext/bg/js/display-window.js +++ b/ext/bg/js/display-window.js @@ -37,6 +37,10 @@ window.displayWindow = new class extends Display { return instYomi().definitionsAddable(definitions, modes).catch(() => []); } + noteView(noteId) { + return instYomi().noteView(noteId); + } + templateRender(template, data) { return instYomi().templateRender(template, data); } diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js index f10134ee..50686ed4 100644 --- a/ext/bg/js/templates.js +++ b/ext/bg/js/templates.js @@ -315,10 +315,10 @@ templates['fields.html'] = template({"1":function(container,depth0,helpers,parti templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) { var stack1, helper, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(2, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.source : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n\n
" + + " \n
\n\n
" + container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper))) + "
\n\n
\n \n \n \n
Kunyomi:\n" + ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") @@ -332,7 +332,7 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "\n"; },"2":function(container,depth0,helpers,partials,data) { - return " \n"; + return " \n \n"; },"4":function(container,depth0,helpers,partials,data) { return " \n"; },"6":function(container,depth0,helpers,partials,data) { @@ -486,10 +486,10 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia },"12":function(container,depth0,helpers,partials,data) { var stack1, alias1=depth0 != null ? depth0 : {}; - return "
\n
\n \n" + return "
\n
\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.addable : depth0),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.playback : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") - + "
\n\n" + + " \n
\n\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(17, data, 0),"inverse":container.program(20, data, 0),"data":data})) != null ? stack1 : "") + "\n" + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reasons : depth0),{"name":"if","hash":{},"fn":container.program(22, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") @@ -499,7 +499,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(34, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + "
\n"; },"13":function(container,depth0,helpers,partials,data) { - return " \n \n"; + return " \n \n \n"; },"15":function(container,depth0,helpers,partials,data) { return " \n"; },"17":function(container,depth0,helpers,partials,data) { diff --git a/ext/bg/js/yomichan.js b/ext/bg/js/yomichan.js index b4beb179..e0bdabc3 100644 --- a/ext/bg/js/yomichan.js +++ b/ext/bg/js/yomichan.js @@ -157,6 +157,10 @@ window.yomichan = new class { }); } + noteView(noteId) { + return this.anki.guiBrowse(`nid:${noteId}`); + } + templateRender(template, data) { return Promise.resolve(handlebarsRender(template, data)); } @@ -211,6 +215,10 @@ window.yomichan = new class { definitionsAddable: ({definitions, modes, callback}) => { promiseCallback(this.definitionsAddable(definitions, modes), callback); + }, + + noteView: ({noteId}) => { + promiseCallback(this.noteView(noteId), callback); } }; -- cgit v1.2.3