view added notes

This commit is contained in:
Alex Yatskov 2017-07-01 18:27:49 -07:00
parent 390cb12896
commit d57c5530b7
11 changed files with 76 additions and 17 deletions

View File

@ -26,7 +26,7 @@ class AnkiConnect {
} }
addNote(note) { addNote(note) {
return this.checkVersion().then(() => this.ankiInvoke('addNote', {note}, null)); return this.checkVersion().then(() => this.ankiInvoke('addNote', {note}));
} }
canAddNotes(notes) { canAddNotes(notes) {
@ -34,15 +34,19 @@ class AnkiConnect {
} }
getDeckNames() { getDeckNames() {
return this.checkVersion().then(() => this.ankiInvoke('deckNames', {}, null)); return this.checkVersion().then(() => this.ankiInvoke('deckNames', {}));
} }
getModelNames() { getModelNames() {
return this.checkVersion().then(() => this.ankiInvoke('modelNames', {}, null)); return this.checkVersion().then(() => this.ankiInvoke('modelNames', {}));
} }
getModelFieldNames(modelName) { 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() { checkVersion() {
@ -60,13 +64,13 @@ class AnkiConnect {
ankiInvoke(action, params, pool) { ankiInvoke(action, params, pool) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (pool !== null && this.asyncPools.hasOwnProperty(pool)) { if (pool && this.asyncPools.hasOwnProperty(pool)) {
this.asyncPools[pool].abort(); this.asyncPools[pool].abort();
} }
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.addEventListener('loadend', () => { xhr.addEventListener('loadend', () => {
if (pool !== null) { if (pool) {
delete this.asyncPools[pool]; delete this.asyncPools[pool];
} }

View File

@ -37,4 +37,8 @@ class AnkiNull {
getModelFieldNames(modelName) { getModelFieldNames(modelName) {
return Promise.resolve([]); return Promise.resolve([]);
} }
guiBrowse(query) {
return Promise.resolve([]);
}
} }

View File

@ -37,6 +37,10 @@ window.displayWindow = new class extends Display {
return instYomi().definitionsAddable(definitions, modes).catch(() => []); return instYomi().definitionsAddable(definitions, modes).catch(() => []);
} }
noteView(noteId) {
return instYomi().noteView(noteId);
}
templateRender(template, data) { templateRender(template, data) {
return instYomi().templateRender(template, data); return instYomi().templateRender(template, data);
} }

View File

@ -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) { templates['kanji.html'] = template({"1":function(container,depth0,helpers,partials,data) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}; var stack1, helper, alias1=depth0 != null ? depth0 : {};
return "<div class=\"entry\" data-type=\"kanji\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n" return "<div class=\"entry\" data-type=\"kanji\">\n <div class=\"actions\">\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.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 : "") + ((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 : "")
+ " </div>\n\n <div class=\"glyph\">" + " <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n </div>\n\n <div class=\"glyph\">"
+ 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))) + 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)))
+ "</div>\n\n <div class=\"reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\n" + "</div>\n\n <div class=\"reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\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 : "") + ((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 : "") + ((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 : "")
+ "</div>\n"; + "</div>\n";
},"2":function(container,depth0,helpers,partials,data) { },"2":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" title=\"Add Kanji (Alt + K)\" alt></a>\n"; return " <a href=\"#\" class=\"action-view-note pending disabled\"><img src=\"/mixed/img/view-note.png\" title=\"View added note (Alt + V)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"kanji\"><img src=\"/mixed/img/add-kanji.png\" title=\"Add Kanji (Alt + K)\" alt></a>\n";
},"4":function(container,depth0,helpers,partials,data) { },"4":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" title=\"Source term (Alt + B)\" alt></a>\n"; return " <a href=\"#\" class=\"source-term\"><img src=\"/mixed/img/source-term.png\" title=\"Source term (Alt + B)\" alt></a>\n";
},"6":function(container,depth0,helpers,partials,data) { },"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) { },"12":function(container,depth0,helpers,partials,data) {
var stack1, alias1=depth0 != null ? depth0 : {}; var stack1, alias1=depth0 != null ? depth0 : {};
return "<div class=\"entry\" data-type=\"term\">\n <div class=\"actions\">\n <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n" return "<div class=\"entry\" data-type=\"term\">\n <div class=\"actions\">\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.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 : "") + ((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 : "")
+ " </div>\n\n" + " <img src=\"/mixed/img/entry-current.png\" class=\"current\" title=\"Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)\" alt>\n </div>\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 : "") + ((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" + "\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 : "") + ((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 : "") + ((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 : "")
+ "</div>\n"; + "</div>\n";
},"13":function(container,depth0,helpers,partials,data) { },"13":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" title=\"Add expression (Alt + E)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" title=\"Add reading (Alt + R)\" alt></a>\n"; return " <a href=\"#\" class=\"action-view-note pending disabled\"><img src=\"/mixed/img/view-note.png\" title=\"View added note (Alt + V)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kanji\"><img src=\"/mixed/img/add-term-kanji.png\" title=\"Add expression (Alt + E)\" alt></a>\n <a href=\"#\" class=\"action-add-note pending disabled\" data-mode=\"term-kana\"><img src=\"/mixed/img/add-term-kana.png\" title=\"Add reading (Alt + R)\" alt></a>\n";
},"15":function(container,depth0,helpers,partials,data) { },"15":function(container,depth0,helpers,partials,data) {
return " <a href=\"#\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" title=\"Play audio (Alt + P)\" alt></a>\n"; return " <a href=\"#\" class=\"action-play-audio\"><img src=\"/mixed/img/play-audio.png\" title=\"Play audio (Alt + P)\" alt></a>\n";
},"17":function(container,depth0,helpers,partials,data) { },"17":function(container,depth0,helpers,partials,data) {

View File

@ -157,6 +157,10 @@ window.yomichan = new class {
}); });
} }
noteView(noteId) {
return this.anki.guiBrowse(`nid:${noteId}`);
}
templateRender(template, data) { templateRender(template, data) {
return Promise.resolve(handlebarsRender(template, data)); return Promise.resolve(handlebarsRender(template, data));
} }
@ -211,6 +215,10 @@ window.yomichan = new class {
definitionsAddable: ({definitions, modes, callback}) => { definitionsAddable: ({definitions, modes, callback}) => {
promiseCallback(this.definitionsAddable(definitions, modes), callback); promiseCallback(this.definitionsAddable(definitions, modes), callback);
},
noteView: ({noteId}) => {
promiseCallback(this.noteView(noteId), callback);
} }
}; };

View File

@ -31,6 +31,10 @@ window.displayFrame = new class extends Display {
return bgDefinitionsAddable(definitions, modes); return bgDefinitionsAddable(definitions, modes);
} }
noteView(noteId) {
return bgNoteView(noteId);
}
templateRender(template, data) { templateRender(template, data) {
return bgTemplateRender(template, data); return bgTemplateRender(template, data);
} }

View File

@ -62,6 +62,9 @@ function bgDefinitionAdd(definition, mode) {
return bgInvoke('definitionAdd', {definition, mode}); return bgInvoke('definitionAdd', {definition, mode});
} }
function bgNoteView(noteId) {
return bgInvoke('noteView', {noteId});
}
/* /*
* Document * Document

BIN
ext/mixed/img/view-note.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B

View File

@ -40,6 +40,10 @@ class Display {
throw 'override me'; throw 'override me';
} }
noteView(noteId) {
throw 'override me';
}
templateRender(template, data) { templateRender(template, data) {
throw 'override me'; throw 'override me';
} }
@ -88,6 +92,7 @@ class Display {
this.entryScroll(context && context.index || 0); this.entryScroll(context && context.index || 0);
$('.action-add-note').click(this.onAddNote.bind(this)); $('.action-add-note').click(this.onAddNote.bind(this));
$('.action-view-note').click(this.onViewNote.bind(this));
$('.action-play-audio').click(this.onPlayAudio.bind(this)); $('.action-play-audio').click(this.onPlayAudio.bind(this));
$('.kanji-link').click(this.onKanjiLookup.bind(this)); $('.kanji-link').click(this.onKanjiLookup.bind(this));
@ -134,7 +139,7 @@ class Display {
adderButtonsUpdate(modes, sequence) { adderButtonsUpdate(modes, sequence) {
return this.definitionsAddable(this.definitions, modes).then(states => { return this.definitionsAddable(this.definitions, modes).then(states => {
if (states === null || sequence !== this.sequence) { if (!states || sequence !== this.sequence) {
return; return;
} }
@ -211,6 +216,13 @@ class Display {
this.noteAdd(this.definitions[index], link.data('mode')); this.noteAdd(this.definitions[index], link.data('mode'));
} }
onViewNote(e) {
e.preventDefault();
const link = $(e.currentTarget);
const index = Display.entryIndexFind(link);
this.noteView(link.data('noteId'));
}
onKeyDown(e) { onKeyDown(e) {
const noteTryAdd = mode => { const noteTryAdd = mode => {
const button = Display.adderButtonFind(this.index, mode); const button = Display.adderButtonFind(this.index, mode);
@ -219,6 +231,13 @@ class Display {
} }
}; };
const noteTryView = mode => {
const button = Display.viewerButtonFind(this.index);
if (button.length !== 0 && !button.hasClass('disabled')) {
this.noteView(button.data('noteId'));
}
};
const handlers = { const handlers = {
27: /* escape */ () => { 27: /* escape */ () => {
this.clearSearch(); this.clearSearch();
@ -303,6 +322,12 @@ class Display {
return true; return true;
} }
},
86: /* v */ () => {
if (e.altKey) {
noteTryView();
}
} }
}; };
@ -326,10 +351,11 @@ class Display {
noteAdd(definition, mode) { noteAdd(definition, mode) {
this.spinner.show(); this.spinner.show();
return this.definitionAdd(definition, mode).then(success => { return this.definitionAdd(definition, mode).then(noteId => {
if (success) { if (noteId) {
const index = this.definitions.indexOf(definition); const index = this.definitions.indexOf(definition);
Display.adderButtonFind(index, mode).addClass('disabled'); Display.adderButtonFind(index, mode).addClass('disabled');
Display.viewerButtonFind(index).removeClass('pending disabled').data('noteId', noteId);
} else { } else {
this.handleError('note could not be added'); this.handleError('note could not be added');
} }
@ -375,4 +401,8 @@ class Display {
static adderButtonFind(index, mode) { static adderButtonFind(index, mode) {
return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`); return $('.entry').eq(index).find(`.action-add-note[data-mode="${mode}"]`);
} }
static viewerButtonFind(index) {
return $('.entry').eq(index).find('.action-view-note');
}
} }

View File

@ -1,13 +1,14 @@
{{#*inline "kanji"}} {{#*inline "kanji"}}
<div class="entry" data-type="kanji"> <div class="entry" data-type="kanji">
<div class="actions"> <div class="actions">
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
{{#if addable}} {{#if addable}}
<a href="#" class="action-view-note pending disabled"><img src="/mixed/img/view-note.png" title="View added note (Alt + V)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="kanji"><img src="/mixed/img/add-kanji.png" title="Add Kanji (Alt + K)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="kanji"><img src="/mixed/img/add-kanji.png" title="Add Kanji (Alt + K)" alt></a>
{{/if}} {{/if}}
{{#if source}} {{#if source}}
<a href="#" class="source-term"><img src="/mixed/img/source-term.png" title="Source term (Alt + B)" alt></a> <a href="#" class="source-term"><img src="/mixed/img/source-term.png" title="Source term (Alt + B)" alt></a>
{{/if}} {{/if}}
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
</div> </div>
<div class="glyph">{{character}}</div> <div class="glyph">{{character}}</div>

View File

@ -20,14 +20,15 @@
{{#*inline "term"}} {{#*inline "term"}}
<div class="entry" data-type="term"> <div class="entry" data-type="term">
<div class="actions"> <div class="actions">
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
{{#if addable}} {{#if addable}}
<a href="#" class="action-view-note pending disabled"><img src="/mixed/img/view-note.png" title="View added note (Alt + V)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="term-kanji"><img src="/mixed/img/add-term-kanji.png" title="Add expression (Alt + E)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="term-kanji"><img src="/mixed/img/add-term-kanji.png" title="Add expression (Alt + E)" alt></a>
<a href="#" class="action-add-note pending disabled" data-mode="term-kana"><img src="/mixed/img/add-term-kana.png" title="Add reading (Alt + R)" alt></a> <a href="#" class="action-add-note pending disabled" data-mode="term-kana"><img src="/mixed/img/add-term-kana.png" title="Add reading (Alt + R)" alt></a>
{{/if}} {{/if}}
{{#if playback}} {{#if playback}}
<a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio (Alt + P)" alt></a> <a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio (Alt + P)" alt></a>
{{/if}} {{/if}}
<img src="/mixed/img/entry-current.png" class="current" title="Current entry (Alt + Up/Down/Home/End/PgUp/PgDn)" alt>
</div> </div>
{{#if reading}} {{#if reading}}