Add new fields to import/export words

This commit is contained in:
Robbie Antenesse 2020-07-31 16:25:26 -06:00
parent b3507128a6
commit ec37fc53a5
2 changed files with 43 additions and 3 deletions

View File

@ -238,14 +238,51 @@ export function importWords() {
});
} else {
const row = results.data;
const importedWord = addWord({
const wordToImport = {
name: removeTags(row.word).trim(),
pronunciation: removeTags(row.pronunciation).trim(),
partOfSpeech: removeTags(row['part of speech']).trim(),
definition: removeTags(row.definition).trim(),
details: removeTags(row.explanation).trim(),
wordId: getNextId(),
}, false);
};
if (typeof row['etymology'] !== 'undefined') {
const etymology = removeTags(row['etymology']).trim().split(',').filter(etymology => etymology.trim() !== '');
if (etymology.length > 0) {
wordToImport.etymology = etymology;
}
}
if (typeof row['etymology (comma-separated)'] !== 'undefined') {
const etymology = removeTags(row['etymology (comma-separated)']).trim().split(',').filter(etymology => etymology.trim() !== '');
if (etymology.length > 0) {
wordToImport.etymology = etymology;
}
}
if (typeof row['related words'] !== 'undefined') {
const related = removeTags(row['related words']).trim().split(',').filter(related => related.trim() !== '');
if (related.length > 0) {
wordToImport.related = related;
}
}
if (typeof row['related words (comma-separated)'] !== 'undefined') {
const related = removeTags(row['related words (comma-separated)']).trim().split(',').filter(related => related.trim() !== '');
if (related.length > 0) {
wordToImport.related = related;
}
}
if (typeof row['principal parts'] !== 'undefined') {
const principalParts = removeTags(row['principal parts']).trim().split(',').filter(principalParts => principalParts.trim() !== '');
if (principalParts.length > 0) {
wordToImport.principalParts = principalParts;
}
}
if (typeof row['principal parts (comma-separated)'] !== 'undefined') {
const principalParts = removeTags(row['principal parts (comma-separated)']).trim().split(',').filter(principalParts => principalParts.trim() !== '');
if (principalParts.length > 0) {
wordToImport.principalParts = principalParts;
}
}
const importedWord = addWord(wordToImport, false);
importedWords.push(importedWord);
@ -306,6 +343,9 @@ export function exportWords() {
'part of speech': word.partOfSpeech,
definition: word.definition,
explanation: word.details,
'etymology (comma-separated)': typeof word.etymology !== 'undefined' ? word.etymology.join(',') : '',
'related words (comma-separated)': typeof word.related !== 'undefined' ? word.related.join(',') : '',
'principal parts (comma-separated)': typeof word.principalParts !== 'undefined' ? word.principalParts.join(',') : '',
}
});
const csv = papa.unparse(words, { quotes: true });

View File

@ -431,7 +431,7 @@ ou=ow"></textarea>
<label class="button">Import Words <input type="file" id="importWordsCSV" accept="text/csv, .csv"><br>
<small>Import a CSV file of words.</small>
</label>
<a class="small button" download="Lexiconga_import-template.csv" href="data:text/csv;charset=utf-8,%22word%22,%22pronunciation%22,%22part of speech%22,%22definition%22,%22explanation%22%0A">Download an example file with the correct formatting</a>
<a class="small button" download="Lexiconga_import-template.csv" href="data:text/csv;charset=utf-8,%22word%22,%22pronunciation%22,%22part of speech%22,%22definition%22,%22explanation%22,%22etymology %28comma-separated%29%22,%22related words %28comma-separated%29%22,%22principal parts %28comma-separated%29%22%0A">Download an example file with the correct formatting</a>
</p>
</div>
<div>