From f77c3c523bd1d2d9d4de5b7b38180e47f236fd8c Mon Sep 17 00:00:00 2001 From: Anh-Thy04 Date: Fri, 23 May 2025 12:54:42 +0200 Subject: [PATCH] AT opmaak dashboard --- application/dashboard/templates/add.html | 72 ++++++++++++++++- application/dashboard/templates/base.html | 81 ++++++++++++++++--- .../dashboard/templates/dashboard.html | 54 +++++++++++-- application/dashboard/views.py | 30 ++++--- 4 files changed, 202 insertions(+), 35 deletions(-) diff --git a/application/dashboard/templates/add.html b/application/dashboard/templates/add.html index 706cb22..3b77ba1 100644 --- a/application/dashboard/templates/add.html +++ b/application/dashboard/templates/add.html @@ -1,18 +1,27 @@ {%extends 'base.html' %} {% block content %} +
+
+

Numberplate

+
+
+
+
+
+
Add numberplate
-
+ {{ form.hidden_tag() }}
- {{ form.numberplate.label }} {{ form.numberplate(class="form-input") }} + {{ form.numberplate(class="form-input",style="width: 200px; height: 40px;") }}
-
- {{ form.submit(class="submit-btn") }} +
+ {{ form.submit(class="btn btn-sm btn-dark", style="width: 200px;") }}
@@ -20,4 +29,59 @@
+
+
+
+
Numberplates
+
+ + + + + + + + + {% for plate in plates %} + + + + + {% endfor %} + +
IDNumberplate
{{ plate.id }}{{ plate.plate }}
+
+
+
+
+ + {% endblock %} \ No newline at end of file diff --git a/application/dashboard/templates/base.html b/application/dashboard/templates/base.html index ada9a2b..7c79ea0 100644 --- a/application/dashboard/templates/base.html +++ b/application/dashboard/templates/base.html @@ -6,6 +6,57 @@ Admin Dashboard + + +
@@ -21,30 +72,40 @@ Dashboard - - Logs - Add numberplate
- Logout + Logout +
-
-
-

Dashboard

-
- - + {%block content%} + {% endblock %}
+ diff --git a/application/dashboard/templates/dashboard.html b/application/dashboard/templates/dashboard.html index 3f37ac2..4f1482d 100644 --- a/application/dashboard/templates/dashboard.html +++ b/application/dashboard/templates/dashboard.html @@ -1,21 +1,37 @@ {%extends 'base.html' %} {% block content %} +
+
+

Dashboard

+
+
+
+
+
-
Registered Numberplates
+
Logs
- + + + - {% for Plates in AllowedPlates %} + {% for form in recent_logs %} - + + + {% endfor %} @@ -25,4 +41,32 @@ -{% endblock %} \ No newline at end of file +
+
+
+
Numberplates
+
+
Time NumberplateGate Status
{{Plates.plate}}{{ form.timestamp.strftime('%H:%M:%S') }}{{ plate.plate }} + + {{ form.allowed }} + +
+ + + + + + + + {% for plate in plates %} + + + + + {% endfor %} + +
IDNumberplate
{{ plate.id }}{{ plate.plate }}
+
+
+
+
+ + + +{% endblock %} diff --git a/application/dashboard/views.py b/application/dashboard/views.py index 76bfd26..51d9acb 100644 --- a/application/dashboard/views.py +++ b/application/dashboard/views.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, request, jsonify from flask_login import login_required from application.dashboard.models import AllowedPlate, LoggedItem from application import db, app @@ -11,32 +11,30 @@ dash_blueprint = Blueprint("dash", __name__, template_folder="templates") @dash_blueprint.route('/dashboard') #@login_required def dashboard(): - #print("test123") - #with app.app_context(): Plates = AllowedPlate.query.all() - print(Plates) - return render_template("dashboard.html", AllowedPlates = Plates) + recent_logs = LoggedItem.query.order_by(LoggedItem.dateLogged.desc()).limit(50).all() + return render_template("dashboard.html", plates=Plates, recent_logs=recent_logs) + @dash_blueprint.route('/add', methods=['GET', 'POST']) #@login_required def add(): - + Plates = AllowedPlate.query.all() form = npForm() if form.validate_on_submit(): if form.numberplate.data: - print(form.numberplate.data) ap = AllowedPlate(plate=form.numberplate.data) - db.session.add(ap) db.session.commit() + # AJAX response + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': + plates = AllowedPlate.query.order_by(AllowedPlate.id).all() + return jsonify({ + 'plates': [{'id': p.id, 'plate': p.plate} for p in plates] + }) + # Normal GET or failed POST + Plates = AllowedPlate.query.order_by(AllowedPlate.id).all() + return render_template("add.html", form=form, plates=Plates) - - return render_template("add.html", form=form) - -@dash_blueprint.route('/logs', methods=['GET', 'POST']) -#@login_required -def logs(): - form = LoggedItem.query.all() - return render_template("logs.html", form=form) \ No newline at end of file