simplify database interface
This commit is contained in:
parent
7d29e5b533
commit
c62cc01642
@ -220,7 +220,7 @@ class Database {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTitles() {
|
async summarize() {
|
||||||
if (this.db) {
|
if (this.db) {
|
||||||
return this.db.dictionaries.toArray();
|
return this.db.dictionaries.toArray();
|
||||||
} else {
|
} else {
|
||||||
@ -228,21 +228,6 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTitlesWithSequences() {
|
|
||||||
if (!this.db) {
|
|
||||||
throw 'Database not initialized';
|
|
||||||
}
|
|
||||||
|
|
||||||
const titles = [];
|
|
||||||
await this.db.dictionaries.each(row => {
|
|
||||||
if (row.hasSequences) {
|
|
||||||
titles.push(row.title);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return titles;
|
|
||||||
}
|
|
||||||
|
|
||||||
async importDictionary(archive, callback) {
|
async importDictionary(archive, callback) {
|
||||||
if (!this.db) {
|
if (!this.db) {
|
||||||
throw 'Database not initialized';
|
throw 'Database not initialized';
|
||||||
|
@ -109,12 +109,12 @@ async function formMainDictionaryOptionsPopulate(options) {
|
|||||||
select.append($('<option class="text-muted" value="">Not selected</option>'));
|
select.append($('<option class="text-muted" value="">Not selected</option>'));
|
||||||
|
|
||||||
let mainDictionary = '';
|
let mainDictionary = '';
|
||||||
const formOptions = [$];
|
for (const dictRow of await utilDatabaseSummarize()) {
|
||||||
const titles = await utilDatabaseGetTitlesWithSequences();
|
if (dictRow.hasSequences) {
|
||||||
for (const title of titles) {
|
select.append($(`<option value="${dictRow.title}">${dictRow.title}</option>`));
|
||||||
select.append($(`<option value="${title}">${title}</option>`));
|
if (dictRow.title === options.general.mainDictionary) {
|
||||||
if (title === options.general.mainDictionary) {
|
mainDictionary = dictRow.title;
|
||||||
mainDictionary = title;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ async function dictionaryGroupsPopulate(options) {
|
|||||||
const dictGroups = $('#dict-groups').empty();
|
const dictGroups = $('#dict-groups').empty();
|
||||||
const dictWarning = $('#dict-warning').hide();
|
const dictWarning = $('#dict-warning').hide();
|
||||||
|
|
||||||
const dictRows = await utilDatabaseGetTitles();
|
const dictRows = await utilDatabaseSummarize();
|
||||||
if (dictRows.length === 0) {
|
if (dictRows.length === 0) {
|
||||||
dictWarning.show();
|
dictWarning.show();
|
||||||
}
|
}
|
||||||
|
@ -75,18 +75,14 @@ function utilAnkiGetDeckNames() {
|
|||||||
return utilBackend().anki.getDeckNames();
|
return utilBackend().anki.getDeckNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function utilDatabaseSummarize() {
|
||||||
|
return utilBackend().translator.database.summarize();
|
||||||
|
}
|
||||||
|
|
||||||
function utilAnkiGetModelFieldNames(modelName) {
|
function utilAnkiGetModelFieldNames(modelName) {
|
||||||
return utilBackend().anki.getModelFieldNames(modelName);
|
return utilBackend().anki.getModelFieldNames(modelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
function utilDatabaseGetTitles() {
|
|
||||||
return utilBackend().translator.database.getTitles();
|
|
||||||
}
|
|
||||||
|
|
||||||
function utilDatabaseGetTitlesWithSequences() {
|
|
||||||
return utilBackend().translator.database.getTitlesWithSequences();
|
|
||||||
}
|
|
||||||
|
|
||||||
function utilDatabasePurge() {
|
function utilDatabasePurge() {
|
||||||
return utilBackend().translator.database.purge();
|
return utilBackend().translator.database.purge();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user