Skip to content

Commit bb4b52e

Browse files
committed
feat(ui): Improve device card with collapsible device info and table layout
Refactored the device information section in `device_card.html` to use a table for better alignment and readability. Implemented a collapsible section for device details, controlled by a new toggle button and JavaScript function. Enhanced visual hierarchy by bolding the labels within the device info table. Also, updated German translations to include the new "Device Info" string.
1 parent ccaad48 commit bb4b52e

File tree

5 files changed

+211
-115
lines changed

5 files changed

+211
-115
lines changed

tronbyt_server/static/css/manager.css

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,3 +1086,50 @@ button.action.w3-button {
10861086
box-sizing: border-box;
10871087
}
10881088
}
1089+
1090+
.device-info-toggle {
1091+
background-color: #f1f1f1;
1092+
color: #333;
1093+
cursor: pointer;
1094+
padding: 10px;
1095+
width: 100%;
1096+
border: none;
1097+
text-align: left;
1098+
font-size: 0.9375rem;
1099+
transition: 0.4s;
1100+
}
1101+
1102+
.device-info-toggle:focus-visible {
1103+
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.5);
1104+
}
1105+
1106+
.device-info-toggle:hover {
1107+
background-color: #ddd;
1108+
}
1109+
1110+
.device-info-content {
1111+
padding: 0 15px;
1112+
overflow: hidden;
1113+
transition: max-height 0.2s ease-out, padding-top 0.2s ease-out, padding-bottom 0.2s ease-out;
1114+
max-height: 0;
1115+
}
1116+
1117+
.device-info-content.is-expanded {
1118+
padding-top: 5px;
1119+
padding-bottom: 5px;
1120+
}
1121+
1122+
.device-info-table {
1123+
width: 100%;
1124+
border-collapse: collapse;
1125+
}
1126+
1127+
.device-info-table td:first-child {
1128+
font-weight: bold;
1129+
}
1130+
1131+
.device-info-table td {
1132+
padding: 4px;
1133+
text-align: left;
1134+
font-size: 0.9em;
1135+
}

tronbyt_server/static/js/manager.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ let draggedIname = null;
403403
document.addEventListener('DOMContentLoaded', function() {
404404
initializeDragAndDrop();
405405
initializeViewToggles();
406+
initializeDeviceInfoToggles();
406407

407408
const webpImages = document.querySelectorAll('[id^="currentWebp-"]');
408409
webpImages.forEach(image => {
@@ -426,6 +427,12 @@ function initializeViewToggles() {
426427
});
427428
}
428429

430+
function initializeDeviceInfoToggles() {
431+
document.querySelectorAll('.device-info-toggle').forEach(button => {
432+
button.addEventListener('click', () => toggleDeviceInfo(button));
433+
});
434+
}
435+
429436
function restoreDevicePreferences(deviceId) {
430437
const prefs = loadDevicePreferences(deviceId);
431438
const appsList = document.getElementById(`appsList-${deviceId}`);
@@ -903,3 +910,27 @@ function handleDropZoneDrop(e) {
903910
// Clean up
904911
zone.classList.remove('active');
905912
}
913+
914+
function toggleDeviceInfo(button) {
915+
const content = document.getElementById(button.getAttribute('aria-controls'));
916+
if (!content) {
917+
return;
918+
}
919+
const icon = button.querySelector('i');
920+
const isExpanded = button.getAttribute('aria-expanded') === 'true';
921+
922+
button.setAttribute('aria-expanded', !isExpanded);
923+
content.classList.toggle('is-expanded');
924+
925+
if (!isExpanded) {
926+
content.style.maxHeight = content.scrollHeight + "px";
927+
if (icon) {
928+
icon.classList.replace('fa-chevron-down', 'fa-chevron-up');
929+
}
930+
} else {
931+
content.style.maxHeight = '0px';
932+
if (icon) {
933+
icon.classList.replace('fa-chevron-up', 'fa-chevron-down');
934+
}
935+
}
936+
}

tronbyt_server/templates/partials/device_card.html

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,31 @@ <h1>
3030
</div>
3131
<div>{{ _('Currently Displaying App') }}</div>
3232
<div class="device-info-box">
33-
{% if device.info.firmware_version %}
34-
<div>{{ _('Firmware Version:') }} {{ device.info.firmware_version }}</div>
35-
{% endif %}
36-
{% if device.info.firmware_type %}
37-
<div>{{ _('Firmware Type:') }} {{ device.info.firmware_type }}</div>
38-
{% endif %}
39-
{% if device.info.protocol_version %}
40-
<div>{{ _('Protocol Version:') }} {{ device.info.protocol_version }}</div>
41-
{% endif %}
42-
{% if device.info.mac_address %}
43-
<div>{{ _('MAC Address:') }} {{ device.info.mac_address }}</div>
44-
{% endif %}
45-
{% if device.info.protocol_type %}
46-
<div>{{ _('Protocol Type:') }} {{ device.info.protocol_type.value }}</div>
47-
{% endif %}
48-
{% if device.last_seen %}
49-
<div>{{ _('Last Seen:') }} {{ device.last_seen.astimezone().strftime('%Y-%m-%d %H:%M:%S') }}</div>
50-
{% endif %}
33+
<button class="device-info-toggle" aria-expanded="false" aria-controls="device-info-content-{{ device.id }}">
34+
<i class="fas fa-chevron-down"></i> {{ _('Device Info') }}
35+
</button>
36+
<div id="device-info-content-{{ device.id }}" class="device-info-content">
37+
<table class="device-info-table">
38+
{% if device.info.firmware_version %}
39+
<tr><td>{{ _('Firmware Version:') }}</td><td>{{ device.info.firmware_version }}</td></tr>
40+
{% endif %}
41+
{% if device.info.firmware_type %}
42+
<tr><td>{{ _('Firmware Type:') }}</td><td>{{ device.info.firmware_type }}</td></tr>
43+
{% endif %}
44+
{% if device.info.protocol_version %}
45+
<tr><td>{{ _('Protocol Version:') }}</td><td>{{ device.info.protocol_version }}</td></tr>
46+
{% endif %}
47+
{% if device.info.mac_address %}
48+
<tr><td>{{ _('MAC Address:') }}</td><td>{{ device.info.mac_address }}</td></tr>
49+
{% endif %}
50+
{% if device.info.protocol_type %}
51+
<tr><td>{{ _('Protocol Type:') }}</td><td>{{ device.info.protocol_type.value }}</td></tr>
52+
{% endif %}
53+
{% if device.last_seen %}
54+
<tr><td>{{ _('Last Seen:') }}</td><td>{{ device.last_seen.astimezone().strftime('%Y-%m-%d %H:%M:%S') }}</td></tr>
55+
{% endif %}
56+
</table>
57+
</div>
5158
</div>
5259
</td>
5360
</tr>
180 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)