From e1034202454e657911f5fd8abad50c646b9e4576 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 7 May 2020 23:57:27 -0600 Subject: [PATCH] Add Prinipal Parts for words --- src/constants.js | 1 + src/js/render/words.js | 6 ++++++ src/js/wordManagement.js | 14 ++++++++++++-- src/php/api/Dictionary.php | 16 +++++++++++----- src/structure.sql | 1 + template-index.html | 3 +++ 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/constants.js b/src/constants.js index c5e6841..6c03ba7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -37,6 +37,7 @@ export const DEFAULT_DICTIONARY = { details: '', etymology: [], related: [], + principalParts: [], wordId: 0 }, */ ], diff --git a/src/js/render/words.js b/src/js/render/words.js index 3087c67..a81c00c 100644 --- a/src/js/render/words.js +++ b/src/js/render/words.js @@ -64,6 +64,8 @@ export function renderWords() { : originalWord.etymology.map(root => getWordReferenceMarkdown(removeTags(root))).join(', '), related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null : originalWord.related.map(relatedWord => getWordReferenceMarkdown(removeTags(relatedWord))).join(', '), + principalParts: typeof originalWord.principalParts === 'undefined' || originalWord.principalParts.length < 1 ? null + : originalWord.principalParts.join(', '), wordId: originalWord.wordId, }); const homonymnNumber = getHomonymnNumber(originalWord); @@ -76,6 +78,7 @@ export function renderWords() { wordsHTML += `

${wordNameDisplay}${homonymnNumber > 0 ? ' ' + homonymnNumber.toString() + '' : ''}

+ ${word.principalParts === null ? '' : `(${word.principalParts})`} ${word.pronunciation} ${word.partOfSpeech} ${isPublic ? `` : ''} @@ -183,6 +186,9 @@ export function renderEditForm(wordId = false) { +
Save Changes diff --git a/src/js/wordManagement.js b/src/js/wordManagement.js index 45a1f70..7afe46e 100644 --- a/src/js/wordManagement.js +++ b/src/js/wordManagement.js @@ -183,7 +183,8 @@ export function submitWordForm() { definition = document.getElementById('wordDefinition').value, details = document.getElementById('wordDetails').value, etymology = document.getElementById('wordEtymology').value, - related = document.getElementById('wordRelated').value; + related = document.getElementById('wordRelated').value, + principalParts = document.getElementById('wordPrincipalParts').value; const word = { name: removeTags(name).trim(), @@ -202,6 +203,10 @@ export function submitWordForm() { word.related = removeTags(related).split(',').map(w => w.trim()).filter(w => w.length > 0); } + if (removeTags(principalParts).trim() !== '') { + word.principalParts = removeTags(principalParts).split(',').map(w => w.trim()).filter(w => w.length > 0); + } + if (validateWord(word)) { addWord(word); sortWords(true); @@ -286,7 +291,8 @@ export function confirmEditWord(id) { definition = document.getElementById('wordDefinition_' + wordId).value, details = document.getElementById('wordDetails_' + wordId).value, etymology = document.getElementById('wordEtymology_' + wordId).value, - related = document.getElementById('wordRelated_' + wordId).value; + related = document.getElementById('wordRelated_' + wordId).value, + principalParts = document.getElementById('wordPrincipalParts_' + wordId).value; const word = { name: removeTags(name).trim(), @@ -305,6 +311,10 @@ export function confirmEditWord(id) { word.related = removeTags(related).split(',').map(w => w.trim()).filter(w => w.length > 0); } + if (removeTags(principalParts).trim() !== '') { + word.principalParts = removeTags(principalParts).split(',').map(w => w.trim()).filter(w => w.length > 0); + } + if (validateWord(word, wordId)) { if (confirm(`Are you sure you want to save changes to "${word.name}"?`)) { document.getElementById('editForm_' + wordId).classList.add('done'); diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index 4cdbbdf..b9205fb 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -215,8 +215,8 @@ WHERE dictionary=$dictionary"; } public function getWords ($user, $dictionary) { - $query = "SELECT words.*, words_advanced.etymology, words_advanced.related FROM words -LEFT JOIN words_advanced ON words_advanced.dictionary = words.dictionary AND words_advanced.word_id = words.word_id + $query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words +LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id JOIN dictionaries ON dictionaries.id = words.dictionary WHERE words.dictionary=$dictionary AND dictionaries.user=$user"; $results = $this->db->query($query)->fetchAll(); @@ -241,6 +241,10 @@ WHERE words.dictionary=$dictionary AND dictionaries.user=$user"; $word['related'] = explode(',', $row['related']); } + if (!is_null($row['principal_parts']) && $row['principal_parts'] !== '') { + $word['principalParts'] = explode(',', $row['principal_parts']); + } + return $word; }, $results); } @@ -267,7 +271,7 @@ WHERE words.dictionary=$dictionary AND dictionaries.user=$user"; } $query1 = 'INSERT INTO words (dictionary, word_id, name, pronunciation, part_of_speech, definition, details, last_updated, created_on) VALUES '; - $query2 = 'INSERT INTO words_advanced (dictionary, word_id, etymology, related) VALUES '; + $query2 = 'INSERT INTO words_advanced (dictionary, word_id, etymology, related, principal_parts) VALUES '; $params1 = array(); $params2 = array(); $word_ids = array(); @@ -289,11 +293,12 @@ WHERE words.dictionary=$dictionary AND dictionaries.user=$user"; $params1[] = $last_updated; $params1[] = $word['createdOn']; - $query2 .= "(?, ?, ?, ?), "; + $query2 .= "(?, ?, ?, ?, ?), "; $params2[] = $dictionary; $params2[] = $word['wordId']; $params2[] = isset($word['etymology']) ? implode(',', $word['etymology']) : ''; $params2[] = isset($word['related']) ? implode(',', $word['related']) : ''; + $params2[] = isset($word['principalParts']) ? implode(',', $word['principalParts']) : ''; } $query1 = trim($query1, ', ') . ' ON DUPLICATE KEY UPDATE name=VALUES(name), @@ -305,7 +310,8 @@ last_updated=VALUES(last_updated), created_on=VALUES(created_on)'; $query2 = trim($query2, ', ') . ' ON DUPLICATE KEY UPDATE etymology=VALUES(etymology), -related=VALUES(related)'; +related=VALUES(related), +principal_parts=VALUES(principal_parts)'; $results1 = $this->db->execute($query1, $params1); diff --git a/src/structure.sql b/src/structure.sql index f2eb7bb..e653398 100644 --- a/src/structure.sql +++ b/src/structure.sql @@ -100,5 +100,6 @@ CREATE TABLE IF NOT EXISTS `words_advanced` ( `word_id` int(11) NOT NULL, `etymology` text NOT NULL COMMENT 'Comma-separated', `related` text NOT NULL COMMENT 'Comma-separated', + `principal_parts` text NOT NULL COMMENT 'Comma-separated', UNIQUE KEY `dictionary_word_id` (`dictionary`,`word_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; diff --git a/template-index.html b/template-index.html index e263748..65af8e6 100644 --- a/template-index.html +++ b/template-index.html @@ -149,6 +149,9 @@ +
Add Word