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
| | /* ============================================================
| | OPS Dashboard — Alpine.js Application Logic
| | ============================================================ */
| |
| | 'use strict';
| |
| | // ----------------------------------------------------------------
| | // Helpers
| | // ----------------------------------------------------------------
| |
| | function formatBytes(bytes) {
| | if (bytes == null || bytes === '') return '—';
| | const n = Number(bytes);
| | if (isNaN(n) || n === 0) return '0 B';
| | const k = 1024;
| | const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
| | const i = Math.floor(Math.log(Math.abs(n)) / Math.log(k));
| | return (n / Math.pow(k, i)).toFixed(i === 0 ? 0 : 1) + ' ' + sizes[i];
| | }
| |
| | function timeAgo(dateInput) {
| | if (!dateInput) return '—';
| | const date = typeof dateInput === 'string' ? new Date(dateInput) : dateInput;
| | if (isNaN(date)) return '—';
| | const secs = Math.floor((Date.now() - date.getTime()) / 1000);
| | if (secs < 60) return secs + 's ago';
| | if (secs < 3600) return Math.floor(secs / 60) + 'm ago';
| | if (secs < 86400) return Math.floor(secs / 3600) + 'h ago';
| | return Math.floor(secs / 86400) + 'd ago';
| | }
| |
| | function ageHours(dateInput) {
| | if (!dateInput) return 0;
| | const date = typeof dateInput === 'string' ? new Date(dateInput) : dateInput;
| | if (isNaN(date)) return 0;
| | return (Date.now() - date.getTime()) / 3600000;
| | }
| |
| | function ageBadgeClass(dateInput) {
| | const h = ageHours(dateInput);
| | if (h >= 48) return 'badge-red';
| | if (h >= 24) return 'badge-yellow';
| | return 'badge-green';
| | }
| |
| | function statusBadgeClass(status, health) {
| | const s = (status || '').toLowerCase();
| | const h = (health || '').toLowerCase();
| | if (s === 'running' && (h === 'healthy' || h === '')) return 'badge-green';
| | if (s === 'running' && h === 'unhealthy') return 'badge-red';
| | if (s === 'running' && h === 'starting') return 'badge-yellow';
| | if (s === 'restarting' || h === 'starting') return 'badge-yellow';
| | if (s === 'exited' || s === 'dead' || s === 'removed') return 'badge-red';
| | if (s === 'paused') return 'badge-yellow';
| | return 'badge-gray';
| | }
| |
| | function statusDotClass(status, health) {
| | const cls = statusBadgeClass(status, health);
| | return cls.replace('badge-', 'status-dot-');
| | }
| |
| | function diskBarClass(pct) {
| | if (pct >= 90) return 'disk-danger';
| | if (pct >= 75) return 'disk-warn';
| | return 'disk-ok';
| | }
| |
| | // ----------------------------------------------------------------
| | // Auth Store
| | // ----------------------------------------------------------------
| |
| | function authStore() {
| | return {
| | token: localStorage.getItem('ops_token') || '',
| | loginInput: '',
| | loginError: '',
| | loading: false,
| |
| | get isAuthenticated() {
| | return !!this.token;
| | },
| |
| | async login() {
| | this.loginError = '';
| | if (!this.loginInput.trim()) {
| | this.loginError = 'Please enter your access token.';
| | return;
| | }
| | this.loading = true;
| | try {
| | const res = await fetch('/api/status/', {
| | headers: { 'Authorization': 'Bearer ' + this.loginInput.trim() }
| | });
| | if (res.ok || res.status === 200) {
| | this.token = this.loginInput.trim();
| | localStorage.setItem('ops_token', this.token);
| | this.loginInput = '';
| | // Trigger page load
| | this.$dispatch('authenticated');
| | } else if (res.status === 401) {
| | this.loginError = 'Invalid token. Please try again.';
| | } else {
| | this.loginError = 'Server error (' + res.status + '). Please try again.';
| | }
| | } catch {
| | this.loginError = 'Could not reach the server.';
| | } finally {
| | this.loading = false;
| | }
| | },
| |
| | logout() {
| | this.token = '';
| | localStorage.removeItem('ops_token');
| | }
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // API Helper
| | // ----------------------------------------------------------------
| |
| | function api(path, options = {}) {
| | const token = localStorage.getItem('ops_token') || '';
| | const headers = Object.assign({ 'Authorization': 'Bearer ' + token }, options.headers || {});
| | if (options.json) {
| | headers['Content-Type'] = 'application/json';
| | options.body = JSON.stringify(options.json);
| | delete options.json;
| | }
| | return fetch(path, Object.assign({}, options, { headers })).then(res => {
| | if (res.status === 401) {
| | localStorage.removeItem('ops_token');
| | window.dispatchEvent(new CustomEvent('unauthorized'));
| | throw new Error('Unauthorized');
| | }
| | return res;
| | });
| | }
| |
| | // ----------------------------------------------------------------
| | // Toast Store
| | // ----------------------------------------------------------------
| |
| | function toastStore() {
| | return {
| | toasts: [],
| | _counter: 0,
| |
| | add(msg, type = 'info', duration = 4000) {
| | const id = ++this._counter;
| | this.toasts.push({ id, msg, type });
| | if (duration > 0) {
| | setTimeout(() => this.remove(id), duration);
| | }
| | return id;
| | },
| |
| | remove(id) {
| | const idx = this.toasts.findIndex(t => t.id === id);
| | if (idx !== -1) this.toasts.splice(idx, 1);
| | },
| |
| | success(msg) { return this.add(msg, 'toast-success'); },
| | error(msg) { return this.add(msg, 'toast-error', 6000); },
| | warn(msg) { return this.add(msg, 'toast-warning'); },
| | info(msg) { return this.add(msg, 'toast-info'); },
| |
| | iconFor(type) {
| | const icons = {
| | 'toast-success': '✓',
| | 'toast-error': '✕',
| | 'toast-warning': '⚠',
| | 'toast-info': 'ℹ'
| | };
| | return icons[type] || 'ℹ';
| | }
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // App Root Store
| | // ----------------------------------------------------------------
| |
| | function appStore() {
| | return {
| | page: 'dashboard',
| | sidebarOpen: false,
| | toast: null,
| |
| | init() {
| | this.toast = Alpine.store('toast');
| | window.addEventListener('unauthorized', () => {
| | Alpine.store('auth').logout();
| | });
| | window.addEventListener('authenticated', () => {
| | this.loadPage('dashboard');
| | });
| | },
| |
| | navigate(page) {
| | this.page = page;
| | this.sidebarOpen = false;
| | this.loadPage(page);
| | },
| |
| | loadPage(page) {
| | const storeMap = {
| | dashboard: 'dashboard',
| | backups: 'backups',
| | restore: 'restore',
| | services: 'services',
| | system: 'system'
| | };
| | const storeName = storeMap[page];
| | if (storeName && Alpine.store(storeName) && Alpine.store(storeName).load) {
| | Alpine.store(storeName).load();
| | }
| | }
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // Dashboard Store
| | // ----------------------------------------------------------------
| |
| | function dashboardStore() {
| | return {
| | projects: [],
| | loading: false,
| | error: null,
| | lastRefresh: null,
| | refreshInterval: null,
| | autoRefreshEnabled: true,
| | refreshing: false,
| |
| | load() {
| | this.fetch();
| | this.startAutoRefresh();
| | },
| |
| | async fetch() {
| | if (this.loading) return;
| | this.loading = true;
| | this.error = null;
| | try {
| | const res = await api('/api/status/');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.projects = this.groupByProject(data);
| | this.lastRefresh = new Date();
| | } catch (e) {
| | if (e.message !== 'Unauthorized') {
| | this.error = e.message || 'Failed to load status';
| | }
| | } finally {
| | this.loading = false;
| | this.refreshing = false;
| | }
| | },
| |
| | groupByProject(data) {
| | // data may be array of containers or object keyed by project
| | let containers = Array.isArray(data) ? data : Object.values(data).flat();
| | const map = {};
| | for (const c of containers) {
| | const proj = c.project || 'Other';
| | if (!map[proj]) map[proj] = [];
| | map[proj].push(c);
| | }
| | return Object.entries(map).map(([name, services]) => ({ name, services }))
| | .sort((a, b) => a.name.localeCompare(b.name));
| | },
| |
| | manualRefresh() {
| | this.refreshing = true;
| | this.fetch();
| | },
| |
| | startAutoRefresh() {
| | this.stopAutoRefresh();
| | if (this.autoRefreshEnabled) {
| | this.refreshInterval = setInterval(() => this.fetch(), 30000);
| | }
| | },
| |
| | stopAutoRefresh() {
| | if (this.refreshInterval) {
| | clearInterval(this.refreshInterval);
| | this.refreshInterval = null;
| | }
| | },
| |
| | toggleAutoRefresh() {
| | this.autoRefreshEnabled = !this.autoRefreshEnabled;
| | if (this.autoRefreshEnabled) {
| | this.startAutoRefresh();
| | } else {
| | this.stopAutoRefresh();
| | }
| | },
| |
| | destroy() {
| | this.stopAutoRefresh();
| | },
| |
| | badgeClass: statusBadgeClass,
| | dotClass: statusDotClass,
| | timeAgo
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // Backups Store
| | // ----------------------------------------------------------------
| |
| | function backupsStore() {
| | return {
| | local: [],
| | offsite: [],
| | loading: false,
| | loadingOffsite: false,
| | error: null,
| | ops: {}, // track per-row operation state: key -> { loading, done, error }
| |
| | load() {
| | this.fetchLocal();
| | this.fetchOffsite();
| | },
| |
| | async fetchLocal() {
| | this.loading = true;
| | this.error = null;
| | try {
| | const res = await api('/api/backups/');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.local = Array.isArray(data) ? data : Object.values(data).flat();
| | } catch (e) {
| | if (e.message !== 'Unauthorized') this.error = e.message;
| | } finally {
| | this.loading = false;
| | }
| | },
| |
| | async fetchOffsite() {
| | this.loadingOffsite = true;
| | try {
| | const res = await api('/api/backups/offsite');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.offsite = Array.isArray(data) ? data : Object.values(data).flat();
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | Alpine.store('toast').error('Offsite: ' + (e.message || 'Failed'));
| | } finally {
| | this.loadingOffsite = false;
| | }
| | },
| |
| | opKey(project, env, action) {
| | return `${action}::${project}::${env}`;
| | },
| |
| | isRunning(project, env, action) {
| | return !!(this.ops[this.opKey(project, env, action)]?.loading);
| | },
| |
| | async backupNow(project, env) {
| | const key = this.opKey(project, env, 'backup');
| | this.ops = { ...this.ops, [key]: { loading: true } };
| | try {
| | const res = await api(`/api/backups/${project}/${env}`, { method: 'POST' });
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | Alpine.store('toast').success(`Backup started: ${project}/${env}`);
| | setTimeout(() => this.fetchLocal(), 2000);
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | Alpine.store('toast').error(`Backup failed: ${e.message}`);
| | } finally {
| | this.ops = { ...this.ops, [key]: { loading: false } };
| | }
| | },
| |
| | async uploadOffsite(project, env) {
| | const key = this.opKey(project, env, 'upload');
| | this.ops = { ...this.ops, [key]: { loading: true } };
| | try {
| | const res = await api(`/api/backups/offsite/upload/${project}/${env}`, { method: 'POST' });
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | Alpine.store('toast').success(`Upload started: ${project}/${env}`);
| | setTimeout(() => this.fetchOffsite(), 3000);
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | Alpine.store('toast').error(`Upload failed: ${e.message}`);
| | } finally {
| | this.ops = { ...this.ops, [key]: { loading: false } };
| | }
| | },
| |
| | retentionRunning: false,
| |
| | async applyRetention() {
| | this.retentionRunning = true;
| | try {
| | const res = await api('/api/backups/offsite/retention', { method: 'POST' });
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | Alpine.store('toast').success('Retention policy applied');
| | setTimeout(() => this.fetchOffsite(), 2000);
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | Alpine.store('toast').error(`Retention failed: ${e.message}`);
| | } finally {
| | this.retentionRunning = false;
| | }
| | },
| |
| | ageBadge: ageBadgeClass,
| | timeAgo,
| | formatBytes
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // Restore Store
| | // ----------------------------------------------------------------
| |
| | function restoreStore() {
| | return {
| | source: 'local',
| | project: '',
| | env: '',
| | dryRun: false,
| | confirming: false,
| | running: false,
| | output: [],
| | sseSource: null,
| | projects: [],
| | envs: [],
| | loadingProjects: false,
| | error: null,
| |
| | load() {
| | this.loadProjectList();
| | },
| |
| | async loadProjectList() {
| | this.loadingProjects = true;
| | try {
| | const endpoint = this.source === 'offsite' ? '/api/backups/offsite' : '/api/backups/';
| | const res = await api(endpoint);
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | const items = Array.isArray(data) ? data : Object.values(data).flat();
| | const projSet = new Set(items.map(i => i.project).filter(Boolean));
| | this.projects = Array.from(projSet).sort();
| | this.project = this.projects[0] || '';
| | this.updateEnvs(items);
| | } catch (e) {
| | if (e.message !== 'Unauthorized') this.error = e.message;
| | } finally {
| | this.loadingProjects = false;
| | }
| | },
| |
| | updateEnvs(items) {
| | if (!items) return;
| | const envSet = new Set(
| | items.filter(i => i.project === this.project).map(i => i.env).filter(Boolean)
| | );
| | this.envs = Array.from(envSet).sort();
| | this.env = this.envs[0] || '';
| | },
| |
| | onSourceChange() {
| | this.project = '';
| | this.env = '';
| | this.envs = [];
| | this.loadProjectList();
| | },
| |
| | onProjectChange() {
| | // Re-fetch envs for this project from the already loaded data
| | this.loadProjectList();
| | },
| |
| | confirm() {
| | if (!this.project || !this.env) {
| | Alpine.store('toast').warn('Select project and environment first');
| | return;
| | }
| | this.confirming = true;
| | },
| |
| | cancel() {
| | this.confirming = false;
| | },
| |
| | async execute() {
| | this.confirming = false;
| | this.running = true;
| | this.output = [];
| |
| | const params = new URLSearchParams({
| | source: this.source,
| | dry_run: this.dryRun ? '1' : '0'
| | });
| | const url = `/api/restore/${this.project}/${this.env}?${params}`;
| |
| | try {
| | this.sseSource = new EventSource(url + '&token=' + encodeURIComponent(localStorage.getItem('ops_token') || ''));
| | this.sseSource.onmessage = (e) => {
| | try {
| | const msg = JSON.parse(e.data);
| | if (msg.done) {
| | this.sseSource.close();
| | this.sseSource = null;
| | this.running = false;
| | if (msg.success) {
| | Alpine.store('toast').success('Restore completed');
| | } else {
| | Alpine.store('toast').error('Restore finished with errors');
| | }
| | return;
| | }
| | const text = msg.line || e.data;
| | this.output.push({ text, cls: this.classifyLine(text) });
| | } catch {
| | this.output.push({ text: e.data, cls: this.classifyLine(e.data) });
| | }
| | this.$nextTick(() => {
| | const el = document.getElementById('restore-output');
| | if (el) el.scrollTop = el.scrollHeight;
| | });
| | };
| | this.sseSource.onerror = () => {
| | if (this.running) {
| | this.running = false;
| | if (this.sseSource) this.sseSource.close();
| | this.sseSource = null;
| | }
| | };
| | } catch (e) {
| | this.running = false;
| | Alpine.store('toast').error('Restore failed: ' + (e.message || 'Unknown error'));
| | }
| | },
| |
| | classifyLine(text) {
| | const t = text.toLowerCase();
| | if (t.includes('error') || t.includes('fail') || t.includes('critical')) return 'line-error';
| | if (t.includes('warn')) return 'line-warn';
| | if (t.includes('ok') || t.includes('success') || t.includes('done')) return 'line-ok';
| | if (t.startsWith('$') || t.startsWith('#') || t.startsWith('>')) return 'line-cmd';
| | return '';
| | },
| |
| | abort() {
| | if (this.sseSource) {
| | this.sseSource.close();
| | this.sseSource = null;
| | }
| | this.running = false;
| | this.output.push({ text: '--- aborted by user ---', cls: 'line-warn' });
| | }
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // Services Store
| | // ----------------------------------------------------------------
| |
| | function servicesStore() {
| | return {
| | projects: [],
| | loading: false,
| | error: null,
| | logModal: { open: false, title: '', lines: [], loading: false },
| | confirmRestart: { open: false, project: '', env: '', service: '', running: false },
| |
| | load() {
| | this.fetch();
| | },
| |
| | async fetch() {
| | this.loading = true;
| | this.error = null;
| | try {
| | const res = await api('/api/status/');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.projects = this.groupByProject(data);
| | } catch (e) {
| | if (e.message !== 'Unauthorized') this.error = e.message;
| | } finally {
| | this.loading = false;
| | }
| | },
| |
| | groupByProject(data) {
| | let containers = Array.isArray(data) ? data : Object.values(data).flat();
| | const map = {};
| | for (const c of containers) {
| | const proj = c.project || 'Other';
| | if (!map[proj]) map[proj] = [];
| | map[proj].push(c);
| | }
| | return Object.entries(map).map(([name, services]) => ({ name, services }))
| | .sort((a, b) => a.name.localeCompare(b.name));
| | },
| |
| | async viewLogs(project, env, service) {
| | this.logModal = {
| | open: true,
| | title: `${service} — logs`,
| | lines: [],
| | loading: true
| | };
| | try {
| | const res = await api(`/api/services/logs/${project}/${env}/${service}?lines=150`);
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.logModal.lines = (data.logs || '').split('\n');
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | this.logModal.lines = ['Error: ' + e.message];
| | } finally {
| | this.logModal.loading = false;
| | this.$nextTick(() => {
| | const el = document.getElementById('log-output');
| | if (el) el.scrollTop = el.scrollHeight;
| | });
| | }
| | },
| |
| | closeLogs() {
| | this.logModal.open = false;
| | },
| |
| | askRestart(project, env, service) {
| | this.confirmRestart = { open: true, project, env, service, running: false };
| | },
| |
| | cancelRestart() {
| | this.confirmRestart.open = false;
| | },
| |
| | async doRestart() {
| | const { project, env, service } = this.confirmRestart;
| | this.confirmRestart.running = true;
| | try {
| | const res = await api(`/api/services/restart/${project}/${env}/${service}`, { method: 'POST' });
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | Alpine.store('toast').success(`${service} restarted`);
| | this.confirmRestart.open = false;
| | setTimeout(() => this.fetch(), 2000);
| | } catch (e) {
| | if (e.message !== 'Unauthorized')
| | Alpine.store('toast').error(`Restart failed: ${e.message}`);
| | } finally {
| | this.confirmRestart.running = false;
| | }
| | },
| |
| | badgeClass: statusBadgeClass,
| | dotClass: statusDotClass
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // System Store
| | // ----------------------------------------------------------------
| |
| | function systemStore() {
| | return {
| | disk: [],
| | health: [],
| | timers: [],
| | info: {},
| | loading: { disk: false, health: false, timers: false, info: false },
| | error: null,
| |
| | load() {
| | this.fetchDisk();
| | this.fetchHealth();
| | this.fetchTimers();
| | this.fetchInfo();
| | },
| |
| | async fetchDisk() {
| | this.loading.disk = true;
| | try {
| | const res = await api('/api/system//disk');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.disk = Array.isArray(data) ? data : (data.filesystems || []);
| | } catch (e) {
| | if (e.message !== 'Unauthorized') this.error = e.message;
| | } finally {
| | this.loading.disk = false;
| | }
| | },
| |
| | async fetchHealth() {
| | this.loading.health = true;
| | try {
| | const res = await api('/api/system//health');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.health = Array.isArray(data) ? data : (data.checks || []);
| | } catch (e) {
| | if (e.message !== 'Unauthorized') {}
| | } finally {
| | this.loading.health = false;
| | }
| | },
| |
| | async fetchTimers() {
| | this.loading.timers = true;
| | try {
| | const res = await api('/api/system//timers');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | const data = await res.json();
| | this.timers = Array.isArray(data) ? data : (data.timers || []);
| | } catch (e) {
| | if (e.message !== 'Unauthorized') {}
| | } finally {
| | this.loading.timers = false;
| | }
| | },
| |
| | async fetchInfo() {
| | this.loading.info = true;
| | try {
| | const res = await api('/api/system//info');
| | if (!res.ok) throw new Error('HTTP ' + res.status);
| | this.info = await res.json();
| | } catch (e) {
| | if (e.message !== 'Unauthorized') {}
| | } finally {
| | this.loading.info = false;
| | }
| | },
| |
| | diskBarClass,
| | formatBytes,
| | timeAgo
| | };
| | }
| |
| | // ----------------------------------------------------------------
| | // Alpine initialization
| | // ----------------------------------------------------------------
| |
| | document.addEventListener('alpine:init', () => {
| | Alpine.store('auth', authStore());
| | Alpine.store('toast', toastStore());
| | Alpine.store('app', appStore());
| | Alpine.store('dashboard', dashboardStore());
| | Alpine.store('backups', backupsStore());
| | Alpine.store('restore', restoreStore());
| | Alpine.store('services', servicesStore());
| | Alpine.store('system', systemStore());
| |
| | // Init app store
| | Alpine.store('app').init();
| |
| | // Load the dashboard if already authenticated
| | if (Alpine.store('auth').isAuthenticated) {
| | Alpine.store('dashboard').load();
| | }
| | });
|
|