13 lines
4.4 KiB
JavaScript
13 lines
4.4 KiB
JavaScript
import {formatDuneDate} from './dune-date.mjs';
|
|
const el=(tag,text,cls)=>{const n=document.createElement(tag);if(text!==undefined)n.textContent=text;if(cls)n.className=cls;return n;};
|
|
export const clanPublicUrl=(clan,kind='clan')=>'https://www.dunerealms.com/'+({clan:'clans',company:'companies',politics:'political-houses'}[kind]||'clans')+'/'+encodeURIComponent(clan.tag);
|
|
export const isRoyalHouse=clan=>(clan.charter_kind||clan.charterKind)==='royal';
|
|
const status=clan=>clan.institution_key?'Protected institution':isRoyalHouse(clan)?'Royal House':clan.charter_kind==='original'?'Keyed clan':'Basic clan';
|
|
function view(clan,kind='clan'){const a=el('a','View '+(kind==='company'?'company':kind==='politics'?'House':'clan')+' →','clan-register-view');a.href=clanPublicUrl(clan,kind);a.target='_top';a.setAttribute('aria-label','View '+clan.name+' public profile');return a;}
|
|
function logo(clan,size){const img=el('img');img.src=clan.emblem;img.alt='';img.width=img.height=size;img.loading='lazy';return img;}
|
|
export function renderClanRegister(host,rows,{kind='clan'}={}){const noun=kind==='company'?'Company':kind==='politics'?'Political House':'Clan';
|
|
host.replaceChildren();const royal=el('section',undefined,'clan-royal-directory'),grid=el('div',undefined,'clan-grid');royal.append(el('h3',kind==='politics'?'Protected Political Houses':kind==='company'?'Major Companies':'Royal Houses'));const houses=rows.filter(r=>kind==='politics'||isRoyalHouse(r));
|
|
for(const clan of houses){const card=el('article',undefined,'clan-card clan-recruit-card'),portrait=el('div',undefined,'clan-directory-portrait'),crest=logo(clan,160);crest.className='clan-directory-crest';portrait.append(crest,el('span',kind==='politics'?'PROTECTED HOUSE':kind==='company'?'MAJOR COMPANY':'ROYAL HOUSE'));const body=el('div',undefined,'clan-directory-body'),tag=el('small','['+clan.tag+']','clan-directory-tag'),footer=el('div',undefined,'clan-directory-footer');footer.append(el('span',Number(clan.member_count)+' members'),view(clan,kind));body.append(tag,el('h3',clan.name),el('p',clan.realm||(kind==='company'?'Independent Company':'Independent House')),el('p',clan.description||(kind==='company'?'This company has not published an introduction yet.':'This House has not published an introduction yet.'),'clan-directory-bio'),footer);card.append(portrait,body);grid.append(card);}if(!houses.length)grid.append(el('p',kind==='company'?'No Major Companies match the current filters.':'No Royal Houses match the current filters.','clan-register-empty'));royal.append(grid);host.append(royal);
|
|
const register=el('section',undefined,'clan-public-register');register.append(el('h3',noun+' Registry'),el('p','Registered organisations · public identity, leadership and membership.'));const wrap=el('div',undefined,'clan-register-scroll'),table=el('table'),head=el('thead'),tr=el('tr');for(const name of [noun,kind==='company'?'Chief Executive':kind==='politics'?'Officeholder':'Owner','Members','Status',kind==='clan'?'Homeworld':'Affiliation',kind==='politics'?'Term begins':'Established','View '+noun.toLowerCase()]){const th=el('th',name);th.scope='col';tr.append(th);}head.append(tr);const body=el('tbody');
|
|
for(const clan of rows){const row=el('tr'),identity=el('td'),name=el('div',undefined,'clan-register-identity'),copy=el('div'),link=el('a',clan.name);link.href=clanPublicUrl(clan,kind);link.target='_top';copy.append(link,el('small','['+clan.tag+']'));name.append(logo(clan,36),copy);identity.append(name);const owner=el('td');if(clan.owner_username){const a=el('a',clan.owner_name||clan.owner_username);a.href='https://www.dunerealms.com/'+(clan.owner_memorial?'memorial/'+encodeURIComponent(clan.owner_memorial):'people/'+encodeURIComponent(clan.owner_username));a.target='_top';owner.append(a);}else owner.append(el('span','Not listed'));const action=el('td');action.append(view(clan,kind));row.append(identity,owner,el('td',clan.member_count==null?'Not published':String(Number(clan.member_count)||0)),el('td',kind==='clan'?status(clan):(clan.standing||'Protected House')),el('td',clan.homeworldName||clan.realm||'Not selected'),el('td',(clan.created_at||clan.term?.startsAt)?formatDuneDate(Number(clan.created_at||clan.term.startsAt)):'—'),action);body.append(row);}if(!rows.length){const row=el('tr'),cell=el('td','No organisations match the current filters.');cell.colSpan=7;row.append(cell);body.append(row);}table.append(head,body);wrap.append(table);register.append(wrap);host.append(register);
|
|
}
|

Staff