backwards compat
This commit is contained in:
parent
5476c10046
commit
ba25fbfd1f
@ -110,6 +110,8 @@ class Database {
|
||||
kunyomi: dictFieldSplit(row.kunyomi),
|
||||
tags: dictFieldSplit(row.tags),
|
||||
glossary: row.meanings,
|
||||
indices: row.indices,
|
||||
stats: row.stats,
|
||||
dictionary: row.dictionary
|
||||
});
|
||||
}
|
||||
@ -168,6 +170,10 @@ class Database {
|
||||
}
|
||||
|
||||
const indexDataLoaded = async summary => {
|
||||
if (summary.version > 2) {
|
||||
throw 'unsupported dictionary version';
|
||||
}
|
||||
|
||||
const count = await this.db.dictionaries.where('title').equals(summary.title).count();
|
||||
if (count > 0) {
|
||||
throw `dictionary "${summary.title}" is already imported`;
|
||||
@ -176,12 +182,13 @@ class Database {
|
||||
await this.db.dictionaries.add(summary);
|
||||
};
|
||||
|
||||
const termDataLoaded = async (title, entries, total, current) => {
|
||||
const termDataLoaded = async (summary, entries, total, current) => {
|
||||
if (callback) {
|
||||
callback(total, current);
|
||||
}
|
||||
|
||||
const rows = [];
|
||||
if (summary.version === 1) {
|
||||
for (const [expression, reading, tags, rules, score, ...glossary] of entries) {
|
||||
rows.push({
|
||||
expression,
|
||||
@ -190,14 +197,27 @@ class Database {
|
||||
rules,
|
||||
score,
|
||||
glossary,
|
||||
dictionary: title
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (const [expression, reading, tags, rules, score, glossary] of entries) {
|
||||
rows.push({
|
||||
expression,
|
||||
reading,
|
||||
tags,
|
||||
rules,
|
||||
score,
|
||||
glossary,
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.db.terms.bulkAdd(rows);
|
||||
};
|
||||
|
||||
const termFreqDataLoaded = async (title, entries, total, current) => {
|
||||
const termFreqDataLoaded = async (summary, entries, total, current) => {
|
||||
if (callback) {
|
||||
callback(total, current);
|
||||
}
|
||||
@ -207,19 +227,20 @@ class Database {
|
||||
rows.push({
|
||||
expression,
|
||||
frequency,
|
||||
dictionary: title
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
|
||||
await this.db.termFreq.bulkAdd(rows);
|
||||
};
|
||||
|
||||
const kanjiDataLoaded = async (title, entries, total, current) => {
|
||||
const kanjiDataLoaded = async (summary, entries, total, current) => {
|
||||
if (callback) {
|
||||
callback(total, current);
|
||||
}
|
||||
|
||||
const rows = [];
|
||||
if (summary.version === 1) {
|
||||
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
|
||||
rows.push({
|
||||
character,
|
||||
@ -227,14 +248,28 @@ class Database {
|
||||
kunyomi,
|
||||
tags,
|
||||
meanings,
|
||||
dictionary: title
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (const [character, onyomi, kunyomi, tags, meanings, indices, stats] of entries) {
|
||||
rows.push({
|
||||
character,
|
||||
onyomi,
|
||||
kunyomi,
|
||||
tags,
|
||||
meanings,
|
||||
indices,
|
||||
stats,
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.db.kanji.bulkAdd(rows);
|
||||
};
|
||||
|
||||
const kanjiFreqDataLoaded = async (title, entries, total, current) => {
|
||||
const kanjiFreqDataLoaded = async (summary, entries, total, current) => {
|
||||
if (callback) {
|
||||
callback(total, current);
|
||||
}
|
||||
@ -244,14 +279,14 @@ class Database {
|
||||
rows.push({
|
||||
character,
|
||||
frequency,
|
||||
dictionary: title
|
||||
dictionary: summary.title
|
||||
});
|
||||
}
|
||||
|
||||
await this.db.kanjiFreq.bulkAdd(rows);
|
||||
};
|
||||
|
||||
const tagDataLoaded = async (title, entries, total, current) => {
|
||||
const tagDataLoaded = async (summary, entries, total, current) => {
|
||||
if (callback) {
|
||||
callback(total, current);
|
||||
}
|
||||
@ -263,7 +298,7 @@ class Database {
|
||||
category,
|
||||
order,
|
||||
notes,
|
||||
dictionary: title
|
||||
dictionary: summary.title
|
||||
});
|
||||
|
||||
rows.push(row);
|
||||
@ -300,11 +335,16 @@ class Database {
|
||||
}
|
||||
|
||||
const index = JSON.parse(await indexFile.async('string'));
|
||||
if (!index.title || !index.version || !index.revision) {
|
||||
if (!index.title || !index.revision) {
|
||||
throw 'unrecognized dictionary format';
|
||||
}
|
||||
|
||||
const summary = {title: index.title, version: index.version, revision: index.revision};
|
||||
const summary = {
|
||||
title: index.title,
|
||||
revision: index.revision,
|
||||
version: index.format || index.version
|
||||
};
|
||||
|
||||
if (indexDataLoaded) {
|
||||
await indexDataLoaded(summary);
|
||||
}
|
||||
@ -345,24 +385,24 @@ class Database {
|
||||
bank.push([name, tag.category, tag.order, tag.notes]);
|
||||
}
|
||||
|
||||
tagDataLoaded(index.title, bank, ++bankTotalCount, bankLoadedCount++);
|
||||
tagDataLoaded(summary, bank, ++bankTotalCount, bankLoadedCount++);
|
||||
}
|
||||
|
||||
const loadBank = async (namer, count, callback) => {
|
||||
const loadBank = async (summary, namer, count, callback) => {
|
||||
if (callback) {
|
||||
for (let i = 0; i < count; ++i) {
|
||||
const bankFile = zip.files[namer(i)];
|
||||
const bank = JSON.parse(await bankFile.async('string'));
|
||||
await callback(index.title, bank, bankTotalCount, bankLoadedCount++);
|
||||
await callback(summary, bank, bankTotalCount, bankLoadedCount++);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await loadBank(buildTermBankName, termBankCount, termDataLoaded);
|
||||
await loadBank(buildTermFreqBankName, termFreqBankCount, termFreqDataLoaded);
|
||||
await loadBank(buildKanjiBankName, kanjiBankCount, kanjiDataLoaded);
|
||||
await loadBank(buildKanjiFreqBankName, kanjiFreqBankCount, kanjiFreqDataLoaded);
|
||||
await loadBank(buildTagBankName, tagBankCount, tagDataLoaded);
|
||||
await loadBank(summary, buildTermBankName, termBankCount, termDataLoaded);
|
||||
await loadBank(summary, buildTermFreqBankName, termFreqBankCount, termFreqDataLoaded);
|
||||
await loadBank(summary, buildKanjiBankName, kanjiBankCount, kanjiDataLoaded);
|
||||
await loadBank(summary, buildKanjiFreqBankName, kanjiFreqBankCount, kanjiFreqDataLoaded);
|
||||
await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded);
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
@ -36,8 +36,12 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </dl>\n </td>\n <td class=\"glossary\">\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["1"] : stack1),{"name":"if","hash":{},"fn":container.program(13, data, 0),"inverse":container.program(16, data, 0),"data":data})) != null ? stack1 : "")
|
||||
+ " </td>\n <td></td>\n </tr>\n </table>\n\n"
|
||||
+ ((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 : "")
|
||||
+ " </td>\n <td>\n <dl>\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.stats : depth0),{"name":"if","hash":{},"fn":container.program(18, data, 0),"inverse":container.program(21, data, 0),"data":data})) != null ? stack1 : "")
|
||||
+ " </dl>\n </td>\n </tr>\n <tr>\n <th colspan=\"3\">Dictionary Indices</th>\n </tr>\n <tr>\n <td colspan=\"3\">\n <dl>\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.indices : depth0),{"name":"if","hash":{},"fn":container.program(23, data, 0),"inverse":container.program(25, data, 0),"data":data})) != null ? stack1 : "")
|
||||
+ " </dl>\n </td>\n </tr>\n </table>\n\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.debug : depth0),{"name":"if","hash":{},"fn":container.program(27, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "</div>\n";
|
||||
},"2":function(container,depth0,helpers,partials,data) {
|
||||
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";
|
||||
@ -84,35 +88,55 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
+ container.escapeExpression(container.lambda(((stack1 = (depth0 != null ? depth0.glossary : depth0)) != null ? stack1["0"] : stack1), depth0))
|
||||
+ "</span>\n";
|
||||
},"18":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.stats : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
|
||||
},"19":function(container,depth0,helpers,partials,data) {
|
||||
var helper, alias1=container.escapeExpression;
|
||||
|
||||
return " <dd><b>"
|
||||
+ alias1(((helper = (helper = helpers.key || (data && data.key)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),{"name":"key","hash":{},"data":data}) : helper)))
|
||||
+ "</b>: "
|
||||
+ alias1(container.lambda(depth0, depth0))
|
||||
+ "</dd>\n";
|
||||
},"21":function(container,depth0,helpers,partials,data) {
|
||||
return " No statistical data found\n";
|
||||
},"23":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.indices : depth0),{"name":"each","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "");
|
||||
},"25":function(container,depth0,helpers,partials,data) {
|
||||
return " No index data found\n";
|
||||
},"27":function(container,depth0,helpers,partials,data) {
|
||||
var stack1, helper, options, buffer =
|
||||
" <pre>";
|
||||
stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(19, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
|
||||
stack1 = ((helper = (helper = helpers.dumpObject || (depth0 != null ? depth0.dumpObject : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"dumpObject","hash":{},"fn":container.program(28, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : (container.nullContext || {}),options) : helper));
|
||||
if (!helpers.dumpObject) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
|
||||
if (stack1 != null) { buffer += stack1; }
|
||||
return buffer + "</pre>\n";
|
||||
},"19":function(container,depth0,helpers,partials,data) {
|
||||
},"28":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return ((stack1 = container.lambda(depth0, depth0)) != null ? stack1 : "");
|
||||
},"21":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
},"30":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
var stack1;
|
||||
|
||||
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(22, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
|
||||
},"22":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
return ((stack1 = helpers.each.call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"each","hash":{},"fn":container.program(31, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "");
|
||||
},"31":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
var stack1;
|
||||
|
||||
return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(23, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
return ((stack1 = helpers.unless.call(depth0 != null ? depth0 : (container.nullContext || {}),(data && data.first),{"name":"unless","hash":{},"fn":container.program(32, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = container.invokePartial(partials.kanji,depth0,{"name":"kanji","hash":{"root":(depths[1] != null ? depths[1].root : depths[1]),"source":(depths[1] != null ? depths[1].source : depths[1]),"addable":(depths[1] != null ? depths[1].addable : depths[1]),"debug":(depths[1] != null ? depths[1].debug : depths[1])},"data":data,"helpers":helpers,"partials":partials,"decorators":container.decorators})) != null ? stack1 : "");
|
||||
},"23":function(container,depth0,helpers,partials,data) {
|
||||
},"32":function(container,depth0,helpers,partials,data) {
|
||||
return "<hr>";
|
||||
},"25":function(container,depth0,helpers,partials,data) {
|
||||
return "<p class=\"note\">No results found.</p>\n";
|
||||
},"34":function(container,depth0,helpers,partials,data) {
|
||||
return "<p class=\"note\">No results found</p>\n";
|
||||
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
var stack1;
|
||||
|
||||
return "\n"
|
||||
+ ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(21, data, 0, blockParams, depths),"inverse":container.program(25, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
|
||||
+ ((stack1 = helpers["if"].call(depth0 != null ? depth0 : (container.nullContext || {}),(depth0 != null ? depth0.definitions : depth0),{"name":"if","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.program(34, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "");
|
||||
},"main_d": function(fn, props, container, depth0, data, blockParams, depths) {
|
||||
|
||||
var decorators = container.decorators;
|
||||
|
@ -53,7 +53,33 @@
|
||||
<span class="glossary-item">{{glossary.[0]}}</span>
|
||||
{{/if}}
|
||||
</td>
|
||||
<td></td>
|
||||
<td>
|
||||
<dl>
|
||||
{{#if stats}}
|
||||
{{#each stats}}
|
||||
<dd><b>{{@key}}</b>: {{.}}</dd>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
No statistical data found
|
||||
{{/if}}
|
||||
</dl>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="3">Dictionary Indices</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<dl>
|
||||
{{#if indices}}
|
||||
{{#each indices}}
|
||||
<dd><b>{{@key}}</b>: {{.}}</dd>
|
||||
{{/each}}
|
||||
{{else}}
|
||||
No index data found
|
||||
{{/if}}
|
||||
</dl>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -69,5 +95,5 @@
|
||||
{{> kanji debug=../debug addable=../addable source=../source root=../root}}
|
||||
{{/each}}
|
||||
{{else}}
|
||||
<p class="note">No results found.</p>
|
||||
<p class="note">No results found</p>
|
||||
{{/if}}
|
||||
|
Loading…
Reference in New Issue
Block a user