-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
773 lines (681 loc) · 44.8 KB
/
dashboard.html
File metadata and controls
773 lines (681 loc) · 44.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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<!DOCTYPE html>
<html lang="nl" class="h-full dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>G2 Ultimate Console | Proxlan Style</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<script src="tailwind_config.js"></script>
<link rel="stylesheet" href="app_styles.css">
<style>
body { font-family: 'Inter', sans-serif; }
/* Glassmorphism Effecten */
.glass-panel {
background: rgba(30, 41, 59, 0.7);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid rgba(255, 255, 255, 0.05);
}
.main-layout {
display: grid;
grid-template-columns: 280px 600px 1fr;
height: 100vh;
gap: 0;
background: radial-gradient(circle at top right, #1e293b, #0f172a);
}
/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar { width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
/* Actieve item animatie */
.item-active {
background: linear-gradient(90deg, rgba(99, 102, 241, 0.15) 0%, rgba(99, 102, 241, 0) 100%);
border-left: 4px solid rgb(var(--color-primary));
}
/* Status Glow */
.glow-green { box-shadow: 0 0 12px rgba(16, 185, 129, 0.4); }
.glow-primary { box-shadow: 0 0 15px rgba(99, 102, 241, 0.3); }
textarea.editor-canvas {
background: #0f172a;
color: #94a3b8;
font-family: 'Fira Code', monospace;
border-radius: 12px;
box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
}
.size-bar {
height: 2px;
background: rgba(255,255,255,0.05);
margin-top: 12px;
border-radius: 2px;
overflow: hidden;
}
.size-fill {
height: 100%;
background: rgb(var(--color-primary));
}
</style>
</head>
<body class="h-full text-slate-300 bg-dark overflow-hidden">
<input type="file" id="import-input" class="hidden" accept=".json" onchange="handleImportFile()">
<div class="main-layout">
<aside class="flex flex-col border-r border-white/5 bg-dark/40 shadow-2xl z-20">
<div class="p-8">
<div class="flex items-center gap-3 mb-2">
<div class="w-10 h-10 bg-primary rounded-xl flex items-center justify-center shadow-lg glow-primary text-white">
<i class="fas fa-database text-xl"></i>
</div>
<div>
<h1 class="text-white font-bold text-lg leading-none">G2 Console</h1>
<span class="text-[10px] text-primary font-bold uppercase tracking-widest">Enterprise API</span>
</div>
</div>
<div id="api-indicator" class="mt-4 px-3 py-1.5 bg-dark_paper rounded-lg border border-white/5 text-[10px] font-mono text-slate-500 hidden truncate"></div>
</div>
<nav class="flex-grow px-4 custom-scrollbar overflow-y-auto">
<div class="space-y-8">
<div>
<span class="px-4 text-[10px] font-bold text-slate-500 uppercase tracking-widest">Overzicht</span>
<div class="mt-4 space-y-1">
<div id="filter-all" onclick="applyFilter('ALL', null)" class="flex justify-between items-center px-4 py-3 rounded-xl cursor-pointer hover:bg-white/5 transition-all group">
<span class="group-hover:text-white transition-colors font-medium"><i class="fas fa-globe-europe mr-3 opacity-50"></i>Alles</span>
<span id="count-all" class="bg-primary/20 text-primary text-[10px] font-bold px-2 py-0.5 rounded-md">0</span>
</div>
</div>
</div>
<div>
<span class="px-4 text-[10px] font-bold text-slate-500 uppercase tracking-widest">Applicaties</span>
<div id="list-apps" class="mt-4 space-y-1"></div>
</div>
<div>
<span class="px-4 text-[10px] font-bold text-slate-500 uppercase tracking-widest">Gebruikers</span>
<div id="list-users" class="mt-4 space-y-1"></div>
</div>
</div>
</nav>
<div class="p-6 bg-dark_paper/30 border-t border-white/5">
<div class="flex justify-between items-center mb-3">
<span class="text-[10px] font-bold text-slate-500 uppercase">Systeem Status</span>
<div class="flex gap-2">
<button onclick="clearErrorLogs()" class="text-slate-500 hover:text-red-400 transition" title="Wis error logs"><i class="fas fa-trash-alt"></i></button>
<button onclick="setApiUrl()" class="text-slate-500 hover:text-white transition"><i class="fas fa-cog"></i></button>
</div>
</div>
<div id="list-errors" class="space-y-2 max-h-32 overflow-y-auto custom-scrollbar"></div>
</div>
</aside>
<main class="flex flex-col bg-dark/20 z-10 border-r border-white/5">
<header class="p-8 pb-4">
<div class="flex justify-between items-end mb-6">
<div>
<h2 id="list-title" class="text-2xl font-bold text-white tracking-tight">Endpoints</h2>
<p class="text-xs text-slate-500 mt-1" id="stat-db-size">Database: 0.00 MB</p>
</div>
<button onclick="refresh()" class="p-3 rounded-xl bg-white/5 hover:bg-white/10 text-slate-400 transition-all border border-white/5">
<i id="refresh-icon" class="fas fa-sync-alt"></i>
</button>
</div>
<div class="flex bg-dark_paper/50 p-1 rounded-xl border border-white/5 w-full">
<button onclick="switchMode('DB')" id="mode-btn-db" class="flex-1 py-2 rounded-lg text-xs font-bold bg-primary text-white shadow-lg transition-all">
<i class="fas fa-database mr-2"></i>Database
</button>
<button onclick="switchMode('FILES')" id="mode-btn-files" class="flex-1 py-2 rounded-lg text-xs font-bold text-slate-500 hover:text-white transition-all">
<i class="fas fa-file-alt mr-2"></i>Files
</button>
</div>
</header>
<div id="endpoints-container" class="flex-grow px-6 pb-8 custom-scrollbar overflow-y-auto space-y-1 max-h-full">
</div>
</main>
<section class="relative flex flex-col h-full overflow-hidden">
<div id="detail-placeholder" class="absolute inset-0 flex flex-col items-center justify-center opacity-20 pointer-events-none">
<i class="fas fa-terminal text-9xl mb-6"></i>
<p class="text-xl font-medium">Selecteer Data Endpoint</p>
</div>
<div id="detail-content" class="hidden h-full flex flex-col">
<div class="p-8">
<div class="glass-panel p-6 rounded-2xl flex justify-between items-center shadow-2xl">
<div class="flex items-center gap-6">
<div class="p-4 bg-primary/10 rounded-2xl border border-primary/20">
<i class="fas fa-folder-open text-3xl text-primary"></i>
</div>
<div>
<div class="flex items-center gap-3">
<h2 id="det-name" class="text-3xl font-bold text-white tracking-tight">...</h2>
</div>
<div class="flex gap-2 mt-2">
<span id="det-lock-badge" class="hidden px-2 py-0.5 rounded-md text-[9px] font-black bg-red-500 text-white uppercase tracking-tighter">Read Only</span>
<span id="det-ttl-badge" class="hidden px-2 py-0.5 rounded-md text-[9px] font-black bg-blue-500 text-white uppercase tracking-tighter">Auto-Purge: <span id="det-ttl-val"></span>d</span>
</div>
</div>
</div>
<div class="flex gap-3">
<button onclick="renameEndpoint()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Hernoemen"><i class="fas fa-pencil-alt"></i></button>
<button onclick="downloadEndpoint()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Export"><i class="fas fa-download"></i></button>
<button onclick="triggerImport()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Import"><i class="fas fa-upload"></i></button>
<button onclick="doClone()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Kloon"><i class="fas fa-copy"></i></button>
<button onclick="truncateEndpoint()" class="w-10 h-10 rounded-xl bg-yellow-500/10 hover:bg-yellow-500/20 flex items-center justify-center text-yellow-500 transition border border-yellow-500/20" title="Leegmaken"><i class="fas fa-eraser"></i></button>
<button onclick="clearUserRecords()" class="w-10 h-10 rounded-xl bg-orange-500/10 hover:bg-orange-500/20 flex items-center justify-center text-orange-500 transition border border-orange-500/20" title="Verwijder gebruiker records"><i class="fas fa-user-times"></i></button>
<button onclick="dropEndpoint()" class="w-10 h-10 rounded-xl bg-red-500/10 hover:bg-red-500/20 flex items-center justify-center text-red-500 transition border border-red-500/20" title="Drop"><i class="fas fa-trash-alt"></i></button>
</div>
</div>
</div>
<div class="px-8 flex items-center justify-between gap-8 mb-6">
<div class="flex bg-dark_paper/50 p-1 rounded-xl border border-white/5">
<button onclick="switchTab('data')" id="tab-btn-data" class="px-6 py-2 rounded-lg text-sm font-bold bg-primary text-white shadow-lg transition-all">Data & Canvas</button>
<button onclick="switchTab('settings')" id="tab-btn-settings" class="px-6 py-2 rounded-lg text-sm font-bold text-slate-500 hover:text-white transition-all">Configuratie</button>
</div>
<div id="search-toolbar" class="flex-grow flex gap-3">
<div class="relative flex-grow">
<i class="fas fa-search absolute left-4 top-1/2 -translate-y-1/2 text-slate-500"></i>
<input type="text" id="search-term" placeholder="Zoek records op ID, eigenaar of inhoud..." class="w-full bg-dark_paper border border-white/5 rounded-xl pl-12 pr-4 py-2.5 text-sm text-white focus:border-primary outline-none transition-all shadow-xl">
</div>
<button onclick="doSearch()" class="px-8 py-2.5 bg-primary text-white rounded-xl text-sm font-bold shadow-lg shadow-primary/20 hover:opacity-90 transition">Query</button>
</div>
</div>
<div class="flex-grow px-8 pb-8 overflow-hidden">
<div class="glass-panel rounded-3xl h-full flex overflow-hidden border border-white/10 shadow-inner">
<div id="tab-data" class="flex h-full w-full">
<div class="w-[340px] border-r border-white/5 flex flex-col h-full bg-black/10">
<div class="p-4 border-b border-white/5 bg-dark/20">
<span class="text-[9px] font-bold text-slate-500 uppercase tracking-widest">Query Resultaten</span>
</div>
<div id="search-results" class="flex-grow overflow-y-auto custom-scrollbar p-3 space-y-2">
<div class="text-center mt-20 text-xs text-slate-600">Voer een zoekopdracht uit om data te inspecteren</div>
</div>
</div>
<div class="flex-grow flex flex-col h-full relative p-6">
<div id="editor-actions" class="hidden absolute top-4 right-4 z-50 flex flex-col gap-2">
<button onclick="saveRecord()" class="w-10 h-10 rounded-xl bg-emerald-500/10 hover:bg-emerald-500/20 flex items-center justify-center text-emerald-500 transition border border-emerald-500/20" title="Bewaar wijzigingen">
<i class="fas fa-save"></i>
</button>
<button onclick="deleteRecord()" class="w-10 h-10 rounded-xl bg-red-500/10 hover:bg-red-500/20 flex items-center justify-center text-red-500 transition border border-red-500/20" title="Verwijder record">
<i class="fas fa-trash"></i>
</button>
</div>
<div id="editor-placeholder" class="m-auto text-slate-600 text-sm">Selecteer een resultaat uit de lijst</div>
<textarea id="json-editor" class="editor-canvas flex-grow p-10 hidden custom-scrollbar outline-none"></textarea>
</div>
</div>
<div id="tab-settings" class="hidden w-full h-full p-12 overflow-y-auto">
<div class="max-w-xl mx-auto space-y-8">
<div class="space-y-4">
<h3 class="text-xl font-bold text-white">Toegangsbeheer</h3>
<div class="p-6 bg-dark_paper rounded-2xl flex items-center justify-between border border-white/5">
<div>
<p class="font-bold text-white">Endpoint Locking</p>
<p class="text-xs text-slate-500 mt-1">Voorkom alle schrijfacties (POST, PUT, DELETE) voor clients.</p>
</div>
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" id="set-locked" class="sr-only peer">
<div class="w-14 h-7 bg-slate-700 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-1 after:left-1 after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-red-500 shadow-lg"></div>
</label>
</div>
</div>
<div class="space-y-4 pt-4 border-t border-white/5">
<h3 class="text-xl font-bold text-white">Data Lifecycle</h3>
<div class="p-6 bg-dark_paper rounded-2xl flex items-center justify-between border border-white/5">
<div>
<p class="font-bold text-white">Automatische Retentie (TTL)</p>
<p class="text-xs text-slate-500 mt-1">Verwijder records die ouder zijn dan het aantal dagen.</p>
</div>
<div class="flex items-center gap-3">
<input type="number" id="set-ttl" class="w-20 bg-dark border border-white/10 rounded-xl p-2.5 text-center font-bold text-white focus:border-primary outline-none" placeholder="0">
<span class="text-sm font-bold">dagen</span>
</div>
</div>
</div>
<button onclick="saveSettings()" class="w-full py-4 bg-primary text-white rounded-2xl font-bold shadow-xl shadow-primary/20 hover:opacity-90 transition-all text-lg">Update Configuratie</button>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<script>
// --- API CONFIG ---
const REMOTE_IP = 'http://10.10.2.20:5000';
let API = window.location.origin;
function initializeApi() {
const isLocal = window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1' ||
window.location.protocol === 'file:' ||
window.location.hostname !== '10.10.2.20';
if (isLocal) {
API = localStorage.getItem('g2_api_url') || REMOTE_IP;
const ind = document.getElementById('api-indicator');
if (ind) {
ind.classList.remove('hidden');
ind.innerHTML = `<i class="fas fa-network-wired mr-2"></i>Remote: ${API}`;
}
}
}
initializeApi();
function setApiUrl() {
const current = localStorage.getItem('g2_api_url') || API;
const newVal = prompt("URL van de G2 Server:", current);
if (newVal) {
localStorage.setItem('g2_api_url', newVal.replace(/\/$/, ""));
window.location.reload();
}
}
let globalData = null;
let currentFilter = { type: 'ALL', value: null };
let currentEp = null;
let currentRecordId = null;
let currentFileClientId = null;
let currentMode = 'DB'; // 'DB' of 'FILES'
function switchMode(m) {
currentMode = m;
currentEp = null;
// UI Update voor buttons
document.getElementById('mode-btn-db').className = m === 'DB'
? "flex-1 py-2 rounded-lg text-xs font-bold bg-primary text-white shadow-lg transition-all"
: "flex-1 py-2 rounded-lg text-xs font-bold text-slate-500 hover:text-white transition-all";
document.getElementById('mode-btn-files').className = m === 'FILES'
? "flex-1 py-2 rounded-lg text-xs font-bold bg-primary text-white shadow-lg transition-all"
: "flex-1 py-2 rounded-lg text-xs font-bold text-slate-500 hover:text-white transition-all";
document.getElementById('list-title').innerText = m === 'DB' ? "Database Endpoints" : "File Endpoints";
document.getElementById('detail-content').classList.add('hidden');
document.getElementById('detail-placeholder').classList.remove('hidden');
renderEndpointsList();
}
async function refresh() {
const icon = document.getElementById('refresh-icon');
if(icon) icon.classList.add('fa-spin');
try {
const res = await fetch(`${API}/api/admin/stats`);
if(!res.ok) throw new Error("Offline");
globalData = await res.json();
document.getElementById('stat-db-size').innerText = `Database: ${globalData.db_info.data_size_mb} MB | Records: ${globalData.db_info.total_objects}`;
const endpointsToCount = currentMode === 'DB' ? globalData.endpoints : globalData.file_endpoints;
document.getElementById('count-all').innerText = endpointsToCount.length;
renderSidebar();
renderEndpointsList();
renderErrorLog();
if(currentEp) loadDetail(currentEp);
} catch(e) {
if(!globalData) {
document.getElementById('endpoints-container').innerHTML = `<div class="p-8 bg-red-500/10 border border-red-500/20 rounded-2xl text-red-500 text-sm font-bold text-center">G2 SERVER OFFLINE: ${API}</div>`;
} else {
console.warn("Background refresh failed, keeping cached data.");
}
} finally {
if(icon) setTimeout(() => icon.classList.remove('fa-spin'), 500);
}
}
function renderSidebar() {
if(!globalData) return;
const apps = {};
const endpointsToProcess = currentMode === 'DB' ? globalData.endpoints : globalData.file_endpoints;
endpointsToProcess.forEach(ep => {
if(ep.name.includes('_')) {
const app = ep.name.split('_')[0];
apps[app] = (apps[app] || 0) + 1;
}
});
document.getElementById('list-apps').innerHTML = Object.keys(apps).map(a =>
`<div class="flex justify-between items-center px-4 py-2.5 rounded-xl cursor-pointer hover:bg-white/5 transition-all group ${currentFilter.value === a ? 'item-active text-white' : ''}" onclick="applyFilter('APP', '${a}')">
<span class="text-sm font-medium group-hover:text-white transition-colors capitalize">${a}</span>
<span class="bg-dark_paper text-[9px] font-bold px-2 py-0.5 rounded-md">${apps[a]}</span>
</div>`
).join('');
// Voor gebruikers in File mode gebruiken we de eigenaren uit file_endpoints
let userList = [];
if(currentMode === 'DB') {
userList = globalData.clients.map(c => ({
id: c.client_id,
count: c.total_records,
last_seen: c.last_seen
}));
} else {
const fileOwners = {};
globalData.file_endpoints.forEach(ep => {
ep.owners.forEach(o => {
fileOwners[o] = (fileOwners[o] || 0) + ep.count;
});
});
userList = Object.keys(fileOwners).map(o => ({
id: o,
count: fileOwners[o],
last_seen: null
}));
}
document.getElementById('list-users').innerHTML = userList.map(u => `
<div class="flex justify-between items-center px-4 py-2.5 rounded-xl cursor-pointer hover:bg-white/5 transition-all group ${currentFilter.value === u.id ? 'item-active text-white' : ''}" onclick="applyFilter('USER', '${u.id}')">
<div class="flex flex-col overflow-hidden">
<span class="text-xs font-bold group-hover:text-white transition-colors truncate">${u.id}</span>
<span class="text-[9px] text-slate-600">${u.last_seen ? timeAgo(u.last_seen) : ''}</span>
</div>
<span class="bg-dark_paper text-[9px] font-bold px-2 py-0.5 rounded-md ml-2">${u.count}</span>
</div>
`).join('');
const allBtn = document.getElementById('filter-all');
if(currentFilter.type === 'ALL') allBtn.classList.add('item-active', 'bg-white/5');
else allBtn.classList.remove('item-active', 'bg-white/5');
}
function applyFilter(t, v) { currentFilter = { type: t, value: v }; renderSidebar(); renderEndpointsList(); }
function renderEndpointsList() {
if(!globalData) return;
const list = document.getElementById('endpoints-container');
let dataToRender = currentMode === 'DB' ? globalData.endpoints : globalData.file_endpoints;
let filtered = (currentFilter.type === 'ALL') ? dataToRender :
(currentFilter.type === 'APP') ? dataToRender.filter(e => e.name.startsWith(currentFilter.value + '_')) :
dataToRender.filter(e => e.owners && e.owners.includes(currentFilter.value));
list.innerHTML = filtered.map(ep => {
let statusClass = 'bg-red-500';
let statusText = 'Offline';
if(currentMode === 'DB') {
if(ep.last_activity && (new Date() - new Date(ep.last_activity)) < 3600000) {
statusClass = 'bg-emerald-500 glow-green';
statusText = 'Recent';
}
} else {
statusClass = 'bg-blue-500'; // Files hebben geen last_activity in stats nog
statusText = 'Files';
}
const active = currentEp === ep.name ? 'item-active bg-white/5 scale-[1.02]' : 'hover:bg-white/5';
const retentionText = (currentMode === 'FILES' || !ep.ttl || ep.ttl == 0) ? '∞' : `${ep.ttl}d`;
const lockText = ep.locked ? 'Locked' : 'Open';
const lockColor = ep.locked ? 'text-red-400' : 'text-emerald-400';
const icon = currentMode === 'DB' ? 'fa-database' : 'fa-folder';
const countInfo = currentMode === 'DB' ? ep.count : `${ep.count} files`;
const sizeInfo = currentMode === 'DB' ? `${ep.size_pct.toFixed(1)}%` : `${ep.size_mb} MB`;
return `<div class="px-4 py-3 rounded-xl glass-panel cursor-pointer transition-all duration-300 group ${active}" onclick="selectEp('${ep.name}')">
<div class="flex items-center justify-between gap-4">
<div class="flex items-center gap-3 min-w-0 flex-1">
<div class="w-2 h-2 rounded-full ${statusClass} flex-shrink-0" title="${statusText}"></div>
<div class="font-mono text-sm text-slate-200 font-bold tracking-tighter truncate min-w-0 flex-1">${ep.name}</div>
</div>
<div class="flex items-center gap-6 text-[11px] font-bold flex-shrink-0">
<div class="text-slate-300">
<i class="fas ${icon} mr-1 opacity-70"></i>${countInfo}
</div>
${currentMode === 'DB' ? `
<div class="text-slate-400">
<i class="fas fa-clock mr-1 opacity-70"></i>${retentionText}
</div>
<div class="${lockColor}">
<i class="fas fa-${ep.locked ? 'lock' : 'unlock'} mr-1 opacity-70"></i>${lockText}
</div>
` : ''}
<div class="text-slate-500">
<i class="fas fa-chart-bar mr-1 opacity-70"></i>${sizeInfo}
</div>
</div>
</div>
</div>`;
}).join('');
}
function selectEp(n) { currentEp = n; renderEndpointsList(); loadDetail(n); }
function loadDetail(n) {
if(!globalData) return;
const endpoints = currentMode === 'DB' ? globalData.endpoints : globalData.file_endpoints;
const ep = endpoints.find(e => e.name === n);
if(!ep) return;
document.getElementById('detail-content').classList.remove('hidden');
document.getElementById('detail-placeholder').classList.add('hidden');
document.getElementById('det-name').innerText = n;
// Verberg/toon DB specifieke opties
const dbElements = ['det-lock-badge', 'det-ttl-badge', 'tab-btn-settings', 'editor-actions'];
dbElements.forEach(id => {
const el = document.getElementById(id);
if(el) el.classList.toggle('hidden', currentMode === 'FILES');
});
if(currentMode === 'DB') {
document.getElementById('set-locked').checked = ep.locked;
document.getElementById('set-ttl').value = ep.ttl || 0;
document.getElementById('det-lock-badge').classList.toggle('hidden', !ep.locked);
document.getElementById('det-ttl-badge').classList.toggle('hidden', !(ep.ttl > 0));
if(ep.ttl > 0) document.getElementById('det-ttl-val').innerText = ep.ttl;
switchTab('data');
} else {
switchTab('data');
doSearch(); // Voor files is doSearch eigenlijk "load files"
}
}
async function doSearch() {
const term = document.getElementById('search-term').value;
if(currentMode === 'DB') {
const res = await fetch(`${API}/api/admin/search`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ collection: currentEp, term })});
const docs = await res.json();
document.getElementById('search-results').innerHTML = docs.map(d => `
<div class="p-4 bg-dark/40 border border-white/5 rounded-2xl mb-2 cursor-pointer hover:border-primary/50 hover:bg-primary/5 transition-all group" onclick="loadRecord('${d._id}')">
<div class="text-[11px] text-primary font-bold font-mono group-hover:scale-[1.02] transition-transform">${d._id}</div>
<div class="flex justify-between mt-2">
<span class="text-[9px] text-slate-500 font-bold uppercase tracking-tighter"><i class="fas fa-user-circle mr-1 opacity-50"></i>${d._client_id}</span>
<span class="text-[9px] text-slate-600">${d._created_at}</span>
</div>
</div>
`).join('');
} else {
// File mode: Lijst bestanden
const res = await fetch(`${API}/api/admin/files/${currentEp}`);
const files = await res.json();
// Filter files op search term indien aanwezig
const filteredFiles = term ? files.filter(f => f.filename.toLowerCase().includes(term.toLowerCase()) || f.client_id.toLowerCase().includes(term.toLowerCase())) : files;
document.getElementById('search-results').innerHTML = filteredFiles.map(f => `
<div class="p-4 bg-dark/40 border border-white/5 rounded-2xl mb-2 cursor-pointer hover:border-primary/50 hover:bg-primary/5 transition-all group" onclick="loadFile('${f.client_id}', '${f.filename}', '${f.url}')">
<div class="text-[11px] text-primary font-bold truncate group-hover:scale-[1.02] transition-transform">${f.filename}</div>
<div class="flex justify-between mt-2">
<span class="text-[9px] text-slate-500 font-bold uppercase tracking-tighter"><i class="fas fa-user-circle mr-1 opacity-50"></i>${f.client_id}</span>
<span class="text-[9px] text-slate-600">${(f.size/1024).toFixed(1)} KB</span>
</div>
</div>
`).join('');
}
}
function closeEditor() {
document.getElementById('json-editor').classList.add('hidden');
document.getElementById('editor-placeholder').classList.remove('hidden');
document.getElementById('editor-actions').classList.add('hidden');
currentRecordId = null;
currentFileClientId = null;
}
async function loadFile(clientId, filename, url) {
currentRecordId = filename;
currentFileClientId = clientId; // We hebben client_id nodig voor delete
const fullUrl = API + url;
// Toon een preview of info over het bestand
let content = `Bestand: ${filename}\nClient: ${clientId}\nURL: ${fullUrl}\n\n`;
if(filename.match(/\.(json|txt|js|css|html)$/i)) {
try {
const res = await fetch(fullUrl);
const text = await res.text();
content += "-- INHOUD --\n\n" + text;
} catch(e) { content += "[Kon inhoud niet laden]"; }
} else if(filename.match(/\.(jpg|jpeg|png|gif|svg|webp)$/i)) {
content += "[Afbeelding - open de URL voor weergave]";
} else {
content += "[Binair bestand]";
}
document.getElementById('json-editor').value = content;
document.getElementById('json-editor').classList.remove('hidden');
document.getElementById('editor-placeholder').classList.add('hidden');
// Custom actions voor files
const actions = document.getElementById('editor-actions');
actions.innerHTML = `
<a href="${fullUrl}" target="_blank" class="w-10 h-10 rounded-xl bg-blue-500/10 hover:bg-blue-500/20 flex items-center justify-center text-blue-500 transition border border-blue-500/20" title="Open in nieuw tabblad">
<i class="fas fa-external-link-alt"></i>
</a>
<button onclick="deleteFile('${clientId}', '${filename}')" class="w-10 h-10 rounded-xl bg-red-500/10 hover:bg-red-500/20 flex items-center justify-center text-red-500 transition border border-red-500/20" title="Verwijder bestand">
<i class="fas fa-trash"></i>
</button>
<button onclick="closeEditor()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Sluiten">
<i class="fas fa-times"></i>
</button>
`;
actions.classList.remove('hidden');
}
async function deleteFile(clientId, filename) {
if(!confirm(`Weet je zeker dat je ${filename} wilt verwijderen?`)) return;
const res = await fetch(`${API}/api/admin/files/${currentEp}/${clientId}/${filename}`, { method: 'DELETE' });
if(res.ok) {
document.getElementById('json-editor').classList.add('hidden');
document.getElementById('editor-placeholder').classList.remove('hidden');
document.getElementById('editor-actions').classList.add('hidden');
refresh();
}
}
async function loadRecord(id) {
currentRecordId = id;
const res = await fetch(`${API}/api/admin/search`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ collection: currentEp, term: id })});
const docs = await res.json();
if(docs[0]) {
document.getElementById('json-editor').value = JSON.stringify(docs[0], null, 4);
document.getElementById('json-editor').classList.remove('hidden');
document.getElementById('editor-placeholder').classList.add('hidden');
const actions = document.getElementById('editor-actions');
actions.innerHTML = `
<button onclick="saveRecord()" class="w-10 h-10 rounded-xl bg-emerald-500/10 hover:bg-emerald-500/20 flex items-center justify-center text-emerald-500 transition border border-emerald-500/20" title="Bewaar wijzigingen">
<i class="fas fa-save"></i>
</button>
<button onclick="deleteRecord()" class="w-10 h-10 rounded-xl bg-red-500/10 hover:bg-red-500/20 flex items-center justify-center text-red-500 transition border border-red-500/20" title="Verwijder record">
<i class="fas fa-trash"></i>
</button>
<button onclick="closeEditor()" class="w-10 h-10 rounded-xl bg-white/5 hover:bg-white/10 flex items-center justify-center text-slate-400 transition border border-white/10" title="Sluiten">
<i class="fas fa-times"></i>
</button>
`;
actions.classList.remove('hidden');
}
}
async function saveRecord() {
try {
const data = JSON.parse(document.getElementById('json-editor').value);
await fetch(`${API}/api/admin/record/${currentEp}/${currentRecordId}`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(data)});
refresh();
} catch(e) { console.error("Invalid JSON"); }
}
async function deleteRecord() {
console.log('Delete button clicked, currentRecordId:', currentRecordId);
if (!currentRecordId) {
console.log('No currentRecordId, returning');
return;
}
if (!confirm('Weet je zeker dat je dit record wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.')) return;
try {
console.log('Making DELETE request to:', `${API}/api/admin/record/${currentEp}/${currentRecordId}`);
const response = await fetch(`${API}/api/admin/record/${currentEp}/${currentRecordId}`, { method: 'DELETE' });
console.log('DELETE response:', response.status);
if (response.ok) {
// Clear the current record view
document.getElementById('json-editor').classList.add('hidden');
document.getElementById('editor-placeholder').classList.remove('hidden');
document.getElementById('editor-actions').classList.add('hidden');
currentRecordId = null;
refresh();
} else {
console.error('Failed to delete record');
}
} catch(e) {
console.error("Error deleting record:", e);
}
}
function triggerImport() { document.getElementById('import-input').click(); }
async function handleImportFile() {
const file = document.getElementById('import-input').files[0];
const owner = prompt("Eigenaar ID voor import?", currentFilter.type === 'USER' ? currentFilter.value : 'ADMIN_RESTORE');
const clear = confirm("⚠️ Collectie eerst leegmaken voor import?");
const reader = new FileReader();
reader.onload = async (e) => {
await fetch(`${API}/api/admin/import`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ collection: currentEp, records: JSON.parse(e.target.result), owner, clear_first: clear })});
refresh();
};
reader.readAsText(file);
}
async function truncateEndpoint() { if(confirm("⚠️ Alle data in deze collectie wissen?")) { await fetch(`${API}/api/admin/clear`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ collection: currentEp })}); refresh(); } }
async function clearUserRecords() {
const defaultUser = (currentFilter.type === 'USER') ? currentFilter.value : '';
const clientId = prompt("Client ID van de gebruiker wiens records je wilt verwijderen:", defaultUser);
if (!clientId) return;
if(confirm(`⚠️ Alle records van gebruiker "${clientId}" in deze collectie wissen?`)) {
await fetch(`${API}/api/admin/clear_user_records`, {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({ collection: currentEp, client_id: clientId })
});
refresh();
}
}
async function dropEndpoint() { if(confirm("⛔ COLLECTIE VOLLEDIG VERWIJDEREN?")) { await fetch(`${API}/api/admin/collections/${currentEp}`, { method: 'DELETE' }); window.location.reload(); } }
function downloadEndpoint() { window.location.href = `${API}/api/admin/export/${currentEp}`; }
async function doClone() { const d = prompt("Naam voor kopie:"); if(d) { await fetch(`${API}/api/admin/clone`, { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ source: currentEp, destination: d })}); refresh(); } }
async function renameEndpoint() {
const oldName = currentEp;
const newName = prompt("Nieuwe naam voor endpoint:", oldName);
if (newName && newName !== oldName) {
try {
// We gaan ervan uit dat de backend een clone+drop of een rename actie ondersteunt.
// Als er geen expliciete rename API is, gebruiken we clone als fallback logic.
const res = await fetch(`${API}/api/admin/clone`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ source: oldName, destination: newName })
});
if (res.ok) {
await fetch(`${API}/api/admin/collections/${oldName}`, { method: 'DELETE' });
currentEp = newName;
refresh();
}
} catch (e) { console.error(e); }
}
}
async function saveSettings() {
await fetch(`${API}/api/admin/settings`, {
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({
collection: currentEp,
locked: document.getElementById('set-locked').checked,
ttl_days: document.getElementById('set-ttl').value
})
});
refresh();
}
async function clearErrorLogs() {
if (!confirm('Weet je zeker dat je alle systeem error logs wilt wissen?')) return;
try {
const response = await fetch(`${API}/api/admin/clear_errors`, { method: 'POST' });
const result = await response.json();
if (response.ok) {
alert(`Succes: ${result.message}`);
refresh();
} else {
alert(`Fout: ${result.error}`);
}
} catch (e) {
alert(`Fout bij wissen error logs: ${e.message}`);
}
}
function renderErrorLog() {
if(!globalData) return;
document.getElementById('list-errors').innerHTML = globalData.errors.map(e => `
<div class="p-2 border-l-2 border-red-500 bg-red-500/5 text-[10px] text-red-400">
<span class="block text-slate-600 font-bold">${e.time.split('T')[1].substr(0,8)}</span> ${e.msg}
</div>
`).join('');
}
function switchTab(t) {
['data','settings'].forEach(x => {
document.getElementById(`tab-${x}`).classList.add('hidden');
document.getElementById(`tab-btn-${x}`).classList.remove('bg-primary', 'text-white', 'shadow-lg');
document.getElementById(`tab-btn-${x}`).classList.add('text-slate-500');
});
document.getElementById(`tab-${t}`).classList.remove('hidden');
document.getElementById(`tab-btn-${t}`).classList.add('bg-primary', 'text-white', 'shadow-lg');
document.getElementById(`tab-btn-${t}`).classList.remove('text-slate-500');
document.getElementById('search-toolbar').classList.toggle('hidden', t === 'settings');
}
function timeAgo(d) {
const s = Math.floor((new Date() - new Date(d))/1000);
if(s<60) return s+"s"; if(s<3600) return Math.floor(s/60)+"m"; if(s<86400) return Math.floor(s/3600)+"u"; return Math.floor(s/86400)+"d";
}
refresh();
setInterval(refresh, 60000);
</script>
</body>
</html>