Dictionary naming
This commit is contained in:
parent
e2f1560afa
commit
d3a0173874
@ -33,7 +33,9 @@ class Dictionary {
|
||||
this.db.version(1).stores({
|
||||
terms: '++id, dictionary, expression, reading',
|
||||
kanji: '++, dictionary, character',
|
||||
entities: '++, dictionary, name',
|
||||
entities: '++, dictionary',
|
||||
termDicts: '++, dictionary',
|
||||
kanjiDicts: '++, dictionary, version',
|
||||
meta: 'name, value',
|
||||
});
|
||||
}
|
||||
@ -135,22 +137,24 @@ class Dictionary {
|
||||
return Promise.reject('database not initialized');
|
||||
}
|
||||
|
||||
const indexLoaded = (dictionary, entities) => {
|
||||
this.entities = entities || {};
|
||||
const indexLoaded = (dictionary, version, entities) => {
|
||||
return this.db.termDicts.add({dictionary, version}).then(() => {
|
||||
this.entities = entities || {};
|
||||
|
||||
const rows = [];
|
||||
for (const name in entities || {}) {
|
||||
rows.push({
|
||||
dictionary,
|
||||
name,
|
||||
value: entities[name]
|
||||
});
|
||||
}
|
||||
const rows = [];
|
||||
for (const name in entities || {}) {
|
||||
rows.push({
|
||||
dictionary,
|
||||
name,
|
||||
value: entities[name]
|
||||
});
|
||||
}
|
||||
|
||||
return this.db.entities.bulkAdd(rows);
|
||||
return this.db.entities.bulkAdd(rows);
|
||||
});
|
||||
};
|
||||
|
||||
const entriesLoaded = (dictionary, entries, total, current) => {
|
||||
const entriesLoaded = (dictionary, version, entries, total, current) => {
|
||||
const rows = [];
|
||||
for (const [expression, reading, tags, ...glossary] of entries) {
|
||||
rows.push({
|
||||
@ -177,7 +181,11 @@ class Dictionary {
|
||||
return Promise.reject('database not initialized');
|
||||
}
|
||||
|
||||
const entriesLoaded = (dictionary, entries, total, current) => {
|
||||
const indexLoaded = (dictionary, version) => {
|
||||
return this.db.kanjiDicts.add({dictionary, version});
|
||||
};
|
||||
|
||||
const entriesLoaded = (dictionary, version, entries, total, current) => {
|
||||
const rows = [];
|
||||
for (const [character, onyomi, kunyomi, tags, ...meanings] of entries) {
|
||||
rows.push({
|
||||
|
@ -121,7 +121,7 @@ function importJsonDb(indexUrl, indexLoaded, entriesLoaded) {
|
||||
const indexDir = indexUrl.slice(0, indexUrl.lastIndexOf('/'));
|
||||
return loadJson(indexUrl).then(index => {
|
||||
if (indexLoaded !== null) {
|
||||
return indexLoaded(index.title, index.entities, index.banks).then(() => index);
|
||||
return indexLoaded(index.title, index.version, index.entities, index.banks).then(() => index);
|
||||
}
|
||||
|
||||
return index;
|
||||
@ -129,7 +129,7 @@ function importJsonDb(indexUrl, indexLoaded, entriesLoaded) {
|
||||
const loaders = [];
|
||||
for (let i = 1; i <= index.banks; ++i) {
|
||||
const bankUrl = `${indexDir}/bank_${i}.json`;
|
||||
loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(index.title, entries, index.banks, i)));
|
||||
loaders.push(() => loadJson(bankUrl).then(entries => entriesLoaded(index.title, index.version, entries, index.banks, i)));
|
||||
}
|
||||
|
||||
let chain = Promise.resolve();
|
||||
|
Loading…
Reference in New Issue
Block a user