Add configurable TIMEZONE for web UI display (UTC storage preserved)

This commit is contained in:
2026-07-17 12:02:58 +07:00
parent 559025d5f7
commit 513b8ede84
12 changed files with 131 additions and 7 deletions
+18 -2
View File
@@ -86,7 +86,7 @@
<td>{{ c.current_cpu_percent | round(1) if c.current_cpu_percent is not none else '-' }}%</td>
<td>{{ c.current_ram_percent | round(1) if c.current_ram_percent is not none else '-' }}%</td>
<td>{{ c.os_info or '-' }}</td>
<td class="last-seen">{% if c.last_seen %}{{ c.last_seen.strftime('%Y-%m-%d %H:%M') }}{% else %}-{% endif %}</td>
<td class="last-seen">{{ c.last_seen | localtime }}</td>
<td>
<a href="/computers/{{ c.id }}" class="btn btn-sm btn-outline-primary">Детали</a>
{% if user.role == 'admin' %}
@@ -116,6 +116,22 @@ function formatCurrentUser(value) {
return escapeHtml(value);
}
function formatServerTime(isoString) {
if (!isoString) return '-';
const d = new Date(isoString);
const parts = new Intl.DateTimeFormat('sv-SE', {
timeZone: window.SERVER_TIMEZONE,
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit',
hour12: false,
}).formatToParts(d);
const p = {};
for (const part of parts) {
if (part.type !== 'literal') p[part.type] = part.value;
}
return `${p.year}-${p.month}-${p.day} ${p.hour}:${p.minute}`;
}
function currentQuery() {
return new URLSearchParams(window.location.search).toString();
}
@@ -173,7 +189,7 @@ async function loadDashboard() {
<td>${c.current_cpu_percent != null ? c.current_cpu_percent.toFixed(1) : '-'}%</td>
<td>${c.current_ram_percent != null ? c.current_ram_percent.toFixed(1) : '-'}%</td>
<td>${escapeHtml(c.os_info || '-')}</td>
<td class="last-seen">${c.last_seen ? c.last_seen.replace('T', ' ').slice(0, 16) : '-'}</td>
<td class="last-seen">${formatServerTime(c.last_seen)}</td>
<td>
<a href="/computers/${c.id}" class="btn btn-sm btn-outline-primary">Детали</a>
${isAdmin ? `<button class="btn btn-sm btn-outline-danger delete-pc" data-id="${c.id}" data-hostname="${escapeHtml(c.hostname)}">Удалить</button>` : ''}