From 434ccc18ee22f5dcf0298e6516adf5e8273ecb6d Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 15 Jan 2017 12:42:44 -0800 Subject: dict priority work --- ext/bg/js/options-form.js | 12 +++++---- ext/bg/js/options.js | 66 +++++++++++++++++++++++++---------------------- ext/bg/js/templates.js | 12 ++++++--- ext/bg/js/util.js | 4 +-- 4 files changed, 53 insertions(+), 41 deletions(-) (limited to 'ext/bg/js') 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))) + " 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))) - + " -->\n \n \n \n \n \n\n
\n Dictionary data is being deleted, please be patient...\n
\n
\n
\n
\n\n
-->\n \n \n \n \n \n\n
\n Dictionary data is being deleted, please be patient...\n
\n
\n
\n
\n\n
\n \n \n
\n
\n