Got the importer working and did some tests.

This commit is contained in:
Robbie Antenesse 2016-06-09 22:27:41 -07:00
parent f4f9f85a30
commit 368fc8cd20
3 changed files with 24 additions and 10 deletions

View File

@ -1,4 +1,6 @@
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."
"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"
1 word pronunciation part of speech equivalent explanation
2 test [tehst] noun Noun an example, per se! no explanation required.
3 test [tehst] verb Verb to test, i.e. to try to see if something works to test, i.e. to "try to see" if something works no explanation required.
4 tested [tehst-ehd] adjective Adjective of or relating to an example no explanation required.
5 testable [tehst-uh-bull] Adjective Able to be have "tests" run on explanation
6

View File

@ -349,10 +349,10 @@ if ($is_viewing) {
<!-- Markdown Parser -->
<script src="js/marked.js"></script>
<!-- JSON Search -->
<script src="js/defiant.js"></script>
<!-- CSV Parser -->
<script src="js/papaparse.js"></script>
<!-- JSON Search -->
<script src="js/defiant.js"></script>
<!-- Diacritics Removal for Exports -->
<script src="js/removeDiacritics.js"></script>
<!-- Helper Functions -->

View File

@ -683,19 +683,31 @@ function ImportWords() {
var resultsArea = document.getElementById("importOptions");
resultsArea.innerHTML = "";
var currentRow = 0; // Because of the header, the first row of data is always on line 2.
var rowsImported = 0;
Papa.parse(file, {
header: true,
step: function(row, parser) {
currentRow++;
if (row.errors.length == 0) {
currentDictionary.words.push({name: row.data["word"], pronunciation: row.data["pronunciation"], partOfSpeech: row.data["part of speech"], simpleDefinition: row.data["equivalent"], longDefinition: row.data["explanation"], wordId: currentDictionary.nextWordId++});
resultsArea.innerHTML += "<p>Imported \"" + row.data["word"] + " successfully</p>";
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++});
resultsArea.innerHTML += "<p>Imported \"" + htmlEntitiesParse(htmlEntities(row.data[0]["word"])).trim() + "\" successfully</p>";
rowsImported++;
} else {
resultsArea.innerHTML += "<p>Error on row " + row.error.row + ": " + row.error.message + "</p>";
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;
},
complete: function(results) {
SaveAndUpdateDictionary();
resultsArea.innerHTML += "<p>The file has finished importing.</p>";
resultsArea.innerHTML += "<p>The file has finished importing " + rowsImported.toString() + " words.</p>";
// Scroll to the bottom.
document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight;
document.getElementById("numberOfWordsInDictionary").innerHTML = currentDictionary.words.length.toString();
}
});
} else {