Server fixes, single phoneme edit
This commit is contained in:
parent
6eb93ec13a
commit
c45588b774
@ -63,16 +63,15 @@ def database():
|
|||||||
final['languages'] = [f.name for f in Language.query.all()]
|
final['languages'] = [f.name for f in Language.query.all()]
|
||||||
final['phonemes'] = [f.name for f in Phoneme.query.all()]
|
final['phonemes'] = [f.name for f in Phoneme.query.all()]
|
||||||
for language in Language.query.all():
|
for language in Language.query.all():
|
||||||
languageobject = {'name': language.name,
|
languageobject = {'id': language.id,
|
||||||
|
'name': language.name,
|
||||||
'source': language.source,
|
'source': language.source,
|
||||||
'phonemes': {}}
|
'phonemes': {}}
|
||||||
languageobject['name'] = language.name
|
|
||||||
for frequency in language.phonemes:
|
for frequency in language.phonemes:
|
||||||
languageobject['phonemes'][frequency.phoneme.name] = frequency.value
|
languageobject['phonemes'][frequency.phoneme.name] = frequency.value
|
||||||
final['values'].append(languageobject)
|
final['values'].append(languageobject)
|
||||||
return final
|
return final
|
||||||
|
|
||||||
|
|
||||||
def phoneme_add(info):
|
def phoneme_add(info):
|
||||||
"""Add or edit value associated with phoneme."""
|
"""Add or edit value associated with phoneme."""
|
||||||
# info = {
|
# info = {
|
||||||
@ -164,11 +163,11 @@ def backend():
|
|||||||
|
|
||||||
# POST method appends input to database['values']
|
# POST method appends input to database['values']
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
recieved = request.get_json()
|
received = request.get_json()
|
||||||
language = Language(name=recieved['name'], source=recieved['source'])
|
language = Language(name=received['name'], source=received['source'])
|
||||||
db.session.add(language)
|
db.session.add(language)
|
||||||
|
|
||||||
for phoneme, value in recieved['phonemes'].items():
|
for phoneme, value in received['phonemes'].items():
|
||||||
with db.session.no_autoflush:
|
with db.session.no_autoflush:
|
||||||
search = Phoneme.query.filter_by(name=phoneme).first()
|
search = Phoneme.query.filter_by(name=phoneme).first()
|
||||||
if not search:
|
if not search:
|
||||||
@ -182,8 +181,8 @@ def backend():
|
|||||||
|
|
||||||
# PATCH method inputs edited language and returns updated database
|
# PATCH method inputs edited language and returns updated database
|
||||||
elif request.method == "PATCH":
|
elif request.method == "PATCH":
|
||||||
recieved = request.get_json()
|
received = request.get_json()
|
||||||
patch_functions[recieved['action']](recieved['data'])
|
patch_functions[received['action']](received['data'])
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return jsonify(database())
|
return jsonify(database())
|
||||||
@ -194,17 +193,18 @@ def backend():
|
|||||||
def updates():
|
def updates():
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
recieved = request.get_json()
|
received = request.get_json()
|
||||||
update = Update(author=recieved['author'],
|
update = Update(author=received['author'],
|
||||||
title=recieved['title'],
|
title=received['title'],
|
||||||
content=recieved['content'])
|
content=received['content'])
|
||||||
db.session.add(update)
|
db.session.add(update)
|
||||||
|
|
||||||
elif request.method == "PATCH":
|
elif request.method == "PATCH":
|
||||||
update = Update.query.filter_by(id=recieved['id']).first()
|
received = request.get_json()
|
||||||
update.name = recieved['author']
|
update = Update.query.filter_by(id=received['id']).first()
|
||||||
update.title = recieved['title']
|
update.name = received['author']
|
||||||
update.content = recieved['content']
|
update.title = received['title']
|
||||||
|
update.content = received['content']
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return jsonify([{"author": update.name,
|
return jsonify([{"author": update.name,
|
||||||
|
|||||||
@ -325,6 +325,7 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#dataTableCont input {
|
#dataTableCont input {
|
||||||
|
border: 1px solid rgba(0,0,0,0.3);
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
|||||||
@ -146,13 +146,13 @@ function generateDropOp() { // For options that change based on data.
|
|||||||
var a = document.createElement("a");
|
var a = document.createElement("a");
|
||||||
p.appendChild(document.createTextNode("Type: " + (langInfo.type || "N/A")));
|
p.appendChild(document.createTextNode("Type: " + (langInfo.type || "N/A")));
|
||||||
p2.appendChild(document.createTextNode("Source: "));
|
p2.appendChild(document.createTextNode("Source: "));
|
||||||
if(langInfo.source.length > 0) {
|
if(langInfo.source === null) {
|
||||||
|
p2.appendChild(document.createTextNode("N/A"));
|
||||||
|
} else if(langInfo.source.length > 0) {
|
||||||
a.href = langInfo.source;
|
a.href = langInfo.source;
|
||||||
srcText = (langInfo.source.length > 60) ? langInfo.source.substring(0, 57) + "..." : langInfo.source;
|
srcText = (langInfo.source.length > 60) ? langInfo.source.substring(0, 57) + "..." : langInfo.source;
|
||||||
a.appendChild(document.createTextNode(srcText));
|
a.appendChild(document.createTextNode(srcText));
|
||||||
p2.appendChild(a);
|
p2.appendChild(a);
|
||||||
} else {
|
|
||||||
p2.appendChild(document.createTextNode("N/A"));
|
|
||||||
}
|
}
|
||||||
info.appendChild(p);
|
info.appendChild(p);
|
||||||
info.appendChild(p2);
|
info.appendChild(p2);
|
||||||
@ -189,20 +189,24 @@ function generateDropOp() { // For options that change based on data.
|
|||||||
}
|
}
|
||||||
p1.appendChild(document.createTextNode(phonemes[i]));
|
p1.appendChild(document.createTextNode(phonemes[i]));
|
||||||
p2.appendChild(document.createTextNode(langInfo.phonemes[phonemes[i]]));
|
p2.appendChild(document.createTextNode(langInfo.phonemes[phonemes[i]]));
|
||||||
p2.onclick = function() {
|
p2.className = "dataEdit";
|
||||||
if(dataOpen) closeEditInput();
|
p2.onclick = function(event) {
|
||||||
|
if(this === event.target) return;
|
||||||
|
closeEditInput();
|
||||||
dataOpen = true;
|
dataOpen = true;
|
||||||
var input = document.createElement("input");
|
var input = document.createElement("input");
|
||||||
var value = this.childNodes[0].nodeValue;
|
var value = this.childNodes[0].nodeValue;
|
||||||
this.removeChild(this.childNodes[0]);
|
this.removeChild(this.childNodes[0]);
|
||||||
this.appendChild(input);
|
this.appendChild(input);
|
||||||
input.value = value;
|
input.value = value;
|
||||||
|
input.id = "dataOpen";
|
||||||
|
input.focus();
|
||||||
}
|
}
|
||||||
dataBox.children[tableNum].appendChild(p1);
|
dataBox.children[tableNum].appendChild(p1);
|
||||||
dataBox.children[tableNum].appendChild(p2);
|
dataBox.children[tableNum].appendChild(p2);
|
||||||
}
|
}
|
||||||
var graphData = Object.entries(langInfo.phonemes).sort(function(a,b) {
|
var graphData = Object.entries(langInfo.phonemes).sort(function(a,b) {
|
||||||
return b[1] - a[1];
|
return b[1] - a[1];
|
||||||
});
|
});
|
||||||
graphData = [graphData.map(function(a,b) {
|
graphData = [graphData.map(function(a,b) {
|
||||||
return a[0];
|
return a[0];
|
||||||
@ -275,36 +279,39 @@ function generateDropOp() { // For options that change based on data.
|
|||||||
}
|
}
|
||||||
|
|
||||||
function closeEditInput() {
|
function closeEditInput() {
|
||||||
var input = document.querySelectorAll("#dataTableCont input")[0];
|
try {
|
||||||
var p = input.parentNode;
|
var input = document.getElementById("dataOpen");
|
||||||
/*$.ajax({
|
var p = input.parentNode;
|
||||||
|
var patchData = {
|
||||||
|
action: 'phoneme_add',
|
||||||
|
data: {
|
||||||
|
language_id: language(dropOpStore["langSelect"]).id,
|
||||||
|
phoneme: p.previousSibling.innerText,
|
||||||
|
value: input.value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$.ajax({
|
||||||
url: serverURL + '/server',
|
url: serverURL + '/server',
|
||||||
type: 'PATCH',
|
type: 'PATCH',
|
||||||
data: {
|
dataType: "json",
|
||||||
action: 'phoneme'
|
contentType: 'application/json;charset=UTF-8',
|
||||||
}
|
data: JSON.stringify(patchData)
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function success(incoming) {
|
function success(incoming) {
|
||||||
data = incoming;
|
p.appendChild(document.createTextNode(input.value));
|
||||||
generateDropOp();
|
p.removeChild(input);
|
||||||
createDrop();
|
|
||||||
},
|
},
|
||||||
function error(e) {
|
function error(e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
);*/
|
);
|
||||||
p.appendChild(document.createTextNode(input.value));
|
dataOpen = false;
|
||||||
p.removeChild(input);
|
} catch(err) {}
|
||||||
dataOpen = false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("click", function(event) {
|
document.addEventListener("click", function(event) {
|
||||||
console.log(event.target);
|
if(event.target.className !== "dataEdit") {
|
||||||
var input = document.querySelectorAll("#dataTableCont input")[0];
|
|
||||||
|
|
||||||
if(dataOpen && !(event.target === input || event.target === input.parentNode)) {
|
|
||||||
closeEditInput();
|
closeEditInput();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user