summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/bg/js/database.js27
-rw-r--r--ext/bg/js/dictionary.js4
-rw-r--r--ext/bg/js/options.js4
-rw-r--r--ext/bg/js/settings.js30
-rw-r--r--ext/bg/js/templates.js4
-rw-r--r--ext/bg/js/translator.js5
-rw-r--r--tmpl/dictionary.html1
7 files changed, 53 insertions, 22 deletions
diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js
index 0de0505d..7a893fc0 100644
--- a/ext/bg/js/database.js
+++ b/ext/bg/js/database.js
@@ -85,25 +85,26 @@ class Database {
return results;
}
- async findTermsBySequence(sequence, dictionary) {
+ async findTermsBySequence(sequence, mainDictionary) {
if (!this.db) {
throw 'Database not initialized';
}
const results = [];
await this.db.terms.where('sequence').equals(sequence).each(row => {
- // if (dictionary === row.dictionary) {
- results.push({
- expression: row.expression,
- reading: row.reading,
- tags: dictFieldSplit(row.tags),
- rules: dictFieldSplit(row.rules),
- glossary: row.glossary,
- score: row.score,
- dictionary: row.dictionary,
- id: row.id,
- sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
- });
+ if (row.dictionary === mainDictionary) {
+ results.push({
+ expression: row.expression,
+ reading: row.reading,
+ tags: dictFieldSplit(row.tags),
+ rules: dictFieldSplit(row.rules),
+ glossary: row.glossary,
+ score: row.score,
+ dictionary: row.dictionary,
+ id: row.id,
+ sequence: typeof row.sequence === 'undefined' ? -1 : row.sequence
+ });
+ }
});
return results;
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 2b289a23..c20df400 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -144,10 +144,10 @@ function dictTermsGroup(definitions, dictionaries) {
return dictTermsSort(results);
}
-function dictTermsMergeBySequence(definitions) {
+function dictTermsMergeBySequence(definitions, mainDictionary) {
const definitionsBySequence = {'-1': []};
for (const definition of definitions) {
- if (definition.sequence > 0) {
+ if (mainDictionary === definition.dictionary && definition.sequence > 0) {
if (!definitionsBySequence[definition.sequence]) {
definitionsBySequence[definition.sequence] = {
reasons: definition.reasons,
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index b49c32da..0aa6d7c6 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -154,6 +154,10 @@ function optionsSetDefaults(options) {
dictionaries: {},
+ dictionary: {
+ main: ''
+ },
+
anki: {
enable: false,
server: 'http://127.0.0.1:8765',
diff --git a/ext/bg/js/settings.js b/ext/bg/js/settings.js
index c5a28a45..4d248304 100644
--- a/ext/bg/js/settings.js
+++ b/ext/bg/js/settings.js
@@ -60,7 +60,11 @@ 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');
- optionsNew.dictionaries[title] = {priority, enabled};
+ const main = dictionary.find('.dict-main').prop('checked');
+ if (main) {
+ optionsNew.dictionary.main = title;
+ }
+ optionsNew.dictionaries[title] = {priority, enabled, main};
});
return {optionsNew, optionsOld};
@@ -237,6 +241,18 @@ 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();
@@ -247,13 +263,14 @@ async function dictionaryGroupsPopulate(options) {
}
for (const dictRow of dictRowsSort(dictRows, options)) {
- const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0};
+ const dictOptions = options.dictionaries[dictRow.title] || {enabled: false, priority: 0, main: false};
const dictHtml = await apiTemplateRender('dictionary.html', {
title: dictRow.title,
version: dictRow.version,
revision: dictRow.revision,
priority: dictOptions.priority,
- enabled: dictOptions.enabled
+ enabled: dictOptions.enabled,
+ main: dictOptions.main
});
dictGroups.append($(dictHtml));
@@ -265,6 +282,11 @@ async function dictionaryGroupsPopulate(options) {
dictionaryGroupsSort();
onFormOptionsChanged(e);
});
+
+ $('.dict-main').change(e => {
+ dictionarySetMain(e);
+ onFormOptionsChanged(e);
+ });
}
async function onDictionaryPurge(e) {
@@ -308,7 +330,7 @@ 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};
+ options.dictionaries[summary.title] = {enabled: true, priority: 0, main: false};
await optionsSave(options);
await dictionaryGroupsPopulate(options);
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index c6de8580..4341322a 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -13,7 +13,9 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ 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)))
+ "</small></h4>\n\n <div class=\"checkbox\">\n <label><input type=\"checkbox\" class=\"dict-enabled\" "
+ ((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=\"form-group options-advanced\">\n <label for=\"dict-"
+ + "> Enable search</label>\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-"
+ 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 81253374..3442124f 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -49,10 +49,11 @@ class Translator {
}
async findTermsMerged(text, dictionaries, alphanumeric) {
+ const options = await apiOptionsGet();
const titles = Object.keys(dictionaries);
const {length, definitions} = await this.findTerms(text, dictionaries, alphanumeric);
- const definitionsBySequence = dictTermsMergeBySequence(definitions);
+ const definitionsBySequence = dictTermsMergeBySequence(definitions, options.dictionary.main);
const definitionsMerged = dictTermsGroup(definitionsBySequence['-1'], dictionaries);
for (const sequence in definitionsBySequence) {
@@ -62,7 +63,7 @@ class Translator {
const result = definitionsBySequence[sequence];
- const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence));
+ const rawDefinitionsBySequence = await this.database.findTermsBySequence(Number(sequence), options.dictionary.main);
const definitionsByGloss = dictTermsMergeByGloss(result, rawDefinitionsBySequence);
// postprocess glossaries
diff --git a/tmpl/dictionary.html b/tmpl/dictionary.html
index f2f7f687..505331ea 100644
--- a/tmpl/dictionary.html
+++ b/tmpl/dictionary.html
@@ -3,6 +3,7 @@
<div class="checkbox">
<label><input type="checkbox" class="dict-enabled" {{#if enabled}}checked{{/if}}> Enable search</label>
+ <label><input type="radio" class="dict-main" {{#if main}}checked{{/if}}> Set as main dictionary</label>
</div>
<div class="form-group options-advanced">
<label for="dict-{{title}}">Result priority</label>