opencode ergebnis V0.1

This commit is contained in:
concierge committed 2026-10-23 00:05:06 +02:00
1 parent 61d86a3d83
commit 7e498ebc3f
71 files changed
+28982 -46

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
const tenant = window.location.pathname.split('/')[1];
const apiBase = `/${tenant}/admin/api`;
function changeRole(accountId, role) {
fetch(`${apiBase}/accounts/${accountId}/role`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({role: role})
}).then(r => r.json()).then(data => {
if (data.success) alert('Rolle geändert');
});
}
function openPasswordModal(accountId) {
document.getElementById('pwdAccountId').value = accountId;
document.getElementById('passwordModal').showModal();
}
function closePasswordModal() {
document.getElementById('passwordModal').close();
document.getElementById('newPassword').value = '';
}
function resetPassword() {
const accountId = document.getElementById('pwdAccountId').value;
const password = document.getElementById('newPassword').value;
fetch(`${apiBase}/accounts/${accountId}/password`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({password: password})
}).then(r => r.json()).then(data => {
if (data.success) {
alert('Passwort zurückgesetzt');
closePasswordModal();
} else {
alert(data.error);
}
});
}
function deleteAccount(accountId) {
if (!confirm('Account wirklich löschen?')) return;
fetch(`${apiBase}/accounts/${accountId}`, {
method: 'DELETE'
}).then(r => r.json()).then(data => {
if (data.success) {
location.reload();
}
});
}
function openCreateAccountModal() {
document.getElementById('createAccountModal').showModal();
}
function closeCreateAccountModal() {
document.getElementById('createAccountModal').close();
document.getElementById('newAccountName').value = '';
document.getElementById('newAccountPassword').value = '';
}
function createAccount() {
const name = document.getElementById('newAccountName').value;
const password = document.getElementById('newAccountPassword').value;
const role = document.getElementById('newAccountRole').value;
fetch(`${apiBase}/accounts`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name, password, role})
}).then(r => r.json()).then(data => {
if (data.success) {
alert('Account angelegt');
location.reload();
} else {
alert(data.error);
}
});
}
+253
View File
@@ -0,0 +1,253 @@
const tenant = window.location.pathname.split('/')[1];
const apiBase = `/${tenant}/admin/api`;
const GROUP_STATES = ['offen', 'unterwegs', 'online', 'pausierend', 'fertig'];
let currentGroupId = null;
function hasPosition(lat, lon) {
return lat !== null && lat !== undefined && lon !== null && lon !== undefined;
}
function formatPosition(lat, lon) {
return hasPosition(lat, lon) ? `${lat}, ${lon}` : 'unbekannt';
}
function showError(data) {
alert(data && data.error ? data.error : 'Aktion fehlgeschlagen');
}
function makeButton(label, className, handler) {
const button = document.createElement('button');
button.type = 'button';
button.textContent = label;
if (className) button.className = className;
button.addEventListener('click', handler);
return button;
}
function updateGruppe(groupId, data) {
fetch(`${apiBase}/gruppen/${groupId}`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(r => r.json()).then(result => {
if (!result.success) showError(result);
}).catch(() => alert('Server nicht erreichbar'));
}
function deleteGruppe(groupId) {
if (!confirm('Gruppe wirklich löschen?')) return;
fetch(`${apiBase}/gruppen/${groupId}`, {
method: 'DELETE'
}).then(r => r.json()).then(data => {
if (data.success) {
location.reload();
} else {
showError(data);
}
}).catch(() => alert('Server nicht erreichbar'));
}
// === Neue Gruppe ===
function openCreateGruppeModal() {
document.getElementById('gruppeAlias').value = '';
document.getElementById('gruppeAccount').value = '';
document.getElementById('createGruppeModal').showModal();
}
function closeCreateGruppeModal() {
document.getElementById('createGruppeModal').close();
document.getElementById('gruppeAlias').value = '';
document.getElementById('gruppeAccount').value = '';
}
function buildStateSelect(state) {
const select = document.createElement('select');
GROUP_STATES.forEach(value => {
const option = document.createElement('option');
option.value = value;
option.textContent = value;
option.selected = value === state;
select.appendChild(option);
});
return select;
}
function buildAccountSelect(accountId) {
const select = document.createElement('select');
const source = document.getElementById('gruppeAccount');
Array.from(source.options).forEach(option => {
const copy = document.createElement('option');
copy.value = option.value;
copy.textContent = option.textContent;
copy.selected = String(option.value) === String(accountId ?? '');
select.appendChild(copy);
});
return select;
}
function addGruppeRow(gruppe) {
const tbody = document.querySelector('#gruppenTable tbody');
const row = document.createElement('tr');
row.dataset.id = gruppe.id;
const idCell = document.createElement('td');
idCell.textContent = gruppe.id;
row.appendChild(idCell);
const aliasCell = document.createElement('td');
const aliasInput = document.createElement('input');
aliasInput.type = 'text';
aliasInput.value = gruppe.aliasname || '';
aliasInput.addEventListener('change',
() => updateGruppe(gruppe.id, {aliasname: aliasInput.value}));
aliasCell.appendChild(aliasInput);
row.appendChild(aliasCell);
const stateCell = document.createElement('td');
const stateSelect = buildStateSelect(gruppe.state);
stateSelect.addEventListener('change',
() => updateGruppe(gruppe.id, {state: stateSelect.value}));
stateCell.appendChild(stateSelect);
row.appendChild(stateCell);
const accountCell = document.createElement('td');
const accountSelect = buildAccountSelect(gruppe.account_id);
accountSelect.addEventListener('change',
() => updateGruppe(gruppe.id, {account_id: accountSelect.value}));
accountCell.appendChild(accountSelect);
row.appendChild(accountCell);
const positionCell = document.createElement('td');
positionCell.className = 'group-position';
positionCell.textContent = formatPosition(gruppe.last_lat, gruppe.last_lon);
row.appendChild(positionCell);
const actionsCell = document.createElement('td');
actionsCell.appendChild(makeButton('Historie', '', () => showHistory(gruppe.id)));
const clearPositionButton = makeButton('Position löschen', 'secondary delete-position',
() => deleteGroupPosition(gruppe.id));
clearPositionButton.disabled = !hasPosition(gruppe.last_lat, gruppe.last_lon);
actionsCell.appendChild(clearPositionButton);
actionsCell.appendChild(makeButton('Löschen', 'secondary', () => deleteGruppe(gruppe.id)));
row.appendChild(actionsCell);
tbody.appendChild(row);
row.scrollIntoView({block: 'nearest'});
}
function createGruppe() {
const aliasname = document.getElementById('gruppeAlias').value;
const accountId = document.getElementById('gruppeAccount').value;
fetch(`${apiBase}/gruppen`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({aliasname, account_id: accountId})
}).then(r => r.json()).then(data => {
if (!data.success) {
showError(data);
return;
}
addGruppeRow({
id: data.id,
aliasname: aliasname,
account_id: accountId || null,
state: 'offen',
last_lat: null,
last_lon: null
});
closeCreateGruppeModal();
}).catch(() => alert('Server nicht erreichbar'));
}
// === Historie / Position ===
function setPositionCell(groupId, lat, lon) {
const row = document.querySelector(`#gruppenTable tr[data-id="${groupId}"]`);
if (!row) return;
const positionCell = row.querySelector('.group-position');
if (positionCell) positionCell.textContent = formatPosition(lat, lon);
const clearButton = row.querySelector('.delete-position');
if (clearButton) clearButton.disabled = !hasPosition(lat, lon);
}
function showHistory(groupId) {
currentGroupId = groupId;
fetch(`${apiBase}/gruppen/${groupId}/history`)
.then(r => r.json())
.then(data => {
const tbody = document.getElementById('historyBody');
tbody.innerHTML = '';
data.forEach(entry => {
const row = document.createElement('tr');
[entry.created_at, entry.from_state || '-', entry.to_state,
formatPosition(entry.last_lat, entry.last_lon)].forEach(value => {
const cell = document.createElement('td');
cell.textContent = value;
row.appendChild(cell);
});
const actionCell = document.createElement('td');
actionCell.appendChild(makeButton('Zustand wiederherstellen', '',
() => revertGroup(entry.id)));
if (hasPosition(entry.last_lat, entry.last_lon)) {
actionCell.appendChild(makeButton('Position setzen', 'secondary',
() => setPositionFromHistory(entry.id, entry.last_lat, entry.last_lon)));
}
row.appendChild(actionCell);
tbody.appendChild(row);
});
document.getElementById('historyModal').showModal();
})
.catch(() => alert('Historie konnte nicht geladen werden'));
}
function setPositionFromHistory(histId, lat, lon) {
if (!confirm('Position aus diesem Historieneintrag übernehmen?')) return;
fetch(`${apiBase}/gruppen/${currentGroupId}/position/history/${histId}`, {
method: 'POST'
}).then(r => r.json()).then(data => {
if (!data.success) {
showError(data);
return;
}
setPositionCell(currentGroupId, lat, lon);
closeHistoryModal();
}).catch(() => alert('Server nicht erreichbar'));
}
function deleteGroupPosition(groupId) {
if (!confirm('Position dieser Gruppe wirklich löschen?')) return;
fetch(`${apiBase}/gruppen/${groupId}/position`, {
method: 'DELETE'
}).then(r => r.json()).then(data => {
if (!data.success) {
showError(data);
return;
}
setPositionCell(groupId, null, null);
}).catch(() => alert('Server nicht erreichbar'));
}
function revertGroup(histId) {
if (!confirm('Zustand wirklich wiederherstellen?')) return;
fetch(`${apiBase}/gruppen/${currentGroupId}/history/${histId}/revert`, {
method: 'POST'
}).then(r => r.json()).then(data => {
if (data.success) {
location.reload();
} else {
showError(data);
}
}).catch(() => alert('Server nicht erreichbar'));
}
function closeHistoryModal() {
document.getElementById('historyModal').close();
}
+155
View File
@@ -0,0 +1,155 @@
const tenant = window.location.pathname.split('/')[1];
const apiBase = `/${tenant}/admin/api`;
let currentStreetId = null;
let editMode = false;
function updateStrasse(streetId, data) {
fetch(`${apiBase}/strassen/${streetId}`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(r => r.json()).then(data => {
if (data.success) {
location.reload();
}
});
}
function deleteStrasse(streetId) {
if (!confirm('Straße wirklich löschen?')) return;
fetch(`${apiBase}/strassen/${streetId}`, {
method: 'DELETE'
}).then(r => r.json()).then(data => {
if (data.success) location.reload();
});
}
function openCreateStrasseModal() {
editMode = false;
document.getElementById('strasseModalTitle').innerText = 'Neue Straße';
document.getElementById('strasseId').value = '';
document.getElementById('strasseName').value = '';
document.getElementById('strasseHnMin').value = '';
document.getElementById('strasseHnMax').value = '';
document.getElementById('strasseBbox').value = '';
document.getElementById('strasseState').value = 'unbearbeitet';
document.getElementById('strasseState').disabled = true;
document.getElementById('strasseGroup').value = '';
document.getElementById('strasseGroup').disabled = true;
document.getElementById('strasseModal').showModal();
}
function editStrasse(streetId) {
editMode = true;
const row = document.querySelector(`tr[data-id="${streetId}"]`);
document.getElementById('strasseModalTitle').innerText = 'Straße bearbeiten';
document.getElementById('strasseId').value = streetId;
document.getElementById('strasseName').value = row.cells[1].innerText;
document.getElementById('strasseHnMin').value = row.cells[4].innerText === '-' ? '' : row.cells[4].innerText;
document.getElementById('strasseHnMax').value = row.cells[5].innerText === '-' ? '' : row.cells[5].innerText;
document.getElementById('strasseBbox').value = row.cells[6].innerText === '-' ? '' : row.cells[6].innerText;
document.getElementById('strasseState').value = row.cells[2].querySelector('select').value;
document.getElementById('strasseState').disabled = false;
document.getElementById('strasseGroup').value = row.cells[3].querySelector('select').value;
document.getElementById('strasseGroup').disabled = false;
document.getElementById('strasseModal').showModal();
}
function closeStrasseModal() {
document.getElementById('strasseModal').close();
}
function saveStrasse() {
const id = document.getElementById('strasseId').value;
const data = {
name: document.getElementById('strasseName').value,
hn_min: document.getElementById('strasseHnMin').value || null,
hn_max: document.getElementById('strasseHnMax').value || null,
bbox: document.getElementById('strasseBbox').value || null,
state: document.getElementById('strasseState').value,
group_id: document.getElementById('strasseGroup').value || null
};
if (!editMode) {
fetch(`${apiBase}/strassen`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(r => r.json()).then(data => {
if (data.success) {
alert('Straße angelegt');
location.reload();
}
});
} else {
fetch(`${apiBase}/strassen/${id}`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
}).then(r => r.json()).then(data => {
if (data.success) {
alert('Gespeichert');
location.reload();
}
});
}
closeStrasseModal();
}
function importCSV(input) {
const file = input.files[0];
if (!file) return;
const formData = new FormData();
formData.append('file', file);
fetch(`${apiBase}/strassen/import`, {
method: 'POST',
body: formData
}).then(r => r.json()).then(data => {
if (data.success) {
alert(`${data.count} Straßen importiert`);
location.reload();
} else {
alert(data.error);
}
});
}
function showStreetHistory(streetId) {
currentStreetId = streetId;
fetch(`${apiBase}/strassen/${streetId}/history`)
.then(r => r.json())
.then(data => {
const tbody = document.getElementById('streetHistoryBody');
tbody.innerHTML = '';
data.forEach(h => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td>${h.created_at}</td>
<td>${h.from_state || '-'}</td>
<td>${h.to_state}</td>
<td>${h.group_id || '-'}</td>
<td><button onclick="revertStreet(${h.id})">Wiederherstellen</button></td>
`;
tbody.appendChild(tr);
});
document.getElementById('streetHistoryModal').showModal();
});
}
function revertStreet(histId) {
if (!confirm('Zustand wirklich wiederherstellen?')) return;
fetch(`${apiBase}/strassen/${currentStreetId}/history/${histId}/revert`, {
method: 'POST'
}).then(r => r.json()).then(data => {
if (data.success) {
alert('Wiederhergestellt');
location.reload();
} else {
alert(data.error);
}
});
}
function closeStreetHistoryModal() {
document.getElementById('streetHistoryModal').close();
}
File diff suppressed because it is too large. Load diff