Liste sortieren, bearbeiten
This commit is contained in:
@@ -15,6 +15,15 @@ function updateSortArrows() {
|
||||
el.style.opacity = currentSort.key === key ? '1' : '0.3';
|
||||
});
|
||||
}
|
||||
|
||||
// Tab-Wechsel Funktion aus index.pug
|
||||
function showTab(tab) {
|
||||
document.getElementById('tabInputContent').style.display = tab === 'input' ? '' : 'none';
|
||||
document.getElementById('tabListContent').style.display = tab === 'list' ? '' : 'none';
|
||||
document.getElementById('tabInput').classList.toggle('active', tab === 'input');
|
||||
document.getElementById('tabList').classList.toggle('active', tab === 'list');
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const saveBtn = document.getElementById('saveBtn');
|
||||
const refreshBtn = document.getElementById('refreshBtn');
|
||||
@@ -27,6 +36,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const limitInput = document.getElementById('limit');
|
||||
const resultDiv = document.getElementById('result');
|
||||
const tableBody = document.querySelector('#entriesTable tbody');
|
||||
const tabInput = document.getElementById('tabInput');
|
||||
const tabList = document.getElementById('tabList');
|
||||
|
||||
let editId = null;
|
||||
|
||||
@@ -153,6 +164,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function clearForm() {
|
||||
espIdInput.value = '';
|
||||
sensorNumberInput.value = '';
|
||||
@@ -267,9 +279,20 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
sensorNumberInput.value = item._id;
|
||||
nameInput.value = item.chip.name || '';
|
||||
descriptionInput.value = item.chip.description || '';
|
||||
// addressInput.value = item.address || '';
|
||||
addressInput.value = '';
|
||||
editId = id;
|
||||
try {
|
||||
const rt = await fetch(`api/holAdresse/${item._id}`)
|
||||
const data = await rt.json();
|
||||
console.dir(data)
|
||||
if (!data.error && data.address) {
|
||||
addressInput.value = data.address;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Fehler beim Adresse holen", e)
|
||||
}
|
||||
saveBtn.textContent = 'Aktualisieren';
|
||||
showTab('input')
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -293,8 +316,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
saveBtn.addEventListener('click', saveEntry);
|
||||
refreshBtn.addEventListener('click', loadEntries);
|
||||
tabInput.addEventListener('click', () => showTab('input'))
|
||||
tabList.addEventListener('click', () => showTab('list'))
|
||||
|
||||
loadEntries();
|
||||
});
|
||||
@@ -5,6 +5,43 @@ import { getCollections, update_pflux, clientClose } from '../db/mongo.js';
|
||||
export function registerAddressRoute(app, requireLogin) {
|
||||
const APIHOST = process.env.APIHOST || 'https://noise.fuerst-stuttgart.de/srv/';
|
||||
|
||||
|
||||
const holAdresse = async (id) => {
|
||||
// Adresse wie bisher holen (über die Sensornummer via nominative)
|
||||
let addressString = '';
|
||||
let addrParts = {};
|
||||
try {
|
||||
const url = APIHOST + 'getaddress/' + `?sensorid=${id}`;
|
||||
console.log(url)
|
||||
const r = await fetch(url, { headers: { 'Accept': 'application/json' } });
|
||||
if (r.ok) {
|
||||
const data = await r.json();
|
||||
const addrObj = data?.erg?.address || data?.address || {};
|
||||
const street = addrObj.street ?? '';
|
||||
const plz = addrObj.plz ?? '';
|
||||
const city = addrObj.city ?? '';
|
||||
const rightPart = [plz, city].filter(Boolean).join(' ').trim();
|
||||
addressString = [street, rightPart].filter(Boolean).join(', ');
|
||||
addrParts = { street, plz, city };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Address lookup failed:', err);
|
||||
}
|
||||
return {
|
||||
address: addressString,
|
||||
parts: addrParts,
|
||||
}
|
||||
}
|
||||
|
||||
app.get('/api/holAdresse/:sensorNumber', requireLogin, async (req, res) => {
|
||||
const sensorNumber = parseInt(req.params.sensorNumber, 10);
|
||||
if (isNaN(sensorNumber)) {
|
||||
return res.status(400).json({ error: 'Ungültige Sensornummer' });
|
||||
}
|
||||
const addr = await holAdresse(sensorNumber)
|
||||
res.json(addr)
|
||||
})
|
||||
|
||||
app.get('/api/address/:sensorNumber', requireLogin, async (req, res) => {
|
||||
const sensorNumber = parseInt(req.params.sensorNumber, 10);
|
||||
if (isNaN(sensorNumber)) {
|
||||
@@ -37,32 +74,9 @@ export function registerAddressRoute(app, requireLogin) {
|
||||
await clientClose()
|
||||
}
|
||||
}
|
||||
const adr = await holAdresse(encodeURIComponent(propEntry._id))
|
||||
adr.props = propsF
|
||||
|
||||
// Adresse wie bisher holen (über die Sensornummer via nominative)
|
||||
let addressString = '';
|
||||
let addrParts = {};
|
||||
try {
|
||||
const url = APIHOST + 'getaddress/' + `?sensorid=${encodeURIComponent(propEntry._id)}`;
|
||||
console.log(url)
|
||||
const r = await fetch(url, { headers: { 'Accept': 'application/json' } });
|
||||
if (r.ok) {
|
||||
const data = await r.json();
|
||||
const addrObj = data?.erg?.address || data?.address || {};
|
||||
const street = addrObj.street ?? '';
|
||||
const plz = addrObj.plz ?? '';
|
||||
const city = addrObj.city ?? '';
|
||||
const rightPart = [plz, city].filter(Boolean).join(' ').trim();
|
||||
addressString = [street, rightPart].filter(Boolean).join(', ');
|
||||
addrParts = { street, plz, city };
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Address lookup failed:', err);
|
||||
}
|
||||
|
||||
return res.json({
|
||||
address: addressString,
|
||||
parts: addrParts,
|
||||
props: propsF
|
||||
});
|
||||
});
|
||||
return res.json(adr)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ html(lang="de")
|
||||
h1 ESP-ID → Sensornummer
|
||||
// Tab Navigation
|
||||
div.tabs
|
||||
button.tab-btn#tabInput.active(type="button" onclick="showTab('input')") Eingabe
|
||||
button.tab-btn#tabList(type="button" onclick="showTab('list')") Liste
|
||||
button.tab-btn#tabInput.active(type="button") Eingabe
|
||||
button.tab-btn#tabList(type="button") Liste
|
||||
|
||||
// Eingabe-Tab
|
||||
div#tabInputContent.tab-content
|
||||
@@ -55,10 +55,3 @@ html(lang="de")
|
||||
th Aktionen
|
||||
tbody
|
||||
script(type="module" src="/global.js")
|
||||
script.
|
||||
function showTab(tab) {
|
||||
document.getElementById('tabInputContent').style.display = tab === 'input' ? '' : 'none';
|
||||
document.getElementById('tabListContent').style.display = tab === 'list' ? '' : 'none';
|
||||
document.getElementById('tabInput').classList.toggle('active', tab === 'input');
|
||||
document.getElementById('tabList').classList.toggle('active', tab === 'list');
|
||||
}
|
||||
Reference in New Issue
Block a user