summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2016-11-05 17:30:00 -0700
committerAlex Yatskov <alex@foosoft.net>2016-11-05 17:30:00 -0700
commite2f1560afa25274d3b0efd3ce8fc8a17740ab7cc (patch)
tree711a2817fc1b2e08e25560164aa151c0e47f4351
parente4fa25894f7827c3461d2a7adc249a6f1aebc48b (diff)
WIP
-rw-r--r--ext/bg/js/dictionary.js41
-rw-r--r--ext/bg/js/util.js8
2 files changed, 33 insertions, 16 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 2c9636ab..a2a4047a 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -20,7 +20,7 @@
class Dictionary {
constructor() {
this.db = null;
- this.dbVer = 3;
+ this.dbVer = 4;
this.entities = null;
}
@@ -31,10 +31,10 @@ class Dictionary {
this.db = new Dexie('dict');
this.db.version(1).stores({
- terms: '++id,expression,reading',
- entities: '++,name',
- kanji: '++,character',
- meta: 'name,value',
+ terms: '++id, dictionary, expression, reading',
+ kanji: '++, dictionary, character',
+ entities: '++, dictionary, name',
+ meta: 'name, value',
});
}
@@ -135,21 +135,31 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const entitiesLoaded = entities => {
+ const indexLoaded = (dictionary, entities) => {
this.entities = entities || {};
const rows = [];
for (const name in entities || {}) {
- rows.push({name, value: entities[name]});
+ rows.push({
+ dictionary,
+ name,
+ value: entities[name]
+ });
}
return this.db.entities.bulkAdd(rows);
};
- const entriesLoaded = (entries, total, current) => {
+ const entriesLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [expression, reading, tags, ...glossary] of entries) {
- rows.push({expression, reading, tags, glossary});
+ rows.push({
+ dictionary,
+ expression,
+ reading,
+ tags,
+ glossary
+ });
}
return this.db.terms.bulkAdd(rows).then(() => {
@@ -159,7 +169,7 @@ class Dictionary {
});
};
- return importJsonDb(indexUrl, entitiesLoaded, entriesLoaded);
+ return importJsonDb(indexUrl, indexLoaded, entriesLoaded);
}
importKanjiDict(indexUrl, callback) {
@@ -167,10 +177,17 @@ class Dictionary {
return Promise.reject('database not initialized');
}
- const entriesLoaded = (entries, total, current) => {
+ const entriesLoaded = (dictionary, entries, total, current) => {
const rows = [];
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
- rows.push({character, onyomi, kunyomi, tags, meanings});
+ rows.push({
+ dictionary,
+ character,
+ onyomi,
+ kunyomi,
+ tags,
+ meanings
+ });
}
return this.db.kanji.bulkAdd(rows).then(() => {
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 888bcb33..9b17f43c 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -117,11 +117,11 @@ function splitField(field) {
return field.length === 0 ? [] : field.split(' ');
}
-function importJsonDb(indexUrl, entitiesLoaded, entriesLoaded) {
+function importJsonDb(indexUrl, indexLoaded, entriesLoaded) {
const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
return loadJson(indexUrl).then(index => {
- if (entitiesLoaded !== null) {
- return entitiesLoaded(index.entities, index.banks).then(() => index);
+ if (indexLoaded !== null) {
+ return indexLoaded(index.title, index.entities, index.banks).then(() => index);
}
return index;
@@ -129,7 +129,7 @@ function importJsonDb(indexUrl, entitiesLoaded, entriesLoaded) {
const loaders = [];
for (let i = 1; i <= index.banks; ++i) {
const bankUrl = `${indexDir}/bank_${i}.json`;
- loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(entries, index.banks, i)));
+ loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(index.title, entries, index.banks, i)));
}
let chain = Promise.resolve();