From 55dd9b1e6b06401e5a5f523fce1f3d6c1db4d9da Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 26 Feb 2017 10:11:23 -0800 Subject: delete unused dictionary deletion code --- ext/bg/js/database.js | 78 +---------------------------------------------- ext/bg/js/options-form.js | 35 +++++---------------- ext/bg/js/templates.js | 8 ++--- ext/bg/options.html | 2 +- 4 files changed, 12 insertions(+), 111 deletions(-) (limited to 'ext') 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))) + " 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))) - + "\n\n \n \n \n \n \n \n \n \n\n
\n Dictionary data is being deleted, please be patient...\n
\n
\n
\n
\n\n
\n