summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-01-15 12:42:44 -0800
committerAlex Yatskov <alex@foosoft.net>2017-01-15 12:42:44 -0800
commit434ccc18ee22f5dcf0298e6516adf5e8273ecb6d (patch)
treea7bda23c9c69341d7918d81408cf55adbe6c2bb2 /ext
parent0c88d3fa273667d30be3ae8e1ee8da527561aa9e (diff)
dict priority work
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/options-form.js12
-rw-r--r--ext/bg/js/options.js66
-rw-r--r--ext/bg/js/templates.js12
-rw-r--r--ext/bg/js/util.js4
4 files changed, 53 insertions, 41 deletions
diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js
index af918aa6..f58c26cc 100644
--- a/ext/bg/js/options-form.js
+++ b/ext/bg/js/options-form.js
@@ -54,9 +54,10 @@ function getFormData() {
$('.dict-group').each((index, element) => {
const dictionary = $(element);
const title = dictionary.data('title');
+ const priority = parseInt(dictionary.find('.dict-priority').val(), 10);
const enableTerms = dictionary.find('.dict-enable-terms').prop('checked');
const enableKanji = dictionary.find('.dict-enable-kanji').prop('checked');
- optionsNew.dictionaries[title] = {enableTerms, enableKanji};
+ optionsNew.dictionaries[title] = {priority, enableTerms, enableKanji};
});
return {optionsNew, optionsOld};
@@ -147,22 +148,23 @@ function populateDictionaries(options) {
let dictCount = 0;
return database().getDictionaries().then(rows => {
rows.forEach(row => {
- const dictoptions = options.dictionaries[row.title] || {enableTerms: false, enableKanji: false};
+ const dictOptions = options.dictionaries[row.title] || {enableTerms: false, enableKanji: false, priority: 0};
const html = Handlebars.templates['dictionary.html']({
title: row.title,
version: row.version,
revision: row.revision,
hasTerms: row.hasTerms,
hasKanji: row.hasKanji,
- enableTerms: dictoptions.enableTerms,
- enableKanji: dictoptions.enableKanji
+ priority: dictOptions.priority,
+ enableTerms: dictOptions.enableTerms,
+ enableKanji: dictOptions.enableKanji
});
dictGroups.append($(html));
++dictCount;
});
- $('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged);
+ $('.dict-enable-terms, .dict-enable-kanji, .dict-priority').change(onOptionsChanged);
$('.dict-delete').click(onDictionaryDelete);
}).catch(error => {
showDictionaryError(error);
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 19e028fb..027a1539 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -20,28 +20,28 @@
function optionsSetDefaults(options) {
const defaults = {
general: {
- autoStart: true,
+ autoStart: true,
audioPlayback: true,
- softKatakana: true,
- groupResults: true,
- showAdvanced: false
+ softKatakana: true,
+ groupResults: true,
+ showAdvanced: false
},
scanning: {
requireShift: true,
- selectText: true,
- delay: 15,
- length: 10
+ selectText: true,
+ delay: 15,
+ length: 10
},
dictionaries: {},
anki: {
- enable: false,
- tags: ['yomichan'],
+ enable: false,
+ tags: ['yomichan'],
sentenceExt: 200,
- terms: {deck: '', model: '', fields: {}},
- kanji: {deck: '', model: '', fields: {}},
+ terms: {deck: '', model: '', fields: {}},
+ kanji: {deck: '', model: '', fields: {}}
}
};
@@ -53,10 +53,10 @@ function optionsSetDefaults(options) {
}
};
- combine(options, defaults);
- combine(options.general, defaults.general);
- combine(options.scanning, defaults.scanning);
- combine(options.anki, defaults.anki);
+ combine(options, defaults);
+ combine(options.general, defaults.general);
+ combine(options.scanning, defaults.scanning);
+ combine(options.anki, defaults.anki);
combine(options.anki.terms, defaults.anki.terms);
combine(options.anki.kanji, defaults.anki.kanji);
@@ -74,28 +74,32 @@ function optionsVersion(options) {
() => {
optionsSetDefaults(options);
- copy(options.general, 'autoStart', options, 'activateOnStartup');
+ copy(options.general, 'autoStart', options, 'activateOnStartup');
copy(options.general, 'audioPlayback', options, 'enableAudioPlayback');
- copy(options.general, 'softKatakana', options, 'enableSoftKatakanaSearch');
- copy(options.general, 'groupResults', options, 'groupTermResults');
- copy(options.general, 'showAdvanced', options, 'showAdvancedOptions');
+ copy(options.general, 'softKatakana', options, 'enableSoftKatakanaSearch');
+ copy(options.general, 'groupResults', options, 'groupTermResults');
+ copy(options.general, 'showAdvanced', options, 'showAdvancedOptions');
copy(options.scanning, 'requireShift', options, 'holdShiftToScan');
- copy(options.scanning, 'selectText', options, 'selectMatchedText');
- copy(options.scanning, 'delay', options, 'scanDelay');
- copy(options.scanning, 'length', options, 'scanLength');
+ copy(options.scanning, 'selectText', options, 'selectMatchedText');
+ copy(options.scanning, 'delay', options, 'scanDelay');
+ copy(options.scanning, 'length', options, 'scanLength');
options.anki.enable = options.ankiMethod === 'ankiconnect';
- copy(options.anki, 'tags', options, 'ankiCardTags');
- copy(options.anki, 'sentenceExt', options, 'sentenceExtent');
- copy(options.anki.terms, 'deck', options, 'ankiTermDeck');
- copy(options.anki.terms, 'model', options, 'ankiTermModel');
- copy(options.anki.terms, 'fields', options, 'ankiTermFields');
- copy(options.anki.kanji, 'deck', options, 'ankiKanjiDeck');
- copy(options.anki.kanji, 'model', options, 'ankiKanjiModel');
- copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
- },
+ copy(options.anki, 'tags', options, 'ankiCardTags');
+ copy(options.anki, 'sentenceExt', options, 'sentenceExtent');
+ copy(options.anki.terms, 'deck', options, 'ankiTermDeck');
+ copy(options.anki.terms, 'model', options, 'ankiTermModel');
+ copy(options.anki.terms, 'fields', options, 'ankiTermFields');
+ copy(options.anki.kanji, 'deck', options, 'ankiKanjiDeck');
+ copy(options.anki.kanji, 'model', options, 'ankiKanjiModel');
+ copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
+
+ for (const title in options.dictionaries) {
+ options.dictionaries[title].priority = 0;
+ }
+ }
];
if (options.version < fixups.length) {
diff --git a/ext/bg/js/templates.js b/ext/bg/js/templates.js
index 89719a24..85b36de3 100644
--- a/ext/bg/js/templates.js
+++ b/ext/bg/js/templates.js
@@ -17,7 +17,13 @@ templates['dictionary.html'] = template({"1":function(container,depth0,helpers,p
+ 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)))
+ " <small>v."
+ alias4(((helper = (helper = helpers.version || (depth0 != null ? depth0.version : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"version","hash":{},"data":data}) : helper)))
- + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"checkbox dict-group-controls "
+ + "</small></h4> -->\n <!-- </div> -->\n <!-- <div class=\"col-xs-4 text-right disabled\"> -->\n <!-- <button type=\"button\" class=\"dict-group-controls dict-delete btn btn-danger\">Delete</button> -->\n <!-- </div> -->\n <!-- </div> -->\n\n <div class=\"dict-delete-progress\">\n Dictionary data is being deleted, please be patient...\n <div class=\"progress\">\n <div class=\"progress-bar progress-bar-striped progress-bar-danger\" style=\"width: 0%\"></div>\n </div>\n </div>\n\n <div class=\"form-group dict-group-controls\">\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)))
+ + "\">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)))
+ + "\" id=\"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)))
+ + "\" class=\"form-control dict-priority\">\n </div>\n <div class=\"checkbox dict-group-controls "
+ ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
+ "\">\n <label><input type=\"checkbox\" class=\"dict-enable-terms\" "
+ ((stack1 = helpers.unless.call(alias1,(depth0 != null ? depth0.hasTerms : depth0),{"name":"unless","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
@@ -173,7 +179,7 @@ templates['term-list.html'] = template({"1":function(container,depth0,helpers,pa
+ " </ul>\n";
},"6":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer =
- " <li><span class=\"term-glossary-item\">";
+ " <li><span class=\"term-glossary-item\">";
stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(7, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
@@ -182,7 +188,7 @@ templates['term-list.html'] = template({"1":function(container,depth0,helpers,pa
return container.escapeExpression(container.lambda(depth0, depth0));
},"9":function(container,depth0,helpers,partials,data) {
var stack1, helper, options, buffer =
- " <div class=\"term-glossary-group term-glossary-item\">";
+ " <div class=\"term-glossary-group term-glossary-item\">";
stack1 = ((helper = (helper = helpers.multiLine || (depth0 != null ? depth0.multiLine : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"multiLine","hash":{},"fn":container.program(10, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
if (!helpers.multiLine) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
if (stack1 != null) { buffer += stack1; }
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 1e49e33c..900a7a2c 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -123,7 +123,7 @@ function groupTermDefs(definitions) {
reading: firstDef.reading,
reasons: firstDef.reasons,
score: groupDefs.reduce((x, y) => x > y ? x : y, Number.MIN_SAFE_INTEGER),
- source: firstDef.source,
+ source: firstDef.source
});
}
@@ -192,7 +192,7 @@ function formatField(field, definition, mode) {
'reading',
'sentence',
'tags',
- 'url',
+ 'url'
];
for (const marker of markers) {