dict priority work

This commit is contained in:
Alex Yatskov 2017-01-15 12:42:44 -08:00
parent 0c88d3fa27
commit 434ccc18ee
5 changed files with 57 additions and 41 deletions

View File

@ -54,9 +54,10 @@ function getFormData() {
$('.dict-group').each((index, element) => { $('.dict-group').each((index, element) => {
const dictionary = $(element); const dictionary = $(element);
const title = dictionary.data('title'); const title = dictionary.data('title');
const priority = parseInt(dictionary.find('.dict-priority').val(), 10);
const enableTerms = dictionary.find('.dict-enable-terms').prop('checked'); const enableTerms = dictionary.find('.dict-enable-terms').prop('checked');
const enableKanji = dictionary.find('.dict-enable-kanji').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}; return {optionsNew, optionsOld};
@ -147,22 +148,23 @@ function populateDictionaries(options) {
let dictCount = 0; let dictCount = 0;
return database().getDictionaries().then(rows => { return database().getDictionaries().then(rows => {
rows.forEach(row => { 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']({ const html = Handlebars.templates['dictionary.html']({
title: row.title, title: row.title,
version: row.version, version: row.version,
revision: row.revision, revision: row.revision,
hasTerms: row.hasTerms, hasTerms: row.hasTerms,
hasKanji: row.hasKanji, hasKanji: row.hasKanji,
enableTerms: dictoptions.enableTerms, priority: dictOptions.priority,
enableKanji: dictoptions.enableKanji enableTerms: dictOptions.enableTerms,
enableKanji: dictOptions.enableKanji
}); });
dictGroups.append($(html)); dictGroups.append($(html));
++dictCount; ++dictCount;
}); });
$('.dict-enable-terms, .dict-enable-kanji').change(onOptionsChanged); $('.dict-enable-terms, .dict-enable-kanji, .dict-priority').change(onOptionsChanged);
$('.dict-delete').click(onDictionaryDelete); $('.dict-delete').click(onDictionaryDelete);
}).catch(error => { }).catch(error => {
showDictionaryError(error); showDictionaryError(error);

View File

@ -41,7 +41,7 @@ function optionsSetDefaults(options) {
tags: ['yomichan'], tags: ['yomichan'],
sentenceExt: 200, sentenceExt: 200,
terms: {deck: '', model: '', fields: {}}, terms: {deck: '', model: '', fields: {}},
kanji: {deck: '', model: '', fields: {}}, kanji: {deck: '', model: '', fields: {}}
} }
}; };
@ -95,7 +95,11 @@ function optionsVersion(options) {
copy(options.anki.kanji, 'deck', options, 'ankiKanjiDeck'); copy(options.anki.kanji, 'deck', options, 'ankiKanjiDeck');
copy(options.anki.kanji, 'model', options, 'ankiKanjiModel'); copy(options.anki.kanji, 'model', options, 'ankiKanjiModel');
copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields'); copy(options.anki.kanji, 'fields', options, 'ankiKanjiFields');
},
for (const title in options.dictionaries) {
options.dictionaries[title].priority = 0;
}
}
]; ];
if (options.version < fixups.length) { if (options.version < fixups.length) {

View File

@ -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))) + 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." + " <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))) + 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 : "") + ((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\" " + "\">\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 : "") + ((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 : "")

View File

@ -123,7 +123,7 @@ function groupTermDefs(definitions) {
reading: firstDef.reading, reading: firstDef.reading,
reasons: firstDef.reasons, reasons: firstDef.reasons,
score: groupDefs.reduce((x, y) => x > y ? x : y, Number.MIN_SAFE_INTEGER), 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', 'reading',
'sentence', 'sentence',
'tags', 'tags',
'url', 'url'
]; ];
for (const marker of markers) { for (const marker of markers) {

View File

@ -17,6 +17,10 @@
</div> </div>
</div> </div>
<div class="form-group dict-group-controls">
<label for="dict-{{title}}">Priority</label>
<input type="number" value="{{priority}}" id="dict-{{title}}" class="form-control dict-priority">
</div>
<div class="checkbox dict-group-controls {{#unless hasTerms}}disabled{{/unless}}"> <div class="checkbox dict-group-controls {{#unless hasTerms}}disabled{{/unless}}">
<label><input type="checkbox" class="dict-enable-terms" {{#unless hasTerms}}disabled{{/unless}} {{#if enableTerms}}checked{{/if}}> Enable term search</label> <label><input type="checkbox" class="dict-enable-terms" {{#unless hasTerms}}disabled{{/unless}} {{#if enableTerms}}checked{{/if}}> Enable term search</label>
</div> </div>