mirror of
https://github.com/StefBuwalda/ProjectIOT.git
synced 2025-10-30 11:19:57 +00:00
Edit en Delete functie toegevoegd
This commit is contained in:
@@ -4,5 +4,6 @@ from wtforms import StringField, SubmitField
|
|||||||
|
|
||||||
|
|
||||||
class npForm(FlaskForm):
|
class npForm(FlaskForm):
|
||||||
numberplate = StringField("add a numberplate", validators=[DataRequired()])
|
numberplate = StringField('Insert plate here:', validators=[DataRequired()])
|
||||||
submit = SubmitField("Submit")
|
submit = SubmitField('Submit')
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title fs-4">Logs</h5>
|
<h5 class="card-title fs-4">Logs</h5>
|
||||||
@@ -29,8 +29,7 @@
|
|||||||
<td><small class="fs-6">{{ log.dateLogged.strftime('%H:%M:%S') }}</small></td>
|
<td><small class="fs-6">{{ log.dateLogged.strftime('%H:%M:%S') }}</small></td>
|
||||||
<td><small class="fs-6">{{ log.plate }}</small></td>
|
<td><small class="fs-6">{{ log.plate }}</small></td>
|
||||||
<td>
|
<td>
|
||||||
<span
|
<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">
|
||||||
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.allowed }}
|
{{ log.allowed }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
@@ -41,9 +40,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card mb-4">
|
<div class="card mb-4">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title fs-4">Numberplates</h5>
|
<h5 class="card-title fs-4">Numberplates</h5>
|
||||||
@@ -60,6 +59,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><small class="fs-6">{{ plate.id }}</small></td>
|
<td><small class="fs-6">{{ plate.id }}</small></td>
|
||||||
<td><small class="fs-6">{{ plate.plate }}</small></td>
|
<td><small class="fs-6">{{ plate.plate }}</small></td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('dash.edit', plate=plate.plate) }}" class="btn btn-sm btn-primary">Edit</a>
|
||||||
|
<form method="POST" action="{{ url_for('dash.delete_plate', plate=plate.plate) }}" style="display:inline;" onsubmit="return confirm('Are you sure you want to delete this numberplate?');">
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger">Delete</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -67,7 +72,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
110
application/dashboard/templates/edit.html
Normal file
110
application/dashboard/templates/edit.html
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
{%extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
|
||||||
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||||
|
<h1 class="display-4 fw-bold" style="color: #313A4D;">Numberplate</h1>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card mb-4">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title fs-4">Edit 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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title fs-4">Change numberplate</h5>
|
||||||
|
<div class="log-container" style="max-height: 250px; overflow-y: auto;">
|
||||||
|
<form method="POST" class="contact-form" id="numberplateForm">
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
<div class="form-field">
|
||||||
|
{{ form.numberplate(class="form-input",style="width: 200px; height: 40px;") }}
|
||||||
|
</div>
|
||||||
|
<div class="button-container" style="margin-top: 15px;">
|
||||||
|
{{ form.submit(class="btn btn-sm btn-dark", style="width: 200px;") }}
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title fs-4">Numberplates</h5>
|
||||||
|
<div class="log-container" style="max-height: 250px; overflow-y: auto;">
|
||||||
|
<table class="table table-sm table-hover" id="numberplatesTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col" class="fs-5">ID</th>
|
||||||
|
<th scope="col" class="fs-5">Numberplate</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="numberplatesBody">
|
||||||
|
{% for plate in plates %}
|
||||||
|
<tr>
|
||||||
|
<td><small class="fs-6">{{ plate.id }}</small></td>
|
||||||
|
<td><small class="fs-6">{{ plate.plate }}</small></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</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 %}
|
||||||
@@ -5,6 +5,8 @@ from flask import (
|
|||||||
jsonify,
|
jsonify,
|
||||||
flash,
|
flash,
|
||||||
send_from_directory,
|
send_from_directory,
|
||||||
|
redirect,
|
||||||
|
url_for
|
||||||
)
|
)
|
||||||
from application.dashboard.models import AllowedPlate, LoggedItem
|
from application.dashboard.models import AllowedPlate, LoggedItem
|
||||||
from application import db
|
from application import db
|
||||||
@@ -15,7 +17,7 @@ dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
|
|||||||
|
|
||||||
|
|
||||||
@dash_blueprint.route("/dashboard")
|
@dash_blueprint.route("/dashboard")
|
||||||
@login_required
|
#@login_required
|
||||||
def dashboard():
|
def dashboard():
|
||||||
Plates = AllowedPlate.query.all()
|
Plates = AllowedPlate.query.all()
|
||||||
logs = (
|
logs = (
|
||||||
@@ -25,7 +27,7 @@ def dashboard():
|
|||||||
|
|
||||||
|
|
||||||
@dash_blueprint.route("/add", methods=["GET", "POST"])
|
@dash_blueprint.route("/add", methods=["GET", "POST"])
|
||||||
@login_required
|
#@login_required
|
||||||
def add():
|
def add():
|
||||||
Plates = AllowedPlate.query.all()
|
Plates = AllowedPlate.query.all()
|
||||||
form = npForm()
|
form = npForm()
|
||||||
@@ -73,3 +75,36 @@ def live_image():
|
|||||||
as_attachment=False,
|
as_attachment=False,
|
||||||
conditional=True,
|
conditional=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@dash_blueprint.route('/logs', methods=['GET', 'POST'])
|
||||||
|
#@login_required
|
||||||
|
def logs():
|
||||||
|
form = LoggedItem.query.all()
|
||||||
|
return render_template("logs.html", form=form)
|
||||||
|
|
||||||
|
@dash_blueprint.route("/edit/<string:plate>",methods=["GET", "POST"])
|
||||||
|
#login_required
|
||||||
|
def edit(plate: str):
|
||||||
|
print(plate)
|
||||||
|
editnp = AllowedPlate.query.filter_by(plate=plate).first_or_404()
|
||||||
|
form = npForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
commit = False
|
||||||
|
if editnp.plate != form.numberplate.data:
|
||||||
|
editnp.plate = form.numberplate.data
|
||||||
|
commit = True
|
||||||
|
if commit:
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for("dash.dashboard"))
|
||||||
|
form.numberplate.data = editnp.plate
|
||||||
|
return render_template("edit.html",form=form)
|
||||||
|
|
||||||
|
@dash_blueprint.route("/delete/<string:plate>", methods=["POST"])
|
||||||
|
#@login_required
|
||||||
|
def delete_plate(plate: str):
|
||||||
|
plate_obj = AllowedPlate.query.filter_by(plate=plate).first_or_404()
|
||||||
|
db.session.delete(plate_obj)
|
||||||
|
db.session.commit()
|
||||||
|
flash("Numberplate deleted successfully.")
|
||||||
|
return redirect(url_for("dash.dashboard"))
|
||||||
Reference in New Issue
Block a user