Compare commits

..

5 Commits

Author SHA1 Message Date
tracer 32133a0d05 some format changes 2022-10-25 19:40:33 +02:00
tracer 572cc1eb89 reverted last name change, not needed 2022-10-25 19:40:33 +02:00
tracer 48585f14ab removed debug statements 2022-10-25 19:40:33 +02:00
tracer 47439fe358 removed debug statements 2022-10-25 19:40:33 +02:00
tracer 8e0a2ff6e8 every click on a column title changes the sort order 2022-10-25 19:40:33 +02:00
2 changed files with 21 additions and 31 deletions

View File

@ -11,10 +11,8 @@ function addAddress(url) {
}
function editAddress(id) {
console.log("editButon")
if (document.getElementById('edit_button_' + id).value === 'Save') {
// save
console.log("save")
const url = "/address/update";
fetch(url, {
method: "POST",
@ -32,8 +30,8 @@ function editAddress(id) {
.then(
response => response.text()
).then(
html => console.log(html)
);
html => console.log(html)
);
document.getElementById('first_' + id).disabled = true
document.getElementById('last_' + id).disabled = true
@ -45,7 +43,6 @@ function editAddress(id) {
document.getElementById('edit_button_' + id).value = 'Edit'
} else {
//switch to edit
console.log("switch to edit")
document.getElementById('first_' + id).disabled = false
document.getElementById('last_' + id).disabled = false
document.getElementById('street_' + id).disabled = false
@ -58,7 +55,6 @@ function editAddress(id) {
}
function deleteAddress(id) {
console.log("del")
if (confirm('Are you sure?')) {
const url = "/address/delete";
fetch(url, {
@ -70,25 +66,29 @@ function deleteAddress(id) {
.then(
response => response.text()
).then(
html => console.log(html)
);
html => console.log(html)
);
let row = document.getElementById('row_' + id)
row.parentNode.removeChild(row)
}
}
function sortBy(column) {
console.log("sortby: " + column)
// switch direction on every call
let currentSortOrder = document.getElementById(column + '_sort')
if (currentSortOrder.innerHTML === 'asc') {
currentSortOrder.innerHTML = 'desc'
} else {
currentSortOrder.innerHTML = 'asc'
}
const table = document.getElementById('address_table');
let dirty = true;
// loop until clean
while (dirty) {
console.log('dirty', dirty)
// assume we are finished
dirty = false
const rows = table.rows;
console.log(rows)
for (let i = 1; i < (rows.length - 2); i++) {
let x = rows[i]
let rowXId = x.id
@ -100,14 +100,14 @@ function sortBy(column) {
let rowYNumber = rowYId.charAt(rowYId.length -1)
let valueY = document.getElementById(column + '_' + rowYNumber).value
console.log(valueX, valueY)
// mind asc & desc
let sortOrder = 1
console.log(valueX.localeCompare(valueY))
let currentSortOrder = document.getElementById(column + '_sort')
let sortOrder = 0
if (currentSortOrder.innerHTML === 'asc') {
sortOrder = 1
} else {
sortOrder = -1
}
if (valueX.localeCompare(valueY) === sortOrder) {
console.log('switch A')
// switch rows
x.parentNode.insertBefore(y, x);
dirty = true
}

View File

@ -84,7 +84,7 @@ class Router
foreach ($this->dynamicRoutes as $route) {
// PHPStorm doesn't know that $parameters are always available,
// (as it is a dynamic route) so the init the array just to mke PHPstorm happy.
// (as it is a dynamic route) so I init the array just to make PHPStorm happy.
$parameters = [];
if (preg_match(pattern: $route->getRegex(), subject: $requestUri, matches: $matches)) {
foreach ($route->getParameters() as $id => $parameter) {
@ -104,7 +104,6 @@ class Router
public function path(string $routeName, array $vars = [])
{
foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) {
if ($route->getName() == $routeName) {
if ($vars) {
// build route for dynamic routes
@ -119,16 +118,7 @@ class Router
}
}
}
// no 404, this is reached only if the code is wrong
// TODO doesn't find the last route
/*
foreach (array_merge($this->dynamicRoutes, $this->staticRoutes) as $route) {
echo $route->getRoute() . '<br>';
if ($routeName == $route->getRoute()) {
echo "equal";
}
}
die("Missing Route: $routeName");
*/
// no 404, this is reached only if the code is buggy
die("Missing Route: $routeName");
}
}