aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/database.js78
-rw-r--r--ext/bg/js/options-form.js35
-rw-r--r--ext/bg/js/templates.js8
-rw-r--r--ext/bg/options.html2
4 files changed, 12 insertions, 111 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 7dc533e3..31573065 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -45,7 +45,7 @@ class Database {
terms: '++id,dictionary,expression,reading',
kanji: '++,dictionary,character',
tagMeta: '++,dictionary',
- dictionaries: '++,title,version',
+ dictionaries: '++,title,version'
});
return this.db.open();
@@ -155,82 +155,6 @@ class Database {
return this.db.dictionaries.toArray();
}
- deleteDictionary(title, callback) {
- if (this.db === null) {
- return Promise.reject('database not initialized');
- }
-
- return this.db.dictionaries.where('title').equals(title).first(info => {
- if (!info) {
- return;
- }
-
- let termCounter = Promise.resolve(0);
- if (info.hasTerms) {
- termCounter = this.db.terms.where('dictionary').equals(title).count();
- }
-
- let kanjiCounter = Promise.resolve(0);
- if (info.hasKanji) {
- kanjiCounter = this.db.kanji.where('dictionary').equals(title).count();
- }
-
- return Promise.all([termCounter, kanjiCounter]).then(([termCount, kanjiCount]) => {
- const rowLimit = 500;
- const totalCount = termCount + kanjiCount;
- let deletedCount = 0;
-
- let termDeleter = Promise.resolve();
- if (info.hasTerms) {
- const termDeleterFunc = () => {
- return this.db.terms.where('dictionary').equals(title).limit(rowLimit).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return termDeleterFunc();
- });
- };
-
- termDeleter = termDeleterFunc();
- }
-
- let kanjiDeleter = Promise.resolve();
- if (info.hasKanji) {
- const kanjiDeleterFunc = () => {
- return this.db.kanji.where('dictionary').equals(title).limit(rowLimit).delete().then(count => {
- if (count === 0) {
- return Promise.resolve();
- }
-
- deletedCount += count;
- if (callback) {
- callback(totalCount, deletedCount);
- }
-
- return kanjiDeleterFunc();
- });
- };
-
- kanjiDeleter = kanjiDeleterFunc();
- }
-
- return Promise.all([termDeleter, kanjiDeleter]);
- });
- }).then(() => {
- return this.db.tagMeta.where('dictionary').equals(title).delete();
- }).then(() => {
- return this.db.dictionaries.where('title').equals(title).delete();
- }).then(() => {
- delete this.cacheTagMeta[title];
- });
- }
-
importDictionary(indexUrl, callback) {
if (this.db === null) {
return Promise.reject('database not initialized');
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index 7824164c..ae0491a2 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -171,7 +171,6 @@ function populateDictionaries(options) {
updateVisibility(options);
$('.dict-enabled, .dict-priority').change(onOptionsChanged);
- $('.dict-delete').click(onDictionaryDelete);
}).catch(showDictionaryError).then(() => {
showDictionarySpinner(false);
if (dictCount === 0) {
@@ -197,33 +196,12 @@ function onDictionaryPurge(e) {
}).then(options => {
options.dictionaries = {};
return optionsSave(options).then(() => {
- yomichan().setOptions(options);
populateDictionaries(options);
+ yomichan().setOptions(options);
});
});
}
-function onDictionaryDelete() {
- showDictionaryError(null);
- showDictionarySpinner(true);
-
- const dictGroup = $(this).closest('.dict-group');
- const dictProgress = dictGroup.find('.dict-delete-progress').show();
- const dictControls = dictGroup.find('.dict-group-controls').hide();
- const setProgress = percent => {
- dictProgress.find('.progress-bar').css('width', `${percent}%`);
- };
-
- setProgress(0.0);
-
- database().deleteDictionary(dictGroup.data('title'), (total, current) => setProgress(current / total * 100.0)).catch(showDictionaryError).then(() => {
- showDictionarySpinner(false);
- dictProgress.hide();
- dictControls.show();
- return optionsLoad().then(populateDictionaries);
- });
-}
-
function onDictionaryImport() {
showDictionaryError(null);
showDictionarySpinner(true);
@@ -231,9 +209,7 @@ function onDictionaryImport() {
const dictUrl = $('#dict-url');
const dictImporter = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
- const setProgress = percent => {
- dictProgress.find('.progress-bar').css('width', `${percent}%`);
- };
+ const setProgress = percent => dictProgress.find('.progress-bar').css('width', `${percent}%`);
setProgress(0.0);
@@ -389,7 +365,12 @@ function onOptionsChanged(e) {
return optionsSave(optionsNew).then(() => {
yomichan().setOptions(optionsNew);
updateVisibility(optionsNew);
- if (optionsNew.anki.enable !== optionsOld.anki.enable || optionsNew.anki.server !== optionsOld.anki.server) {
+
+ const ankiUpdated =
+ optionsNew.anki.enable !== optionsOld.anki.enable ||
+ optionsNew.anki.server !== optionsOld.anki.server;
+
+ if (ankiUpdated) {
showAnkiError(null);
showAnkiSpinner(true);
return populateAnkiDeckAndModel(optionsNew);
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index ba4d0b86..5fb894c1 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -11,13 +11,9 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ " <small>rev."
+ alias4(((helper = (helper = helpers.revision || (depth0 != null ? depth0.revision : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"revision","hash":{},"data":data}) : helper)))
- + "</small></h4>\n\n <!-- <div class=\"row\"> -->\n <!-- <div class=\"col-xs-8\"> -->\n <!-- <h4><span class=\"text-muted glyphicon glyphicon-book\"></span> "
- + alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
- + " <small>v."
- + alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper)))
- + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"checkbox dict-group-controls\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ + "</small></h4>\n\n <div class=\"checkbox\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.enabled : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Enable search</label>\n </div>\n <div class=\"form-group dict-group-controls options-advanced\">\n <label for=\"dict-"
+ + "> Enable search</label>\n </div>\n <div class=\"form-group options-advanced\">\n <label for=\"dict-"
+ alias4(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"title","hash":{},"data":data}) : helper)))
+ "\">Result priority</label>\n <input type=\"number\" value=\""
+ alias4(((helper = (helper = helpers.priority || (depth0 != null ? depth0.priority : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"priority","hash":{},"data":data}) : helper)))
diff --git a/ext/bg/options.html b/ext/bg/options.html
index 03e328d2..27f75367 100644
--- a/ext/bg/options.html
+++ b/ext/bg/options.html
@@ -7,7 +7,7 @@
<link rel="stylesheet" type="text/css" href="../lib/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css">
<style>
#anki-spinner, #anki-general, #anki-error,
- #dict-spinner, #dict-error, #dict-warning, #dict-purge-progress, #dict-import-progress, .dict-delete-progress,
+ #dict-spinner, #dict-error, #dict-warning, #dict-purge-progress, #dict-import-progress,
.options-advanced {
display: none;
}