mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 18:59:57 +00:00
Add function dashboard added
This commit is contained in:
4
app.py
4
app.py
@@ -2,7 +2,7 @@ from application import app
|
||||
from application.api.views import api_blueprint
|
||||
from application.auth.views import auth_blueprint
|
||||
from application.dashboard.views import dash_blueprint
|
||||
from flask import redirect, url_for
|
||||
from flask import redirect, url_for, render_template
|
||||
|
||||
app.register_blueprint(api_blueprint, url_prefix="/api")
|
||||
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
||||
@@ -16,4 +16,4 @@ def home():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="192.168.137.1", port=2222, debug=True)
|
||||
app.run(host="localhost", port=2222, debug=True)
|
||||
|
||||
8
application/dashboard/forms.py
Normal file
8
application/dashboard/forms.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms.validators import DataRequired
|
||||
from wtforms import StringField, SubmitField
|
||||
from application import db
|
||||
|
||||
class npForm(FlaskForm):
|
||||
numberplate = StringField('add a numberplate', validators=[DataRequired()])
|
||||
submit = SubmitField('Submit')
|
||||
23
application/dashboard/templates/add.html
Normal file
23
application/dashboard/templates/add.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{%extends 'base.html' %}
|
||||
{% block content %}
|
||||
|
||||
<div class="col-md-12">
|
||||
<div class="card mb-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title fs-4">Add numberplate</h5>
|
||||
<div class="log-container" style="max-height: 250px; overflow-y: auto;">
|
||||
<form method="POST" class="contact-form">
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="form-field">
|
||||
{{ form.numberplate.label }} {{ form.numberplate(class="form-input") }}
|
||||
</div>
|
||||
<div class="button-container">
|
||||
{{ form.submit(class="submit-btn") }}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -18,9 +18,12 @@
|
||||
<hr style="border: 1px solid white; margin-top: 0;">
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active text-white" href="/">
|
||||
<a class="nav-link active text-white" href="/dash/dashboard">
|
||||
Dashboard
|
||||
</a>
|
||||
<a class="nav-link active text-white" href="/dash/add">
|
||||
Add numberplate
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="d-flex justify-content-center mt-3">
|
||||
@@ -33,6 +36,7 @@
|
||||
<h1 class="display-4 fw-bold" style="color: #313A4D;">Dashboard</h1>
|
||||
</div>
|
||||
|
||||
|
||||
{%block content%}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for log in recent_logs %}
|
||||
{% for form in recent_logs %}
|
||||
<tr>
|
||||
<td><small class="fs-6">{{ log.timestamp.strftime('%H:%M:%S') }}</small></td>
|
||||
<td><small class="fs-6">{{ log.action }}</small></td>
|
||||
<td><small class="fs-6">{{ form.timestamp.strftime('%H:%M:%S') }}</small></td>
|
||||
<td><small class="fs-6">{{ form.plate }}</small></td>
|
||||
<td>
|
||||
<span class="badge {% if log.status == 'success' %}bg-success{% elif log.status == 'warning' %}bg-warning{% elif log.status == 'error' %}bg-danger{% else %}bg-secondary{% endif %} fs-6">
|
||||
{{ log.status }}
|
||||
{{ form.allowed }}
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,3 +1,33 @@
|
||||
from flask import Blueprint
|
||||
from flask import Blueprint, render_template
|
||||
from flask_login import login_required
|
||||
from application.models import AllowedPlate, LoggedItem
|
||||
from application import db, app
|
||||
from application.dashboard.forms import npForm
|
||||
|
||||
dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
|
||||
|
||||
|
||||
|
||||
@dash_blueprint.route('/dashboard')
|
||||
#@login_required
|
||||
def dashboard():
|
||||
form = LoggedItem.query.all()
|
||||
return render_template("dashboard.html", form=form)
|
||||
|
||||
@dash_blueprint.route('/add', methods=['GET', 'POST'])
|
||||
#@login_required
|
||||
def add():
|
||||
|
||||
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()
|
||||
|
||||
|
||||
|
||||
return render_template("add.html", form=form)
|
||||
Reference in New Issue
Block a user