-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.html
More file actions
497 lines (457 loc) · 18.8 KB
/
Copy pathdashboard.html
File metadata and controls
497 lines (457 loc) · 18.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cronologia esportazioni — Strumento Poster</title>
<link rel="stylesheet" href="css/base.css">
<style>
/* Dashboard-specific overrides — base.css defines tokens (--accent, --border, --text, ...) */
html, body { overflow: auto; }
body {
background: var(--bg-app);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
font-size: 13px;
}
.page {
max-width: 1100px;
margin: 32px auto;
padding: 0 20px 64px;
}
.header {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
padding-bottom: 14px;
border-bottom: 1px solid var(--border);
margin-bottom: 20px;
flex-wrap: wrap;
}
.header h1 { font-size: 22px; font-weight: 700; margin: 0 0 2px; letter-spacing: -0.3px; }
.header p { color: var(--text-muted); margin: 0; font-size: 12px; }
.btn {
padding: 7px 12px;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
font-size: 12px;
font-weight: 500;
color: var(--text);
background: var(--bg-panel);
cursor: pointer;
transition: background var(--transition), border-color var(--transition);
display: inline-flex; align-items: center; gap: 6px;
font-family: inherit;
}
.btn:hover { background: var(--bg-section-hov); border-color: #bbb; }
.btn--accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--accent:hover { background: var(--accent-hov); border-color: var(--accent-hov); }
.btn--danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; }
.toolbar {
display: flex; gap: 10px; flex-wrap: wrap;
align-items: flex-end;
padding: 12px 14px;
background: var(--bg-panel);
border: 1px solid var(--border);
border-radius: var(--radius);
margin-bottom: 16px;
}
.toolbar .field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 180px; }
.toolbar label {
font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
color: var(--text-muted); font-weight: 700;
}
.toolbar select, .toolbar input[type="text"] {
padding: 6px 8px; border: 1px solid var(--border);
border-radius: var(--radius-sm); font-size: 12px;
font-family: inherit; color: var(--text);
background: var(--bg-panel); outline: none;
transition: border-color var(--transition);
}
.toolbar select:focus, .toolbar input[type="text"]:focus { border-color: var(--border-focus); }
.toolbar .stretch { margin-left: auto; }
.tablewrap {
background: var(--bg-panel);
border: 1px solid var(--border);
border-radius: var(--radius);
overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; }
th {
font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
color: var(--text-muted); font-weight: 700;
background: var(--bg-section);
border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-section); }
.col-actions { text-align: right; white-space: nowrap; }
.col-actions .btn { padding: 4px 8px; font-size: 11px; }
.badge {
display: inline-block;
padding: 2px 7px;
border-radius: 999px;
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.04em;
background: var(--bg-section);
color: var(--text-muted);
}
.badge--png { background: rgba(34,197,94,0.12); color: #16803c; }
.badge--pdf { background: rgba(239,68,68,0.12); color: #b91c1c; }
.badge--json { background: rgba(79,142,247,0.14); color: #1e57c8; }
.empty {
padding: 48px 16px;
text-align: center;
color: var(--text-muted);
font-size: 13px;
}
.src {
display: inline-block;
font-size: 9px;
text-transform: uppercase;
letter-spacing: 0.08em;
padding: 1px 6px;
border-radius: 4px;
margin-left: 6px;
background: rgba(0,0,0,0.05);
color: var(--text-muted);
}
/* Confirmation modal */
.modal-backdrop {
position: fixed; inset: 0;
background: rgba(0,0,0,0.4);
display: none;
align-items: center; justify-content: center;
z-index: 1000;
}
.modal-backdrop.show { display: flex; }
.modal {
background: var(--bg-panel);
padding: 22px 26px;
border-radius: var(--radius);
max-width: 380px; width: 92%;
box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
.modal h2 { margin: 0 0 6px; font-size: 16px; }
.modal p { margin: 0 0 18px; color: var(--text-muted); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.toast {
position: fixed;
bottom: 18px; right: 18px;
padding: 10px 18px;
background: #1a1a1a; color: #fff;
border-radius: var(--radius);
font-size: 12px;
box-shadow: 0 6px 22px rgba(0,0,0,0.18);
transform: translateY(80px);
transition: transform 0.25s cubic-bezier(0.175,0.885,0.32,1.275);
z-index: 1100;
}
.toast.show { transform: translateY(0); }
</style>
</head>
<body>
<div class="page">
<div class="header">
<div>
<h1>Cronologia esportazioni</h1>
<p>Tutte le esportazioni effettuate su questo browser. <span id="src-info" class="src">solo locale</span></p>
</div>
<div style="display:flex; gap:8px;">
<a href="index.html" class="btn">← Torna all'editor</a>
<button class="btn btn--danger" id="btn-clear">Svuota cronologia</button>
</div>
</div>
<div class="toolbar">
<div class="field">
<label for="filter-month">Mese</label>
<select id="filter-month">
<option value="all">Tutti i mesi</option>
</select>
</div>
<div class="field">
<label for="filter-format">Formato</label>
<select id="filter-format">
<option value="all">Tutti</option>
<option value="png">PNG</option>
<option value="pdf">PDF</option>
<option value="json">JSON</option>
</select>
</div>
<div class="field" style="flex:2">
<label for="filter-search">Cerca per titolo</label>
<input type="text" id="filter-search" placeholder="Cerca…">
</div>
<div class="stretch">
<span id="count" style="font-size:11px;color:var(--text-muted)"></span>
</div>
</div>
<div class="tablewrap">
<table id="logs-table">
<thead>
<tr>
<th>Data e ora</th>
<th>Titolo</th>
<th>Formato</th>
<th>Formato pagina</th>
<th class="col-actions">Azioni</th>
</tr>
</thead>
<tbody id="logs-body"></tbody>
</table>
<div class="empty" id="empty" style="display:none">
Nessuna esportazione registrata.
</div>
</div>
</div>
<!-- Confirm modal -->
<div class="modal-backdrop" id="modal-backdrop">
<div class="modal">
<h2 id="modal-title">Sei sicuro?</h2>
<p id="modal-text">Questa azione non può essere annullata.</p>
<div class="modal-actions">
<button class="btn" id="modal-cancel">Annulla</button>
<button class="btn btn--accent" id="modal-ok">Conferma</button>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
// ──────────────────────────────────────────────────────────────
// State
// ──────────────────────────────────────────────────────────────
let allLogs = []; // merged local + server
let serverAvailable = false;
const LS_KEY = 'poster_logs';
// ──────────────────────────────────────────────────────────────
// Helpers
// ──────────────────────────────────────────────────────────────
const $ = (id) => document.getElementById(id);
function escHTML(s) {
return String(s == null ? '' : s)
.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')
.replace(/"/g,'"').replace(/'/g,''');
}
function formatDate(iso) {
if (!iso) return '—';
// Accept ISO ('2026-01-01T...') or 'YYYY-MM-DD HH:MM:SS'
const d = new Date(typeof iso === 'string' ? iso.replace(' ', 'T') : iso);
if (isNaN(d)) return iso;
return d.toLocaleString('it-IT');
}
function monthKey(iso) {
if (typeof iso !== 'string') return '';
// Take YYYY-MM regardless of separator (T or space)
return iso.substring(0, 7);
}
function safeFilename(title) {
return String(title || 'export').replace(/[/\\?%*:|"<>]/g, '-').trim().slice(0, 64) || 'export';
}
function showToast(msg) {
const t = $('toast');
t.textContent = msg;
t.classList.add('show');
clearTimeout(showToast._t);
showToast._t = setTimeout(() => t.classList.remove('show'), 2500);
}
function confirmDialog(title, text) {
return new Promise(resolve => {
$('modal-title').textContent = title;
$('modal-text').textContent = text;
$('modal-backdrop').classList.add('show');
const cleanup = (val) => {
$('modal-backdrop').classList.remove('show');
$('modal-cancel').onclick = null;
$('modal-ok').onclick = null;
resolve(val);
};
$('modal-cancel').onclick = () => cleanup(false);
$('modal-ok').onclick = () => cleanup(true);
});
}
// ──────────────────────────────────────────────────────────────
// Data loading — local + (optional) server, deduped by id
// ──────────────────────────────────────────────────────────────
function loadLocal() {
try {
const raw = localStorage.getItem(LS_KEY);
const arr = raw ? JSON.parse(raw) : [];
return Array.isArray(arr) ? arr.map(e => ({ ...e, _src: 'local' })) : [];
} catch (e) {
console.warn('[dashboard] localStorage read failed:', e);
return [];
}
}
async function loadServer() {
try {
// Try the dashboard endpoint first; fall back to none if 404 (static host).
const res = await fetch('dashboard_api.php?action=list_logs&t=' + Date.now(), { cache: 'no-store' });
if (!res.ok) return [];
const data = await res.json();
if (data.status !== 'success' || !Array.isArray(data.logs)) return [];
serverAvailable = true;
return data.logs.map(e => ({ ...e, _src: 'server' }));
} catch (e) {
return [];
}
}
function mergeLogs(local, server) {
// Dedupe by id, prefer the entry that has state attached.
const map = new Map();
const consider = (e) => {
if (!e || e.id == null) return;
const prev = map.get(e.id);
if (!prev) { map.set(e.id, e); return; }
// Prefer entry with state; otherwise keep first.
if (!prev.state && e.state) map.set(e.id, e);
};
local.forEach(consider);
server.forEach(consider);
// Sort newest first
return [...map.values()].sort((a, b) => {
const ta = new Date(typeof a.timestamp === 'string' ? a.timestamp.replace(' ','T') : a.timestamp).getTime() || 0;
const tb = new Date(typeof b.timestamp === 'string' ? b.timestamp.replace(' ','T') : b.timestamp).getTime() || 0;
return tb - ta;
});
}
async function reload() {
const [local, server] = await Promise.all([Promise.resolve(loadLocal()), loadServer()]);
allLogs = mergeLogs(local, server);
$('src-info').textContent = serverAvailable ? 'locale + server' : 'solo locale';
buildMonthFilter();
render();
}
// ──────────────────────────────────────────────────────────────
// Filtering / rendering
// ──────────────────────────────────────────────────────────────
function buildMonthFilter() {
const sel = $('filter-month');
const current = sel.value;
const months = [...new Set(allLogs.map(l => monthKey(l.timestamp)).filter(Boolean))]
.sort().reverse();
const labels = { '01':'Gennaio','02':'Febbraio','03':'Marzo','04':'Aprile','05':'Maggio','06':'Giugno','07':'Luglio','08':'Agosto','09':'Settembre','10':'Ottobre','11':'Novembre','12':'Dicembre' };
let html = '<option value="all">Tutti i mesi</option>';
months.forEach(m => {
const [y, mm] = m.split('-');
html += `<option value="${m}">${labels[mm] || mm} ${y}</option>`;
});
sel.innerHTML = html;
sel.value = months.includes(current) ? current : 'all';
}
function getFiltered() {
const month = $('filter-month').value;
const format = $('filter-format').value;
const search = $('filter-search').value.toLowerCase().trim();
return allLogs.filter(l => {
if (month !== 'all' && monthKey(l.timestamp) !== month) return false;
if (format !== 'all' && l.format !== format) return false;
if (search && !String(l.title || '').toLowerCase().includes(search)) return false;
return true;
});
}
function render() {
const tbody = $('logs-body');
const filtered = getFiltered();
$('count').textContent = `${filtered.length} di ${allLogs.length}`;
if (filtered.length === 0) {
tbody.innerHTML = '';
$('empty').style.display = 'block';
$('empty').textContent = allLogs.length === 0
? 'Nessuna esportazione registrata.'
: 'Nessun risultato per i filtri selezionati.';
return;
}
$('empty').style.display = 'none';
tbody.innerHTML = filtered.map(l => {
const fmt = String(l.format || '').toLowerCase();
const fmtClass = (fmt === 'png' || fmt === 'pdf' || fmt === 'json') ? `badge--${fmt}` : '';
return `
<tr data-id="${escHTML(l.id)}">
<td style="color:var(--text-muted)">
${escHTML(formatDate(l.timestamp))}
<span class="src">${escHTML(l._src)}</span>
</td>
<td><strong>${escHTML(l.title || 'Senza Titolo')}</strong></td>
<td><span class="badge ${fmtClass}">${escHTML(l.format || '—')}</span></td>
<td style="color:var(--text-muted)">${escHTML(l.sizeId || '—')}</td>
<td class="col-actions">
${l.state ? `<button class="btn" data-action="download">↓ JSON</button>` : ''}
<button class="btn btn--danger" data-action="delete">Elimina</button>
</td>
</tr>`;
}).join('');
}
// ──────────────────────────────────────────────────────────────
// Actions
// ──────────────────────────────────────────────────────────────
function downloadEntry(entry) {
if (!entry.state) {
showToast('Questa voce non ha lo stato salvato.');
return;
}
const filename = `${safeFilename(entry.title)}_${(entry.timestamp || '').replace(/[: ]/g, '-')}.json`;
const blob = new Blob([JSON.stringify(entry.state, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url; a.download = filename; a.click();
setTimeout(() => URL.revokeObjectURL(url), 5000);
}
async function deleteEntry(entry) {
const ok = await confirmDialog('Elimina voce', `Vuoi davvero eliminare l'export di "${entry.title || 'Senza Titolo'}"?`);
if (!ok) return;
// Local removal
try {
const raw = localStorage.getItem(LS_KEY);
const arr = raw ? JSON.parse(raw) : [];
if (Array.isArray(arr)) {
const next = arr.filter(e => String(e.id) !== String(entry.id));
localStorage.setItem(LS_KEY, JSON.stringify(next));
}
} catch (e) { console.warn('[dashboard] local delete failed:', e); }
// Server removal (best effort — only if server endpoint is present)
if (serverAvailable) {
try {
await fetch(`dashboard_api.php?action=delete_log&id=${encodeURIComponent(entry.id)}`, { cache: 'no-store' });
} catch (e) { /* ignore */ }
}
showToast('Voce eliminata.');
reload();
}
async function clearAll() {
const ok = await confirmDialog('Svuota cronologia', 'Verranno rimosse TUTTE le voci da questo browser. Procedere?');
if (!ok) return;
try { localStorage.removeItem(LS_KEY); } catch (e) {}
if (serverAvailable) {
try { await fetch('dashboard_api.php?action=clear_logs', { cache: 'no-store' }); } catch (e) {}
}
showToast('Cronologia svuotata.');
reload();
}
// Event delegation for table actions
$('logs-body').addEventListener('click', (e) => {
const btn = e.target.closest('button[data-action]');
if (!btn) return;
const tr = btn.closest('tr');
if (!tr) return;
const id = tr.dataset.id;
const entry = allLogs.find(l => String(l.id) === String(id));
if (!entry) return;
if (btn.dataset.action === 'download') downloadEntry(entry);
if (btn.dataset.action === 'delete') deleteEntry(entry);
});
// Filter listeners
$('filter-month').addEventListener('change', render);
$('filter-format').addEventListener('change', render);
$('filter-search').addEventListener('input', render);
$('btn-clear').addEventListener('click', clearAll);
// Init
reload();
</script>
</body>
</html>