Compare commits

...

6 Commits

Author SHA1 Message Date
ef3c1f4bfe Fixed deploys 2021-11-27 13:28:39 +01:00
Marce Coll
f04bb3f69b Merge branch 'main' of ssh://git.lajuntament.space:2222/lajuntament/absencia-de-presencia 2021-11-27 13:26:01 +01:00
Marce Coll
139e11b5fc Some style, fixed JS 2021-11-27 13:25:20 +01:00
ad26ef0196 Calia uwsgi! 2021-11-27 13:10:46 +01:00
5729cbe18a Fitxers de deploy 2021-11-27 13:09:11 +01:00
Marce Coll
7a8ae86a1c Habemus frontend 2021-11-27 13:05:12 +01:00
8 changed files with 115 additions and 5 deletions

14
deploy/Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM python:3.8
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py .
COPY static static
COPY templates templates
COPY deploy/presencia.ini .
CMD ["uwsgi", "--ini", "presencia.ini"]

10
deploy/presencia.ini Normal file
View File

@@ -0,0 +1,10 @@
[uwsgi]
module = main:app
chown = www-data:www-data
uid = www-data
gid = www-data
chdir = /app/
processes = 4
threads = 2
http = 0.0.0.0:5000
wsgi-disable-file-wrapper = false

9
deploy/publish.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -e
# BUILD
docker build . -f deploy/Dockerfile -t presencia
# PUBLISH
docker tag presencia marc.sastre.cat/presencia
docker push marc.sastre.cat/presencia

View File

@@ -3,7 +3,7 @@ import re
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"}
app = flask.Flask(__name__)
@@ -43,6 +43,11 @@ def calcula():
return calcula_presencia(frase)
@app.route("/static/<path:path>")
def static_files(path):
return flask.send_from_directory('static', path)
def xor(a, b):
return (a and not b) or (b and not a)

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
Flask==2.0.2
uwsgi==2.0.19.1

View File

@@ -0,0 +1,38 @@
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;
});
const afegirPart = (t) => {
const frase = g('frase');
let conector = ' de ';
if (frase.value === '') {
conector = 'la ';
}
g('frase').value = g('frase').value + conector + t;
}
g('absencia').addEventListener('click', () => {
afegirPart('absencia')
});
g('presencia').addEventListener('click', () => {
afegirPart('presencia')
});
})

23
static/style.css Normal file
View File

@@ -0,0 +1,23 @@
button {
padding: 30px;
font-size: 14px;
}
#frase {
width: 800px;
height: 300px;
text-align: center;
font-size: 17px;
}
#container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#buttons {
padding: 50px;
}

View File

@@ -1,11 +1,20 @@
<html>
<head>
<title>Absencia de Presencia</title>
<script src="/static/index.js"></script>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<form>
<input type="text"/>
<input type="submit"/>
</form>
<div id="container">
<textarea id="frase"></textarea>
<div id="buttons">
<button id="absencia">Absencia</button>
<button id="presencia">Presencia</button>
<button id="submit">Calcula</button>
</div>
</div>
<p id="response"></p>
</body>
</html>