Add Prinipal Parts for words
This commit is contained in:
parent
d5e2ddec93
commit
e103420245
|
@ -37,6 +37,7 @@ export const DEFAULT_DICTIONARY = {
|
||||||
details: '',
|
details: '',
|
||||||
etymology: [],
|
etymology: [],
|
||||||
related: [],
|
related: [],
|
||||||
|
principalParts: [],
|
||||||
wordId: 0
|
wordId: 0
|
||||||
}, */
|
}, */
|
||||||
],
|
],
|
||||||
|
|
|
@ -64,6 +64,8 @@ export function renderWords() {
|
||||||
: originalWord.etymology.map(root => getWordReferenceMarkdown(removeTags(root))).join(', '),
|
: originalWord.etymology.map(root => getWordReferenceMarkdown(removeTags(root))).join(', '),
|
||||||
related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null
|
related: typeof originalWord.related === 'undefined' || originalWord.related.length < 1 ? null
|
||||||
: originalWord.related.map(relatedWord => getWordReferenceMarkdown(removeTags(relatedWord))).join(', '),
|
: originalWord.related.map(relatedWord => getWordReferenceMarkdown(removeTags(relatedWord))).join(', '),
|
||||||
|
principalParts: typeof originalWord.principalParts === 'undefined' || originalWord.principalParts.length < 1 ? null
|
||||||
|
: originalWord.principalParts.join(', '),
|
||||||
wordId: originalWord.wordId,
|
wordId: originalWord.wordId,
|
||||||
});
|
});
|
||||||
const homonymnNumber = getHomonymnNumber(originalWord);
|
const homonymnNumber = getHomonymnNumber(originalWord);
|
||||||
|
@ -76,6 +78,7 @@ export function renderWords() {
|
||||||
wordsHTML += `<article class="entry" id="${word.wordId}">
|
wordsHTML += `<article class="entry" id="${word.wordId}">
|
||||||
<header>
|
<header>
|
||||||
<h4 class="word"><span class="orthographic-translation">${wordNameDisplay}</span>${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
|
<h4 class="word"><span class="orthographic-translation">${wordNameDisplay}</span>${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
|
||||||
|
${word.principalParts === null ? '' : `<span class="principalParts">(${word.principalParts})</span>`}
|
||||||
<span class="pronunciation">${word.pronunciation}</span>
|
<span class="pronunciation">${word.pronunciation}</span>
|
||||||
<span class="part-of-speech">${word.partOfSpeech}</span>
|
<span class="part-of-speech">${word.partOfSpeech}</span>
|
||||||
${isPublic ? `<a class="small button share-link" href="${shareLink}" target="_blank" title="Public Link to Word">➦</a>` : ''}
|
${isPublic ? `<a class="small button share-link" href="${shareLink}" target="_blank" title="Public Link to Word">➦</a>` : ''}
|
||||||
|
@ -183,6 +186,9 @@ export function renderEditForm(wordId = false) {
|
||||||
<label>Related Words<br>
|
<label>Related Words<br>
|
||||||
<input id="wordRelated_${wordId}" maxlength="2500" placeholder="comma,separated,related,words" value="${word.hasOwnProperty('related') ? word.related : ''}">
|
<input id="wordRelated_${wordId}" maxlength="2500" placeholder="comma,separated,related,words" value="${word.hasOwnProperty('related') ? word.related : ''}">
|
||||||
</label>
|
</label>
|
||||||
|
<label>Principal Parts<a href="https://en.wikipedia.org/wiki/Principal_parts" target="_blank" class="label-button">What's This?</a><br>
|
||||||
|
<input id="wordPrincipalParts_${wordId}" maxlength="2500" placeholder="comma,separated,principal,parts" value="${word.hasOwnProperty('principalParts') ? word.principalParts : ''}">
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="wordErrorMessage_${wordId}"></div>
|
<div id="wordErrorMessage_${wordId}"></div>
|
||||||
<a class="button edit-save-changes" id="editWordButton_${wordId}">Save Changes</a>
|
<a class="button edit-save-changes" id="editWordButton_${wordId}">Save Changes</a>
|
||||||
|
|
|
@ -183,7 +183,8 @@ export function submitWordForm() {
|
||||||
definition = document.getElementById('wordDefinition').value,
|
definition = document.getElementById('wordDefinition').value,
|
||||||
details = document.getElementById('wordDetails').value,
|
details = document.getElementById('wordDetails').value,
|
||||||
etymology = document.getElementById('wordEtymology').value,
|
etymology = document.getElementById('wordEtymology').value,
|
||||||
related = document.getElementById('wordRelated').value;
|
related = document.getElementById('wordRelated').value,
|
||||||
|
principalParts = document.getElementById('wordPrincipalParts').value;
|
||||||
|
|
||||||
const word = {
|
const word = {
|
||||||
name: removeTags(name).trim(),
|
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);
|
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)) {
|
if (validateWord(word)) {
|
||||||
addWord(word);
|
addWord(word);
|
||||||
sortWords(true);
|
sortWords(true);
|
||||||
|
@ -286,7 +291,8 @@ export function confirmEditWord(id) {
|
||||||
definition = document.getElementById('wordDefinition_' + wordId).value,
|
definition = document.getElementById('wordDefinition_' + wordId).value,
|
||||||
details = document.getElementById('wordDetails_' + wordId).value,
|
details = document.getElementById('wordDetails_' + wordId).value,
|
||||||
etymology = document.getElementById('wordEtymology_' + 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 = {
|
const word = {
|
||||||
name: removeTags(name).trim(),
|
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);
|
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 (validateWord(word, wordId)) {
|
||||||
if (confirm(`Are you sure you want to save changes to "${word.name}"?`)) {
|
if (confirm(`Are you sure you want to save changes to "${word.name}"?`)) {
|
||||||
document.getElementById('editForm_' + wordId).classList.add('done');
|
document.getElementById('editForm_' + wordId).classList.add('done');
|
||||||
|
|
|
@ -215,8 +215,8 @@ WHERE dictionary=$dictionary";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWords ($user, $dictionary) {
|
public function getWords ($user, $dictionary) {
|
||||||
$query = "SELECT words.*, words_advanced.etymology, words_advanced.related FROM words
|
$query = "SELECT words.*, wa.etymology, wa.related, wa.principal_parts FROM words
|
||||||
LEFT JOIN words_advanced ON words_advanced.dictionary = words.dictionary AND words_advanced.word_id = words.word_id
|
LEFT JOIN words_advanced wa ON wa.dictionary = words.dictionary AND wa.word_id = words.word_id
|
||||||
JOIN dictionaries ON dictionaries.id = words.dictionary
|
JOIN dictionaries ON dictionaries.id = words.dictionary
|
||||||
WHERE words.dictionary=$dictionary AND dictionaries.user=$user";
|
WHERE words.dictionary=$dictionary AND dictionaries.user=$user";
|
||||||
$results = $this->db->query($query)->fetchAll();
|
$results = $this->db->query($query)->fetchAll();
|
||||||
|
@ -241,6 +241,10 @@ WHERE words.dictionary=$dictionary AND dictionaries.user=$user";
|
||||||
$word['related'] = explode(',', $row['related']);
|
$word['related'] = explode(',', $row['related']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_null($row['principal_parts']) && $row['principal_parts'] !== '') {
|
||||||
|
$word['principalParts'] = explode(',', $row['principal_parts']);
|
||||||
|
}
|
||||||
|
|
||||||
return $word;
|
return $word;
|
||||||
}, $results);
|
}, $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 ';
|
$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();
|
$params1 = array();
|
||||||
$params2 = array();
|
$params2 = array();
|
||||||
$word_ids = array();
|
$word_ids = array();
|
||||||
|
@ -289,11 +293,12 @@ WHERE words.dictionary=$dictionary AND dictionaries.user=$user";
|
||||||
$params1[] = $last_updated;
|
$params1[] = $last_updated;
|
||||||
$params1[] = $word['createdOn'];
|
$params1[] = $word['createdOn'];
|
||||||
|
|
||||||
$query2 .= "(?, ?, ?, ?), ";
|
$query2 .= "(?, ?, ?, ?, ?), ";
|
||||||
$params2[] = $dictionary;
|
$params2[] = $dictionary;
|
||||||
$params2[] = $word['wordId'];
|
$params2[] = $word['wordId'];
|
||||||
$params2[] = isset($word['etymology']) ? implode(',', $word['etymology']) : '';
|
$params2[] = isset($word['etymology']) ? implode(',', $word['etymology']) : '';
|
||||||
$params2[] = isset($word['related']) ? implode(',', $word['related']) : '';
|
$params2[] = isset($word['related']) ? implode(',', $word['related']) : '';
|
||||||
|
$params2[] = isset($word['principalParts']) ? implode(',', $word['principalParts']) : '';
|
||||||
}
|
}
|
||||||
$query1 = trim($query1, ', ') . ' ON DUPLICATE KEY UPDATE
|
$query1 = trim($query1, ', ') . ' ON DUPLICATE KEY UPDATE
|
||||||
name=VALUES(name),
|
name=VALUES(name),
|
||||||
|
@ -305,7 +310,8 @@ last_updated=VALUES(last_updated),
|
||||||
created_on=VALUES(created_on)';
|
created_on=VALUES(created_on)';
|
||||||
$query2 = trim($query2, ', ') . ' ON DUPLICATE KEY UPDATE
|
$query2 = trim($query2, ', ') . ' ON DUPLICATE KEY UPDATE
|
||||||
etymology=VALUES(etymology),
|
etymology=VALUES(etymology),
|
||||||
related=VALUES(related)';
|
related=VALUES(related),
|
||||||
|
principal_parts=VALUES(principal_parts)';
|
||||||
|
|
||||||
$results1 = $this->db->execute($query1, $params1);
|
$results1 = $this->db->execute($query1, $params1);
|
||||||
|
|
||||||
|
|
|
@ -100,5 +100,6 @@ CREATE TABLE IF NOT EXISTS `words_advanced` (
|
||||||
`word_id` int(11) NOT NULL,
|
`word_id` int(11) NOT NULL,
|
||||||
`etymology` text NOT NULL COMMENT 'Comma-separated',
|
`etymology` text NOT NULL COMMENT 'Comma-separated',
|
||||||
`related` 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`)
|
UNIQUE KEY `dictionary_word_id` (`dictionary`,`word_id`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||||
|
|
|
@ -149,6 +149,9 @@
|
||||||
<label>Related Words<br>
|
<label>Related Words<br>
|
||||||
<input id="wordRelated" maxlength="2500" placeholder="comma,separated,related,words">
|
<input id="wordRelated" maxlength="2500" placeholder="comma,separated,related,words">
|
||||||
</label>
|
</label>
|
||||||
|
<label>Principal Parts<a href="https://en.wikipedia.org/wiki/Principal_parts" target="_blank" class="label-button">What's This?</a><br>
|
||||||
|
<input id="wordPrincipalParts" maxlength="2500" placeholder="comma,separated,principal,parts">
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="wordErrorMessage"></div>
|
<div id="wordErrorMessage"></div>
|
||||||
<a class="button" id="addWordButton">Add Word</a>
|
<a class="button" id="addWordButton">Add Word</a>
|
||||||
|
|
Loading…
Reference in New Issue