Diff -- /var/www/vhosts/3dshawn.com/site1/MODS/PageWrapper.pm

O Operator
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
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
11package MODS::PageWrapper;
22#======================================================================
33# DriftSense -- page wrapper.
44#
55# Loads TEMPLATES/page_wrapper.html, injects the CGI's rendered body
66# into $page_body, sets branding + active-nav-item tvars, and hands
77# the whole thing back through MODS::Template so its normal tag
88# resolution (variables, [if:...], [url:...]) runs.
99#
1010# Usage from a CGI:
1111# my $load = MODS::PageWrapper->new;
1212# $load->wrapper(
1313# page_title => 'Dashboard',
1414# page_key => 'dashboard', # sets $active_dashboard = 1 for the sidebar
1515# body_html => $rendered_body,
1616# userinfo => $u,
1717# );
1818#======================================================================
1919use strict;
2020use warnings;
2121use MODS::Config;
2222use MODS::Template;
2323
2424my $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.
29my $ASSET_VERSION;
30sub _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}
2543
2644sub new { return bless({}, shift); }
2745
2846sub wrapper {
2947 my ($self, %args) = @_;
3048 my $tpl = MODS::Template->new;
3149
3250 my $userinfo = $args{userinfo} || {};
3351 my $initials = _initials($userinfo->{display_name} || $userinfo->{email} || 'User');
3452
3553 my $tvars = {
3654 # Branding
3755 brand_name => $cfg->settings('brand_name') || 'DriftSense',
3856 brand_tagline => $cfg->settings('brand_tagline') || '',
57
58 # Asset cache-bust stamp -- max mtime of shipped CSS/JS
59 asset_version => _asset_version(),
3960
4061 # Page identity
4162 page_title => $args{page_title} || 'DriftSense',
4263 page_body => $args{body_html} // (@{$args{body_lines} || []} ? join('', @{$args{body_lines}}) : ''),
4364
4465 # User
4566 user_name => $userinfo->{display_name} || $userinfo->{email} || 'Operator',
4667 user_initials => $initials,
4768
4869 # Sidebar active-item flags (page_key sets exactly one)
4970 active_dashboard => 0,
5071 active_file_changes => 0,
5172 active_schema_changes => 0,
5273 active_table_locks => 0,
5374 active_named_releases => 0,
5475 active_databases => 0,
5576 active_file_monitors => 0,
5677 active_servers => 0,
5778 active_containers => 0,
5879 active_settings => 0,
5980 };
6081 my $key = $args{page_key} || '';
6182 $tvars->{"active_$key"} = 1 if exists $tvars->{"active_$key"};
6283
6384 my @html = $tpl->template('page_wrapper.html', $tvars);
6485 print @html;
6586 return;
6687}
6788
6889sub _initials {
6990 my $s = shift; $s //= '';
7091 my @p = split /[\s\@\.]+/, $s, 3;
7192 my $i = '';
7293 $i .= uc(substr($p[0], 0, 1)) if defined $p[0] && length $p[0];
7394 $i .= uc(substr($p[1], 0, 1)) if defined $p[1] && length $p[1];
7495 $i = uc(substr($s, 0, 1)) unless length $i;
7596 return $i;
7697}
7798
78991;