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-12 00:19:46

Added
+1
lines
Removed
-0
lines
Context
101
unchanged
Blobs
from ca35d1fc0760
to ab583ffe8e9c
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;
2525
2626# Cache-bust CSS/JS by the newest mtime among the assets we ship. Recomputed
2727# per-process; requests inside the same worker share the value, but a new
2828# deploy touches files and the next worker start picks it up automatically.
2929my $ASSET_VERSION;
3030sub _asset_version {
3131 return $ASSET_VERSION if defined $ASSET_VERSION;
3232 my $base = '/var/www/vhosts/3dshawn.com/site1';
3333 my $max = 0;
3434 for my $p ("$base/assets/styles/drift_sense.css",
3535 "$base/assets/js/tz_localize.js",
3636 "$base/assets/js/ds_charts.js") {
3737 my @st = stat $p;
3838 $max = $st[9] if @st && $st[9] > $max;
3939 }
4040 $ASSET_VERSION = $max || time;
4141 return $ASSET_VERSION;
4242}
4343
4444sub new { return bless({}, shift); }
4545
4646sub wrapper {
4747 my ($self, %args) = @_;
4848 my $tpl = MODS::Template->new;
4949
5050 my $userinfo = $args{userinfo} || {};
5151 my $initials = _initials($userinfo->{display_name} || $userinfo->{email} || 'User');
5252
5353 my $tvars = {
5454 # Branding
5555 brand_name => $cfg->settings('brand_name') || 'DriftSense',
5656 brand_tagline => $cfg->settings('brand_tagline') || '',
5757
5858 # Asset cache-bust stamp -- max mtime of shipped CSS/JS
5959 asset_version => _asset_version(),
6060
6161 # Page identity
6262 page_title => $args{page_title} || 'DriftSense',
6363 page_body => $args{body_html} // (@{$args{body_lines} || []} ? join('', @{$args{body_lines}}) : ''),
6464
6565 # User
6666 user_name => $userinfo->{display_name} || $userinfo->{email} || 'Operator',
6767 user_initials => $initials,
6868
6969 # Sidebar active-item flags (page_key sets exactly one)
7070 active_dashboard => 0,
7171 active_file_changes => 0,
7272 active_schema_changes => 0,
7373 active_table_locks => 0,
7474 active_named_releases => 0,
7575 active_alerts => 0,
7676 active_export => 0,
77 active_purge_log => 0,
7778 active_databases => 0,
7879 active_file_monitors => 0,
7980 active_servers => 0,
8081 active_containers => 0,
8182 active_settings => 0,
8283 };
8384 my $key = $args{page_key} || '';
8485 $tvars->{"active_$key"} = 1 if exists $tvars->{"active_$key"};
8586
8687 my @html = $tpl->template('page_wrapper.html', $tvars);
8788 print @html;
8889 return;
8990}
9091
9192sub _initials {
9293 my $s = shift; $s //= '';
9394 my @p = split /[\s\@\.]+/, $s, 3;
9495 my $i = '';
9596 $i .= uc(substr($p[0], 0, 1)) if defined $p[0] && length $p[0];
9697 $i .= uc(substr($p[1], 0, 1)) if defined $p[1] && length $p[1];
9798 $i = uc(substr($s, 0, 1)) unless length $i;
9899 return $i;
99100}
100101
1011021;