aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-10-19 20:05:45 -0400
committerGitHub <noreply@github.com>2020-10-19 20:05:45 -0400
commit23230b8a7c5eb66357d5bcafb4184def13c5954b (patch)
tree4cfd684091bdccb00993a4302c9d975680eb5770 /ext/bg/js
parent91b4feb934f524fc30be9300480ac584b65c6166 (diff)
Backup controller refactor (#946)
* Update IDs * Change how default fieldTemplates is assigned * Ensure no missing fields * Fix error display during import
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/options.js4
-rw-r--r--ext/bg/js/settings/backup-controller.js35
2 files changed, 22 insertions, 17 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 42a1f3d4..9e89e9bd 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -129,6 +129,10 @@ class OptionsUtil {
return this._schemaValidator.getValidValueOrDefault(this._optionsSchema);
}
+ getValidValueOrDefault(options) {
+ return this._schemaValidator.getValidValueOrDefault(this._optionsSchema, options);
+ }
+
createValidatingProxy(options) {
return this._schemaValidator.createProxy(options, this._optionsSchema);
}
diff --git a/ext/bg/js/settings/backup-controller.js b/ext/bg/js/settings/backup-controller.js
index 50390d5c..454ede85 100644
--- a/ext/bg/js/settings/backup-controller.js
+++ b/ext/bg/js/settings/backup-controller.js
@@ -37,15 +37,15 @@ class BackupController {
async prepare() {
await this._optionsUtil.prepare();
- this._settingsResetModal = this._modalController.getModal('settings-reset-modal');
- this._settingsImportErrorModal = this._modalController.getModal('settings-import-error-modal');
- this._settingsImportWarningModal = this._modalController.getModal('settings-import-warning-modal');
+ this._settingsResetModal = this._modalController.getModal('settings-reset');
+ this._settingsImportErrorModal = this._modalController.getModal('settings-import-error');
+ this._settingsImportWarningModal = this._modalController.getModal('settings-import-warning');
- document.querySelector('#settings-export').addEventListener('click', this._onSettingsExportClick.bind(this), false);
- document.querySelector('#settings-import').addEventListener('click', this._onSettingsImportClick.bind(this), false);
+ document.querySelector('#settings-export-button').addEventListener('click', this._onSettingsExportClick.bind(this), false);
+ document.querySelector('#settings-import-button').addEventListener('click', this._onSettingsImportClick.bind(this), false);
document.querySelector('#settings-import-file').addEventListener('change', this._onSettingsImportFileChange.bind(this), false);
- document.querySelector('#settings-reset').addEventListener('click', this._onSettingsResetClick.bind(this), false);
- document.querySelector('#settings-reset-modal-confirm').addEventListener('click', this._onSettingsResetConfirmClick.bind(this), false);
+ document.querySelector('#settings-reset-button').addEventListener('click', this._onSettingsResetClick.bind(this), false);
+ document.querySelector('#settings-reset-confirm-button').addEventListener('click', this._onSettingsResetConfirmClick.bind(this), false);
}
// Private
@@ -75,7 +75,7 @@ class BackupController {
// Format options
for (const {options} of optionsFull.profiles) {
if (options.anki.fieldTemplates === fieldTemplatesDefault || !options.anki.fieldTemplates) {
- delete options.anki.fieldTemplates; // Default
+ options.anki.fieldTemplates = null;
}
}
@@ -152,23 +152,19 @@ class BackupController {
// Importing
async _settingsImportSetOptionsFull(optionsFull) {
- try {
- await this._settingsController.setAllSettings(optionsFull);
- } catch (e) {
- yomichan.logError(e);
- }
+ await this._settingsController.setAllSettings(optionsFull);
}
_showSettingsImportError(error) {
yomichan.logError(error);
- document.querySelector('#settings-import-error-modal-message').textContent = `${error}`;
+ document.querySelector('#settings-import-error-message').textContent = `${error}`;
this._settingsImportErrorModal.setVisible(true);
}
async _showSettingsImportWarnings(warnings) {
const modal = this._settingsImportWarningModal;
- const buttons = document.querySelectorAll('.settings-import-warning-modal-import-button');
- const messageContainer = document.querySelector('#settings-import-warning-modal-message');
+ const buttons = document.querySelectorAll('.settings-import-warning-import-button');
+ const messageContainer = document.querySelector('#settings-import-warning-message');
if (buttons.length === 0 || messageContainer === null) {
return {result: false};
}
@@ -340,6 +336,7 @@ class BackupController {
// Upgrade options
optionsFull = await this._optionsUtil.update(optionsFull);
+ optionsFull = this._optionsUtil.getValidValueOrDefault(optionsFull);
// Check for warnings
const sanitizationWarnings = this._settingsImportSanitizeOptions(optionsFull, true);
@@ -388,6 +385,10 @@ class BackupController {
const optionsFull = this._optionsUtil.getDefault();
// Assign options
- await this._settingsImportSetOptionsFull(optionsFull);
+ try {
+ await this._settingsImportSetOptionsFull(optionsFull);
+ } catch (e) {
+ yomichan.logError(e);
+ }
}
}