Add support for importing multiple dictionaries at once
This commit is contained in:
parent
e091c7ebe2
commit
e5dcb41824
@ -511,6 +511,7 @@ async function onDictionaryImport(e) {
|
|||||||
const dictFile = $('#dict-file');
|
const dictFile = $('#dict-file');
|
||||||
const dictControls = $('#dict-importer').hide();
|
const dictControls = $('#dict-importer').hide();
|
||||||
const dictProgress = $('#dict-import-progress').show();
|
const dictProgress = $('#dict-import-progress').show();
|
||||||
|
const dictImportInfo = document.querySelector('#dict-import-info');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dictionaryErrorsShow(null);
|
dictionaryErrorsShow(null);
|
||||||
@ -523,33 +524,45 @@ async function onDictionaryImport(e) {
|
|||||||
storageUpdateStats();
|
storageUpdateStats();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
setProgress(0.0);
|
|
||||||
|
|
||||||
const exceptions = [];
|
const exceptions = [];
|
||||||
const summary = await utilDatabaseImport(e.target.files[0], updateProgress, exceptions);
|
const files = [...e.target.files];
|
||||||
for (const options of toIterable(await getOptionsArray())) {
|
|
||||||
const dictionaryOptions = SettingsDictionaryListUI.createDictionaryOptions();
|
for (let i = 0, ii = files.length; i < ii; ++i) {
|
||||||
dictionaryOptions.enabled = true;
|
setProgress(0.0);
|
||||||
options.dictionaries[summary.title] = dictionaryOptions;
|
if (ii > 1) {
|
||||||
if (summary.sequenced && options.general.mainDictionary === '') {
|
dictImportInfo.hidden = false;
|
||||||
options.general.mainDictionary = summary.title;
|
dictImportInfo.textContent = `(${i + 1} of ${ii})`;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
await settingsSaveOptions();
|
|
||||||
|
|
||||||
if (exceptions.length > 0) {
|
const summary = await utilDatabaseImport(files[i], updateProgress, exceptions);
|
||||||
exceptions.push(`Dictionary may not have been imported properly: ${exceptions.length} error${exceptions.length === 1 ? '' : 's'} reported.`);
|
for (const options of toIterable(await getOptionsArray())) {
|
||||||
dictionaryErrorsShow(exceptions);
|
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();
|
await settingsSaveOptions();
|
||||||
const options = await apiOptionsGet(optionsContext);
|
|
||||||
onDatabaseUpdated(options);
|
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) {
|
} catch (err) {
|
||||||
dictionaryErrorsShow([err]);
|
dictionaryErrorsShow([err]);
|
||||||
} finally {
|
} finally {
|
||||||
dictionarySpinnerShow(false);
|
dictionarySpinnerShow(false);
|
||||||
|
|
||||||
|
dictImportInfo.hidden = false;
|
||||||
|
dictImportInfo.textContent = '';
|
||||||
dictFile.val('');
|
dictFile.val('');
|
||||||
dictControls.show();
|
dictControls.show();
|
||||||
dictProgress.hide();
|
dictProgress.hide();
|
||||||
|
@ -434,6 +434,7 @@
|
|||||||
|
|
||||||
<div id="dict-import-progress">
|
<div id="dict-import-progress">
|
||||||
Dictionary data is being imported, please be patient...
|
Dictionary data is being imported, please be patient...
|
||||||
|
<span id="dict-import-info" hidden></span>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar progress-bar-striped" style="width: 0%"></div>
|
<div class="progress-bar progress-bar-striped" style="width: 0%"></div>
|
||||||
</div>
|
</div>
|
||||||
@ -449,7 +450,7 @@
|
|||||||
<button class="btn btn-primary" id="dict-file-button">Import Dictionary</button>
|
<button class="btn btn-primary" id="dict-file-button">Import Dictionary</button>
|
||||||
<button class="btn btn-danger" id="dict-purge-button">Purge Database</button>
|
<button class="btn btn-danger" id="dict-purge-button">Purge Database</button>
|
||||||
</div>
|
</div>
|
||||||
<div hidden><input type="file" id="dict-file"></div>
|
<div hidden><input type="file" id="dict-file" multiple></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" tabindex="-1" role="dialog" id="dict-purge-modal">
|
<div class="modal fade" tabindex="-1" role="dialog" id="dict-purge-modal">
|
||||||
|
Loading…
Reference in New Issue
Block a user