include sequence property in header data

This commit is contained in:
Alex Yatskov 2017-10-29 10:59:50 -07:00
parent c62cc01642
commit d6603fd031
2 changed files with 5 additions and 14 deletions

View File

@ -233,7 +233,7 @@ class Database {
throw 'Database not initialized'; throw 'Database not initialized';
} }
const indexDataValid = async summary => { const indexDataLoaded = async summary => {
if (summary.version > 2) { if (summary.version > 2) {
throw 'Unsupported dictionary version'; throw 'Unsupported dictionary version';
} }
@ -242,9 +242,7 @@ class Database {
if (count > 0) { if (count > 0) {
throw 'Dictionary is already imported'; throw 'Dictionary is already imported';
} }
};
const indexDataLoaded = async summary => {
await this.db.dictionaries.add(summary); await this.db.dictionaries.add(summary);
}; };
@ -282,8 +280,6 @@ class Database {
} }
} }
summary.hasSequences = rows.every(row => row.sequence >= 0);
await this.db.terms.bulkAdd(rows); await this.db.terms.bulkAdd(rows);
}; };
@ -381,7 +377,6 @@ class Database {
return await Database.importDictionaryZip( return await Database.importDictionaryZip(
archive, archive,
indexDataValid,
indexDataLoaded, indexDataLoaded,
termDataLoaded, termDataLoaded,
termMetaDataLoaded, termMetaDataLoaded,
@ -393,7 +388,6 @@ class Database {
static async importDictionaryZip( static async importDictionaryZip(
archive, archive,
indexDataValid,
indexDataLoaded, indexDataLoaded,
termDataLoaded, termDataLoaded,
termMetaDataLoaded, termMetaDataLoaded,
@ -416,10 +410,11 @@ class Database {
const summary = { const summary = {
title: index.title, title: index.title,
revision: index.revision, revision: index.revision,
sequenced: index.sequenced,
version: index.format || index.version version: index.format || index.version
}; };
await indexDataValid(summary); await indexDataLoaded(summary);
const buildTermBankName = index => `term_bank_${index + 1}.json`; const buildTermBankName = index => `term_bank_${index + 1}.json`;
const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`; const buildTermMetaBankName = index => `term_meta_bank_${index + 1}.json`;
@ -476,10 +471,6 @@ class Database {
await loadBank(summary, buildKanjiMetaBankName, kanjiMetaBankCount, kanjiMetaDataLoaded); await loadBank(summary, buildKanjiMetaBankName, kanjiMetaBankCount, kanjiMetaDataLoaded);
await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded); await loadBank(summary, buildTagBankName, tagBankCount, tagDataLoaded);
if (indexDataLoaded) {
await indexDataLoaded(summary);
}
return summary; return summary;
} }
} }

View File

@ -110,7 +110,7 @@ async function formMainDictionaryOptionsPopulate(options) {
let mainDictionary = ''; let mainDictionary = '';
for (const dictRow of await utilDatabaseSummarize()) { for (const dictRow of await utilDatabaseSummarize()) {
if (dictRow.hasSequences) { if (dictRow.sequenced) {
select.append($(`<option value="${dictRow.title}">${dictRow.title}</option>`)); select.append($(`<option value="${dictRow.title}">${dictRow.title}</option>`));
if (dictRow.title === options.general.mainDictionary) { if (dictRow.title === options.general.mainDictionary) {
mainDictionary = dictRow.title; mainDictionary = dictRow.title;
@ -342,7 +342,7 @@ async function onDictionaryImport(e) {
const options = await optionsLoad(); const options = await optionsLoad();
const summary = await utilDatabaseImport(e.target.files[0], updateProgress); const summary = await utilDatabaseImport(e.target.files[0], updateProgress);
options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false}; options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false};
if (summary.hasSequences && options.general.mainDictionary === '') { if (summary.sequenced && options.general.mainDictionary === '') {
options.general.mainDictionary = summary.title; options.general.mainDictionary = summary.title;
} }
await optionsSave(options); await optionsSave(options);