Compare commits

..

2 Commits

Author SHA1 Message Date
2fd19db88d Typo 2026-02-08 17:39:34 +01:00
0b27d68c0c Installed Formatter and extracted javascript window logic from index 2026-02-08 17:14:37 +01:00
3 changed files with 414 additions and 307 deletions

View File

@ -1,337 +1,349 @@
<!DOCTYPE html> <!doctype html>
<html> <html>
<head>
<link href="www/bootstrap.min.css" rel="stylesheet" />
<script src="www/bootstrap.bundle.min.js"></script>
<script defer src="www/alpinejs.min.js"></script>
<script defer src="www/windows.js"></script>
<head> <style>
<link href="www/bootstrap.min.css" rel="stylesheet"> [x-cloak] {
<script src="www/bootstrap.bundle.min.js"></script> display: none !important;
<script defer src="www/alpinejs.min.js"></script> }
<style> body {
[x-cloak] { background-color: #f8f9fa;
display: none !important; /* Create 20px x 20px Grid */
} background-image:
linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px),
linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
background-size: 20px 20px;
height: 100vh;
margin: 0;
overflow: hidden;
}
body { .draggable-card {
background-color: #f8f9fa; width: 450px;
/* Create 20px x 20px Grid */ z-index: 1000;
background-image: user-select: none;
linear-gradient(90deg, rgba(0, 0, 0, .03) 1px, transparent 1px), }
linear-gradient(rgba(0, 0, 0, .03) 1px, transparent 1px);
background-size: 20px 20px;
height: 100vh;
margin: 0;
overflow: hidden;
}
.draggable-card { .drag-handle {
width: 450px; cursor: move;
z-index: 1000; }
user-select: none;
}
.drag-handle { .card {
cursor: move; transition:
} width 0.1s ease,
height 0.1s ease,
left 0.1s ease,
top 0.1s ease;
}
.card { .card[style*="cursor: move"] {
transition: width 0.1s ease, height 0.1s ease, left 0.1s ease, top 0.1s ease; transition: none;
} }
</style>
.card[style*="cursor: move"] { <script>
transition: none; document.addEventListener("alpine:init", () => {
} Alpine.store("ui", {
</style> topZ: 1000,
getNewZ() {
return ++this.topZ;
},
});
<script> Alpine.store("adapters", ["can0", "can1", "vcan0"]);
document.addEventListener('alpine:init', () => { Alpine.store("selected_adapter", "");
Alpine.store("selected_bitrate", "");
Alpine.store("can_connected", false);
});
</script>
Alpine.store("ui", { <script>
topZ: 1000, let socket = new WebSocket("ws://localhost:8000/echo");
getNewZ() {return ++this.topZ}
});
Alpine.store("adapters", ["can0", "can1", "vcan0"]); socket.onopen = function (e) {
Alpine.store("selected_adapter", ""); console.log("[open] Connection established");
Alpine.store("selected_bitrate", ""); console.log("Sending to server");
Alpine.store("can_connected", false); };
});
function windowBox(id, initialX = 50, initialY = 50) {
// Load saved data or user defaults
const saved = JSON.parse(localStorage.getItem(`win_${id}`)) || {x: initialX, y: initialY, min: false};
return { socket.onmessage = function (event) {
id: id, console.log(`[message] Data received from server: ${event.data}`);
pos: {x: saved.x, y: saved.y}, let mes;
lastPos: {x: saved.x, y: saved.y}, try {
dragging: false, mes = JSON.parse(event.data);
minimized: saved.min, } catch {
fullscreen: false, mes = null;
zIndex: Alpine.store('ui').topZ, }
offset: {x: 0, y: 0},
init() { if (mes != null) {
// Move window in viewport when browser is other size handleCommand(mes);
this.keepInBounds(); } else {
}, console.log(`${event.data} is not valid JSON`);
}
};
focus() { socket.onclose = function (event) {
this.zIndex = Alpine.store('ui').getNewZ(); if (event.wasClean) {
}, alert(
`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`,
);
} else {
// e.g. server process killed or network down
// event.code is usually 1006 in this case
console.log("[close] Connection died");
}
};
startDrag(e) { socket.onerror = function (error) {
if (e.target.closest('button') || this.fullscreen) return; console.log(`[error]`);
this.focus(); };
this.dragging = true;
this.offset.x = e.clientX - this.pos.x;
this.offset.y = e.clientY - this.pos.y;
},
onDrag(e) { function handleCommand(command) {
if (!this.dragging) return; switch (command.cmd) {
case "value":
console.log("CHANGE VALUE");
Alpine.store(command.name, command.value);
break;
}
}
</script>
</head>
// Calc new position <body>
let newX = e.clientX - this.offset.x; <h1>Alox Debug Tool</h1>
let newY = e.clientY - this.offset.y; <div
x-data="windowBox('window_id' ,100, 100)"
@mousemove.window="onDrag"
@mouseup.window="stopDrag"
@mousedown="focus"
class="card shadow-lg position-absolute"
:class="{ 'w-100 h-100 m-0 shadow-none': fullscreen }"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '400px'};`"
x-cloak
>
<div
class="card-header bg-dark text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag"
@dblclick="toggleFullscreen"
>
<h6 class="mb-0">CAN Interface</h6>
// Boundary Check <div class="d-flex align-items-center gap-1">
const margin = 20; <span
this.pos.x = Math.max(margin - 350, Math.min(newX, window.innerWidth - 50)); class="badge me-1"
this.pos.y = Math.max(0, Math.min(newY, window.innerHeight - 40)); :class="socket.readyState === 1 ? 'bg-success' : 'bg-danger'"
}, >WS</span
>
stopDrag() { <button
this.dragging = false; class="btn btn-sm btn-outline-light py-0 px-2"
this.save(); @click="toggleFullscreen"
}, >
<span></span>
</button>
keepInBounds() { <button
if (this.pos.x > window.innerWidth) this.pos.x = window.innerWidth - 400; class="btn btn-sm btn-outline-light py-0 px-2"
if (this.pos.y > window.innerHeight) this.pos.y = 50; @click="minimized = !minimized"
}, >
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
save() { <div x-show="!minimized" class="flex-grow-1 overflow-auto">
localStorage.setItem(`win_${this.id}`, JSON.stringify({ <div class="card-body">
x: this.pos.x, <p>HIER DER INHALT DER COMPONENT</p>
y: this.pos.y, </div>
min: this.minimized </div>
})); </div>
},
reset() { <div
localStorage.removeItem(`win_${this.id}`); x-data="windowBox('can_config', 100, 100)"
location.reload(); @mousemove.window="onDrag"
}, @mouseup.window="stopDrag"
@mousedown="focus"
class="card shadow-lg position-absolute"
:class="{ 'w-100 h-100 m-0 shadow-none': fullscreen }"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '400px'};`"
x-cloak
>
<div
class="card-header bg-dark text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag"
@dblclick="toggleFullscreen"
>
<h6 class="mb-0">CAN Interface</h6>
toggleMinimize() { <div class="d-flex align-items-center gap-1">
this.minimized = !this.minimized; <span
this.save(); class="badge me-1"
}, :class="socket.readyState === 1 ? 'bg-success' : 'bg-danger'"
>WS</span
>
toggleFullscreen() { <button
if (!this.fullscreen) { class="btn btn-sm btn-outline-light py-0 px-2"
this.lastPos = {...this.pos}; // Save Position @click="toggleFullscreen"
this.pos = {x: 0, y: 0}; >
this.fullscreen = true; <span></span>
} else { </button>
this.pos = {...this.lastPos}; // Back to old Position
this.fullscreen = false;
}
this.focus();
}
}
}
</script> <button
class="btn btn-sm btn-outline-light py-0 px-2"
@click="minimized = !minimized"
>
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
<script> <div x-show="!minimized" class="flex-grow-1 overflow-auto">
let socket = new WebSocket("ws://localhost:8000/echo"); <div class="card-body">
<label class="form-label small fw-bold text-uppercase text-muted"
>Interface</label
>
<div
class="input-group mb-3"
x-data="{ open: false }"
@click.outside="open = false"
>
<button
class="btn btn-outline-secondary dropdown-toggle"
type="button"
@click="open = !open"
:disabled="$store.can_connected"
>
Adapter
</button>
<ul
class="dropdown-menu"
:class="{ 'show': open }"
x-show="open"
style="display: block"
>
<template x-for="adapter in $store.adapters">
<li>
<button
class="dropdown-item"
type="button"
x-text="adapter"
@click="$store.selected_adapter = adapter; open = false"
></button>
</li>
</template>
</ul>
<input
type="text"
class="form-control bg-light"
readonly
:value="$store.selected_adapter || 'Select Interface...'"
/>
</div>
socket.onopen = function (e) { <label class="form-label small fw-bold text-uppercase text-muted"
console.log("[open] Connection established"); >Bitrate (kbps)</label
console.log("Sending to server"); >
}; <div
class="input-group mb-4"
x-data="{ open: false }"
@click.outside="open = false"
>
<button
class="btn btn-outline-secondary dropdown-toggle"
type="button"
@click="open = !open"
:disabled="$store.can_connected"
>
Speed
</button>
<ul
class="dropdown-menu"
:class="{ 'show': open }"
x-show="open"
style="display: block"
>
<template
x-for="rate in ['10', '20', '50', '100', '125', '250', '500', '800', '1000']"
>
<li>
<button
class="dropdown-item"
type="button"
x-text="rate + ' kbps'"
@click="$store.selected_bitrate = rate; open = false"
></button>
</li>
</template>
</ul>
<input
type="text"
class="form-control bg-light"
readonly
:value="$store.selected_bitrate ? $store.selected_bitrate + ' kbps' : 'Select Speed...'"
/>
</div>
socket.onmessage = function (event) { <div class="d-grid">
console.log(`[message] Data received from server: ${event.data}`); <button
let mes; x-show="!$store.can_connected"
try { class="btn btn-primary btn-lg"
mes = JSON.parse(event.data) type="button"
} catch { :disabled="!$store.selected_adapter || !$store.selected_bitrate"
mes = null @click="socket.send(JSON.stringify({cmd: 'connect', adapter: $store.selected_adapter, bitrate: parseInt($store.selected_bitrate)}))"
} >
Connect to CAN
</button>
if (mes != null) { <button
handleCommand(mes) x-show="$store.can_connected"
} else { x-cloak
console.log(`${event.data} is not valid JSON`) class="btn btn-danger btn-lg"
} type="button"
}; @click="socket.send(JSON.stringify({cmd: 'disconnect'}))"
>
socket.onclose = function (event) { Disconnect
if (event.wasClean) { </button>
alert(`[close] Connection closed cleanly, code=${event.code} reason=${event.reason}`); </div>
} else { </div>
// e.g. server process killed or network down </div>
// event.code is usually 1006 in this case </div>
console.log('[close] Connection died');
}
};
socket.onerror = function (error) {
console.log(`[error]`);
};
function handleCommand(command) {
switch (command.cmd) {
case "value":
console.log("CHANGE VALUE");
Alpine.store(command.name, command.value);
break;
}
}
</script>
</head>
<body>
<h1>Alox Debug Tool</h1>
<div x-data="windowBox('window_id' ,100, 100)" @mousemove.window="onDrag" @mouseup.window="stopDrag"
@mousedown="focus" class="card shadow-lg position-absolute"
:class="{ 'w-100 h-100 m-0 shadow-none': fullscreen }"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '400px'};`"
x-cloak>
<div class="card-header bg-dark text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag" @dblclick="toggleFullscreen">
<h6 class="mb-0">CAN Interface</h6>
<div class="d-flex align-items-center gap-1">
<span class="badge me-1"
:class="socket.readyState === 1 ? 'bg-success' : 'bg-danger'">WS</span>
<button class="btn btn-sm btn-outline-light py-0 px-2" @click="toggleFullscreen">
<span></span>
</button>
<button class="btn btn-sm btn-outline-light py-0 px-2" @click="minimized = !minimized">
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
<div x-show="!minimized" class="flex-grow-1 overflow-auto">
<div class="card-body">
<p>HIER DER INHALT DER COMPONENT</p>
</div>
</div>
</div>
<div x-data="windowBox('can_config', 100, 100)" @mousemove.window="onDrag" @mouseup.window="stopDrag"
@mousedown="focus" class="card shadow-lg position-absolute"
:class="{ 'w-100 h-100 m-0 shadow-none': fullscreen }"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '400px'};`"
x-cloak>
<div class="card-header bg-dark text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag" @dblclick="toggleFullscreen">
<h6 class="mb-0">CAN Interface</h6>
<div class="d-flex align-items-center gap-1">
<span class="badge me-1"
:class="socket.readyState === 1 ? 'bg-success' : 'bg-danger'">WS</span>
<button class="btn btn-sm btn-outline-light py-0 px-2" @click="toggleFullscreen">
<span></span>
</button>
<button class="btn btn-sm btn-outline-light py-0 px-2" @click="minimized = !minimized">
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
<div x-show="!minimized" class="flex-grow-1 overflow-auto">
<div class="card-body">
<label class="form-label small fw-bold text-uppercase text-muted">Interface</label>
<div class="input-group mb-3" x-data="{ open: false }" @click.outside="open = false">
<button class="btn btn-outline-secondary dropdown-toggle" type="button"
@click="open = !open" :disabled="$store.can_connected">
Adapter
</button>
<ul class="dropdown-menu" :class="{ 'show': open }" x-show="open"
style="display: block;">
<template x-for="adapter in $store.adapters">
<li>
<button class="dropdown-item" type="button"
x-text="adapter"
@click="$store.selected_adapter = adapter; open = false"></button>
</li>
</template>
</ul>
<input type="text" class="form-control bg-light" readonly
:value="$store.selected_adapter || 'Select Interface...'">
</div>
<label class="form-label small fw-bold text-uppercase text-muted">Bitrate (kbps)</label>
<div class="input-group mb-4" x-data="{ open: false }" @click.outside="open = false">
<button class="btn btn-outline-secondary dropdown-toggle" type="button"
@click="open = !open" :disabled="$store.can_connected">
Speed
</button>
<ul class="dropdown-menu" :class="{ 'show': open }" x-show="open"
style="display: block;">
<template
x-for="rate in ['10', '20', '50', '100', '125', '250', '500', '800', '1000']">
<li>
<button class="dropdown-item" type="button"
x-text="rate + ' kbps'"
@click="$store.selected_bitrate = rate; open = false"></button>
</li>
</template>
</ul>
<input type="text" class="form-control bg-light" readonly
:value="$store.selected_bitrate ? $store.selected_bitrate + ' kbps' : 'Select Speed...'">
</div>
<div class="d-grid">
<button x-show="!$store.can_connected" class="btn btn-primary btn-lg"
type="button"
:disabled="!$store.selected_adapter || !$store.selected_bitrate"
@click="socket.send(JSON.stringify({cmd: 'connect', adapter: $store.selected_adapter, bitrate: parseInt($store.selected_bitrate)}))">
Connect to CAN
</button>
<button x-show="$store.can_connected" x-cloak class="btn btn-danger btn-lg"
type="button" @click="socket.send(JSON.stringify({cmd: 'disconnect'}))">
Disconnect
</button>
</div>
</div>
</div>
</div>
<div x-data="windowBox('can_log', 500, 50)" @mousemove.window="onDrag" @mouseup.window="stopDrag"
@mousedown="focus" class="card shadow-lg position-absolute draggable-card"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '500px'};`"
x-cloak>
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag">
<h6 class="mb-0">📜 CAN Log</h6>
<div class="d-flex gap-1">
<button class="btn btn-sm btn-outline-light py-0" @click="toggleMinimize">
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
<div x-show="!minimized" class="card-body bg-dark text-success font-monospace small"
style="height: 200px; overflow-y: auto;">
<div>[0.001] ID: 0x123 Data: FF AA 00</div>
<div>[0.005] ID: 0x456 Data: 12 34 56</div>
</div>
</div>
</body>
<div
x-data="windowBox('can_log', 500, 50)"
@mousemove.window="onDrag"
@mouseup.window="stopDrag"
@mousedown="focus"
class="card shadow-lg position-absolute draggable-card"
:style="`left: ${pos.x}px; top: ${pos.y}px; z-index: ${zIndex}; width: ${fullscreen ? '100vw' : '500px'};`"
x-cloak
>
<div
class="card-header bg-primary text-white d-flex justify-content-between align-items-center drag-handle"
@mousedown="startDrag"
>
<h6 class="mb-0">📜 CAN Log</h6>
<div class="d-flex gap-1">
<button
class="btn btn-sm btn-outline-light py-0"
@click="toggleMinimize"
>
<span x-text="minimized ? '+' : ''"></span>
</button>
</div>
</div>
<div
x-show="!minimized"
class="card-body bg-dark text-success font-monospace small"
style="height: 200px; overflow-y: auto"
>
<div>[0.001] ID: 0x123 Data: FF AA 00</div>
<div>[0.005] ID: 0x456 Data: 12 34 56</div>
</div>
</div>
</body>
</html> </html>

View File

@ -0,0 +1,95 @@
function windowBox(id, initialX = 50, initialY = 50) {
// Load saved data or user defaults
const saved = JSON.parse(localStorage.getItem(`win_${id}`)) || {
x: initialX,
y: initialY,
min: false,
};
return {
id: id,
pos: { x: saved.x, y: saved.y },
lastPos: { x: saved.x, y: saved.y },
dragging: false,
minimized: saved.min,
fullscreen: false,
zIndex: Alpine.store("ui").topZ,
offset: { x: 0, y: 0 },
init() {
// Move window in viewport when browser is other size
this.keepInBounds();
},
focus() {
this.zIndex = Alpine.store("ui").getNewZ();
},
startDrag(e) {
if (e.target.closest("button") || this.fullscreen) return;
this.focus();
this.dragging = true;
this.offset.x = e.clientX - this.pos.x;
this.offset.y = e.clientY - this.pos.y;
},
onDrag(e) {
if (!this.dragging) return;
// Calc new position
let newX = e.clientX - this.offset.x;
let newY = e.clientY - this.offset.y;
// Boundary Check
const margin = 20;
this.pos.x = Math.max(
margin - 350,
Math.min(newX, window.innerWidth - 50),
);
this.pos.y = Math.max(0, Math.min(newY, window.innerHeight - 40));
},
stopDrag() {
this.dragging = false;
this.save();
},
keepInBounds() {
if (this.pos.x > window.innerWidth) this.pos.x = window.innerWidth - 400;
if (this.pos.y > window.innerHeight) this.pos.y = 50;
},
save() {
localStorage.setItem(
`win_${this.id}`,
JSON.stringify({
x: this.pos.x,
y: this.pos.y,
min: this.minimized,
}),
);
},
reset() {
localStorage.removeItem(`win_${this.id}`);
location.reload();
},
toggleMinimize() {
this.minimized = !this.minimized;
this.save();
},
toggleFullscreen() {
if (!this.fullscreen) {
this.lastPos = { ...this.pos }; // Save Position
this.pos = { x: 0, y: 0 };
this.fullscreen = true;
} else {
this.pos = { ...this.lastPos }; // Back to old Position
this.fullscreen = false;
}
this.focus();
},
};
}

View File

@ -1,4 +1,4 @@
# Convetions # Conventions
## Naming ## Naming