svg editor gut

This commit is contained in:
2026-02-12 09:05:36 +01:00
parent 78455ca1e6
commit 98fac55ffd
4 changed files with 50 additions and 1 deletions

View File

@@ -8,6 +8,8 @@
'10': { width: 420, height: 80 } '10': { width: 420, height: 80 }
}; };
let portOptionsInput = null;
function initEditor() { function initEditor() {
const editor = document.getElementById('device-type-shape-editor'); const editor = document.getElementById('device-type-shape-editor');
const svg = document.getElementById('shape-canvas'); const svg = document.getElementById('shape-canvas');
@@ -36,6 +38,7 @@
portNameLabel: document.getElementById('shape-port-name-label'), portNameLabel: document.getElementById('shape-port-name-label'),
deleteButton: document.getElementById('shape-delete') deleteButton: document.getElementById('shape-delete')
}; };
portOptionsInput = document.getElementById('shape-port-options');
const metaInputs = { const metaInputs = {
formFactor: document.getElementById('shape-meta-form-factor'), formFactor: document.getElementById('shape-meta-form-factor'),
@@ -68,6 +71,7 @@
let selectedShapeId = null; let selectedShapeId = null;
let shapes = []; let shapes = [];
let meta = getDefaultMeta(); let meta = getDefaultMeta();
let portNameOptions = readPortOptions();
const definition = readDefinition(hiddenInput.value); const definition = readDefinition(hiddenInput.value);
shapes = normalizeShapeList(definition.shapes); shapes = normalizeShapeList(definition.shapes);
@@ -78,6 +82,7 @@
bindOverlayEvents(overlay); bindOverlayEvents(overlay);
bindMetaEvents(); bindMetaEvents();
applyFormFactorPreset(); applyFormFactorPreset();
populatePortSelect();
applyMetaToInputs(); applyMetaToInputs();
persist(); persist();
render(); render();
@@ -250,6 +255,20 @@
}); });
} }
function populatePortSelect() {
if (!overlay.portName) {
return;
}
portNameOptions = readPortOptions();
overlay.portName.innerHTML = '<option value="">- Port wählen -</option>';
portNameOptions.forEach((name) => {
const option = document.createElement('option');
option.value = name;
option.textContent = name;
overlay.portName.appendChild(option);
});
}
function handleMetaInputChange(event) { function handleMetaInputChange(event) {
const targetId = event?.target?.id; const targetId = event?.target?.id;
applyMetaFromInputs(); applyMetaFromInputs();
@@ -402,6 +421,8 @@
return; return;
} }
populatePortSelect();
overlay.type.value = selected.type; overlay.type.value = selected.type;
overlay.x.value = selected.x; overlay.x.value = selected.x;
overlay.y.value = selected.y; overlay.y.value = selected.y;
@@ -662,6 +683,27 @@
} }
} }
function readPortOptions() {
if (!portOptionsInput) {
return [];
}
const raw = String(portOptionsInput.value || '').trim();
if (!raw) {
return [];
}
try {
const parsed = JSON.parse(raw);
if (!Array.isArray(parsed)) {
return [];
}
return parsed.filter((value) => typeof value === 'string');
} catch (error) {
return [];
}
}
function readDefinition(raw) { function readDefinition(raw) {
const parsed = readJson(raw); const parsed = readJson(raw);
if (Array.isArray(parsed)) { if (Array.isArray(parsed)) {

View File

@@ -12,6 +12,7 @@
* -> bewusst simpel & erweiterbar * -> bewusst simpel & erweiterbar
*/ */
(() => {
/* ========================= /* =========================
* Konfiguration * Konfiguration
* ========================= */ * ========================= */
@@ -287,3 +288,4 @@ document.addEventListener('keydown', (e) => {
// TODO: Delete -> Gerät entfernen? // TODO: Delete -> Gerät entfernen?
}); });
})();

View File

@@ -12,6 +12,7 @@
* Abhängigkeiten: keine (Vanilla JS) * Abhängigkeiten: keine (Vanilla JS)
*/ */
(() => {
/* ========================= /* =========================
* Konfiguration * Konfiguration
* ========================= */ * ========================= */
@@ -256,3 +257,4 @@ document.addEventListener('keydown', (e) => {
deleteSelectedPort(); deleteSelectedPort();
} }
}); });
})();

View File

@@ -234,7 +234,9 @@ $pageTitle = $isEdit ? "Gerätetyp bearbeiten: " . htmlspecialchars($deviceType[
</label> </label>
<label id="shape-port-name-label" hidden> <label id="shape-port-name-label" hidden>
Port-Name Port-Name
<input type="text" id="shape-param-port-name" placeholder="z.B. Gi1/0/1"> <select id="shape-param-port-name">
<option value="">- Port wählen -</option>
</select>
</label> </label>
</div> </div>
@@ -299,6 +301,7 @@ $pageTitle = $isEdit ? "Gerätetyp bearbeiten: " . htmlspecialchars($deviceType[
<?php endif; ?> <?php endif; ?>
</tbody> </tbody>
</table> </table>
<input type="hidden" id="shape-port-options" value="<?php echo htmlspecialchars(json_encode(array_values(array_column($ports, 'name'))), ENT_QUOTES); ?>">
<div class="port-actions"> <div class="port-actions">
<button type="button" class="button" id="add-port-row">+ Port hinzufügen</button> <button type="button" class="button" id="add-port-row">+ Port hinzufügen</button>