Added filtering by blank part of speech, fixed part of speech dropdown for edits, added import template CSV to download, updated import test to test blank part of speech.

This commit is contained in:
Robbie Antenesse 2016-06-10 11:35:57 -07:00
parent 368fc8cd20
commit 9deb9087e6
4 changed files with 46 additions and 23 deletions

View File

@ -1,15 +1,17 @@
<div class="settingsCol">
<h2>Import</h2>
<div id="importOptions">
<h2>Import</h2>
<div id="importOptions">
<div class="settingsCol">
<label>
<span>Word List</span>
</label>
<p style="font-size:12px;">This process imports words in a CSV format to the currently loaded dictionary. <small>(You can save an Excel file as a CSV)</small></p>
<p style="font-size:12px;">The CSV file must have a header line in this order: word,pronunciation,part of speech,equivalent,explanation. Your words must be formatted in the appropriate order.</p>
<p style="font-size:12px;">Make sure the parts of speech for each word correspond to your dictionary's parts of speech or else it will be lost if you edit the word. If a part of speech is left blank, you can find the blanks using the "Blank" option in the Filter.</p>
<p style="font-size:12px;">This process imports words in a CSV format to the currently loaded dictionary. <small>(Note: You can save an Excel file as a CSV)</small></p>
<p style="font-size:12px;">The CSV file must have a header line in this order: word,pronunciation,part of speech,equivalent,explanation. Your word data must be in the appropriate order according to the headers. You can use <span class="clickable inline-button" onclick="download('import_template.csv','word,pronunciation,part of speech,equivalent,explanation\n');">this CSV as a template</span> if you need help.</p>
<p style="font-size:12px;">Make sure the parts of speech for each word correspond to your dictionary's parts of speech or else you won't be able to find it using a filter. If a part of speech is left blank, you can find the blanks using the "Blank" option in the Filter so you can clean up.</p>
<p style="font-size:12px;">At a minimum, all of your words <em>must</em> have the "word" field <em>and</em> either the "equivalent" or "explanation" field filled out in the CSV file.</p>
<input type="file" id="importWordsCSV" />
<button type="button" onclick="ImportWords(); return false;">Import Words</button>
</div>
<div class="settingsCol">
<label>
<span>Full Dictionary</span>
<p style="font-size:12px;">This process imports a full dictionary previously exported from Lexiconga in a .dict format.</p>

View File

@ -1,6 +1,4 @@
"word","pronunciation","part of speech","equivalent","explanation"
"test","[tehst]","Noun","an example, per se!","no explanation required."
test,"[tehst]","Verb","to test, i.e. to ""try to see"" if something works","no explanation required."
"tested","[tehst-ehd]",Adjective,"of or relating to an example","no explanation required."
"testable","[tehst-uh-bull]","Adjective","Able to be have ""tests"" run on","explanation"
word,pronunciation,part of speech,equivalent,explanation
test0, [tehst], ,dah,
test1, [tehst], a ,dah,
test2, [tehst], a ,dah,
1 word pronunciation part of speech equivalent explanation
2 test test0 [tehst] Noun an example, per se! dah no explanation required.
3 test test1 [tehst] Verb a to test, i.e. to "try to see" if something works dah no explanation required.
4 tested test2 [tehst-ehd] [tehst] Adjective a of or relating to an example dah no explanation required.
testable [tehst-uh-bull] Adjective Able to be have "tests" run on explanation

View File

@ -68,7 +68,7 @@ function AddWord() {
}
}
} else {
currentDictionary.words.push({name: word, pronunciation: pronunciation, partOfSpeech: partOfSpeech, simpleDefinition: simpleDefinition, longDefinition: longDefinition, wordId: currentDictionary.nextWordId++});
currentDictionary.words.push({name: word, pronunciation: pronunciation, partOfSpeech: ((partOfSpeech.length > 0) ? partOfSpeech : " "), simpleDefinition: simpleDefinition, longDefinition: longDefinition, wordId: currentDictionary.nextWordId++});
FocusAfterAddingNewWord();
NewWordNotification(word);
SaveAndUpdateDictionary(false);
@ -103,7 +103,7 @@ function ShowWordEditForm(index) {
<input type="text" id="pronunciation' + indexString + '" value="' + htmlEntitiesParse(word.pronunciation) + '" onkeydown="SubmitWordOnCtrlEnter(this)" />\
</label>\
<label><span>Part of Speech</span>\
<select id="partOfSpeech' + indexString + '" value="' + htmlEntitiesParse(word.partOfSpeech) + '" onkeydown="SubmitWordOnCtrlEnter(this)"></select>\
<select id="partOfSpeech' + indexString + '" onkeydown="SubmitWordOnCtrlEnter(this)"></select>\
</label>\
<label><span>Equivalent Word(s)</span>\
<input type="text" id="simpleDefinition' + indexString + '" value="' + htmlEntitiesParse(word.simpleDefinition) + '" onkeydown="SubmitWordOnCtrlEnter(this)" />\
@ -121,6 +121,7 @@ function ShowWordEditForm(index) {
document.getElementById("entry" + indexString).innerHTML = editForm;
SetPartsOfSpeech("partOfSpeech" + indexString);
document.getElementById("partOfSpeech" + indexString).value = htmlEntitiesParse(word.partOfSpeech);
}
function CancelEditForm(index) {
@ -160,7 +161,7 @@ function EditWord(indexString) {
function UpdateWord(wordIndex, word, pronunciation, partOfSpeech, simpleDefinition, longDefinition) {
currentDictionary.words[wordIndex].name = word;
currentDictionary.words[wordIndex].pronunciation = pronunciation;
currentDictionary.words[wordIndex].partOfSpeech = partOfSpeech;
currentDictionary.words[wordIndex].partOfSpeech = ((partOfSpeech.length > 0) ? partOfSpeech : " ");
currentDictionary.words[wordIndex].simpleDefinition = simpleDefinition;
currentDictionary.words[wordIndex].longDefinition = longDefinition;
@ -690,15 +691,19 @@ function ImportWords() {
header: true,
step: function(row, parser) {
currentRow++;
if (row.errors.length == 0) {
currentDictionary.words.push({name: htmlEntities(row.data[0]["word"]).trim(), pronunciation: htmlEntities(row.data[0]["pronunciation"]).trim(), partOfSpeech: htmlEntities(row.data[0]["part of speech"]).trim(), simpleDefinition: htmlEntities(row.data[0]["equivalent"]).trim(), longDefinition: htmlEntities(row.data[0]["explanation"]).trim(), wordId: currentDictionary.nextWordId++});
// If there are no errors OR the word and either equivalent or explanation contain data, then import it.
if ((row.data[0].word.trim().length > 0 && (row.data[0].equivalent.trim().length > 0 || row.data[0].explanation.trim().length > 0)) || row.errors.length == 0) {
currentDictionary.words.push({name: htmlEntities(row.data[0]["word"]).trim(), pronunciation: htmlEntities(row.data[0]["pronunciation"]).trim(), partOfSpeech: ((htmlEntities(row.data[0]["part of speech"]).trim().length > 0) ? htmlEntities(row.data[0]["part of speech"]).trim() : " "), simpleDefinition: htmlEntities(row.data[0]["equivalent"]).trim(), longDefinition: htmlEntities(row.data[0]["explanation"]).trim(), wordId: currentDictionary.nextWordId++});
resultsArea.innerHTML += "<p>Imported \"" + htmlEntitiesParse(htmlEntities(row.data[0]["word"])).trim() + "\" successfully</p>";
rowsImported++;
} else {
// If it's not just an empty line, give an error.
if (row.data[0].word.trim().length > 0) {
for (var i = 0; i < row.errors.length; i++) {
resultsArea.innerHTML += "<p>Error on record #" + currentRow.toString() + ": " + row.errors[i].message + "</p>";
}
}
}
// Scroll to the bottom.
document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight;
},

View File

@ -588,11 +588,17 @@ function SetPartsOfSpeech (selectId) {
var wordFiltersSelected = GetSelectedFilters();
// Clear parts of speech.
for (var i = partsOfSpeechSelect.options.length - 1; i >= 0; i--) {
for (var i = partsOfSpeechSelect.options.length; i > 0; i--) {
partsOfSpeechSelect.removeChild(partsOfSpeechSelect.options[i]);
}
wordFilterOptions.innerHTML = "";
// Insert blank part of speech as first dropdown option.
var blankpartOfSpeechOption = document.createElement('option');
blankpartOfSpeechOption.appendChild(document.createTextNode(""));
blankpartOfSpeechOption.value = " ";
partsOfSpeechSelect.appendChild(blankpartOfSpeechOption);
// Rebuild parts of speech
var newPartsOfSpeech = htmlEntitiesParse(currentDictionary.settings.partsOfSpeech).trim().split(",");
for (var j = 0; j < newPartsOfSpeech.length; j++) {
@ -614,6 +620,18 @@ function SetPartsOfSpeech (selectId) {
wordFilterLabel.appendChild(wordFilterCheckbox);
wordFilterOptions.appendChild(wordFilterLabel);
}
// Insert blank part of speech as last filter option
var blankwordFilterLabel = document.createElement('label');
blankwordFilterLabel.appendChild(document.createTextNode("Blanks "));
blankwordFilterLabel['part-of-speech'] = " ";
blankwordFilterLabel.className = 'filterOption';
var blankwordFilterCheckbox = document.createElement('input');
blankwordFilterCheckbox.type = 'checkbox';
blankwordFilterCheckbox.onchange = function(){ShowDictionary()};
if (wordFiltersSelected.indexOf(" ") > -1) blankwordFilterCheckbox.checked = true;
blankwordFilterLabel.appendChild(blankwordFilterCheckbox);
wordFilterOptions.appendChild(blankwordFilterLabel);
}
function GetSelectedFilters() {