-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.templ
More file actions
2577 lines (2416 loc) · 106 KB
/
Copy pathbase.templ
File metadata and controls
2577 lines (2416 loc) · 106 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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package layouts
import "context"
import "encoding/json"
import "github.com/sarg3nt/gearbox/internal/framework/auth"
import "github.com/sarg3nt/gearbox/internal/framework/models"
import "github.com/sarg3nt/gearbox/internal/framework/ui"
import "github.com/sarg3nt/gearbox/internal/framework/middleware"
import "strings"
// activeBoxIDForChip returns the active box's ID, or "" if no box is
// selected — used as the data-active-box-id attribute on the chip so the
// switcher palette can mark the current row.
func activeBoxIDForChip(active *models.BoxConfig, has bool) string {
if !has || active == nil {
return ""
}
return active.ID
}
// gearLabelForPath maps a request path to its display label (the human-
// readable gear name shown in the header breadcrumb). Returns "" for paths
// the breadcrumb shouldn't claim (e.g. the bare root, which RootRedirect
// resolves anyway).
func gearLabelForPath(path string) string {
switch {
case path == "/" || path == "":
return ""
case path == "/bx" || strings.HasPrefix(path, "/bx/"):
return "Bx"
case path == "/home" || strings.HasPrefix(path, "/home/"):
// /home's title role is taken over by the per-page board selector
// — surfacing both "Home" in the breadcrumb and the board name
// next to it is redundant. The page emits the board name via the
// hoisted page-header-source.
return ""
case path == "/haproxy" || strings.HasPrefix(path, "/haproxy/"):
return "HAProxy"
case path == "/metrics" || strings.HasPrefix(path, "/metrics/"):
return "Metrics"
case path == "/logs" || strings.HasPrefix(path, "/logs/"):
return "Logs"
case path == "/services" || strings.HasPrefix(path, "/services/"):
return "Services"
case path == "/certificates" || strings.HasPrefix(path, "/certificates/"):
return "Certificates"
case path == "/traffic" || strings.HasPrefix(path, "/traffic/"):
return "Traffic"
case path == "/alerts" || strings.HasPrefix(path, "/alerts/"):
return "Alerts"
case path == "/os-updates" || strings.HasPrefix(path, "/os-updates/"):
return "OS Updates"
case path == "/config/firewall" || strings.HasPrefix(path, "/config/firewall/"):
return "Firewall Configuration"
case path == "/config/haproxy" || strings.HasPrefix(path, "/config/haproxy/"):
return "HAProxy Configuration"
case path == "/settings" || strings.HasPrefix(path, "/settings/"):
return "Settings"
case path == "/welcome":
return "Welcome"
}
return ""
}
// encodeBoxesJSON serializes the box roster for the switcher palette's
// dataset. We only ship `id` and `name` — the agent URL and API key never
// leave the server, even though they are present in the source slice.
func encodeBoxesJSON(boxes []models.BoxConfig) string {
type lite struct {
ID string `json:"id"`
Name string `json:"name"`
}
out := make([]lite, 0, len(boxes))
for _, b := range boxes {
out = append(out, lite{ID: b.ID, Name: b.Name})
}
b, err := json.Marshal(out)
if err != nil {
return "[]"
}
return string(b)
}
// encodeGearsJSON serializes the per-user gear list for the command
// palette. Filters to integrations the user can view AND that are
// enabled — disabled gears would point at empty pages and clutter the
// list. The label / path mapping mirrors what OrderedIntegrationLinks
// renders into the sidebar.
func encodeGearsJSON(ctx context.Context) string {
type lite struct {
Name string `json:"name"`
Label string `json:"label"`
Path string `json:"path"`
Enabled bool `json:"enabled"`
}
out := make([]lite, 0, 16)
integrations, ok := auth.GetGearOrderFromContext(ctx)
if ok {
for _, i := range integrations {
if !i.Enabled {
continue
}
if !canViewIntegration(ctx, i.Name) {
continue
}
path := integrationPath(i.Name)
out = append(out, lite{
Name: i.Name,
Label: gearLabelForName(i.Name),
Path: path,
Enabled: i.Enabled,
})
}
}
b, err := json.Marshal(out)
if err != nil {
return "[]"
}
return string(b)
}
// encodePagesJSON serializes the user's reachable settings/profile pages
// for the command palette. Source of truth is models.SettingsPagesFor —
// the Settings template renders cards from the same slice, so the palette
// can never dangle a 403 destination or omit a page the user can reach.
// Augmented with palette-only entries (Settings root, Profile sub-pages,
// Add-a-box) that don't need their own Settings card.
func encodePagesJSON(ctx context.Context) string {
type lite struct {
Name string `json:"name"`
Label string `json:"label"`
Path string `json:"path"`
}
user, _ := auth.GetUserFromContext(ctx)
perms, _ := auth.GetUserPermissionsFromContext(ctx)
pages := models.SettingsPagesFor(user, perms)
out := make([]lite, 0, len(pages)+4)
// Always reachable, but not their own Settings card.
out = append(out, lite{Name: "settings", Label: "Settings", Path: "/settings"})
out = append(out, lite{Name: "change-password", Label: "Change password", Path: "/settings/change-password"})
for _, p := range pages {
out = append(out, lite{Name: p.Name, Label: p.Label, Path: p.Path})
// Surface "Add a box" alongside the Boxes card for one-keystroke
// access from anywhere — only when the user can see Boxes itself.
if p.Name == "boxes" {
out = append(out, lite{Name: "boxes-new", Label: "Add a box", Path: "/settings/boxes/new"})
}
}
b, err := json.Marshal(out)
if err != nil {
return "[]"
}
return string(b)
}
// gearLabelForName returns the user-facing label for a gear name. Mirrors
// the labels used by SidebarLink* templates so the palette matches the
// sidebar's vocabulary exactly.
func gearLabelForName(name string) string {
switch name {
case "bx":
return "Bx"
case "home":
return "Home"
case "haproxy":
return "HAProxy"
case "metrics":
return "Metrics"
case "logs":
return "Logs"
case "services":
return "Services"
case "certificates":
return "Certificates"
case "traffic":
return "Traffic"
case "alerts":
return "Alerts"
case "os_updates":
return "OS Updates"
}
return name
}
// isActivePath checks if the current path matches the nav link
func isActivePath(href, currentPath string) bool {
if href == "/" {
return currentPath == "/" || currentPath == ""
}
return strings.HasPrefix(currentPath, href)
}
// getPath extracts the path from the variadic argument
func getPath(paths []string) string {
if len(paths) > 0 {
return paths[0]
}
return ""
}
// shouldHideSidebar determines if the sidebar should be hidden based on context
// Returns true if there are no servers configured (initial setup state)
func shouldHideSidebar(ctx context.Context, currentPath string) bool {
// Check if gear status is in context - if not, we're in initial setup
_, hasPluginStatus := auth.GetGearStatusFromContext(ctx)
_, hasPluginOrder := auth.GetGearOrderFromContext(ctx)
// If neither gear status nor order is set, we're in initial setup (no servers)
// Hide the sidebar to provide a cleaner first-time experience
return !hasPluginStatus && !hasPluginOrder
}
templ Base(title string, user *models.User, currentPath ...string) {
<!DOCTYPE html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>{ title } - Gearbox</title>
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
<link rel="alternate icon" href="/favicon.ico"/>
<!-- Asset Loading: CDN (production) vs Local (dev with USE_LOCAL_ASSETS=true) -->
if middleware.UseLocalAssets(ctx) {
<!-- Local assets for CSP-compliant development -->
<script src="/static/js/vendor/tailwind.js"></script>
} else {
<!-- CDN assets for production (always up-to-date) -->
<script src="https://cdn.tailwindcss.com"></script>
}
<script>
// Configure Tailwind for dark mode
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
sidebar: {
light: '#ffffff',
dark: '#1e293b'
}
}
}
}
}
</script>
<script>
// Immediately apply sidebar state to prevent flash
(function() {
const isCollapsed = localStorage.getItem('sidebarCollapsed') === 'true';
if (isCollapsed) {
document.documentElement.classList.add('sidebar-initially-collapsed');
}
})();
</script>
if middleware.UseLocalAssets(ctx) {
<!-- Local JavaScript libraries -->
<script src="/static/js/vendor/htmx.min.js"></script>
<script src="/static/js/vendor/morphdom-umd.min.js"></script>
<script src="/static/js/vendor/chart.umd.min.js"></script>
<script src="/static/js/vendor/hammer.min.js"></script>
<script src="/static/js/vendor/chartjs-plugin-zoom.min.js"></script>
<link rel="stylesheet" href="/static/css/vendor/tabulator.min.css"/>
<script src="/static/js/vendor/tabulator.min.js"></script>
<script src="/static/js/vendor/sortable.min.js"></script>
} else {
<!-- CDN JavaScript libraries -->
<script src="https://unpkg.com/htmx.org@1.9.10/dist/htmx.min.js"></script>
<script src="https://unpkg.com/morphdom@2.7.4/dist/morphdom-umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8/hammer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@2.0.1/dist/chartjs-plugin-zoom.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/tabulator-tables@6.3.0/dist/css/tabulator.min.css"/>
<script src="https://unpkg.com/tabulator-tables@6.3.0/dist/js/tabulator.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
}
<!-- Chart widget styles and utilities -->
<link rel="stylesheet" href="/static/css/charts/charts.css"/>
<script src="/static/js/charts/chart-defaults.js"></script>
<style>
/* SortableJS sidebar drag styles (single class names required by SortableJS) */
.sortable-ghost {
@apply bg-blue-50 dark:bg-slate-700;
}
.sortable-chosen {
@apply opacity-50;
}
.sortable-drag {
@apply opacity-75;
}
/* Base styles */
.metric-card {
@apply bg-white dark:bg-slate-800 rounded-lg shadow p-6;
}
.metric-value {
@apply text-3xl font-bold text-blue-600 dark:text-blue-400;
}
.metric-label {
@apply text-sm text-gray-600 dark:text-gray-400;
}
.status-up {
@apply text-green-600 dark:text-green-400;
}
.status-down {
@apply text-red-600 dark:text-red-400;
}
.status-degraded {
@apply text-yellow-600 dark:text-yellow-400;
}
/* Global form control styles */
select, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"] {
height: 42px;
min-height: 42px;
}
select {
cursor: pointer;
}
input[type="checkbox"] {
width: 1.25rem;
height: 1.25rem;
cursor: pointer;
}
/* Compact controls inside the header bar. Every page's
per-page-source div is hoisted into #header-page-content,
so this single rule slims every gear's toolbar without
touching individual templates. Wins on specificity over
per-page Tailwind classes (ID beats class). */
#header-page-content select,
#header-page-content input[type="text"],
#header-page-content input[type="search"],
#header-page-content input[type="number"] {
height: 30px;
min-height: 30px;
padding-top: 0.125rem;
padding-bottom: 0.125rem;
font-size: 0.8125rem; /* 13px */
line-height: 1rem;
}
#header-page-content select {
padding-left: 0.5rem;
padding-right: 1.75rem;
}
#header-page-content input[type="text"],
#header-page-content input[type="search"] {
padding-left: 0.625rem;
padding-right: 0.625rem;
}
/* Header buttons (refresh, copy, download, …) get the same
compact footprint as the surrounding selects. */
#header-page-content button {
min-height: 30px;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
}
/* Sidebar transition */
.sidebar {
transition: width 0.3s ease-in-out;
overflow: hidden;
}
.sidebar-collapsed {
width: 4rem;
}
.sidebar-expanded {
width: 16rem;
}
.sidebar-text {
/* When expanding: delay opacity until sidebar has expanded enough */
transition: opacity 0.15s ease-in-out 0.15s;
white-space: nowrap;
}
.sidebar-collapsed .sidebar-text {
/* When collapsed/collapsing: no delay, hide immediately.
Also collapse layout width so the nav icon can center
inside the 4rem rail — without `width: 0` the
invisible label still occupies its intrinsic width and
shoves the icon left. */
transition:
opacity 0.1s ease-in-out 0s,
width 0.2s ease-in-out 0s;
opacity: 0;
width: 0;
overflow: hidden;
display: inline-block; /* needed so width: 0 takes effect */
}
/* Collapsed nav links: center the icon. The default expanded
layout uses `flex items-center space-x-3 px-4 border-l-4`
which adds ~20px of left offset (border + padding) plus a
space-x-3 gap before the text. When the sidebar shrinks
to 4rem and the text width collapses to 0, those rules
leave the icon stranded near the left edge / clipped on
the right. Force-center, drop the side padding, and
neutralize the space-x-3 margin (which Tailwind keeps
applying to the SVG because the preceding `.hidden`
drag-handle uses the class `.hidden` rather than the
HTML `[hidden]` attribute that space-x-3 filters on). */
.sidebar-collapsed .nav-link,
.sidebar-initially-collapsed .nav-link {
justify-content: center;
padding-left: 0;
padding-right: 0;
}
.sidebar-collapsed .nav-link > * + *,
.sidebar-initially-collapsed .nav-link > * + * {
margin-left: 0;
}
/* Sidebar nav scrollbar — overlay-style (Slack/Linear pattern):
invisible until hover, then a thin pill fades in. Keeps the
sidebar quiet on tall viewports; usable when the gear list
exceeds the available height. */
.sidebar-overlay-scroll {
/* Firefox */
scrollbar-width: thin;
scrollbar-color: transparent transparent;
transition: scrollbar-color 0.2s ease-in-out;
}
.sidebar-overlay-scroll:hover {
scrollbar-color: rgba(148, 163, 184, 0.5) transparent;
}
/* WebKit (Chrome, Safari, Edge) */
.sidebar-overlay-scroll::-webkit-scrollbar {
width: 6px;
}
.sidebar-overlay-scroll::-webkit-scrollbar-track {
background: transparent;
}
.sidebar-overlay-scroll::-webkit-scrollbar-thumb {
background: transparent;
border-radius: 3px;
transition: background 0.2s ease-in-out;
}
.sidebar-overlay-scroll:hover::-webkit-scrollbar-thumb {
background: rgba(148, 163, 184, 0.5);
}
.dark .sidebar-overlay-scroll:hover::-webkit-scrollbar-thumb {
background: rgba(100, 116, 139, 0.5);
}
/* Initial sidebar state from localStorage */
.sidebar-initially-collapsed #sidebar {
width: 4rem;
}
.sidebar-initially-collapsed #main-content {
margin-left: 4rem;
}
.sidebar-initially-collapsed header {
left: 4rem;
}
.sidebar-initially-collapsed .sidebar-text {
opacity: 0;
}
/* Below md (~768px) pop the page's toolbar out as a sheet
under the header. `#header-page-content.filters-open` uses
ID+class specificity (1,1,0) which beats the .hidden
utility (0,1,0), so no !important needed.
Layout strategy inside the sheet:
- Selects, text inputs, and search inputs each take a
full row (one per row) so labels and placeholders are
legible on a phone-width screen.
- Icon-style buttons (refresh, copy, download,
fullscreen) share a row at the bottom — stacking them
would look silly on pages with several icon buttons
(Logs is the motivating example). They're recognized
as "icon buttons" by being <button> elements that
contain only an <svg> child after my own padding rules
normalize them; CSS just packs naturally-sized buttons
together with flex-wrap. */
@media (max-width: 767px) {
#header-page-content.filters-open {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
align-content: flex-start;
gap: 0.5rem;
position: fixed;
top: 55px;
left: 4rem;
right: 0;
padding: 0.75rem 1rem;
background-color: #ffffff;
border-bottom: 1px solid #e5e7eb;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
z-index: 39;
max-height: 75vh;
overflow-y: auto;
}
.dark #header-page-content.filters-open {
background-color: rgb(30 41 59); /* slate-800 */
border-bottom-color: rgb(51 65 85); /* slate-700 */
}
/* Hide the per-page spacer div (flex-1) — it's only
useful for the inline-row layout. */
#header-page-content.filters-open > .flex-1 {
display: none;
}
/* Each inner control row (the per-page wrapper that
bundles selects + inputs + buttons) becomes a flex
wrap so its children can mix full-row wide controls
with shared-row icon buttons. */
#header-page-content.filters-open .flex {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
margin: 0;
}
/* Tailwind's space-x-* utilities add margin-left to
every child after the first. With our gap-based
layout that's redundant and creates uneven shifting,
so neutralise them. */
#header-page-content.filters-open .space-x-1 > :not([hidden]) ~ :not([hidden]),
#header-page-content.filters-open .space-x-2 > :not([hidden]) ~ :not([hidden]),
#header-page-content.filters-open .space-x-3 > :not([hidden]) ~ :not([hidden]),
#header-page-content.filters-open .space-x-4 > :not([hidden]) ~ :not([hidden]) {
margin-left: 0;
}
/* Wide controls (selects + text inputs) force a new
row by being 100%-wide flex items. */
#header-page-content.filters-open select,
#header-page-content.filters-open input[type="text"],
#header-page-content.filters-open input[type="search"],
#header-page-content.filters-open input[type="number"] {
flex: 1 0 100%;
width: 100%;
}
/* Input wrappers (e.g. <div class="relative"> with a
clear button inside) also take a full row so the
input inside can stretch. */
#header-page-content.filters-open .relative {
flex: 1 0 100%;
width: 100%;
}
/* Buttons keep their natural width and flow inline —
the row at the bottom of the sheet packs the icon
buttons (refresh, copy, download, fullscreen, …). */
#header-page-content.filters-open button {
flex: 0 0 auto;
}
/* The font-size slider on /logs is inside a small flex
container; let it sit on its own row with its label
and current-value badge. */
#header-page-content.filters-open input[type="range"] {
flex: 1 1 auto;
}
}
/* Below md (~768px) force the sidebar to its collapsed (icon-
only) rail regardless of the user's saved preference — full-
width sidebar eats most of a phone viewport. ID-scoped rules
beat the .sidebar-expanded/.sidebar-collapsed class rules on
specificity, so the user's toggle state is left intact and
restored when the viewport widens again. */
@media (max-width: 767px) {
#sidebar {
width: 4rem;
}
#sidebar .sidebar-text {
opacity: 0;
width: 0;
overflow: hidden;
display: inline-block;
}
#sidebar #sidebar-toggle-btn,
#sidebar #sidebar-edit-banner {
display: none;
}
#main-content {
margin-left: 4rem;
}
header {
left: 4rem;
}
/* Center the nav icons just like .sidebar-collapsed does. */
#sidebar .nav-link {
justify-content: center;
padding-left: 0;
padding-right: 0;
}
#sidebar .nav-link > * + * {
margin-left: 0;
}
}
/* Main content transition */
.main-content {
transition: margin-left 0.3s ease-in-out;
}
/* Sidebar-aware responsive grid for backend cards */
/* When sidebar is expanded (256px), switch to 2 cols earlier and 1 col earlier */
@media (max-width: 1279px) {
.sidebar-expanded ~ #main-content .backend-card-grid,
:not(.sidebar-initially-collapsed) #main-content .backend-card-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 1023px) {
.backend-card-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 767px) {
.backend-card-grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
/* Dark mode Tabulator (legacy — for non-datagrid-unifi instances like statusgrid).
New tables should opt into the UniFi skin via createDataGrid(). */
.dark .tabulator:not(.datagrid-unifi) {
background-color: #1e293b;
border-color: #475569;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header {
background-color: #334155;
border-color: #475569;
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col {
background-color: #334155;
border-color: #475569;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col .tabulator-col-content {
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col.tabulator-sortable .tabulator-col-title {
color: #e2e8f0;
}
/* Header column hover */
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col:hover {
background-color: #475569 !important;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col:hover .tabulator-col-content,
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-col:hover .tabulator-col-title {
color: #ffffff !important;
}
.tabulator .tabulator-header .tabulator-header-filter input,
.tabulator .tabulator-header .tabulator-header-filter select {
padding-top: 2px;
padding-bottom: 2px;
min-height: unset;
height: 24px;
font-size: 0.75rem;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-header-filter input,
.dark .tabulator:not(.datagrid-unifi) .tabulator-header .tabulator-header-filter select {
background-color: #1e293b;
border-color: #475569;
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row {
background-color: #1e293b !important;
border-color: #475569;
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row .tabulator-cell {
background-color: #1e293b !important;
border-color: #475569;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-row-even,
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-row-even .tabulator-cell {
background-color: #273549 !important;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-row-odd,
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-row-odd .tabulator-cell {
background-color: #1e293b !important;
}
/* Hover states - Tabulator uses .tabulator-selectable:hover */
@media (hover:hover) and (pointer:fine) {
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-selectable:hover {
background-color: #64748b !important;
color: #ffffff !important;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-selectable:hover .tabulator-cell {
background-color: #64748b !important;
color: #ffffff !important;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-selectable:hover .tabulator-frozen {
background-color: #64748b !important;
color: #ffffff !important;
}
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-footer {
background-color: #334155;
border-color: #475569;
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-footer .tabulator-page {
background-color: #1e293b;
border-color: #475569;
color: #e2e8f0;
}
.dark .tabulator:not(.datagrid-unifi) .tabulator-footer .tabulator-page.active {
background-color: #3b82f6;
color: white;
}
/* Dropdown menu */
.dropdown-menu {
display: none;
}
.dropdown-menu.show {
display: block;
}
</style>
<!-- Custom CSS Components -->
<link rel="stylesheet" href="/static/css/utilities.css"/>
<link rel="stylesheet" href="/static/css/components/cards.css"/>
<link rel="stylesheet" href="/static/css/components/modals.css"/>
<link rel="stylesheet" href="/static/css/components/buttons.css"/>
<link rel="stylesheet" href="/static/css/components/datagrid.css"/>
<script src="/static/js/common/datagrid.js"></script>
<script>
// Theme management
function getThemePreference() {
const stored = localStorage.getItem('theme');
if (stored) return stored;
return 'system';
}
function getEffectiveTheme() {
const pref = getThemePreference();
if (pref === 'system') {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
return pref;
}
function applyTheme() {
const theme = getEffectiveTheme();
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
updateThemeIcon();
}
function setTheme(theme) {
localStorage.setItem('theme', theme);
applyTheme();
// Close dropdown
document.getElementById('theme-dropdown')?.classList.remove('show');
}
function updateThemeIcon() {
const pref = getThemePreference();
const btnLight = document.getElementById('theme-btn-light');
const btnDark = document.getElementById('theme-btn-dark');
const btnSystem = document.getElementById('theme-btn-system');
// Reset all buttons
[btnLight, btnDark, btnSystem].forEach(btn => {
if (btn) {
btn.classList.remove('bg-blue-100', 'dark:bg-blue-900', 'text-blue-600', 'dark:text-blue-400');
}
});
// Highlight active button
const activeBtn = pref === 'light' ? btnLight : pref === 'dark' ? btnDark : btnSystem;
if (activeBtn) {
activeBtn.classList.add('bg-blue-100', 'dark:bg-blue-900', 'text-blue-600', 'dark:text-blue-400');
}
}
function toggleUserDropdown() {
const dropdown = document.getElementById('user-dropdown');
const button = document.getElementById('user-button');
if (dropdown && button) {
const isShowing = dropdown.classList.contains('show');
if (!isShowing) {
// Position the dropdown above the button, to the right of the sidebar
const buttonRect = button.getBoundingClientRect();
const dropdownHeight = dropdown.offsetHeight || 300; // Estimate if not visible
// Position dropdown to appear above the button and to its right
dropdown.style.left = buttonRect.right + 8 + 'px';
dropdown.style.bottom = (window.innerHeight - buttonRect.bottom) + 'px';
dropdown.style.top = 'auto';
}
dropdown.classList.toggle('show');
}
}
// Apply theme immediately to prevent flash
applyTheme();
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (getThemePreference() === 'system') {
applyTheme();
}
});
// Close dropdown when clicking outside
document.addEventListener('click', function(e) {
const userDropdown = document.getElementById('user-dropdown');
const userButton = document.getElementById('user-button');
if (userDropdown && userButton && !userButton.contains(e.target) && !userDropdown.contains(e.target)) {
userDropdown.classList.remove('show');
}
});
// Sidebar management
function getSidebarState() {
const stored = localStorage.getItem('sidebarCollapsed');
return stored === 'true';
}
// Header "Filters" popover (narrow viewports only). Pops
// #header-page-content out from its inline header slot into a
// fixed sheet just below the header. The state is one CSS
// class on the content node — no DOM moves, so per-page
// listeners on the controls keep working untouched. Auto-
// closes on Escape, click outside, and when the viewport
// widens back to md+.
function toggleHeaderFilters() {
const content = document.getElementById('header-page-content');
const btn = document.getElementById('header-filters-btn');
if (!content || !btn) return;
const opening = !content.classList.contains('filters-open');
content.classList.toggle('filters-open');
btn.setAttribute('aria-expanded', opening ? 'true' : 'false');
}
// Expose to other modules (shortcut-help.js calls this when
// `/` is pressed and the focus target lives in the hidden
// header content slot).
window.toggleHeaderFilters = toggleHeaderFilters;
function closeHeaderFilters() {
const content = document.getElementById('header-page-content');
const btn = document.getElementById('header-filters-btn');
if (!content || !btn) return;
if (!content.classList.contains('filters-open')) return;
content.classList.remove('filters-open');
btn.setAttribute('aria-expanded', 'false');
}
document.addEventListener('click', function (e) {
const content = document.getElementById('header-page-content');
if (!content || !content.classList.contains('filters-open')) return;
const btn = document.getElementById('header-filters-btn');
if (btn && btn.contains(e.target)) return;
if (content.contains(e.target)) return;
closeHeaderFilters();
});
document.addEventListener('keydown', function (e) {
if (e.key !== 'Escape') return;
const content = document.getElementById('header-page-content');
if (content && content.classList.contains('filters-open')) {
closeHeaderFilters();
}
});
window.addEventListener('resize', function () {
if (window.matchMedia('(min-width: 768px)').matches) {
closeHeaderFilters();
}
});
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('main-content');
const header = document.querySelector('header');
const iconCollapse = document.getElementById('sidebar-icon-collapse');
const iconExpand = document.getElementById('sidebar-icon-expand');
const isCollapsed = sidebar.classList.contains('sidebar-collapsed');
if (isCollapsed) {
sidebar.classList.remove('sidebar-collapsed');
sidebar.classList.add('sidebar-expanded');
mainContent.classList.remove('ml-16');
mainContent.classList.add('ml-64');
if (header) {
header.style.left = '16rem'; // 64 * 4px = 256px = 16rem
}
// Show collapse icon, hide expand icon
if (iconCollapse) iconCollapse.classList.remove('hidden');
if (iconExpand) iconExpand.classList.add('hidden');
localStorage.setItem('sidebarCollapsed', 'false');
} else {
sidebar.classList.add('sidebar-collapsed');
sidebar.classList.remove('sidebar-expanded');
mainContent.classList.add('ml-16');
mainContent.classList.remove('ml-64');
if (header) {
header.style.left = '4rem'; // 16 * 4px = 64px = 4rem
}
// Show expand icon, hide collapse icon
if (iconCollapse) iconCollapse.classList.add('hidden');
if (iconExpand) iconExpand.classList.remove('hidden');
localStorage.setItem('sidebarCollapsed', 'true');
}
}
function applySidebarState() {
const isCollapsed = getSidebarState();
const sidebar = document.getElementById('sidebar');
const mainContent = document.getElementById('main-content');
const header = document.querySelector('header');
const iconCollapse = document.getElementById('sidebar-icon-collapse');
const iconExpand = document.getElementById('sidebar-icon-expand');
// IMPORTANT: apply the correct sidebar/main-content classes
// BEFORE removing the .sidebar-initially-collapsed pin from
// <html>. Otherwise on a navigation where the user has the
// sidebar collapsed:
// 1. <html>.sidebar-initially-collapsed is removed → the
// ID-scoped width override goes away.
// 2. The sidebar still carries its default
// .sidebar-expanded class from the server HTML, so the
// cascade snaps width to 16rem.
// 3. JS then adds .sidebar-collapsed → width transitions
// back to 4rem.
// Step 2→3 animates because of `transition: width 0.3s` on
// .sidebar, producing a visible "twitch" left-to-right on
// every gear click. Applying classes first keeps the
// computed width pinned the whole time.
if (sidebar && mainContent) {
if (isCollapsed) {
sidebar.classList.add('sidebar-collapsed');
sidebar.classList.remove('sidebar-expanded');
mainContent.classList.add('ml-16');
mainContent.classList.remove('ml-64');
if (header) {
header.style.left = '4rem';
}
// Show expand icon, hide collapse icon
if (iconCollapse) iconCollapse.classList.add('hidden');
if (iconExpand) iconExpand.classList.remove('hidden');
} else {
sidebar.classList.remove('sidebar-collapsed');
sidebar.classList.add('sidebar-expanded');
mainContent.classList.remove('ml-16');
mainContent.classList.add('ml-64');
if (header) {
header.style.left = '16rem';
}
// Show collapse icon, hide expand icon
if (iconCollapse) iconCollapse.classList.remove('hidden');
if (iconExpand) iconExpand.classList.add('hidden');
}
}
// Now safe to drop the initial-state pin — the regular
// class-based rules resolve to the same width.
document.documentElement.classList.remove('sidebar-initially-collapsed');
}
// Sidebar edit mode state
let sidebarEditMode = false;
let sidebarSortable = null;
// Prevent navigation when in edit mode
function preventNavClick(e) {
e.preventDefault();
}
function toggleSidebarEditMode() {
sidebarEditMode = !sidebarEditMode;
const iconEdit = document.getElementById('sidebar-icon-edit');
const iconSave = document.getElementById('sidebar-icon-save');
const banner = document.getElementById('sidebar-edit-banner');
const sidebar = document.getElementById('sidebar');
const dragHandles = document.querySelectorAll('.nav-drag-handle');
const navLinks = document.querySelectorAll('.nav-link');
if (sidebarEditMode) {
// Enter edit mode
if (iconEdit) iconEdit.classList.add('hidden');
if (iconSave) iconSave.classList.remove('hidden');
if (banner) {
banner.classList.remove('hidden');
banner.classList.add('flex');
}
if (sidebar) sidebar.classList.add('sidebar-edit-mode');
// Show drag handle indicators
dragHandles.forEach(handle => handle.classList.remove('hidden'));
// Prevent link navigation — entire item is draggable
// Remove first to avoid duplicate listeners from rapid toggling
navLinks.forEach(link => {
link.removeEventListener('click', preventNavClick);
link.addEventListener('click', preventNavClick);
link.style.cursor = 'grab';
});
// Initialize Sortable if not already done
initSidebarSortable();
} else {
// Exit edit mode (save)
if (iconEdit) iconEdit.classList.remove('hidden');