forked from unimatrix/web
Unify staff and public government directories with Order artwork and shared banners
This commit is contained in:
parent
30bb09ad6b
commit
8f3c7e06c5
3 changed files with 139 additions and 15 deletions
|
|
@ -26,7 +26,7 @@ export function projectPublicOrganisation(rows,orderRows=[],officialRows=[]){
|
|||
const holders=(type,key,role)=>staff.filter(p=>p.functions.some(f=>f.scopeType===type&&f.scopeKey===key&&f.role===role)).map(p=>({username:p.username,displayName:p.displayName,title:p.title}));
|
||||
const organisation=ORGANISATION.map(d=>({key:d.key,label:d.label,heads:holders('department',d.key,'department_head'),branches:d.branches.map(b=>({...b,leads:holders('branch',b.key,'branch_lead'),members:holders('branch',b.key,'officer')}))}));
|
||||
const order=[...new Map(orderRows.map(r=>[r.username,{username:r.username,displayName:r.display_name||r.username,citation:r.citation||'',profile:r.slug?'/memorial/'+encodeURIComponent(r.slug):'/people/'+encodeURIComponent(r.username)}])).values()];
|
||||
const officialAccounts=officialRows.filter(r=>r.id===OFFICIAL_ACCOUNT.id&&r.username===OFFICIAL_ACCOUNT.username&&r.role==='official_account').map(r=>({username:r.username,displayName:'DuneRealms',title:'Official DuneRealms Account',bio:r.bio||'Official account operated by the DuneRealms owner. Verify this profile through the staff directory.',profile:'/people/'+r.username,avatar:'https://cp.dunerealms.com/api/avatars/face/roster/'+r.username,official:true,functions:[],seals:[]}));
|
||||
const officialAccounts=officialRows.filter(r=>r.id===OFFICIAL_ACCOUNT.id&&r.username===OFFICIAL_ACCOUNT.username&&r.role==='official_account').map(r=>({username:r.username,displayName:'DuneRealms',title:'Official DuneRealms Account',bio:r.bio||'Official DuneRealms announcements and correspondence. Verify this profile through the staff directory.',profile:'/people/'+r.username,avatar:'https://cp.dunerealms.com/api/avatars/face/roster/'+r.username,official:true,functions:[],seals:[]}));
|
||||
return {model:'organisation-v2',publishedOnly:true,executives:staff.filter(p=>p.functions.some(f=>f.scopeType==='organisation')).map(p=>({username:p.username,displayName:p.displayName,title:p.title})),organisation,staff,order,officialAccounts};
|
||||
}
|
||||
export async function readPublicOrganisation(db){
|
||||
|
|
|
|||
27
website/node/public-government.mjs
Normal file
27
website/node/public-government.mjs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import {electionDates,electionWindow} from '../control-panel/public/election-rules.mjs';
|
||||
export const PUBLIC_OFFICES=Object.freeze([
|
||||
{key:'emperor',kind:'imperial',faction:'imperium',office:'emperor',name:'Office of the Emperor',scope:'The Imperium',art:'emperor-v1.png',description:'The elected imperial office, representing the realms across the Imperium.'},
|
||||
...[['atreides','House Aerdrecht','house-aerdrecht-v1.png'],['harkonnen','House Harkveen','house-harkveen-v1.png'],['corrino','House Korenholt','house-korenholt-v1.png'],['ordos','House Oordwijk','house-oordwijk-v1.png'],['fremen','Vrijduin','house-vrijduin-v1.png'],['veiled_concord','The Veiled Concord','veiled-concord-v1.png']].map(([faction,scope,art])=>({key:faction,kind:'house',faction,office:faction==='veiled_concord'?'reverent_mother':'house_leader',name:faction==='veiled_concord'?'Office of the Reverent Mother':scope+' Leadership',scope,art,description:faction==='veiled_concord'?'The elected leadership of the Veiled Concord.':'The elected leadership and public representation of '+scope+'.'}))
|
||||
]);
|
||||
export function projectGovernment(terms,now=Date.now()){
|
||||
return PUBLIC_OFFICES.map(office=>{
|
||||
const active=terms.filter(t=>t.kind===office.kind&&t.faction===office.faction&&t.office===office.office&&t.outcome==='winner'&&Number(t.starts_at)<=now&&Number(t.expires_at)>now);
|
||||
const term=active.length===1?active[0]:null;
|
||||
const holder=term&&/^[a-z0-9_]{3,32}$/i.test(term.username||'')?{username:term.username,name:term.display_name||term.username,profile:'/people/'+encodeURIComponent(term.username),avatar:'https://cp.dunerealms.com/api/avatars/face/roster/'+encodeURIComponent(term.username)}:null;
|
||||
return {...office,state:holder?'occupied':active.length?'verification_pending':'vacant',holder,term:holder?{startsAt:Number(term.starts_at),expiresAt:Number(term.expires_at)}:null};
|
||||
});
|
||||
}
|
||||
export function publicElectionCalendar(now=Date.now()){
|
||||
return ['house','imperial'].map(kind=>{
|
||||
const dates=electionDates(kind,now-3*3600000,1),window=electionWindow(kind,dates[0],now);
|
||||
return {kind,...window,termWeeks:kind==='house'?2:4};
|
||||
});
|
||||
}
|
||||
export function createPublicGovernment(db,{clock=Date.now}={}){return async request=>{
|
||||
if(request.method!=='GET')return Response.json({message:'Read-only public office register.'},{status:405});
|
||||
if(new URL(request.url).search)return Response.json({message:'No identity overrides are accepted.'},{status:400});
|
||||
try{
|
||||
const now=clock(),rows=await db.prepare("SELECT t.kind,t.faction,t.office,t.starts_at,t.expires_at,t.outcome,a.username,a.display_name FROM political_office_terms t LEFT JOIN site_accounts a ON a.id=t.user_id AND a.password_hash NOT LIKE '!%' WHERE t.outcome='winner' AND t.starts_at<=? AND t.expires_at>? ORDER BY t.starts_at DESC LIMIT 100").bind(now,now).all();
|
||||
return Response.json({offices:projectGovernment(rows.results||[],now),elections:publicElectionCalendar(now),observedAt:now},{headers:{'Cache-Control':'public,max-age=30'}});
|
||||
}catch{return Response.json({message:'The public office register is temporarily unavailable.'},{status:503,headers:{'Cache-Control':'no-store'}});}
|
||||
};}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import {startNativeSyncRetryWorker} from './native-sync-outbox.mjs';
|
||||
import {createPublicGovernment} from './public-government.mjs';
|
||||
import {createMemorials} from './memorials.mjs';
|
||||
import {initializeLifeStatus} from './life-status.mjs';
|
||||
import {SHARED_HEADER} from '../scripts/portal-navigation.mjs';
|
||||
|
|
@ -30,6 +31,7 @@ export function createApplication(db,settings={}) {
|
|||
const gitIdentity=createGitIdentityRoute(db,settings,origin);
|
||||
const worldStatus=createWorldStatus(settings);
|
||||
const publicRoster=createPublicStaffRoster(db);const memorials=createMemorials(db,settings);
|
||||
const publicGovernment=createPublicGovernment(db);
|
||||
const contact=createContact(settings);
|
||||
const gameLink=createGameLink(db,settings,origin);
|
||||
const rewards=createCommunityRewards(db,settings,origin);
|
||||
|
|
@ -55,6 +57,7 @@ export function createApplication(db,settings={}) {
|
|||
if(url.pathname==='/api/game-link'||url.pathname.startsWith('/api/game-link/'))return gameLink(request);
|
||||
if(url.pathname.startsWith('/api/contact/'))return contact(request);
|
||||
if(url.pathname==='/api/staff/roster')return publicRoster(request);
|
||||
if(url.pathname==='/api/public/government')return publicGovernment(request);
|
||||
if(url.pathname==='/api/companies'){
|
||||
if(request.method!=='GET')return Response.json({message:'Method not allowed'},{status:405});
|
||||
return Response.json({companies:await listPublicCompanies(db)},{headers:{'Cache-Control':'no-store'}});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff