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:35:25

Added
+3
lines
Removed
-1
lines
Context
101
unchanged
Blobs
from ab583ffe8e9c
to 65ecf633cf3a
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",
35 "$base/assets/styles/help_tips.css",
3536 "$base/assets/js/tz_localize.js",
36 "$base/assets/js/ds_charts.js") {
37 "$base/assets/js/ds_charts.js",
38 "$base/assets/js/ds_help.js") {
3739 my @st = stat $p;
3840 $max = $st[9] if @st && $st[9] > $max;
3941 }
4042 $ASSET_VERSION = $max || time;
4143 return $ASSET_VERSION;
4244}
4345
4446sub new { return bless({}, shift); }
4547
4648sub wrapper {
4749 my ($self, %args) = @_;
4850 my $tpl = MODS::Template->new;
4951
5052 my $userinfo = $args{userinfo} || {};
5153 my $initials = _initials($userinfo->{display_name} || $userinfo->{email} || 'User');
5254
5355 my $tvars = {
5456 # Branding
5557 brand_name => $cfg->settings('brand_name') || 'DriftSense',
5658 brand_tagline => $cfg->settings('brand_tagline') || '',
5759
5860 # Asset cache-bust stamp -- max mtime of shipped CSS/JS
5961 asset_version => _asset_version(),
6062
6163 # Page identity
6264 page_title => $args{page_title} || 'DriftSense',
6365 page_body => $args{body_html} // (@{$args{body_lines} || []} ? join('', @{$args{body_lines}}) : ''),
6466
6567 # User
6668 user_name => $userinfo->{display_name} || $userinfo->{email} || 'Operator',
6769 user_initials => $initials,
6870
6971 # Sidebar active-item flags (page_key sets exactly one)
7072 active_dashboard => 0,
7173 active_file_changes => 0,
7274 active_schema_changes => 0,
7375 active_table_locks => 0,
7476 active_named_releases => 0,
7577 active_alerts => 0,
7678 active_export => 0,
7779 active_purge_log => 0,
7880 active_databases => 0,
7981 active_file_monitors => 0,
8082 active_servers => 0,
8183 active_containers => 0,
8284 active_settings => 0,
8385 };
8486 my $key = $args{page_key} || '';
8587 $tvars->{"active_$key"} = 1 if exists $tvars->{"active_$key"};
8688
8789 my @html = $tpl->template('page_wrapper.html', $tvars);
8890 print @html;
8991 return;
9092}
9193
9294sub _initials {
9395 my $s = shift; $s //= '';
9496 my @p = split /[\s\@\.]+/, $s, 3;
9597 my $i = '';
9698 $i .= uc(substr($p[0], 0, 1)) if defined $p[0] && length $p[0];
9799 $i .= uc(substr($p[1], 0, 1)) if defined $p[1] && length $p[1];
98100 $i = uc(substr($s, 0, 1)) unless length $i;
99101 return $i;
100102}
101103
1021041;