mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-29 18:59:57 +00:00
Merge branch 'main' of https://github.com/StefBuwalda/ProjectIOT
This commit is contained in:
@@ -80,6 +80,24 @@
|
||||
<span class="text-muted"> </span>
|
||||
</div>
|
||||
</footer>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
||||
<symbol id="check-circle-fill" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
|
||||
</symbol>
|
||||
</svg>
|
||||
|
||||
<div class="position-fixed w-25 m-3 bottom-0" style="z-index: 1050;">
|
||||
{% for message in get_flashed_messages() %}
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<svg class="bi flex-shrink-0 me-2" width="15" height="15" role="img" aria-label="Success:">
|
||||
<use xlink:href="#check-circle-fill" />
|
||||
</svg>
|
||||
{{message}}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -29,6 +29,7 @@ def login():
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
flash("Succesfully logged out")
|
||||
return redirect("/")
|
||||
|
||||
|
||||
|
||||
@@ -55,34 +55,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('numberplateForm').addEventListener('submit', async function (e) {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const formData = new FormData(form);
|
||||
|
||||
const response = await fetch(form.action || window.location.pathname, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
// Update the table body
|
||||
const tbody = document.getElementById('numberplatesBody');
|
||||
tbody.innerHTML = '';
|
||||
data.plates.forEach(plate => {
|
||||
tbody.innerHTML += `<tr>
|
||||
<td><small class="fs-6">${plate.id}</small></td>
|
||||
<td><small class="fs-6">${plate.plate}</small></td>
|
||||
</tr>`;
|
||||
});
|
||||
form.reset();
|
||||
} else {
|
||||
alert('Failed to add numberplate.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
18
application/dashboard/templates/flash.html
Normal file
18
application/dashboard/templates/flash.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="d-none">
|
||||
<symbol id="check-circle-fill" viewBox="0 0 16 16">
|
||||
<path
|
||||
d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z" />
|
||||
</symbol>
|
||||
</svg>
|
||||
|
||||
<div class="position-fixed w-25 bottom-0" style="z-index: 1050;">
|
||||
{% for message in get_flashed_messages() %}
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<svg class="bi flex-shrink-0 me-2" width="15" height="15" role="img" aria-label="Success:">
|
||||
<use xlink:href="#check-circle-fill" />
|
||||
</svg>
|
||||
{{message}}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
After Width: | Height: | Size: 866 B |
@@ -7,11 +7,14 @@ from flask import (
|
||||
send_from_directory,
|
||||
redirect,
|
||||
url_for
|
||||
send_file,
|
||||
)
|
||||
from application.dashboard.models import AllowedPlate, LoggedItem
|
||||
from application import db
|
||||
import application
|
||||
from application.dashboard.forms import npForm
|
||||
from flask_login import login_required
|
||||
from io import BytesIO
|
||||
|
||||
dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
|
||||
|
||||
@@ -29,7 +32,6 @@ def dashboard():
|
||||
@dash_blueprint.route("/add", methods=["GET", "POST"])
|
||||
#@login_required
|
||||
def add():
|
||||
Plates = AllowedPlate.query.all()
|
||||
form = npForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
@@ -43,18 +45,8 @@ def add():
|
||||
db.session.add(ap)
|
||||
db.session.commit()
|
||||
flash("Numberplate succesfully added")
|
||||
|
||||
# Update the list on the page with JavaScript
|
||||
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
|
||||
]
|
||||
}
|
||||
)
|
||||
# form wasn't valid
|
||||
Plates = AllowedPlate.query.all()
|
||||
return render_template(
|
||||
"add.html", form=npForm(formdata=None), plates=Plates
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user