Add Phonology Notes

This commit is contained in:
Robbie Antenesse 2019-07-10 12:14:27 -06:00 committed by Robbie Antenesse
parent a1ea105f66
commit a2542fe7a1
7 changed files with 33 additions and 13 deletions

View File

@ -1,6 +1,6 @@
import { getTimestampInSeconds } from "./helpers"; import { getTimestampInSeconds } from "./helpers";
export const MIGRATE_VERSION = '2.0.1'; export const MIGRATE_VERSION = '2.0.2';
export const DEFAULT_DICTIONARY = { export const DEFAULT_DICTIONARY = {
name: 'New', name: 'New',
specification: 'Dictionary', specification: 'Dictionary',
@ -12,6 +12,7 @@ export const DEFAULT_DICTIONARY = {
consonants: [], consonants: [],
vowels: [], vowels: [],
blends: [], blends: [],
notes: '',
}, },
phonotactics: { phonotactics: {
onset: [], onset: [],

View File

@ -14,8 +14,8 @@ export function updateDictionary () {
export function openEditModal() { export function openEditModal() {
const { name, specification, description, partsOfSpeech, alphabeticalOrder } = window.currentDictionary; const { name, specification, description, partsOfSpeech, alphabeticalOrder } = window.currentDictionary;
const { consonants, vowels, blends } = window.currentDictionary.details.phonology; const { phonology, phonotactics, orthography, grammar } = window.currentDictionary.details;
const { phonotactics, orthography, grammar } = window.currentDictionary.details; const { consonants, vowels, blends } = phonology;
const { allowDuplicates, caseSensitive, sortByDefinition, theme, isPublic } = window.currentDictionary.settings; const { allowDuplicates, caseSensitive, sortByDefinition, theme, isPublic } = window.currentDictionary.settings;
document.getElementById('editName').value = name; document.getElementById('editName').value = name;
@ -27,6 +27,8 @@ export function openEditModal() {
document.getElementById('editConsonants').value = consonants.join(' '); document.getElementById('editConsonants').value = consonants.join(' ');
document.getElementById('editVowels').value = vowels.join(' '); document.getElementById('editVowels').value = vowels.join(' ');
document.getElementById('editBlends').value = blends.join(' '); document.getElementById('editBlends').value = blends.join(' ');
document.getElementById('editPhonologyNotes').value = phonology.notes;
document.getElementById('editOnset').value = phonotactics.onset.join(','); document.getElementById('editOnset').value = phonotactics.onset.join(',');
document.getElementById('editNucleus').value = phonotactics.nucleus.join(','); document.getElementById('editNucleus').value = phonotactics.nucleus.join(',');
document.getElementById('editCoda').value = phonotactics.coda.join(','); document.getElementById('editCoda').value = phonotactics.coda.join(',');
@ -60,6 +62,8 @@ export function saveEditModal() {
updatedDictionary.details.phonology.consonants = document.getElementById('editConsonants').value.split(' ').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonology.consonants = document.getElementById('editConsonants').value.split(' ').map(val => val.trim()).filter(val => val !== '');
updatedDictionary.details.phonology.vowels = document.getElementById('editVowels').value.split(' ').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonology.vowels = document.getElementById('editVowels').value.split(' ').map(val => val.trim()).filter(val => val !== '');
updatedDictionary.details.phonology.blends = document.getElementById('editBlends').value.split(' ').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonology.blends = document.getElementById('editBlends').value.split(' ').map(val => val.trim()).filter(val => val !== '');
updatedDictionary.details.phonology.notes = removeTags(document.getElementById('editPhonologyNotes').value.trim());
updatedDictionary.details.phonotactics.onset = document.getElementById('editOnset').value.split(',').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonotactics.onset = document.getElementById('editOnset').value.split(',').map(val => val.trim()).filter(val => val !== '');
updatedDictionary.details.phonotactics.nucleus = document.getElementById('editNucleus').value.split(',').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonotactics.nucleus = document.getElementById('editNucleus').value.split(',').map(val => val.trim()).filter(val => val !== '');
updatedDictionary.details.phonotactics.coda = document.getElementById('editCoda').value.split(',').map(val => val.trim()).filter(val => val !== ''); updatedDictionary.details.phonotactics.coda = document.getElementById('editCoda').value.split(',').map(val => val.trim()).filter(val => val !== '');

View File

@ -106,6 +106,7 @@ export function migrateDictionary() {
switch (window.currentDictionary.version) { switch (window.currentDictionary.version) {
default: console.error('Unknown version'); break; default: console.error('Unknown version'); break;
case '2.0.0': { case '2.0.0': {
window.currentDictionary.details.phonology.notes = '';
window.currentDictionary.details.phonotactics = Object.assign({}, window.currentDictionary.details.phonology.phonotactics); window.currentDictionary.details.phonotactics = Object.assign({}, window.currentDictionary.details.phonology.phonotactics);
delete window.currentDictionary.details.phonology.phonotactics; delete window.currentDictionary.details.phonology.phonotactics;
window.currentDictionary.details.phonotactics.notes = window.currentDictionary.details.phonotactics.exceptions; window.currentDictionary.details.phonotactics.notes = window.currentDictionary.details.phonotactics.exceptions;

View File

@ -62,12 +62,14 @@ export function renderDetails() {
const consonantHTML = `<p><strong>Consonants</strong><br>${consonants.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`; const consonantHTML = `<p><strong>Consonants</strong><br>${consonants.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`;
const vowelHTML = `<p><strong>Vowels</strong><br>${vowels.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`; const vowelHTML = `<p><strong>Vowels</strong><br>${vowels.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`;
const blendHTML = blends.length > 0 ? `<p><strong>Polyphthongs&nbsp;/&nbsp;Blends</strong><br>${blends.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>` : ''; const blendHTML = blends.length > 0 ? `<p><strong>Polyphthongs&nbsp;/&nbsp;Blends</strong><br>${blends.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>` : '';
const phonologyNotesHTML = phonology.notes.trim().length > 0 ? '<p><strong>Notes</strong></p><div>' + md(removeTags(phonology.notes)) + '</div>' : '';
const phonologyHTML = `<h3>Phonology</h3> const phonologyHTML = `<h3>Phonology</h3>
<div class="split two"> <div class="split two">
<div>${consonantHTML}</div> <div>${consonantHTML}</div>
<div>${vowelHTML}</div> <div>${vowelHTML}</div>
</div> </div>
${blendHTML}`; ${blendHTML}
${phonologyNotesHTML}`;
const { onset, nucleus, coda } = phonotactics; const { onset, nucleus, coda } = phonotactics;
const onsetHTML = `<p><strong>Onset</strong><br>${onset.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`; const onsetHTML = `<p><strong>Onset</strong><br>${onset.map(letter => `<span class="tag">${letter}</span>`).join(' ')}</p>`;
@ -76,29 +78,32 @@ export function renderDetails() {
const phonotacticsNotesHTML = phonotactics.notes.trim().length > 0 ? '<p><strong>Notes</strong></p><div>' + md(removeTags(phonotactics.notes)) + '</div>' : ''; const phonotacticsNotesHTML = phonotactics.notes.trim().length > 0 ? '<p><strong>Notes</strong></p><div>' + md(removeTags(phonotactics.notes)) + '</div>' : '';
const phonotacticsHTML = onset.length + nucleus.length + coda.length + phonotacticsNotesHTML.length > 0 const phonotacticsHTML = onset.length + nucleus.length + coda.length + phonotacticsNotesHTML.length > 0
? `<h3>Phonotactics</h3> ? `<h3>Phonotactics</h3>
<div class="split three"> ${onset.length > 0 || nucleus.length > 0 || coda.length > 0
? `<div class="split three">
<div>${onsetHTML}</div> <div>${onsetHTML}</div>
<div>${nucleusHTML}</div> <div>${nucleusHTML}</div>
<div>${codaHTML}</div> <div>${codaHTML}</div>
</div> </div>` : ''}
${phonotacticsNotesHTML}` ${phonotacticsNotesHTML}`
: ''; : '';
const { translations } = orthography; const { translations } = orthography;
const translationsHTML = `<p><strong>Translations</strong><br>${translations.map(translation => { const translationsHTML = translations.length > 0 ? `<p><strong>Translations</strong><br>${translations.map(translation => {
translation = translation.split('=').map(value => value.trim()); translation = translation.split('=').map(value => value.trim());
if (translation.length > 1 && translation[0] !== '' && translation[1] !== '') { if (translation.length > 1 && translation[0] !== '' && translation[1] !== '') {
return `<span><span class="tag">${translation[0]}</span><span class="tag orthographic-translation">${translation[1]}</span></span>`; return `<span><span class="tag">${translation[0]}</span><span class="tag orthographic-translation">${translation[1]}</span></span>`;
} }
return false; return false;
}).filter(html => html !== false).join(' ')}</p>`; }).filter(html => html !== false).join(' ')}</p>` : '';
const orthographyNotesHTML = orthography.notes.trim().length > 0 ? '<p><strong>Notes</strong><br>' + md(removeTags(orthography.notes)) + '</div>' : ''; const orthographyNotesHTML = orthography.notes.trim().length > 0 ? '<p><strong>Notes</strong><br>' + md(removeTags(orthography.notes)) + '</div>' : '';
const orthographyHTML = translations.length > 0 || orthographyNotesHTML.length > 0 const orthographyHTML = translations.length + orthographyNotesHTML.length > 0
? `<h3>Orthography</h3> ? `<h3>Orthography</h3>
${translations.length > 0 ? translationsHTML : ''} ${translationsHTML}
${orthographyNotesHTML}` ${orthographyNotesHTML}`
: ''; : '';
const grammarHTML = '<h3>Grammar</h3><div>' + md(removeTags(grammar.notes)) + '</div>'; const grammarHTML = grammar.notes.trim().length > 0 ? '<h3>Grammar</h3><div>'
+ (grammar.notes.trim().length > 0 ? md(removeTags(grammar.notes)) : '')
+ '</div>' : '';
detailsPanel.innerHTML = generalHTML + phonologyHTML + phonotacticsHTML + orthographyHTML + grammarHTML; detailsPanel.innerHTML = generalHTML + phonologyHTML + phonotacticsHTML + orthographyHTML + grammarHTML;
} }

View File

@ -33,14 +33,15 @@ class Dictionary {
$insert_dictionary = $this->db->execute($insert_dictionary_query, array($new_id, $user, 'A new dictionary.', time())); $insert_dictionary = $this->db->execute($insert_dictionary_query, array($new_id, $user, 'A new dictionary.', time()));
if ($insert_dictionary === true) { if ($insert_dictionary === true) {
$insert_linguistics_query = "INSERT INTO dictionary_linguistics (dictionary, parts_of_speech, phonotactics_notes, translations, orthography_notes, grammar_notes) $insert_linguistics_query = "INSERT INTO dictionary_linguistics (dictionary, parts_of_speech, phonology_notes, phonotactics_notes, translations, orthography_notes, grammar_notes)
VALUES ($new_id, ?, ?, ?, ?, ?)"; VALUES ($new_id, ?, ?, ?, ?, ?, ?)";
$insert_linguistics = $this->db->execute($insert_linguistics_query, array( $insert_linguistics = $this->db->execute($insert_linguistics_query, array(
$this->defaults['partsOfSpeech'], $this->defaults['partsOfSpeech'],
'', '',
'', '',
'', '',
'', '',
'',
)); ));
if ($insert_linguistics === true) { if ($insert_linguistics === true) {
@ -110,6 +111,7 @@ VALUES ($new_id, ?, ?, ?, ?, ?)";
'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(), 'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(),
'vowels' => $result['vowels'] !== '' ? explode(' ', $result['vowels']) : array(), 'vowels' => $result['vowels'] !== '' ? explode(' ', $result['vowels']) : array(),
'blends' => $result['blends'] !== '' ? explode(' ', $result['blends']) : array(), 'blends' => $result['blends'] !== '' ? explode(' ', $result['blends']) : array(),
'notes' => $result['phonology_notes'],
), ),
'phonotactics' => array( 'phonotactics' => array(
'onset' => $result['onset'] !== '' ? explode(',', $result['onset']) : array(), 'onset' => $result['onset'] !== '' ? explode(',', $result['onset']) : array(),
@ -287,6 +289,7 @@ VALUES ($new_id, ?, ?, ?, ?, ?)";
'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(), 'consonants' => $result['consonants'] !== '' ? explode(' ', $result['consonants']) : array(),
'vowels' => $result['vowels'] !== '' ? explode(' ', $result['vowels']) : array(), 'vowels' => $result['vowels'] !== '' ? explode(' ', $result['vowels']) : array(),
'blends' => $result['blends'] !== '' ? explode(' ', $result['blends']) : array(), 'blends' => $result['blends'] !== '' ? explode(' ', $result['blends']) : array(),
'notes' => $result['phonology_notes'],
), ),
'phonotactics' => array( 'phonotactics' => array(
'onset' => $result['onset'] !== '' ? explode(',', $result['onset']) : array(), 'onset' => $result['onset'] !== '' ? explode(',', $result['onset']) : array(),
@ -351,6 +354,7 @@ SET parts_of_speech=:parts_of_speech,
consonants=:consonants, consonants=:consonants,
vowels=:vowels, vowels=:vowels,
blends=:blends, blends=:blends,
phonology_notes=:phonology_notes,
onset=:onset, onset=:onset,
nucleus=:nucleus, nucleus=:nucleus,
coda=:coda, coda=:coda,
@ -366,6 +370,7 @@ WHERE dictionary=$dictionary";
':consonants' => implode(' ', $linguistics['phonology']['consonants']), ':consonants' => implode(' ', $linguistics['phonology']['consonants']),
':vowels' => implode(' ', $linguistics['phonology']['vowels']), ':vowels' => implode(' ', $linguistics['phonology']['vowels']),
':blends' => implode(' ', $linguistics['phonology']['blends']), ':blends' => implode(' ', $linguistics['phonology']['blends']),
':phonology_notes' => $linguistics['phonology']['notes'],
':onset' => implode(',', $linguistics['phonotactics']['onset']), ':onset' => implode(',', $linguistics['phonotactics']['onset']),
':nucleus' => implode(',', $linguistics['phonotactics']['nucleus']), ':nucleus' => implode(',', $linguistics['phonotactics']['nucleus']),
':coda' => implode(',', $linguistics['phonotactics']['coda']), ':coda' => implode(',', $linguistics['phonotactics']['coda']),

View File

@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS `dictionary_linguistics` (
`consonants` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated', `consonants` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated',
`vowels` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated', `vowels` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated',
`blends` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated', `blends` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Space-separated',
`phonology_notes` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'Markdown',
`onset` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated', `onset` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated',
`nucleus` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated', `nucleus` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated',
`coda` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated', `coda` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '' COMMENT 'Comma-separated',

View File

@ -292,6 +292,9 @@
</label> </label>
</div> </div>
</div> </div>
<label>Notes <small>(Markdown-enabled)</small><br>
<textarea id="editPhonologyNotes"></textarea>
</label>
<h3>Phonotactics</h3> <h3>Phonotactics</h3>
<div class="split three"> <div class="split three">
<div> <div>