Habemus frontend
This commit is contained in:
7
main.py
7
main.py
@@ -3,7 +3,7 @@ import re
|
|||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
|
||||||
text2bool = {"absència": True, "presència": False, "absent": True, "present": False}
|
text2bool = {"absència": True, "absencia": True, "presencia": False, "presència": False, "absent": True, "present": False}
|
||||||
bool2text = {True: "absent", False: "present"}
|
bool2text = {True: "absent", False: "present"}
|
||||||
|
|
||||||
app = flask.Flask(__name__)
|
app = flask.Flask(__name__)
|
||||||
@@ -43,6 +43,11 @@ def calcula():
|
|||||||
return calcula_presencia(frase)
|
return calcula_presencia(frase)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/static/<path:path>")
|
||||||
|
def static_files(path):
|
||||||
|
return flask.send_from_directory('static', path)
|
||||||
|
|
||||||
|
|
||||||
def xor(a, b):
|
def xor(a, b):
|
||||||
return (a and not b) or (b and not a)
|
return (a and not b) or (b and not a)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
const r = (callback) => window.addEventListener('DOMContentLoaded', callback);
|
||||||
|
const g = (name) => document.getElementById(name);
|
||||||
|
|
||||||
|
r(() => {
|
||||||
|
g('submit').addEventListener('click', async () => {
|
||||||
|
const frase = g('frase').value;
|
||||||
|
const response = await fetch('/calcula', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
'frase': frase
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const resultat = await response.text();
|
||||||
|
g('response').innerHTML = resultat;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Absencia de Presencia</title>
|
<title>Absencia de Presencia</title>
|
||||||
|
<script src="/static/index.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form>
|
<div>
|
||||||
<input type="text"/>
|
<input type="text" id="frase"/>
|
||||||
<input type="submit"/>
|
<input type="button" id="submit"/>
|
||||||
</form>
|
</div>
|
||||||
|
|
||||||
|
<p id="response"></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user