aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings-dictionaries.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-02 16:58:21 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-11-07 20:30:55 -0500
commite5dcb418248667e3aa4627d5660ff2f951d58237 (patch)
tree6fa2298728b3afc29771f8e14e4a2caf59a0f20b /ext/bg/js/settings-dictionaries.js
parente091c7ebe2f6780b6a88df313c9f20170a8e5c1c (diff)
Add support for importing multiple dictionaries at once
Diffstat (limited to 'ext/bg/js/settings-dictionaries.js')
-rw-r--r--ext/bg/js/settings-dictionaries.js47
1 files changed, 30 insertions, 17 deletions
diff --git a/ext/bg/js/settings-dictionaries.js b/ext/bg/js/settings-dictionaries.js
index bf1b232f..c40648e0 100644
--- a/ext/bg/js/settings-dictionaries.js
+++ b/ext/bg/js/settings-dictionaries.js
@@ -511,6 +511,7 @@ async function onDictionaryImport(e) {
const dictFile = $('#dict-file');
const dictControls = $('#dict-importer').hide();
const dictProgress = $('#dict-import-progress').show();
+ const dictImportInfo = document.querySelector('#dict-import-info');
try {
dictionaryErrorsShow(null);
@@ -523,33 +524,45 @@ async function onDictionaryImport(e) {
storageUpdateStats();
}
};
- setProgress(0.0);
const exceptions = [];
- const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
- for (const options of toIterable(await getOptionsArray())) {
- const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
- dictionaryOptions.enabled = true;
- options.dictionaries[summary.title] = dictionaryOptions;
- if (summary.sequenced && options.general.mainDictionary === '') {
- options.general.mainDictionary = summary.title;
+ const files = [...e.target.files];
+
+ for (let i = 0, ii = files.length; i < ii; ++i) {
+ setProgress(0.0);
+ if (ii > 1) {
+ dictImportInfo.hidden = false;
+ dictImportInfo.textContent = `(${i + 1} of ${ii})`;
}
- }
- await settingsSaveOptions();
- if (exceptions.length > 0) {
- exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
- dictionaryErrorsShow(exceptions);
- }
+ const summary = await utilDatabaseImport(files[i], updateProgress, exceptions);
+ for (const options of toIterable(await getOptionsArray())) {
+ const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
+ dictionaryOptions.enabled = true;
+ options.dictionaries[summary.title] = dictionaryOptions;
+ if (summary.sequenced && options.general.mainDictionary === '') {
+ options.general.mainDictionary = summary.title;
+ }
+ }
- const optionsContext = getOptionsContext();
- const options = await apiOptionsGet(optionsContext);
- onDatabaseUpdated(options);
+ await settingsSaveOptions();
+
+ if (exceptions.length > 0) {
+ exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
+ dictionaryErrorsShow(exceptions);
+ }
+
+ const optionsContext = getOptionsContext();
+ const options = await apiOptionsGet(optionsContext);
+ onDatabaseUpdated(options);
+ }
} catch (err) {
dictionaryErrorsShow([err]);
} finally {
dictionarySpinnerShow(false);
+ dictImportInfo.hidden = false;
+ dictImportInfo.textContent = '';
dictFile.val('');
dictControls.show();
dictProgress.hide();