From fd6622400f64b2d568d38bde72f9fd75f8d06beb Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 Nov 2016 17:10:31 -0800 Subject: Templates --- ext/bg/js/dictionary.js | 10 +++++----- ext/bg/js/options-form.js | 36 +++++++++++++++++------------------- ext/bg/js/templates.js | 18 ++++++++++++++++++ ext/bg/js/util.js | 10 +++++++--- ext/bg/options.html | 14 ++++++++------ tmpl/dictionary.html | 21 +++++++++++++++++++++ 6 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 tmpl/dictionary.html diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js index 5859350b..008bc483 100644 --- a/ext/bg/js/dictionary.js +++ b/ext/bg/js/dictionary.js @@ -131,7 +131,7 @@ class Dictionary { }); } - getNames() { + getInfo() { if (this.db === null) { return Promise.reject('database not initialized'); } @@ -144,8 +144,8 @@ class Dictionary { return Promise.reject('database not initialized'); } - const indexLoaded = (dictionary, version, entities) => { - return this.db.dictionaries.add({dictionary, version}).then(() => { + const indexLoaded = (dictionary, version, entities, hasTerms, hasKanji) => { + return this.db.dictionaries.add({dictionary, version, hasTerms, hasKanji}).then(() => { this.entities = entities || {}; const rows = []; @@ -161,7 +161,7 @@ class Dictionary { }); }; - const termsLoaded = (dictionary, version, entries, total, current) => { + const termsLoaded = (dictionary, entries, total, current) => { const rows = []; for (const [expression, reading, tags, ...glossary] of entries) { rows.push({ @@ -180,7 +180,7 @@ class Dictionary { }); }; - const kanjiLoaded = (dictionary, version, entries, total, current) => { + const kanjiLoaded = (dictionary, entries, total, current) => { const rows = []; for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) { rows.push({ diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 060ee269..ec603eed 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -155,25 +155,21 @@ function populateAnkiDeckAndModel(opts) { } function populateDictionaries() { - // const dictGroups = $('.dictionaries'); - // dictGroups.empty(); - - // yomichan().translator.dictionary.getNames().then(rows => { - // for (const row of rows) { - // const dictPanel = $('
', {class: 'dictionary panel panel-default'}); - // const dictRow = $('
', {class: 'panel-body row'}).appendTo(dictPanel); - - // const title = $('
', {class: 'col-xs-8'}); - // $('

').append().html(` ${row.dictionary} v.${row.version}`).appendTo(title); - // title.appendTo(dictRow); - - // const controls = $('
', {class: 'col-xs-4 text-right'}); - // $('\n
\n

\n\n" + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.hasKanji : depth0),{"name":"if","hash":{},"fn":container.program(3, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "") + + "
\n"; +},"useData":true}); templates['footer.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { var helper; diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js index eaa7dd01..e99cdeab 100644 --- a/ext/bg/js/util.js +++ b/ext/bg/js/util.js @@ -121,7 +121,13 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/')); return loadJson(indexUrl).then(index => { if (indexLoaded !== null) { - return indexLoaded(index.title, index.version).then(() => index); + return indexLoaded( + index.title, + index.version, + index.entities, + index.termBanks > 0, + index.kanjiBanks > 0 + ).then(() => index); } return index; @@ -134,7 +140,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const bankUrl = `${indexDir}/term_bank_${i}.json`; loaders.push(() => loadJson(bankUrl).then(entries => termsLoaded( index.title, - index.version, entries, banksTotal, banksLoaded++ @@ -145,7 +150,6 @@ function importJsonDb(indexUrl, indexLoaded, termsLoaded, kanjiLoaded) { const bankUrl = `${indexDir}/kanji_bank_${i}.json`; loaders.push(() => loadJson(bankUrl).then(entries => kanjiLoaded( index.title, - index.version, entries, banksTotal, banksLoaded++ diff --git a/ext/bg/options.html b/ext/bg/options.html index 1136eefc..acd786cf 100644 --- a/ext/bg/options.html +++ b/ext/bg/options.html @@ -124,18 +124,18 @@
- -

Yomichan features automatic flashcard creation for Anki, a free application designed to help you retain knowledge. While the AnkiConnect plugin offers the best experience, it is also possible to create flashcards through AnkiWeb, provided you already have an account.

+ +
@@ -217,6 +217,8 @@ + + diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html new file mode 100644 index 00000000..21847722 --- /dev/null +++ b/tmpl/dictionary.html @@ -0,0 +1,21 @@ +
+
+
+

{{name}} v.{{version}}

+
+
+ +
+
+ + {{#if hasTerms}} +
+ +
+ {{/if}} + {{#if hasKanji}} +
+ +
+ {{/if}} +
-- cgit v1.2.3