| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
/* ---- Typography CSS-var helper ---- */ |
| 5 |
var _typoKeys = {family:'font-family',weight:'font-weight',style:'font-style',decoration:'text-decoration',transform:'text-transform'}; |
| 6 |
var _respKeys = {sizeDesktop:'font-size-d',sizeTablet:'font-size-t',sizeMobile:'font-size-m',lineHeightDesktop:'line-height-d',lineHeightTablet:'line-height-t',lineHeightMobile:'line-height-m',letterSpacingDesktop:'letter-spacing-d',letterSpacingTablet:'letter-spacing-t',letterSpacingMobile:'letter-spacing-m',wordSpacingDesktop:'word-spacing-d',wordSpacingTablet:'word-spacing-t',wordSpacingMobile:'word-spacing-m'}; |
| 7 |
function typoCssVarsForEl(el, obj, prefix) { |
| 8 |
if (!obj || typeof obj !== 'object') return; |
| 9 |
var k; |
| 10 |
for (k in _typoKeys) { if (obj[k]) el.style.setProperty(prefix + _typoKeys[k], obj[k]); } |
| 11 |
for (k in _respKeys) { if (obj[k] !== undefined && obj[k] !== '') el.style.setProperty(prefix + _respKeys[k], obj[k]); } |
| 12 |
} |
| 13 |
|
| 14 |
function mk(tag, cls, styles) { var d = document.createElement(tag); if (cls) d.className = cls; if (styles) Object.keys(styles).forEach(function (k) { d.style[k] = styles[k]; }); return d; } |
| 15 |
function tx(tag, cls, text, styles) { var d = mk(tag, cls, styles); d.textContent = text; return d; } |
| 16 |
function ap(p) { Array.prototype.slice.call(arguments, 1).forEach(function (c) { if (c) p.appendChild(c); }); return p; } |
| 17 |
|
| 18 |
function statusInfo(s, a) { |
| 19 |
var map = { |
| 20 |
operational: { label: 'Operational', bg: a.operationalBg, color: a.operationalColor, dot: '#16a34a' }, |
| 21 |
degraded: { label: 'Degraded', bg: a.degradedBg, color: a.degradedColor, dot: '#d97706' }, |
| 22 |
outage: { label: 'Outage', bg: a.outageBg, color: a.outageColor, dot: '#dc2626' }, |
| 23 |
maintenance: { label: 'Maintenance', bg: a.maintenanceBg, color: a.maintenanceColor, dot: '#6366f1' } |
| 24 |
}; |
| 25 |
return map[s] || map.operational; |
| 26 |
} |
| 27 |
|
| 28 |
function overallBanner(s) { |
| 29 |
if (s === 'operational') return { text: '� |
| 30 |
All Systems Operational', bg: '#14532d', color: '#dcfce7' }; |
| 31 |
if (s === 'partial') return { text: '⚠️ Partial Service Disruption', bg: '#78350f', color: '#fef9c3' }; |
| 32 |
if (s === 'major') return { text: '🔴 Major Outage in Progress', bg: '#991b1b', color: '#fee2e2' }; |
| 33 |
return { text: '🔧 Scheduled Maintenance', bg: '#3730a3', color: '#e0e7ff' }; |
| 34 |
} |
| 35 |
|
| 36 |
function updateDotColor(status, a) { |
| 37 |
if (status === 'investigating') return a.updateDotInvestigating; |
| 38 |
if (status === 'identified') return a.updateDotIdentified; |
| 39 |
if (status === 'monitoring') return a.updateDotMonitoring; |
| 40 |
return a.updateDotResolved; |
| 41 |
} |
| 42 |
|
| 43 |
function incidentBorderColor(severity, a) { |
| 44 |
if (severity === 'major') return a.incidentBorderMajor; |
| 45 |
if (severity === 'minor') return a.incidentBorderMinor; |
| 46 |
return a.incidentBorderNotice; |
| 47 |
} |
| 48 |
|
| 49 |
function buildBlock(appEl) { |
| 50 |
if (appEl.dataset.rendered) return; |
| 51 |
appEl.dataset.rendered = '1'; |
| 52 |
|
| 53 |
var a = Object.assign({ |
| 54 |
pageTitle: 'System Status', overallStatus: 'operational', |
| 55 |
lastUpdated: '', showLastUpdated: true, |
| 56 |
components: [], showUptime: true, showDescription: true, |
| 57 |
incidents: [], showIncidents: true, |
| 58 |
incidentsLabel: 'Recent Incidents', componentsLabel: 'Components', |
| 59 |
fontSize: 14, titleFontSize: 26, lineHeight: 168, borderRadius: 12, |
| 60 |
bgColor: '#ffffff', borderColor: '#e5e7eb', headerBg: '#0f172a', |
| 61 |
headerColor: '#ffffff', metaColor: '#94a3b8', sectionHeadColor: '#111827', |
| 62 |
componentNameColor: '#1f2937', componentDescColor: '#6b7280', uptimeColor: '#6b7280', |
| 63 |
operationalBg: '#dcfce7', operationalColor: '#14532d', |
| 64 |
degradedBg: '#fef9c3', degradedColor: '#713f12', |
| 65 |
outageBg: '#fee2e2', outageColor: '#991b1b', |
| 66 |
maintenanceBg: '#e0e7ff', maintenanceColor: '#3730a3', |
| 67 |
incidentBorderMajor: '#ef4444', incidentBorderMinor: '#f59e0b', incidentBorderNotice: '#3b82f6', |
| 68 |
updateDotInvestigating: '#f59e0b', updateDotIdentified: '#ef4444', |
| 69 |
updateDotMonitoring: '#3b82f6', updateDotResolved: '#22c55e' |
| 70 |
}, JSON.parse(appEl.dataset.opts || '{}')); |
| 71 |
|
| 72 |
var lh = (a.lineHeight / 100).toFixed(2); |
| 73 |
var ob = overallBanner(a.overallStatus); |
| 74 |
|
| 75 |
/* Typography CSS vars on app element */ |
| 76 |
appEl.style.setProperty('--bksp-tt-sz', a.titleFontSize + 'px'); |
| 77 |
appEl.style.setProperty('--bksp-bd-sz', a.fontSize + 'px'); |
| 78 |
appEl.style.setProperty('--bksp-bd-lh', lh); |
| 79 |
if (a.fontWeight) appEl.style.setProperty('--bksp-bd-wt', a.fontWeight); |
| 80 |
typoCssVarsForEl(appEl, a.titleTypo, '--bksp-tt-'); |
| 81 |
typoCssVarsForEl(appEl, a.bodyTypo, '--bksp-bd-'); |
| 82 |
typoCssVarsForEl(appEl, a.sectionHeadTypo, '--bksp-sh-'); |
| 83 |
typoCssVarsForEl(appEl, a.componentNameTypo, '--bksp-cn-'); |
| 84 |
typoCssVarsForEl(appEl, a.incidentTitleTypo, '--bksp-it-'); |
| 85 |
|
| 86 |
var wrap = mk('div', 'bkbg-sp-wrap'); |
| 87 |
wrap.style.cssText = 'border:1px solid ' + a.borderColor + ';border-radius:' + a.borderRadius + 'px;overflow:hidden;background:' + a.bgColor; |
| 88 |
|
| 89 |
// Header |
| 90 |
var header = mk('div', 'bkbg-sp-header'); |
| 91 |
header.style.background = a.headerBg; |
| 92 |
var title = tx('h2', 'bkbg-sp-title', a.pageTitle); |
| 93 |
title.style.color = a.headerColor; |
| 94 |
ap(header, title); |
| 95 |
if (a.showLastUpdated && a.lastUpdated) { |
| 96 |
var meta = tx('div', 'bkbg-sp-meta', 'Last updated: ' + a.lastUpdated); |
| 97 |
meta.style.color = a.metaColor; |
| 98 |
ap(header, meta); |
| 99 |
} |
| 100 |
ap(wrap, header); |
| 101 |
|
| 102 |
// Overall banner |
| 103 |
var banner = tx('div', 'bkbg-sp-banner', ob.text); |
| 104 |
banner.style.cssText = 'background:' + ob.bg + ';color:' + ob.color; |
| 105 |
ap(wrap, banner); |
| 106 |
|
| 107 |
// Components section |
| 108 |
var compSec = mk('div', 'bkbg-sp-section'); |
| 109 |
var compHead = tx('h3', 'bkbg-sp-section-head', a.componentsLabel); |
| 110 |
compHead.style.color = a.sectionHeadColor; |
| 111 |
ap(compSec, compHead); |
| 112 |
|
| 113 |
var compList = mk('div', 'bkbg-sp-comp-list'); |
| 114 |
compList.style.cssText = 'border:1px solid ' + a.borderColor; |
| 115 |
a.components.forEach(function (comp, i) { |
| 116 |
var si = statusInfo(comp.status, a); |
| 117 |
var row = mk('div', 'bkbg-sp-comp-row'); |
| 118 |
if (i > 0) { row.style.borderTopColor = a.borderColor; } |
| 119 |
|
| 120 |
var left = mk('div'); |
| 121 |
var name = tx('div', 'bkbg-sp-comp-name', comp.name); |
| 122 |
name.style.color = a.componentNameColor; |
| 123 |
ap(left, name); |
| 124 |
if (a.showDescription && comp.description) { |
| 125 |
var desc = tx('div', 'bkbg-sp-comp-desc', comp.description); |
| 126 |
desc.style.color = a.componentDescColor; |
| 127 |
ap(left, desc); |
| 128 |
} |
| 129 |
|
| 130 |
var right = mk('div', 'bkbg-sp-comp-right'); |
| 131 |
if (a.showUptime) { |
| 132 |
var upt = tx('span', 'bkbg-sp-uptime', comp.uptime + '%'); |
| 133 |
upt.style.color = a.uptimeColor; |
| 134 |
ap(right, upt); |
| 135 |
} |
| 136 |
var badge = mk('span', 'bkbg-sp-status-badge'); |
| 137 |
badge.style.cssText = 'background:' + si.bg + ';color:' + si.color; |
| 138 |
var dot = mk('span', 'bkbg-sp-status-dot'); |
| 139 |
dot.style.background = si.dot; |
| 140 |
ap(badge, dot, document.createTextNode(si.label)); |
| 141 |
ap(right, badge); |
| 142 |
ap(row, left, right); |
| 143 |
ap(compList, row); |
| 144 |
}); |
| 145 |
ap(compSec, compList); |
| 146 |
ap(wrap, compSec); |
| 147 |
|
| 148 |
// Incidents section |
| 149 |
if (a.showIncidents && a.incidents.length > 0) { |
| 150 |
var incSec = mk('div', 'bkbg-sp-section'); |
| 151 |
incSec.style.paddingTop = '0'; |
| 152 |
var incHead = tx('h3', 'bkbg-sp-section-head', a.incidentsLabel); |
| 153 |
incHead.style.color = a.sectionHeadColor; |
| 154 |
ap(incSec, incHead); |
| 155 |
|
| 156 |
var incList = mk('div', 'bkbg-sp-incidents'); |
| 157 |
a.incidents.forEach(function (inc) { |
| 158 |
var borderC = incidentBorderColor(inc.severity, a); |
| 159 |
var card = mk('div', 'bkbg-sp-incident'); |
| 160 |
card.style.cssText = 'border-color:' + a.borderColor + ';border-left-color:' + borderC + ';background:#fafafa'; |
| 161 |
|
| 162 |
var incH = mk('div', 'bkbg-sp-inc-header'); |
| 163 |
var incTitle = tx('strong', 'bkbg-sp-inc-title', inc.title); |
| 164 |
incTitle.style.color = a.componentNameColor; |
| 165 |
var incMeta = mk('div', 'bkbg-sp-inc-meta'); |
| 166 |
var incDate = tx('span', 'bkbg-sp-inc-date', inc.date); |
| 167 |
incDate.style.color = a.componentDescColor; |
| 168 |
var sevBadge = tx('span', 'bkbg-sp-severity-badge', inc.severity.toUpperCase()); |
| 169 |
sevBadge.style.cssText = 'background:' + borderC + '22;color:' + borderC; |
| 170 |
ap(incMeta, incDate, sevBadge); |
| 171 |
ap(incH, incTitle, incMeta); |
| 172 |
ap(card, incH); |
| 173 |
|
| 174 |
var updList = mk('div', 'bkbg-sp-updates'); |
| 175 |
(inc.updates || []).forEach(function (u) { |
| 176 |
var dotColor = updateDotColor(u.status, a); |
| 177 |
var uRow = mk('div', 'bkbg-sp-update-row'); |
| 178 |
var uDot = mk('span', 'bkbg-sp-update-dot'); |
| 179 |
uDot.style.background = dotColor; |
| 180 |
var uTime = tx('span', 'bkbg-sp-update-time', u.time); |
| 181 |
uTime.style.color = a.componentDescColor; |
| 182 |
var uMsg = tx('span', 'bkbg-sp-update-msg', u.message); |
| 183 |
uMsg.style.color = a.componentNameColor; |
| 184 |
ap(uRow, uDot, uTime, uMsg); |
| 185 |
ap(updList, uRow); |
| 186 |
}); |
| 187 |
ap(card, updList); |
| 188 |
ap(incList, card); |
| 189 |
}); |
| 190 |
ap(incSec, incList); |
| 191 |
ap(wrap, incSec); |
| 192 |
} |
| 193 |
|
| 194 |
appEl.innerHTML = ''; |
| 195 |
appEl.appendChild(wrap); |
| 196 |
} |
| 197 |
|
| 198 |
function init() { document.querySelectorAll('.bkbg-status-page-app').forEach(buildBlock); } |
| 199 |
if (document.readyState !== 'loading') { init(); } else { document.addEventListener('DOMContentLoaded', init); } |
| 200 |
})(); |
| 201 |
|