доработка README
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -10,6 +11,10 @@ import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -33,6 +38,215 @@ func writeJSON(w http.ResponseWriter, v any) {
|
||||
json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
|
||||
// HandleLogFiles - список доступных лог-файлов
|
||||
func (a *API) HandleLogFiles(w http.ResponseWriter, r *http.Request) {
|
||||
dataDir, err := logger.GetDataLogsDir()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
files, err := filepath.Glob(filepath.Join(dataDir, "gpio-*.bin"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
type LogFileInfo struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
ModTime time.Time `json:"mod_time"`
|
||||
Time string `json:"time"`
|
||||
Date string `json:"date"`
|
||||
Hour int `json:"hour"`
|
||||
IsActive bool `json:"is_active"`
|
||||
}
|
||||
|
||||
var result []LogFileInfo
|
||||
for _, file := range files {
|
||||
info, err := os.Stat(file)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Парсим имя файла: gpio-2026-06-16-11.bin
|
||||
base := filepath.Base(file)
|
||||
parts := strings.Split(strings.TrimSuffix(base, ".bin"), "-")
|
||||
|
||||
var fileTime time.Time
|
||||
if len(parts) == 5 {
|
||||
year, _ := strconv.Atoi(parts[1])
|
||||
month, _ := strconv.Atoi(parts[2])
|
||||
day, _ := strconv.Atoi(parts[3])
|
||||
hour, _ := strconv.Atoi(parts[4])
|
||||
fileTime = time.Date(year, time.Month(month), day, hour, 0, 0, 0, time.Local)
|
||||
} else {
|
||||
fileTime = info.ModTime()
|
||||
}
|
||||
|
||||
result = append(result, LogFileInfo{
|
||||
Name: base,
|
||||
Path: file,
|
||||
Size: info.Size(),
|
||||
ModTime: info.ModTime(),
|
||||
Time: fileTime.Format("02.01.2006 15:00"),
|
||||
Date: fileTime.Format("2006-01-02"),
|
||||
Hour: fileTime.Hour(),
|
||||
IsActive: false,
|
||||
})
|
||||
}
|
||||
|
||||
// Сортируем по времени (новые сверху)
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].ModTime.After(result[j].ModTime)
|
||||
})
|
||||
|
||||
writeJSON(w, result)
|
||||
}
|
||||
|
||||
// HandleLogData - чтение данных из конкретного bin файла
|
||||
func (a *API) HandleLogData(w http.ResponseWriter, r *http.Request) {
|
||||
filename := r.URL.Query().Get("file")
|
||||
if filename == "" {
|
||||
http.Error(w, "missing file parameter", 400)
|
||||
return
|
||||
}
|
||||
|
||||
// Защита от path traversal
|
||||
filename = filepath.Base(filename)
|
||||
dataDir, err := logger.GetDataLogsDir()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
filePath := filepath.Join(dataDir, filename)
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
http.Error(w, "file not found", 404)
|
||||
return
|
||||
}
|
||||
|
||||
// Читаем бинарный файл
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
type Sample struct {
|
||||
Timestamp int64 `json:"ts"`
|
||||
Time string `json:"time"`
|
||||
Value byte `json:"value"`
|
||||
Count byte `json:"count"`
|
||||
Strength byte `json:"strength"`
|
||||
StrengthName string `json:"strength_name"`
|
||||
}
|
||||
|
||||
var samples []Sample
|
||||
buf := make([]byte, 9) // 8 байт timestamp + 1 байт value
|
||||
|
||||
for {
|
||||
n, err := f.Read(buf)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
if n < 9 {
|
||||
continue
|
||||
}
|
||||
|
||||
ts := int64(binary.LittleEndian.Uint64(buf[0:8]))
|
||||
value := buf[8]
|
||||
|
||||
data := logger.ParseGPIO(value)
|
||||
|
||||
samples = append(samples, Sample{
|
||||
Timestamp: ts,
|
||||
Time: time.UnixMicro(ts).Format("2006-01-02 15:04:05.000"),
|
||||
Value: value,
|
||||
Count: data.Count,
|
||||
Strength: data.Strength,
|
||||
StrengthName: logger.GetStrengthName(data.Strength),
|
||||
})
|
||||
}
|
||||
|
||||
// Ограничиваем количество точек для производительности
|
||||
if len(samples) > 10000 {
|
||||
// Берем каждую N-ю точку
|
||||
step := len(samples) / 10000
|
||||
var filtered []Sample
|
||||
for i := 0; i < len(samples); i += step {
|
||||
filtered = append(filtered, samples[i])
|
||||
}
|
||||
samples = filtered
|
||||
}
|
||||
|
||||
writeJSON(w, map[string]any{
|
||||
"filename": filename,
|
||||
"total": len(samples),
|
||||
"samples": samples,
|
||||
})
|
||||
}
|
||||
|
||||
// HandleLogEvents - чтение событий
|
||||
func (a *API) HandleLogEvents(w http.ResponseWriter, r *http.Request) {
|
||||
limit := 100
|
||||
if l := r.URL.Query().Get("limit"); l != "" {
|
||||
if parsed, err := strconv.Atoi(l); err == nil {
|
||||
limit = parsed
|
||||
}
|
||||
}
|
||||
|
||||
eventsPath, err := logger.GetEventHumanLogPath()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(eventsPath)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
lines := strings.Split(string(content), "\n")
|
||||
// Берем последние N строк
|
||||
if len(lines) > limit+1 {
|
||||
lines = lines[len(lines)-limit-1:]
|
||||
}
|
||||
|
||||
// Парсим строки для JSON
|
||||
type Event struct {
|
||||
Time string `json:"time"`
|
||||
Event string `json:"event"`
|
||||
}
|
||||
|
||||
var events []Event
|
||||
for _, line := range lines {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
// Формат: [2026-06-16 11:23:45.123] EVENT: СЕРВЕР_ЗАПУЩЕН
|
||||
parts := strings.SplitN(line, "] EVENT: ", 2)
|
||||
if len(parts) == 2 {
|
||||
events = append(events, Event{
|
||||
Time: strings.TrimPrefix(parts[0], "["),
|
||||
Event: parts[1],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
writeJSON(w, map[string]any{
|
||||
"events": events,
|
||||
"total": len(events),
|
||||
})
|
||||
}
|
||||
|
||||
func (a *API) HandleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
latest, ok := a.buf.GetLatest()
|
||||
idle := time.Since(a.buf.LastWriteTime())
|
||||
@@ -299,6 +513,12 @@ func main() {
|
||||
case "/cam":
|
||||
// Передаем URL камеры из конфигурации
|
||||
handleCamProxyWithURL(w, r, *cameraURL)
|
||||
case "/log/files":
|
||||
cors(api.HandleLogFiles)(w, r)
|
||||
case "/log/data":
|
||||
cors(api.HandleLogData)(w, r)
|
||||
case "/log/events":
|
||||
cors(api.HandleLogEvents)(w, r)
|
||||
default:
|
||||
http.Error(w, "not found", 404)
|
||||
}
|
||||
|
||||
@@ -31,3 +31,7 @@
|
||||
|
||||
#### Установка TypeScript и типов Node.js
|
||||
```npm install -D typescript @types/node```
|
||||
|
||||
```bash
|
||||
chmod +x node_modules/.bin/tsc
|
||||
```
|
||||
@@ -13,11 +13,11 @@
|
||||
|
||||
<div class="header-bar">
|
||||
<h1>GPIO МОНИТОРИНГ В РЕАЛЬНОМ ВРЕМЕНИ</h1>
|
||||
<div id="server-time" class="header-time">--:--:--</div>
|
||||
<button id="camToggle" class="cam-btn">
|
||||
<span class="cam-btn-icon">📷</span>
|
||||
<span class="cam-btn-text">Камера</span>
|
||||
</button>
|
||||
<div style="display:flex; gap:12px; align-items:center;">
|
||||
<a href="/logs.html" style="color:#00ff88; text-decoration:none; font-size:14px; border:1px solid #00ff88; padding:6px 14px; border-radius:6px;">📋 Журнал</a>
|
||||
<div id="server-time" class="header-time">--:--:--</div>
|
||||
<button id="camToggle" class="cam-btn">📷 КАМЕРА</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layout">
|
||||
@@ -63,11 +63,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card wide">
|
||||
<h3>ГРАФИК КАНАЛА 1</h3>
|
||||
<canvas id="signalChart" height="120"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="card wide">
|
||||
<h3 class="accordion-header" id="history-header">▶ ПРИНЯТЫЕ ДАННЫЕ</h3>
|
||||
<div class="accordion-body" id="history-body">
|
||||
@@ -82,7 +77,7 @@
|
||||
<div class="resizer" id="dragBar"></div>
|
||||
|
||||
<!-- RIGHT: камера -->
|
||||
<div class="panel right" id="rightPanel">
|
||||
<div class="panel right hidden" id="rightPanel">
|
||||
<div class="cam-modal">
|
||||
<div class="cam-header">
|
||||
<span>Видео с камеры</span>
|
||||
|
||||
@@ -18,8 +18,6 @@ export function initCamera(): void {
|
||||
camImage = document.getElementById("camImage") as HTMLImageElement;
|
||||
crosshair = document.getElementById("crosshair");
|
||||
|
||||
// Проверяем доступность потока
|
||||
checkStreamAvailability();
|
||||
|
||||
const btn = document.getElementById("camToggle");
|
||||
|
||||
@@ -37,6 +35,7 @@ export function initCamera(): void {
|
||||
// Показываем перекрестие
|
||||
if (crosshair) {
|
||||
crosshair.style.display = "block";
|
||||
crosshair.style.opacity = "0.5";
|
||||
}
|
||||
|
||||
if (camImage) {
|
||||
@@ -114,29 +113,6 @@ export function initCamera(): void {
|
||||
|
||||
btn?.addEventListener("click", toggle);
|
||||
|
||||
// Проверка доступности камеры
|
||||
async function checkStreamAvailability(): Promise<void> {
|
||||
try {
|
||||
const response = await fetch('/api/stream');
|
||||
const data: StreamResponse = await response.json();
|
||||
|
||||
if (data.available && data.cam) {
|
||||
console.log("[camera] stream available:", data.source);
|
||||
// Автозапуск если камера доступна
|
||||
if (!isOpen) {
|
||||
open();
|
||||
}
|
||||
} else {
|
||||
console.log("[camera] stream not available");
|
||||
if (crosshair) {
|
||||
crosshair.style.display = 'none';
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("[camera] check failed:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// Мониторинг состояния потока
|
||||
function startStreamMonitoring(): void {
|
||||
stopStreamMonitoring();
|
||||
|
||||
373
cmd/server/web/logs.html
Normal file
373
cmd/server/web/logs.html
Normal file
@@ -0,0 +1,373 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Журнал логов</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
<style>
|
||||
/* Дополнительные стили для журнала */
|
||||
.logs-container {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
height: calc(100vh - 120px);
|
||||
}
|
||||
|
||||
.logs-sidebar {
|
||||
flex: 0 0 280px;
|
||||
border-right: 1px solid #00ff88;
|
||||
padding-right: 16px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.logs-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.log-file-item {
|
||||
padding: 8px 12px;
|
||||
margin: 4px 0;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
border: 1px solid transparent;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.log-file-item:hover {
|
||||
background: rgba(0,255,136,0.1);
|
||||
border-color: #00ff88;
|
||||
}
|
||||
|
||||
.log-file-item.active {
|
||||
background: rgba(0,255,136,0.2);
|
||||
border-color: #00ff88;
|
||||
}
|
||||
|
||||
.log-file-item .file-name {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.log-file-item .file-info {
|
||||
font-size: 11px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.log-stats {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.log-stat-card {
|
||||
padding: 12px;
|
||||
border: 1px solid #00ff88;
|
||||
border-radius: 4px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.log-stat-card .value {
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.log-stat-card .label {
|
||||
font-size: 11px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
text-align: left;
|
||||
padding: 6px 8px;
|
||||
border-bottom: 1px solid #00ff88;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: #050805;
|
||||
}
|
||||
|
||||
.data-table td {
|
||||
padding: 4px 8px;
|
||||
border-bottom: 1px solid rgba(0,255,136,0.1);
|
||||
}
|
||||
|
||||
.data-table tr:hover {
|
||||
background: rgba(0,255,136,0.05);
|
||||
}
|
||||
|
||||
.strength-0 { color: #666; }
|
||||
.strength-1 { color: #88ff88; }
|
||||
.strength-2 { color: #ffaa44; }
|
||||
.strength-3 { color: #ff4444; }
|
||||
|
||||
.events-list {
|
||||
font-family: monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.events-list .event-time {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
padding: 6px 16px;
|
||||
background: transparent;
|
||||
color: #00ff88;
|
||||
border: 1px solid #00ff88;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.tab-btn.active {
|
||||
background: rgba(0,255,136,0.2);
|
||||
}
|
||||
|
||||
.tab-btn:hover {
|
||||
background: rgba(0,255,136,0.1);
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="header-bar">
|
||||
<h1>📋 ЖУРНАЛ ЛОГОВ</h1>
|
||||
<div id="server-time" class="header-time">--:--:--</div>
|
||||
<a href="/" style="color:#00ff88; text-decoration:none; font-size:14px;">← На главную</a>
|
||||
</div>
|
||||
|
||||
<div class="logs-container">
|
||||
<div class="logs-sidebar">
|
||||
<h3 style="margin-top:0;">📁 Файлы данных</h3>
|
||||
<div id="fileList"></div>
|
||||
</div>
|
||||
|
||||
<div class="logs-content">
|
||||
<div class="tabs">
|
||||
<button class="tab-btn active" data-tab="data">📊 Данные</button>
|
||||
<button class="tab-btn" data-tab="stats">📈 Статистика</button>
|
||||
<button class="tab-btn" data-tab="events">📋 События</button>
|
||||
</div>
|
||||
|
||||
<div id="tab-data" class="tab-content active">
|
||||
<div id="logStats" class="log-stats"></div>
|
||||
<div id="chartContainer" style="margin-bottom:16px;">
|
||||
<canvas id="logChart" height="200"></canvas>
|
||||
</div>
|
||||
<div id="dataTableContainer" style="max-height:400px; overflow-y:auto;"></div>
|
||||
</div>
|
||||
|
||||
<div id="tab-stats" class="tab-content">
|
||||
<div id="statsContent">Выберите файл для просмотра статистики</div>
|
||||
</div>
|
||||
|
||||
<div id="tab-events" class="tab-content">
|
||||
<div id="eventsContent" class="events-list">Загрузка...</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
import { drawChart } from '/dist/chart.js';
|
||||
|
||||
// Состояние
|
||||
let currentFile = null;
|
||||
let currentData = null;
|
||||
let currentEvents = [];
|
||||
|
||||
// DOM элементы
|
||||
const fileList = document.getElementById('fileList');
|
||||
const logStats = document.getElementById('logStats');
|
||||
const dataTableContainer = document.getElementById('dataTableContainer');
|
||||
const logChart = document.getElementById('logChart');
|
||||
const eventsContent = document.getElementById('eventsContent');
|
||||
|
||||
// Загрузка списка файлов
|
||||
async function loadFileList() {
|
||||
try {
|
||||
const response = await fetch('/api/log/files');
|
||||
const files = await response.json();
|
||||
|
||||
fileList.innerHTML = '';
|
||||
files.forEach(file => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'log-file-item';
|
||||
if (currentFile === file.name) div.classList.add('active');
|
||||
div.innerHTML = `
|
||||
<div class="file-name">${file.name}</div>
|
||||
<div class="file-info">${file.time} | ${(file.size/1024).toFixed(1)} KB</div>
|
||||
`;
|
||||
div.addEventListener('click', () => loadFileData(file.name));
|
||||
fileList.appendChild(div);
|
||||
});
|
||||
|
||||
// Автоматически загружаем первый файл
|
||||
if (files.length > 0 && !currentFile) {
|
||||
loadFileData(files[0].name);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading file list:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Загрузка данных файла
|
||||
async function loadFileData(filename) {
|
||||
currentFile = filename;
|
||||
|
||||
// Обновляем активный элемент в списке
|
||||
document.querySelectorAll('.log-file-item').forEach(el => el.classList.remove('active'));
|
||||
const items = document.querySelectorAll('.log-file-item');
|
||||
for (const item of items) {
|
||||
if (item.textContent.includes(filename)) {
|
||||
item.classList.add('active');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/log/data?file=${encodeURIComponent(filename)}`);
|
||||
const data = await response.json();
|
||||
currentData = data;
|
||||
|
||||
renderData(data);
|
||||
} catch (error) {
|
||||
console.error('Error loading data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Отрисовка данных
|
||||
function renderData(data) {
|
||||
const samples = data.samples || [];
|
||||
|
||||
// Статистика
|
||||
if (samples.length > 0) {
|
||||
const values = samples.map(s => s.value);
|
||||
const counts = samples.map(s => s.count);
|
||||
const max = Math.max(...values);
|
||||
const min = Math.min(...values);
|
||||
const avg = values.reduce((a,b) => a + b, 0) / values.length;
|
||||
const totalObjects = counts.reduce((a,b) => a + b, 0);
|
||||
|
||||
logStats.innerHTML = `
|
||||
<div class="log-stat-card">
|
||||
<div class="value">${samples.length}</div>
|
||||
<div class="label">Всего точек</div>
|
||||
</div>
|
||||
<div class="log-stat-card">
|
||||
<div class="value">${max}</div>
|
||||
<div class="label">Максимум</div>
|
||||
</div>
|
||||
<div class="log-stat-card">
|
||||
<div class="value">${avg.toFixed(1)}</div>
|
||||
<div class="label">Среднее</div>
|
||||
</div>
|
||||
<div class="log-stat-card">
|
||||
<div class="value">${totalObjects}</div>
|
||||
<div class="label">Объектов всего</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// График
|
||||
if (logChart && samples.length > 0) {
|
||||
const history = samples.map(s => s.count);
|
||||
drawChart(logChart, history);
|
||||
}
|
||||
|
||||
// Таблица — только Время, Объектов, Сила
|
||||
if (samples.length > 0) {
|
||||
let html = `<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Время</th>
|
||||
<th>Объектов</th>
|
||||
<th>Сила</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>`;
|
||||
|
||||
const displaySamples = samples.slice(-200);
|
||||
displaySamples.forEach(s => {
|
||||
const strengthClass = `strength-${s.strength}`;
|
||||
html += `<tr>
|
||||
<td>${s.time}</td>
|
||||
<td>${s.count}</td>
|
||||
<td class="${strengthClass}">${s.strength_name}</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
html += '</tbody></table>';
|
||||
dataTableContainer.innerHTML = html;
|
||||
} else {
|
||||
dataTableContainer.innerHTML = '<p>Нет данных</p>';
|
||||
}
|
||||
}
|
||||
|
||||
// Загрузка событий
|
||||
async function loadEvents() {
|
||||
try {
|
||||
const response = await fetch('/api/log/events?limit=200');
|
||||
const data = await response.json();
|
||||
currentEvents = data.events || [];
|
||||
|
||||
let html = '';
|
||||
currentEvents.forEach(e => {
|
||||
html += `<div><span class="event-time">[${e.time}]</span> ${e.event}</div>`;
|
||||
});
|
||||
eventsContent.innerHTML = html || 'Нет событий';
|
||||
} catch (error) {
|
||||
eventsContent.innerHTML = 'Ошибка загрузки событий';
|
||||
}
|
||||
}
|
||||
|
||||
// Переключение табов
|
||||
document.querySelectorAll('.tab-btn[data-tab]').forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
document.querySelectorAll('.tab-btn[data-tab]').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
|
||||
const tabName = btn.dataset.tab;
|
||||
document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
|
||||
document.getElementById(`tab-${tabName}`).classList.add('active');
|
||||
|
||||
if (tabName === 'events') {
|
||||
loadEvents();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Инициализация
|
||||
loadFileList();
|
||||
|
||||
// Обновление времени
|
||||
function updateTime() {
|
||||
const now = new Date();
|
||||
document.getElementById('server-time').textContent = now.toLocaleTimeString();
|
||||
}
|
||||
setInterval(updateTime, 1000);
|
||||
updateTime();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user