MC/website/web/staff-directory.js
2026-11-27 23:43:05 +00:00

19 lines
5.4 KiB
JavaScript

const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
const files=Object.fromEntries(['community_operations','dunerealms_operations','customer_support','sales_accounts','content_creative','news_media','trust_safety','it_operations','engineering','people_operations','legal_compliance'].map(key=>[key,'scope-'+key+'-v1-150.png']));
function seal(file,label){const img=el('img');img.src='/assets/seals/'+file;img.alt=label;img.loading='lazy';img.addEventListener('error',()=>{img.hidden=true;},{once:true});return img;}
function profile(p){const a=el('a',p.displayName||p.username);a.href=/^\/(?:people|memorial)\/[a-z0-9_%.-]+$/i.test(p.profile||'')?p.profile:'/people/'+encodeURIComponent(p.username);return a;}
function holders(people,empty='VACANT'){const wrap=el('div',undefined,'staff-holders');if(!people.length)wrap.append(el('span',empty,'staff-vacant'));for(const p of people)wrap.append(profile(p));return wrap;}
function card(p){const c=el('article',undefined,'staff-person'),head=el('header'),avatar=el('img');avatar.src=p.avatar||'https://cp.dunerealms.com/api/avatars/face/roster/'+encodeURIComponent(p.username);avatar.alt='';avatar.loading='lazy';avatar.width=avatar.height=64;head.append(avatar,profile(p));c.append(head,el('p',p.title||p.rank||'Staff','staff-title'),el('p',p.bio||'','staff-bio'));
const list=el('ul');for(const f of p.functions||[]){const li=el('li');li.append(el('strong',f.scopeLabel),el('span',f.roleLabel));list.append(li);}c.append(list);
const marks=el('div',undefined,'staff-marks'),seen=new Set();if(p.personalSeal?.file&&/^[a-z0-9_-]+\.png$/.test(p.personalSeal.file)){const personal=seal(p.personalSeal.file,p.personalSeal.label);personal.className='staff-personal-mark';c.insertBefore(personal,list);}for(const f of p.functions||[]){const file=files[f.scopeKey];if(file&&!seen.has(file)){marks.append(seal(file,f.scopeLabel+' function seal'));seen.add(file);}}
for(const a of p.seals||[])if(/^[a-z0-9_-]+\.png$/.test(a.file||''))marks.append(seal(a.file,a.label||'Earned honour'));if(marks.childElementCount){const details=el('details');details.append(el('summary','Function seals & earned honours'),marks);c.append(details);}const link=profile(p);link.textContent='View profile →';link.className='staff-profile-link';c.append(link);return c;}
function render(data){const chart=document.querySelector('#organisation-chart'),cards=document.querySelector('#staff-members'),order=document.querySelector('#order-members');
if(data.model!=='organisation-v2'){const people=new Map();for(const g of data.groups||[])for(const p of g.staff||[])people.set(p.username,p);for(const p of people.values())cards.append(card(p));chart.append(el('p','The new organigram will appear when its migration is activated.','staff-empty'));document.querySelector('#staff-status').textContent=people.size+' existing public staff profiles.';return;}
const exec=el('div',undefined,'staff-executives');for(const p of data.executives){const c=el('article'),text=el('div'),person=data.staff.find(s=>s.username===p.username);if(person?.personalSeal)c.append(seal(person.personalSeal.file,p.title+' personal seal'));text.append(el('small',p.title),profile(p));c.append(text);exec.append(c);}chart.append(exec);
const deps=el('div',undefined,'staff-departments');for(const d of data.organisation){const section=el('section',undefined,'staff-department'),head=el('header');head.append(seal(files[d.key],d.label),el('h3',d.label));section.append(head,el('small','DEPARTMENT HEAD'),holders(d.heads));const branches=el('div',undefined,'staff-branches');for(const b of d.branches){const c=el('article');const title=el('header',undefined,'staff-branch-title');title.append(seal(files[b.key],b.label),el('h4',b.label));c.append(title,el('small','BRANCH LEAD'),holders(b.leads),el('small','OFFICERS'),holders(b.members,'No published officers'));branches.append(c);}section.append(branches);deps.append(section);}chart.append(deps);
for(const p of data.staff)cards.append(card(p));if(!data.staff.length)cards.append(el('p','No staff profiles are published yet.','staff-empty'));
for(const p of data.officialAccounts||[]){const c=el('article',undefined,'staff-person');c.append(seal('master-imperial-150.png','DuneRealms official insignia'),el('span','✓ VERIFIED OFFICIAL ACCOUNT','staff-verified'),el('h3','DuneRealms'),el('p','Official announcements and correspondence.'));const link=profile(p);link.textContent='Verify official profile →';link.className='staff-profile-link';c.append(link);document.querySelector('#official-accounts').append(c);document.querySelector('#official-account-section').hidden=false;}
for(const p of data.order){const c=el('article',undefined,'staff-order-member');c.append(seal('order-crysknife-v1.png','Holy Order of the Crysknife'),profile(p));if(p.citation)c.append(el('p',p.citation));order.append(c);}if(!data.order.length)order.append(el('p','No public Order memberships are listed.','staff-empty'));
document.querySelector('#staff-status').textContent=data.staff.length+' published staff profiles · Functions from the central organisation register.';
}
try{const r=await fetch('/api/staff/roster',{cache:'no-store',headers:{Accept:'application/json'}});if(!r.ok)throw Error();const data=await r.json();if(data.model!=='organisation-v2'&&!Array.isArray(data.groups))throw Error();render(data);}catch{document.querySelector('#staff-status').textContent='The staff register is temporarily unavailable. Please contact Support for assistance.';}