1
0

Löschen-Funktion hinzugefügt

This commit is contained in:
Anna Christina Naß 2025-07-15 16:29:51 +02:00
parent 217b157bee
commit 3db8f20f27
8 changed files with 87 additions and 10 deletions

32
delete.php Normal file
View File

@ -0,0 +1,32 @@
<?php
include 'config.php';
include 'functions.php';
// CORS
header("Access-Control-Allow-Origin: *");
header('Access-Control-Max-Age: 86400'); // cache for 1 day
if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
http_response_code(204);
header("Access-Control-Allow-Headers: origin, content-type, accept");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Private-Network: true");
exit(0);
}
if (!isset($_GET['id']))
die(return_error(400, "Keine ID angegeben."));
$id = (int)$_GET['id'];
$dbconn = pg_connect($dbconnstring)
or die(return_error(500, 'Datenbankfehler: ' . pg_last_error()));
$query = "DELETE FROM tests WHERE id=" . $id;
$result = pg_query($dbconn, $query)
or die(return_error('Datenbankfehler: ' . pg_last_error()));
pg_close($dbconn);
echo return_success();
?>

7
js/bootstrap.bundle.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

7
js/bootstrap.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -46,7 +46,7 @@ function result_color(result) {
function parse_and_show_pluslife_result(overall_result, channel_results){
$("#testresult").append(result_text(overall_result));
if (result_text(overall_result) == "ungueltig")
if (result_text(overall_result) == "Ungültig")
$("#testresult").addClass("ungueltig");
else
$("#testresult").addClass(result_text(overall_result).toLowerCase());
@ -107,6 +107,21 @@ function update_chart(timestamp, overall_result, result_channels, sampledata){
chart.update();
}
function delete_test() {
var id = new URLSearchParams(window.location.search).get('id');
$.ajax({
url: "delete.php?id=" + id,
async: false,
dataType: "json",
success: function (data) {
window.location.href="index.php";
},
error: function (request, status, error) {
show_error("Fehler: " + error);
}
});
}
function show_error(text) {
console.log(text);
@ -123,5 +138,16 @@ function show_error(text) {
} else {
show_error("Konnte Testdaten nicht laden");
}
const deleteModal = new bootstrap.Modal('#deleteModal', { keyboard: false, backdrop: 'static' });
$("#btn-delete-yes").click(function () {
delete_test();
deleteModal.hide();
});
$("#btn-delete").click(function () {
deleteModal.show();
});
// ARIA Warnung wg. aria-hidden umgehen:
$('#deleteModal').on('hide.bs.modal', () => { document.activeElement.blur(); });
})();

View File

@ -29,7 +29,7 @@
<p/>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
{% block js %}{% endblock %}
</body>
</html>

View File

@ -16,6 +16,7 @@ var json = {{ test|raw }};
<div class="row justify-content-center chart-container" style="position: relative; min-height: 400px; max-height:600px;">
<canvas id="data"></canvas>
</div>
<button class="btn btn-danger float-end" id="btn-delete">Test löschen</button>
<table class="mx-auto w-auto ergebnistabelle">
<tbody>
<tr><th scope="row">Teststart:</th><td><span id="testdate"></span></tr>
@ -30,5 +31,23 @@ var json = {{ test|raw }};
</div>
</div>
<div class="modal" id="deleteModal" role="dialog" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Test löschen</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h4 class="text-center">Diesen Test wirklich löschen?</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" id="btn-delete-yes">Ja</button>
<button type="button" class="btn btn-default" data-bs-dismiss="modal">Nein</button>
</div>
</div>
</div>
</div>
{% endblock %}