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