Files
2026-02-20 17:50:40 +00:00

315 lines
10 KiB
C

#ifndef WEB_FILES_H
#define WEB_FILES_H
const char HTML_FILES[] = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Manager - ESP32 Logger</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #1a1a2e;
color: #eee;
line-height: 1.6;
}
.header {
background: #16213e;
padding: 1rem;
text-align: center;
border-bottom: 2px solid #e94560;
}
.header h1 { color: #e94560; font-size: 1.5rem; }
.nav {
background: #0f3460;
padding: 0.5rem;
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 0.5rem;
}
.nav a {
color: #fff;
text-decoration: none;
padding: 0.5rem 1rem;
border-radius: 4px;
transition: background 0.3s;
}
.nav a:hover, .nav a.active { background: #e94560; }
.container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
.toolbar {
background: #16213e;
padding: 1rem;
border-radius: 8px;
margin-bottom: 1rem;
display: flex;
gap: 1rem;
flex-wrap: wrap;
}
.btn {
background: #e94560;
color: #fff;
border: none;
padding: 0.5rem 1rem;
border-radius: 4px;
cursor: pointer;
transition: background 0.3s;
}
.btn:hover { background: #ff6b6b; }
.btn:disabled { background: #666; cursor: not-allowed; }
.file-list {
background: #16213e;
border-radius: 8px;
overflow: hidden;
}
.file-header {
display: grid;
grid-template-columns: 40px 2fr 1fr 1fr 120px;
padding: 1rem;
background: #0f3460;
font-weight: bold;
}
.file-item {
display: grid;
grid-template-columns: 40px 2fr 1fr 1fr 120px;
padding: 1rem;
border-bottom: 1px solid #0f3460;
align-items: center;
}
.file-item:hover { background: #1a1a2e; }
.file-item:last-child { border-bottom: none; }
.checkbox {
width: 20px;
height: 20px;
cursor: pointer;
}
.file-name { color: #00d9ff; }
.file-size { color: #aaa; }
.file-date { color: #aaa; }
.file-actions {
display: flex;
gap: 0.5rem;
}
.btn-small {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.btn-blue { background: #3498db; }
.btn-red { background: #e74c3c; }
.empty-state {
text-align: center;
padding: 3rem;
color: #666;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background: #16213e;
padding: 2rem;
border-radius: 8px;
max-width: 500px;
width: 90%;
}
.modal h3 { margin-bottom: 1rem; color: #e94560; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; }
.form-group input, .form-group textarea {
width: 100%;
padding: 0.5rem;
background: #0f3460;
border: 1px solid #e94560;
color: #fff;
border-radius: 4px;
}
.modal-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 1rem;
}
</style>
</head>
<body>
<div class="header">
<h1>File Manager</h1>
</div>
<nav class="nav">
<a href="/">Dashboard</a>
<a href="/graph">Graph</a>
<a href="/files" class="active">Files</a>
<a href="/can">CAN Transmit</a>
<a href="/settings">Settings</a>
</nav>
<div class="container">
<div class="toolbar">
<button class="btn" id="btnSelectAll" onclick="toggleSelectAll()">Select All</button>
<button class="btn" onclick="downloadSelected()" id="btnDownload">Download Selected</button>
<button class="btn btn-red" onclick="deleteSelected()" id="btnDelete">Delete Selected</button>
<button class="btn" onclick="refreshFiles()">Refresh</button>
</div>
<div class="file-list" id="fileList">
<div class="file-header">
<input type="checkbox" class="checkbox" onchange="toggleSelectAll()">
<div>Name</div>
<div>Size</div>
<div>Date</div>
<div>Actions</div>
</div>
<div id="fileItems"></div>
</div>
</div>
<div class="modal" id="commentModal">
<div class="modal-content">
<h3>Add Comment</h3>
<div class="form-group">
<label>Comment:</label>
<textarea id="commentText" rows="3"></textarea>
</div>
<div class="modal-actions">
<button class="btn" onclick="closeModal()">Cancel</button>
<button class="btn btn-blue" onclick="saveComment()">Save</button>
</div>
</div>
</div>
<script>
let files = [];
let selectedFiles = new Set();
let currentCommentFile = null;
function loadFiles() {
fetch('/api/files')
.then(r => r.json())
.then(data => {
files = data;
renderFiles();
});
}
function renderFiles() {
const container = document.getElementById('fileItems');
if (files.length === 0) {
container.innerHTML = '<div class="empty-state">No log files found</div>';
return;
}
container.innerHTML = files.map(file => `
<div class="file-item">
<input type="checkbox" class="checkbox"
${selectedFiles.has(file.name) ? 'checked' : ''}
onchange="toggleFile('${file.name}')">
<div class="file-name">${file.name}</div>
<div class="file-size">${formatSize(file.size)}</div>
<div class="file-date">${file.date}</div>
<div class="file-actions">
<button class="btn btn-small btn-blue" onclick="downloadFile('${file.name}')">Download</button>
<button class="btn btn-small" onclick="showCommentModal('${file.name}')">Comment</button>
<button class="btn btn-small btn-red" onclick="deleteFile('${file.name}')">Delete</button>
</div>
</div>
`).join('');
}
function formatSize(bytes) {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1024*1024) return (bytes/1024).toFixed(1) + ' KB';
return (bytes/(1024*1024)).toFixed(1) + ' MB';
}
function toggleFile(name) {
if (selectedFiles.has(name)) {
selectedFiles.delete(name);
} else {
selectedFiles.add(name);
}
updateToolbar();
}
function toggleSelectAll() {
if (selectedFiles.size === files.length) {
selectedFiles.clear();
} else {
files.forEach(f => selectedFiles.add(f.name));
}
renderFiles();
updateToolbar();
}
function updateToolbar() {
const hasSelection = selectedFiles.size > 0;
document.getElementById('btnDownload').disabled = !hasSelection;
document.getElementById('btnDelete').disabled = !hasSelection;
}
function downloadFile(name) {
window.location.href = '/api/files/download?name=' + encodeURIComponent(name);
}
function downloadSelected() {
selectedFiles.forEach(name => downloadFile(name));
}
function deleteFile(name) {
if (!confirm('Delete ' + name + '?')) return;
fetch('/api/files/delete?name=' + encodeURIComponent(name), {method: 'DELETE'})
.then(() => loadFiles());
}
function deleteSelected() {
if (!confirm('Delete ' + selectedFiles.size + ' files?')) return;
selectedFiles.forEach(name => {
fetch('/api/files/delete?name=' + encodeURIComponent(name), {method: 'DELETE'});
});
selectedFiles.clear();
setTimeout(loadFiles, 500);
}
function showCommentModal(name) {
currentCommentFile = name;
document.getElementById('commentModal').style.display = 'flex';
}
function closeModal() {
document.getElementById('commentModal').style.display = 'none';
currentCommentFile = null;
}
function saveComment() {
const comment = document.getElementById('commentText').value;
// TODO: Save comment
closeModal();
}
function refreshFiles() {
loadFiles();
}
loadFiles();
</script>
</body>
</html>
)rawliteral";
#endif // WEB_FILES_H