diff --git a/import_test.csv b/import_test.csv index 3f809c9..3203999 100644 --- a/import_test.csv +++ b/import_test.csv @@ -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" \ No newline at end of file diff --git a/index.php b/index.php index e8069d2..0d29fe8 100644 --- a/index.php +++ b/index.php @@ -349,10 +349,10 @@ if ($is_viewing) { - - + + diff --git a/js/dictionaryBuilder.js b/js/dictionaryBuilder.js index 038e4d1..4d07205 100644 --- a/js/dictionaryBuilder.js +++ b/js/dictionaryBuilder.js @@ -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 += "

Imported \"" + row.data["word"] + " successfully

"; + 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 += "

Imported \"" + htmlEntitiesParse(htmlEntities(row.data[0]["word"])).trim() + "\" successfully

"; + rowsImported++; } else { - resultsArea.innerHTML += "

Error on row " + row.error.row + ": " + row.error.message + "

"; + for (var i = 0; i < row.errors.length; i++) { + resultsArea.innerHTML += "

Error on record #" + currentRow.toString() + ": " + row.errors[i].message + "

"; + } } + // Scroll to the bottom. + document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; }, complete: function(results) { SaveAndUpdateDictionary(); - resultsArea.innerHTML += "

The file has finished importing.

"; + resultsArea.innerHTML += "

The file has finished importing " + rowsImported.toString() + " words.

"; + // Scroll to the bottom. + document.getElementById("importOptions").scrollTop = document.getElementById("importOptions").scrollHeight; + document.getElementById("numberOfWordsInDictionary").innerHTML = currentDictionary.words.length.toString(); } }); } else {