Trying to add PapaParse for importing CSV files of words, but for some reason it's not recognizing the Papa object.

This commit is contained in:
Robbie Antenesse 2016-06-08 13:43:58 -06:00
parent f48ca733f9
commit f4f9f85a30
9 changed files with 1495 additions and 5 deletions

20
IMPORT.form Normal file
View File

@ -0,0 +1,20 @@
<div class="settingsCol">
<h2>Import</h2>
<div id="importOptions">
<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;">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>
<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>
<input type="file" id="importFile" />
<button type="button" onclick="ImportDictionary(); return false;">Import Dictionary</button>
</label>
</div>
</div>

View File

@ -42,7 +42,7 @@ Some of the ads may be served by Google. Google's use of the DART cookie enables
### Changes to this privacy policy ### Changes to this privacy policy
Lexiconga Dictionary Builder has the discretion to update this privacy policy at any time. When we do, we will post a notification on the main page of our Site. We encourage Users to frequently check this page for any changes to stay informed about how we are helping to protect the personal information we collect. You acknowledge and agree that it is your responsibility to review this privacy policy periodically and become aware of modifications. Lexiconga Dictionary Builder has the discretion to update this privacy policy at any time. When we do, we will post a notification on the main page of our Site. We encourage Users to frequently check this page for any changes to stay informed about how we are helping to protect the personal information we collect. You acknowledge and agree that it is your responsibility to review this privacy policy periodically and become aware of modifications.
###Your acceptance of these terms ### Your acceptance of these terms
By using this Site, you signify your acceptance of this policy. If you do not agree to this policy, please do not use our Site. Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes. This policy was originally generated using PrivacyPolicies.com and modified for our use. By using this Site, you signify your acceptance of this policy. If you do not agree to this policy, please do not use our Site. Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes. This policy was originally generated using PrivacyPolicies.com and modified for our use.
### Contacting us ### Contacting us

View File

@ -188,4 +188,5 @@ I hope you enjoy Lexiconga and that it helps you build some awesome languages.
## Libraries Used ## Libraries Used
* [Marked.js](https://github.com/chjj/marked) by Christopher Jeffrey (JJ) (a.k.a. chjj) * [Marked.js](https://github.com/chjj/marked) by Christopher Jeffrey (JJ) (a.k.a. chjj)
* [Defiant.js](http://defiantjs.com) by Hakan Bilgin (a.k.a. hbi99) * [Defiant.js](http://defiantjs.com) by Hakan Bilgin (a.k.a. hbi99)
* [Papa Parse](http://papaparse.com/) by Matt Holt (a.k.a. mholt)
* [removeDiacritics.js](http://stackoverflow.com/a/18391901/3508346) by [rdllopes](http://meta.stackoverflow.com/users/1879686/rdllopes) * [removeDiacritics.js](http://stackoverflow.com/a/18391901/3508346) by [rdllopes](http://meta.stackoverflow.com/users/1879686/rdllopes)

4
import_test.csv Normal file
View File

@ -0,0 +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."
1 word pronunciation part of speech equivalent explanation
2 test [tehst] noun an example, per se! no explanation required.
3 test [tehst] verb to test, i.e. to try to see if something works no explanation required.
4 tested [tehst-ehd] adjective of or relating to an example no explanation required.

View File

@ -256,9 +256,7 @@ if ($is_viewing) {
<label><button type="button" onclick="CreateNewDictionary()" style="cursor:pointer;">Create a New Dictionary</button></label> <label><button type="button" onclick="CreateNewDictionary()" style="cursor:pointer;">Create a New Dictionary</button></label>
<?php } ?> <?php } ?>
<label> <label>
<span>Import Dictionary</span> <button type="button" onclick="ShowInfo('importForm')">Import...</button>
<input type="file" id="importFile" />
<button type="button" onclick="ImportDictionary(); return false;">Import</button>
</label> </label>
<?php if ($current_user > 0) { //If logged in, show the log out button. ?> <?php if ($current_user > 0) { //If logged in, show the log out button. ?>
<label><button type="button" onclick="DeleteCurrentDictionary()" style="cursor:pointer;">Delete Current Dictionary</button></label> <label><button type="button" onclick="DeleteCurrentDictionary()" style="cursor:pointer;">Delete Current Dictionary</button></label>
@ -353,6 +351,8 @@ if ($is_viewing) {
<script src="js/marked.js"></script> <script src="js/marked.js"></script>
<!-- JSON Search --> <!-- JSON Search -->
<script src="js/defiant.js"></script> <script src="js/defiant.js"></script>
<!-- CSV Parser -->
<script src="js/papaparse.js"></script>
<!-- Diacritics Removal for Exports --> <!-- Diacritics Removal for Exports -->
<script src="js/removeDiacritics.js"></script> <script src="js/removeDiacritics.js"></script>
<!-- Helper Functions --> <!-- Helper Functions -->
@ -367,7 +367,7 @@ if ($is_viewing) {
<?php } ?> <?php } ?>
<?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?> <?php if ($_GET['adminoverride'] != "noadsortracking") { include_once("php/google/analytics.php"); } ?>
<script> <script>
var aboutText = termsText = privacyText = loginForm = forgotForm = "Loading..."; var aboutText = termsText = privacyText = loginForm = forgotForm = importForm = "Loading...";
<?php if ($is_viewing) { ?> <?php if ($is_viewing) { ?>
window.onload = function () { window.onload = function () {
ShowPublicDictionary(); ShowPublicDictionary();
@ -378,6 +378,7 @@ if ($is_viewing) {
GetTextFile("PRIVACY.md", "privacyText", true); GetTextFile("PRIVACY.md", "privacyText", true);
GetTextFile("LOGIN.form", "loginForm", false); GetTextFile("LOGIN.form", "loginForm", false);
GetTextFile("FORGOT.form", "forgotForm", false); GetTextFile("FORGOT.form", "forgotForm", false);
GetTextFile("IMPORT.form", "importForm", false);
} }
<?php } else { ?> <?php } else { ?>
ready(function() { ready(function() {

View File

@ -670,6 +670,40 @@ function ImportDictionary() {
} }
} }
function ImportWords() {
if (currentDictionary.externalID > 0 || confirm("This will add words in a correctly formatted CSV file to your currently loaded dictionary. Do you still want to import?")) {
if (!window.FileReader) {
alert('Your browser is not supported');
return false;
}
if (document.getElementById("importWordsCSV").files.length > 0) {
var file = document.getElementById("importWordsCSV").files[0];
var resultsArea = document.getElementById("importOptions");
resultsArea.innerHTML = "";
Papa.parse(file, {
header: true,
step: function(row, parser) {
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>";
} else {
resultsArea.innerHTML += "<p>Error on row " + row.error.row + ": " + row.error.message + "</p>";
}
},
complete: function(results) {
SaveAndUpdateDictionary();
resultsArea.innerHTML += "<p>The file has finished importing.</p>";
}
});
} else {
alert("You must add a file to import.");
}
}
}
function WordIndex(word) { function WordIndex(word) {
for (var i = 0; i < currentDictionary.words.length; i++) for (var i = 0; i < currentDictionary.words.length; i++)
{ {

6
js/min/papaparse.js Normal file

File diff suppressed because one or more lines are too long

1423
js/papaparse.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@ function Initialize() {
GetTextFile("PRIVACY.md", "privacyText", true); GetTextFile("PRIVACY.md", "privacyText", true);
GetTextFile("LOGIN.form", "loginForm", false); GetTextFile("LOGIN.form", "loginForm", false);
GetTextFile("FORGOT.form", "forgotForm", false); GetTextFile("FORGOT.form", "forgotForm", false);
GetTextFile("IMPORT.form", "importForm", false);
SetKeyboardShortcuts(); SetKeyboardShortcuts();
} }