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