aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2017-10-24 16:23:13 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2017-10-24 16:23:13 +0300
commit78442fff1a995632f2b315994f2540459ee20eca (patch)
tree171311101b93d3a5be284c3dab93987f663fefe4 /ext
parentdf0d2beb735c75948feccd64398e6187c61c2fde (diff)
settings: main dictionary selection as dropdown
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/database.js15
-rw-r--r--ext/bg/js/options.js3
-rw-r--r--ext/bg/js/settings.js66
-rw-r--r--ext/bg/js/templates.js4
-rw-r--r--ext/bg/js/translator.js5
-rw-r--r--ext/bg/js/util.js4
-rw-r--r--ext/bg/settings.html5
7 files changed, 73 insertions, 29 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 9e90e6de..fcf8ef3f 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -228,6 +228,21 @@ class Database {
}
}
+ async getTitlesWithSequences() {
+ if (!this.db) {
+ throw 'Database not initialized';
+ }
+
+ const titles = [];
+ await this.db.dictionaries.each(row => {
+ if (row.hasSequences) {
+ titles.push(row.title);
+ }
+ });
+
+ return titles;
+ }
+
async importDictionary(archive, callback) {
if (!this.db) {
throw 'Database not initialized';
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 2cb7dbec..4d18c166 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -203,7 +203,8 @@ function optionsSetDefaults(options) {
popupOffset: 10,
showGuide: true,
compactTags: false,
- compactGlossaries: false
+ compactGlossaries: false,
+ mainDictionary: ''
},
scanning: {
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index 37e5126e..36f2bdf9 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -25,6 +25,7 @@ async function formRead() {
optionsNew.general.compactTags = $('#compact-tags').prop('checked');
optionsNew.general.compactGlossaries = $('#compact-glossaries').prop('checked');
optionsNew.general.resultOutputMode = $('#result-output-mode').val();
+ optionsNew.general.mainDictionary = $('#main-dictionary').val();
optionsNew.general.audioSource = $('#audio-playback-source').val();
optionsNew.general.audioVolume = parseFloat($('#audio-playback-volume').val());
optionsNew.general.debugInfo = $('#show-debug-info').prop('checked');
@@ -62,9 +63,8 @@ async function formRead() {
const title = dictionary.data('title');
const priority = parseInt(dictionary.find('.dict-priority').val(), 10);
const enabled = dictionary.find('.dict-enabled').prop('checked');
- const main = dictionary.find('.dict-main').prop('checked');
const allowSecondarySearches = dictionary.find('.dict-allow-secondary-searches').prop('checked');
- optionsNew.dictionaries[title] = {priority, enabled, main, allowSecondarySearches};
+ optionsNew.dictionaries[title] = {priority, enabled, allowSecondarySearches};
});
return {optionsNew, optionsOld};
@@ -85,6 +85,13 @@ function formUpdateVisibility(options) {
advanced.hide();
}
+ const merge = $('.options-merge');
+ if (options.general.resultOutputMode === 'merge') {
+ merge.show();
+ } else {
+ merge.hide();
+ }
+
const debug = $('#debug');
if (options.general.debugInfo) {
const temp = utilIsolate(options);
@@ -97,6 +104,29 @@ function formUpdateVisibility(options) {
}
}
+async function formMainDictionaryOptionsPopulate(options) {
+ const select = $('#main-dictionary').empty();
+
+ let titles = await utilDatabaseGetTitlesWithSequences();
+ titles = titles.filter(title => options.dictionaries[title].enabled);
+ const formOptionsHtml = [];
+ let mainDictionarySelected = false;
+ for (title of titles) {
+ if (options.general.mainDictionary === title) {
+ mainDictionarySelected = true;
+ }
+ formOptionsHtml.push(`<option value="${title}"${options.general.mainDictionary === title ? ' selected' : ''}>${title}</option>`);
+ }
+
+ if (!mainDictionarySelected) {
+ options.general.mainDictionary = '';
+ }
+
+ const notSelectedOptionHtml = `<option value=""${!mainDictionarySelected ? ' selected' : ''}>(Not selected)</option>`;
+
+ select.append($([notSelectedOptionHtml].concat(formOptionsHtml).join('')));
+}
+
async function onFormOptionsChanged(e) {
try {
if (!e.originalEvent && !e.isTrigger) {
@@ -104,6 +134,7 @@ async function onFormOptionsChanged(e) {
}
const {optionsNew, optionsOld} = await formRead();
+ await formMainDictionaryOptionsPopulate(optionsNew);
await optionsSave(optionsNew);
formUpdateVisibility(optionsNew);
@@ -131,6 +162,7 @@ async function onReady() {
$('#compact-tags').prop('checked', options.general.compactTags);
$('#compact-glossaries').prop('checked', options.general.compactGlossaries);
$('#result-output-mode').val(options.general.resultOutputMode);
+ $('#main-dictionary').val(options.general.mainDictionary);
$('#audio-playback-source').val(options.general.audioSource);
$('#audio-playback-volume').val(options.general.audioVolume);
$('#show-debug-info').prop('checked', options.general.debugInfo);
@@ -172,6 +204,8 @@ async function onReady() {
ankiErrorShow(e);
}
+ await formMainDictionaryOptionsPopulate(options);
+
formUpdateVisibility(options);
}
@@ -243,18 +277,6 @@ function dictionaryGroupsSort() {
dictGroups.append(dictGroupChildren);
}
-function dictionarySetMain(e) {
- const mainDictionary = $(e.target).closest('.dict-group');
- const mainDictionaryTitle = mainDictionary.data('title');
-
- $('.dict-group').each((index, element) => {
- const dictionary = $(element);
- if (dictionary.data('title') !== mainDictionaryTitle) {
- dictionary.find('.dict-main').prop('checked', false);
- }
- });
-}
-
async function dictionaryGroupsPopulate(options) {
const dictGroups = $('#dict-groups').empty();
const dictWarning = $('#dict-warning').hide();
@@ -265,14 +287,13 @@ async function dictionaryGroupsPopulate(options) {
}
for (const dictRow of dictRowsSort(dictRows, options)) {
- const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0, main: false, allowSecondarySearches: false};
+ const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0, allowSecondarySearches: false};
const dictHtml = await apiTemplateRender('dictionary.html', {
title: dictRow.title,
version: dictRow.version,
revision: dictRow.revision,
priority: dictOptions.priority,
enabled: dictOptions.enabled,
- main: dictOptions.main,
allowSecondarySearches: dictOptions.allowSecondarySearches
});
@@ -285,11 +306,6 @@ async function dictionaryGroupsPopulate(options) {
dictionaryGroupsSort();
onFormOptionsChanged(e);
});
-
- $('.dict-main').change(e => {
- dictionarySetMain(e);
- onFormOptionsChanged(e);
- });
}
async function onDictionaryPurge(e) {
@@ -305,9 +321,11 @@ async function onDictionaryPurge(e) {
await utilDatabasePurge();
const options = await optionsLoad();
options.dictionaries = {};
+ options.general.mainDictionary = '';
await optionsSave(options);
await dictionaryGroupsPopulate(options);
+ await formMainDictionaryOptionsPopulate(options);
} catch (e) {
dictionaryErrorShow(e);
} finally {
@@ -333,10 +351,14 @@ async function onDictionaryImport(e) {
const options = await optionsLoad();
const summary = await utilDatabaseImport(e.target.files[0], updateProgress);
- options.dictionaries[summary.title] = {enabled: true, priority: 0, main: false, allowSecondarySearches: false};
+ options.dictionaries[summary.title] = {enabled: true, priority: 0, allowSecondarySearches: false};
+ if (summary.hasSequences && !options.general.mainDictionary) {
+ options.general.mainDictionary = summary.title;
+ }
await optionsSave(options);
await dictionaryGroupsPopulate(options);
+ await formMainDictionaryOptionsPopulate(options);
} catch (e) {
dictionaryErrorShow(e);
} finally {
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index e5640394..9f72e661 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -15,9 +15,7 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ ((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=\"checkbox options-advanced\">\n <label><input type=\"checkbox\" class=\"dict-allow-secondary-searches\" "
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.allowSecondarySearches : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Allow secondary searches</label>\n </div>\n <div class=\"radio\">\n <label><input type=\"radio\" class=\"dict-main\" "
- + ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.main : depth0),{"name":"if","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
- + "> Set as main dictionary</label>\n </div>\n <div class=\"form-group options-advanced\">\n <label for=\"dict-"
+ + "> Allow secondary searches</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/js/translator.js b/ext/bg/js/translator.js
index 5fcdea76..e6790fbf 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -57,12 +57,11 @@ class Translator {
async findTermsMerged(text, dictionaries, alphanumeric) {
const options = await apiOptionsGet();
- const mainDictionary = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].main).concat([''])[0];
const secondarySearchTitles = Object.keys(options.dictionaries).filter(dict => options.dictionaries[dict].allowSecondarySearches);
const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
- const definitionsBySequence = dictTermsMergeBySequence(definitions, mainDictionary);
+ const definitionsBySequence = dictTermsMergeBySequence(definitions, options.general.mainDictionary);
const definitionsMerged = [];
const mergedByTermIndices = new Set();
@@ -73,7 +72,7 @@ class Translator {
const result = definitionsBySequence[sequence];
- const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), mainDictionary);
+ const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.general.mainDictionary);
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
const secondarySearchResults = [];
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 91b16e79..60f6452b 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -87,6 +87,10 @@ function utilDatabaseGetTitles() {
return utilBackend().translator.database.getTitles();
}
+function utilDatabaseGetTitlesWithSequences() {
+ return utilBackend().translator.database.getTitlesWithSequences();
+}
+
function utilDatabasePurge() {
return utilBackend().translator.database.purge();
}
diff --git a/ext/bg/settings.html b/ext/bg/settings.html
index 408d5aab..8c457652 100644
--- a/ext/bg/settings.html
+++ b/ext/bg/settings.html
@@ -60,6 +60,11 @@
</select>
</div>
+ <div class="form-group options-merge">
+ <label for="main-dictionary">Main dictionary</label>
+ <select class="form-control" id="main-dictionary"></select>
+ </div>
+
<div class="form-group">
<label for="audio-playback-source">Audio playback source</label>
<select class="form-control" id="audio-playback-source">