Compare commits

..

6 Commits

Author SHA1 Message Date
AndreStork e6c8964f19 Merge branch 'webui' 2026-03-03 11:45:21 +01:00
AndreStork f273daefc5 Aggiunta link pagina Web UI in index 2026-03-03 11:39:47 +01:00
AndreStork fef6f7f015 Aggiunta pagina handling form delete 2026-03-03 11:36:42 +01:00
AndreStork 326362d157 Aggiunta pulsante elimina 2026-02-26 13:43:56 +01:00
AndreStork 8a15a29dcf Aggiunto handling aggiunta compiti da Web UI 2026-02-26 13:38:26 +01:00
AndreStork 11e4e393e8 Aggiunta web ui base 2026-02-26 13:28:35 +01:00
+45 -3
View File
@@ -1,4 +1,4 @@
from flask import Flask, jsonify, request, render_template from flask import Flask, jsonify, request, render_template, redirect
import json import json
import os import os
@@ -29,8 +29,8 @@ app = Flask(__name__)
@app.route("/", methods=["GET"]) @app.route("/", methods=["GET"])
def home(): def home():
html = "<h1>Home page API REST Compiti</h1><h2>ciao, 3cx merda</h2>" html = "<h1>Home page API REST Compiti</h1>"
html += "<a href=\"/doc\">Documentazione</a>" html += "<a href=\"/ui\">Apri interfaccia web</a><br><a href=\"/doc\">Documentazione</a>"
return html, 200 return html, 200
@app.route("/doc", methods=["GET"]) @app.route("/doc", methods=["GET"])
@@ -68,4 +68,46 @@ def delete_compito(id):
update_file() update_file()
return jsonify([]), 404 return jsonify([]), 404
@app.route("/ui")
def web_ui():
# Tabella compiti
html = "<table border>"
for ciscomerda in compiti:
html += "<tr>"
html += f"<td>{ciscomerda["descrizione"]}</td><td><a href=\"/form_delete?id={ciscomerda["id"]}\" class=\"button\">Elimina</a>"
html += "</tr>"
html += "</table>"
html += "<form action=\"/form_add\">"
html += "<input type=\"text\" name=\"descrizione\" placeholder=\"Descrizione compito\">"
html += "<input type=\"submit\" value=\"Aggiungi compito\">"
html += "</form>"
return html, 200
@app.route("/form_add")
def form_add():
if not request.args.get("descrizione"):
return "Errore: descrizione mancante", 400
else:
global id_counter
d = request.args.get("descrizione")
compiti.append({"id": id_counter, "descrizione": d})
id_counter += 1
update_file()
return redirect("/ui")
@app.route("/form_delete")
def form_delete():
if not request.args.get("id"):
return "Errore: id mancante", 400
else:
id = int(request.args.get("id"))
for ciscomerda in compiti:
if ciscomerda["id"] == id:
compiti.remove(ciscomerda)
update_file()
return redirect("/ui")
return "Errore: compito non trovato", 404
app.run("0.0.0.0") app.run("0.0.0.0")