This commit is contained in:
Alex Yatskov 2016-11-13 13:29:35 -08:00
parent 2587b9ae6b
commit a9eea9f634
3 changed files with 52 additions and 38 deletions

View File

@ -159,7 +159,7 @@ class Database {
let termDeleter = Promise.resolve();
if (info.hasTerms) {
const termDeleterFunc = () => {
return this.db.terms.where('dictionary').equals(title).limit(1000).delete().then(count => {
return this.db.terms.where('dictionary').equals(title).limit(500).delete().then(count => {
if (count === 0) {
return Promise.resolve();
}
@ -179,7 +179,7 @@ class Database {
let kanjiDeleter = Promise.resolve();
if (info.hasKanji) {
const kanjiDeleterFunc = () => {
return this.db.kanji.where('dictionary').equals(title).limit(1000).delete().then(count => {
return this.db.kanji.where('dictionary').equals(title).limit(500).delete().then(count => {
if (count === 0) {
return Promise.resolve();
}

View File

@ -115,40 +115,6 @@ function updateVisibility(opts) {
}
}
function populateDictionaries(opts) {
const dictGroups = $('#dict-groups');
dictGroups.empty();
const dictError = $('#dict-error');
dictError.hide();
const dictSpinner = $('#dict-spinner');
dictSpinner.show();
return database().getDictionaries().then(rows => {
rows.forEach(row => {
const dictOpts = opts.dictionaries[row.title] || {enableTerms: false, enableKanji: false};
const html = Handlebars.templates['dictionary.html']({
title: row.title,
version: row.version,
hasTerms: row.hasTerms,
hasKanji: row.hasKanji,
enableTerms: dictOpts.enableTerms,
enableKanji: dictOpts.enableKanji
});
dictGroups.append($(html));
});
$('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged);
$('.dict-delete').click(onDictionaryDelete);
}).catch(error => {
dictError.show().find('span').text(error);
}).then(() => {
dictSpinner.hide();
});
}
function onDictionaryDelete() {
const dictGroup = $(this).closest('.dict-group');
@ -199,7 +165,7 @@ function onDictionaryImport() {
const dictUrl = $('#dict-url');
loadOptions().then(opts => {
database().importDictionary(dictUrl.val(), callback).then(summary => {
opts.dictionaries[summary.title] = {hasTerms: summary.hasTerms, hasKanji: summary.hasKanji};
opts.dictionaries[summary.title] = {enableTerms: summary.hasTerms, enableKanji: summary.hasKanji};
return saveOptions(opts);
}).then(() => {
return populateDictionaries(opts);
@ -302,6 +268,49 @@ function populateAnkiFields(element, opts) {
});
}
function populateDictionaries(opts) {
const dictGroups = $('#dict-groups');
dictGroups.empty();
const dictError = $('#dict-error');
dictError.hide();
const dictWarning = $('#dict-warning');
dictWarning.hide();
const dictSpinner = $('#dict-spinner');
dictSpinner.show();
let dictCount = 0;
return database().getDictionaries().then(rows => {
rows.forEach(row => {
const dictOpts = opts.dictionaries[row.title] || {enableTerms: false, enableKanji: false};
const html = Handlebars.templates['dictionary.html']({
title: row.title,
version: row.version,
hasTerms: row.hasTerms,
hasKanji: row.hasKanji,
enableTerms: dictOpts.enableTerms,
enableKanji: dictOpts.enableKanji
});
dictGroups.append($(html));
++dictCount;
});
$('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged);
$('.dict-delete').click(onDictionaryDelete);
}).catch(error => {
dictError.show().find('span').text(error);
}).then(() => {
if (dictCount === 0) {
dictWarning.show();
}
dictSpinner.hide();
});
}
function onOptionsChanged(e) {
if (!e.originalEvent && !e.isTrigger) {
return;

View File

@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css">
<style>
#anki-spinner, #anki-general, #anki-error,
#dict-spinner, .dict-import-progress, .dict-delete-progress,
#dict-spinner, #dict-error, #dict-warning, .dict-import-progress, .dict-delete-progress,
#options-advanced {
display: none;
}
@ -70,6 +70,11 @@
<div id="dict-groups"></div>
<div class="alert alert-warning" id="dict-warning">
<strong>No dictionaries found:</strong>
please use the dropdown below to install packaged and external dictionaries
</div>
<div class="alert alert-danger" id="dict-error">
<strong>Error:</strong>
<span></span>