Diff -- /var/www/vhosts/3dshawn.com/site1/MODS/PageWrapper.pm
Diff
/var/www/vhosts/3dshawn.com/site1/MODS/PageWrapper.pm
modified on local at 2026-07-10 23:23:35
Added
+21
lines
Removed
-0
lines
Context
78
unchanged
Blobs
from f3ebd1740b5e
to 3a22da864a4f
to 3a22da864a4f
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.| 1 | 1 | package MODS::PageWrapper; |
| 2 | 2 | #====================================================================== |
| 3 | 3 | # DriftSense -- page wrapper. |
| 4 | 4 | # |
| 5 | 5 | # Loads TEMPLATES/page_wrapper.html, injects the CGI's rendered body |
| 6 | 6 | # into $page_body, sets branding + active-nav-item tvars, and hands |
| 7 | 7 | # the whole thing back through MODS::Template so its normal tag |
| 8 | 8 | # resolution (variables, [if:...], [url:...]) runs. |
| 9 | 9 | # |
| 10 | 10 | # Usage from a CGI: |
| 11 | 11 | # my $load = MODS::PageWrapper->new; |
| 12 | 12 | # $load->wrapper( |
| 13 | 13 | # page_title => 'Dashboard', |
| 14 | 14 | # page_key => 'dashboard', # sets $active_dashboard = 1 for the sidebar |
| 15 | 15 | # body_html => $rendered_body, |
| 16 | 16 | # userinfo => $u, |
| 17 | 17 | # ); |
| 18 | 18 | #====================================================================== |
| 19 | 19 | use strict; |
| 20 | 20 | use warnings; |
| 21 | 21 | use MODS::Config; |
| 22 | 22 | use MODS::Template; |
| 23 | 23 | |
| 24 | 24 | my $cfg = MODS::Config->new; |
| 25 | ||
| 26 | # Cache-bust CSS/JS by the newest mtime among the assets we ship. Recomputed | |
| 27 | # per-process; requests inside the same worker share the value, but a new | |
| 28 | # deploy touches files and the next worker start picks it up automatically. | |
| 29 | my $ASSET_VERSION; | |
| 30 | sub _asset_version { | |
| 31 | return $ASSET_VERSION if defined $ASSET_VERSION; | |
| 32 | my $base = '/var/www/vhosts/3dshawn.com/site1'; | |
| 33 | my $max = 0; | |
| 34 | for my $p ("$base/assets/styles/drift_sense.css", | |
| 35 | "$base/assets/js/tz_localize.js", | |
| 36 | "$base/assets/js/ds_charts.js") { | |
| 37 | my @st = stat $p; | |
| 38 | $max = $st[9] if @st && $st[9] > $max; | |
| 39 | } | |
| 40 | $ASSET_VERSION = $max || time; | |
| 41 | return $ASSET_VERSION; | |
| 42 | } | |
| 25 | 43 | |
| 26 | 44 | sub new { return bless({}, shift); } |
| 27 | 45 | |
| 28 | 46 | sub wrapper { |
| 29 | 47 | my ($self, %args) = @_; |
| 30 | 48 | my $tpl = MODS::Template->new; |
| 31 | 49 | |
| 32 | 50 | my $userinfo = $args{userinfo} || {}; |
| 33 | 51 | my $initials = _initials($userinfo->{display_name} || $userinfo->{email} || 'User'); |
| 34 | 52 | |
| 35 | 53 | my $tvars = { |
| 36 | 54 | # Branding |
| 37 | 55 | brand_name => $cfg->settings('brand_name') || 'DriftSense', |
| 38 | 56 | brand_tagline => $cfg->settings('brand_tagline') || '', |
| 57 | ||
| 58 | # Asset cache-bust stamp -- max mtime of shipped CSS/JS | |
| 59 | asset_version => _asset_version(), | |
| 39 | 60 | |
| 40 | 61 | # Page identity |
| 41 | 62 | page_title => $args{page_title} || 'DriftSense', |
| 42 | 63 | page_body => $args{body_html} // (@{$args{body_lines} || []} ? join('', @{$args{body_lines}}) : ''), |
| 43 | 64 | |
| 44 | 65 | # User |
| 45 | 66 | user_name => $userinfo->{display_name} || $userinfo->{email} || 'Operator', |
| 46 | 67 | user_initials => $initials, |
| 47 | 68 | |
| 48 | 69 | # Sidebar active-item flags (page_key sets exactly one) |
| 49 | 70 | active_dashboard => 0, |
| 50 | 71 | active_file_changes => 0, |
| 51 | 72 | active_schema_changes => 0, |
| 52 | 73 | active_table_locks => 0, |
| 53 | 74 | active_named_releases => 0, |
| 54 | 75 | active_databases => 0, |
| 55 | 76 | active_file_monitors => 0, |
| 56 | 77 | active_servers => 0, |
| 57 | 78 | active_containers => 0, |
| 58 | 79 | active_settings => 0, |
| 59 | 80 | }; |
| 60 | 81 | my $key = $args{page_key} || ''; |
| 61 | 82 | $tvars->{"active_$key"} = 1 if exists $tvars->{"active_$key"}; |
| 62 | 83 | |
| 63 | 84 | my @html = $tpl->template('page_wrapper.html', $tvars); |
| 64 | 85 | print @html; |
| 65 | 86 | return; |
| 66 | 87 | } |
| 67 | 88 | |
| 68 | 89 | sub _initials { |
| 69 | 90 | my $s = shift; $s //= ''; |
| 70 | 91 | my @p = split /[\s\@\.]+/, $s, 3; |
| 71 | 92 | my $i = ''; |
| 72 | 93 | $i .= uc(substr($p[0], 0, 1)) if defined $p[0] && length $p[0]; |
| 73 | 94 | $i .= uc(substr($p[1], 0, 1)) if defined $p[1] && length $p[1]; |
| 74 | 95 | $i = uc(substr($s, 0, 1)) unless length $i; |
| 75 | 96 | return $i; |
| 76 | 97 | } |
| 77 | 98 | |
| 78 | 99 | 1; |