From 2ee97bb102dea7ba6c88a66eac0776f2a7a5df26 Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Fri, 20 Nov 2026 21:24:02 +0100 Subject: [PATCH] Style live JARVIS registers with key icons and faction-specific deed seals --- .../public/cp-v2/cp-v2-code-type-icon.mjs | 8 ++++++++ .../public/cp-v2/cp-v2-codex-management.css | 3 +++ .../public/cp-v2/cp-v2-jarvis-register.mjs | 3 ++- .../public/cp-v2/cp-v2-register-presentation.mjs | 11 +++++++++++ website/node/jarvis-management.mjs | 2 +- website/tests/jarvis-management.test.mjs | 3 +++ website/tests/jarvis-register-presentation.test.mjs | 6 ++++++ 7 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 website/control-panel/public/cp-v2/cp-v2-register-presentation.mjs create mode 100644 website/tests/jarvis-register-presentation.test.mjs diff --git a/website/control-panel/public/cp-v2/cp-v2-code-type-icon.mjs b/website/control-panel/public/cp-v2/cp-v2-code-type-icon.mjs index be1a33ca..b5a5894f 100644 --- a/website/control-panel/public/cp-v2/cp-v2-code-type-icon.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-code-type-icon.mjs @@ -7,3 +7,11 @@ export function createCodeTypeIcon(kind){ if(['silver','gold'].includes(art)){image.classList.add('reward-type-'+art);image.style.backgroundImage='url(https://cp.dunerealms.com/assets/organisation-deed-keys-v1.png)';}else image.style.backgroundImage='url(https://www.dunerealms.com/assets/'+art+')'; summary.append(image,text);details.append(summary,help);return details; } + +// Shared visual catalogue for private codes and the management register. +const keyAliases={'clan-founding':'clan','company-founding':'company','clan-subhouse':'subhouse','company-subsidiary':'subsidiary','political-clan':'politics-clan','political-appointment':'politics','staff-office-royal':'politics','staff-company-royal':'politics'}; +const systemIcons={'entity-state':['Entity state','esk-key-v1.png'],'system-identity':['System identity','nav-account-v2.webp'],'progression-policy':['Progression policy','exchange-quests-v1.png'],quest:['Quest','exchange-quests-v1.png'],'quest-milestone':['Quest milestone','exchange-quests-v1.png'],'gazette-news':['Gazette publication','nav-home-v2.webp'],'entity-transfer':['Organisation transfer','nav-clan-v2.webp'],'staff-parent-link':['Staff parent link','nav-staff-v2.webp'],'clan-administration':['Clan administration','nav-clan-v2.webp'],'account-test-identity':['Synthetic game identity','nav-account-v2.webp'],'xp-correction':['Experience correction','exchange-quests-v1.png'],'xp-transfer':['Season experience transfer','exchange-quests-v1.png'],'economy-snapshot':['Economic snapshot','imperial-postbank-v2.png'],'project-action':['Project action','nav-manual-v2.webp']}; +export function keyTypePresentation(type){ + const code=types[keyAliases[type]||type];if(code)return {label:code[0],art:code[2]}; + const system=systemIcons[type];return system?{label:system[0],art:system[1]}:{label:String(type||'Unclassified key').replaceAll('-',' '),art:'nav-manual-v2.webp'}; +} diff --git a/website/control-panel/public/cp-v2/cp-v2-codex-management.css b/website/control-panel/public/cp-v2/cp-v2-codex-management.css index 754e5068..d859feb4 100644 --- a/website/control-panel/public/cp-v2/cp-v2-codex-management.css +++ b/website/control-panel/public/cp-v2/cp-v2-codex-management.css @@ -8,3 +8,6 @@ .codex-management-grid>.codex-register-frame{grid-column:1/-1}.codex-live-register .codex-table-scroll{overflow-x:auto;max-width:100%;min-width:0}.codex-live-register table{min-width:780px;table-layout:auto}.codex-live-register th,.codex-live-register td{white-space:nowrap;overflow-wrap:normal;word-break:normal}.codex-live-register .jarvis-copy-reference{padding:7px 10px;border:1px solid #a48b4d;border-radius:6px;background:#18372d;color:#eed594;cursor:pointer;white-space:nowrap} .codex-management-hero{flex-wrap:wrap}.codex-management-hero>div{flex:1;min-width:180px}.codex-management-hero>.codex-header-validator{flex:0 1 390px;min-width:0;max-width:100%;padding:14px}.codex-header-validator h3{font-size:18px;margin:0 0 6px}.codex-header-validator p{font-size:12px;margin:5px 0 10px}.codex-header-validator form{display:flex;gap:8px}.codex-header-validator input{flex:1;min-width:0;padding:10px;border:1px solid #667b61;border-radius:6px;background:#102a24;color:#eee6cf}.codex-header-validator button{flex:none;border:1px solid #b99b56;border-radius:6px;background:#214536;color:#f0db9e;padding:9px 12px}.codex-header-validation-result:empty{display:none}.codex-header-validation-result{padding:14px 18px}.codex-live-register .jarvis-copy-reference{font-size:18px;line-height:1.1}.codex-live-register .jarvis-copy-reference:focus-visible{outline:2px solid #f1d58d;outline-offset:3px}@media(max-width:600px){.codex-management-hero>.codex-header-validator{flex-basis:100%;width:100%}} + +/* Dev Alpha registers: compact artwork, alternating rows, clear focus. */ +.codex-live-register tbody tr:nth-child(odd){background:#123127}.codex-live-register tbody tr:nth-child(even){background:#1b3b30}.codex-live-register tbody tr:hover{background:#294a39}.codex-live-register td{vertical-align:middle}.codex-live-register .jarvis-copy-reference{display:inline-flex;align-items:center;justify-content:center;padding:5px;border-color:#8e8050;background:#10291f}.jarvis-register-icon{display:block;width:54px;height:58px;background:center/contain no-repeat}.jarvis-register-icon.jarvis-register-silver,.jarvis-register-icon.jarvis-register-gold{background-size:200% 100%}.jarvis-register-silver{background-position:left center}.jarvis-register-gold{background-position:right center}.codex-live-register td:nth-child(2){white-space:normal;min-width:160px;max-width:260px} diff --git a/website/control-panel/public/cp-v2/cp-v2-jarvis-register.mjs b/website/control-panel/public/cp-v2/cp-v2-jarvis-register.mjs index 3cb8dcbb..f311dd68 100644 --- a/website/control-panel/public/cp-v2/cp-v2-jarvis-register.mjs +++ b/website/control-panel/public/cp-v2/cp-v2-jarvis-register.mjs @@ -1,3 +1,4 @@ +import {registerPresentation} from './cp-v2-register-presentation.mjs'; import {createUserAPI} from './cp-v2-user-api.mjs'; const el=(tag,text)=>{const node=document.createElement(tag);if(text!==undefined)node.textContent=text;return node;}; const date=value=>value?new Date(Number(value)).toLocaleString('en-GB'):'—'; @@ -8,7 +9,7 @@ export function createJarvisRegister(section,{fetcher=fetch}={}){ async function load(){if(!active||busy)return;loaded=true;busy=true;previous.disabled=next.disabled=refresh.disabled=true;status.textContent='Opening the J.A.R.V.I.S. register…';try{ const data=await api.request('/api/jarvis/management?section='+encodeURIComponent(section)+'&page='+page);if(!active)return;records.replaceChildren(); if(section==='seasons'){records.append(el('p',data.edition.stage+' · '+data.edition.version+' · '+data.edition.season));previous.hidden=next.hidden=pageLabel.hidden=true;} - else{const wrap=el('div'),table=el('table'),head=el('thead'),headers=el('tr'),body=el('tbody');wrap.className='codex-table-scroll';for(const [title]of columns[section]){const th=el('th',title);th.scope='col';headers.append(th);}head.append(headers);for(const row of data.records){const tr=el('tr');for(const [,key]of columns[section]){const value=typeof key==='function'?key(row):key.endsWith('_at')||key==='next_attempt'?date(row[key]):row[key];const cell=el('td');if((key==='id'||key==='target_id')&&typeof value==='string'&&value){const button=el('button');const icon=el('span','🔑');icon.setAttribute('aria-hidden','true');button.append(icon);button.type='button';button.className='jarvis-copy-reference';button.title='Copy ID';button.setAttribute('aria-label','Copy '+section+' reference');button.onclick=()=>navigator.clipboard.writeText(value).then(()=>{if(active)status.textContent='Reference copied.';}).catch(()=>{if(active)status.textContent='The reference could not be copied. Check clipboard access.';});cell.append(button);}else if(value&&typeof value==='object'){const details=el('details');details.append(el('summary','Event fields'));const pre=el('pre',JSON.stringify(value,null,2));pre.style.cssText='white-space:pre-wrap;overflow-wrap:anywhere;max-width:420px;font-size:11px';details.append(pre);cell.append(details);}else cell.textContent=value===null||value===undefined?'—':String(value);tr.append(cell);}body.append(tr);}table.append(head,body);wrap.append(table);records.append(wrap);if(!data.records.length)records.append(el('p','No records in this register.'));pageLabel.textContent='Page '+page;previous.disabled=page<=1;next.disabled=!data.hasMore;} + else{const wrap=el('div'),table=el('table'),head=el('thead'),headers=el('tr'),body=el('tbody');wrap.className='codex-table-scroll';for(const [title]of columns[section]){const th=el('th',title);th.scope='col';headers.append(th);}head.append(headers);for(const row of data.records){const tr=el('tr');for(const [,key]of columns[section]){const value=typeof key==='function'?key(row):key.endsWith('_at')||key==='next_attempt'?date(row[key]):row[key];const cell=el('td');if((key==='id'||key==='target_id')&&typeof value==='string'&&value){const button=el('button');const visual=registerPresentation(section,row),icon=el('span');icon.className='jarvis-register-icon';icon.setAttribute('aria-hidden','true');if(['silver','gold'].includes(visual.art)){icon.className+=' jarvis-register-'+visual.art;icon.style.backgroundImage='url(https://cp.dunerealms.com/assets/organisation-deed-keys-v1.png)';}else icon.style.backgroundImage='url(https://www.dunerealms.com/assets/'+visual.art+')';button.append(icon);button.type='button';button.className='jarvis-copy-reference';button.title=visual.label+' · Copy reference';button.setAttribute('aria-label','Copy '+section+' reference');button.onclick=()=>navigator.clipboard.writeText(value).then(()=>{if(active)status.textContent='Reference copied.';}).catch(()=>{if(active)status.textContent='The reference could not be copied. Check clipboard access.';});cell.append(button);}else if(value&&typeof value==='object'){const details=el('details');details.append(el('summary','Event fields'));const pre=el('pre',JSON.stringify(value,null,2));pre.style.cssText='white-space:pre-wrap;overflow-wrap:anywhere;max-width:420px;font-size:11px';details.append(pre);cell.append(details);}else if(key==='type'&&['keys','deeds'].includes(section))cell.textContent=registerPresentation(section,row).label;else cell.textContent=value===null||value===undefined?'—':String(value);tr.append(cell);}body.append(tr);}table.append(head,body);wrap.append(table);records.append(wrap);if(!data.records.length)records.append(el('p','No records in this register.'));pageLabel.textContent='Page '+page;previous.disabled=page<=1;next.disabled=!data.hasMore;} status.textContent='Live register · private codes and signing material are not displayed.'; }catch(error){if(active){records.replaceChildren();status.textContent=error.message;}}finally{busy=false;if(active)refresh.disabled=false;}} previous.onclick=()=>{if(page>1){page--;void load();}};next.onclick=()=>{page++;void load();};refresh.onclick=()=>void load(); diff --git a/website/control-panel/public/cp-v2/cp-v2-register-presentation.mjs b/website/control-panel/public/cp-v2/cp-v2-register-presentation.mjs new file mode 100644 index 00000000..c3afdbd6 --- /dev/null +++ b/website/control-panel/public/cp-v2/cp-v2-register-presentation.mjs @@ -0,0 +1,11 @@ +import {ELECTIONS} from '../political-catalog.mjs'; +import {keyTypePresentation} from './cp-v2-code-type-icon.mjs'; +const offices={imperial:'emperor',house:'house_leader',bene:'reverent_mother',guild:'guild_leader',clan_delegate:'clan_delegate',naib_chair:'naib_chair'}; +export function registerPresentation(section,row){ + if(section==='deeds'){ + const matches=ELECTIONS.filter(e=>offices[e.kind]===row.type&&(!row.faction||e.faction===row.faction)); + if(matches.length===1)return {label:matches[0].label,art:'seals/'+matches[0].seal}; + return {label:row.type==='house_leader'?'House leadership · House not recorded':String(row.type||'Office deed').replaceAll('_',' '),art:'seals/office-landsraad.png'}; + } + return keyTypePresentation(section==='states'?'entity-state':row.type); +} diff --git a/website/node/jarvis-management.mjs b/website/node/jarvis-management.mjs index a79846c6..1055db70 100644 --- a/website/node/jarvis-management.mjs +++ b/website/node/jarvis-management.mjs @@ -9,7 +9,7 @@ const SECTIONS={ history:{store:'central',sql:'SELECT e.id,e.key_id AS instrument,e.event_type AS action,a.username AS actor,e.target_id,e.created_at FROM organisation_key_events e LEFT JOIN site_accounts a ON a.id=e.account_id ORDER BY e.created_at DESC,e.id DESC'}, listings:{store:'bank',sql:'SELECT id,title,definition_id AS type,organisation_name AS owner,state,created_at FROM jarvis_listings ORDER BY created_at DESC,id DESC'}, delivery:{store:'bank',sql:'SELECT p.id,l.title AS listing,p.channel,p.state,p.attempts,p.next_attempt,p.created_at FROM jarvis_promotion_jobs p JOIN jarvis_listings l ON l.id=p.listing_id ORDER BY p.created_at DESC,p.id DESC'}, - deeds:{store:'central',sql:'SELECT t.id,t.office AS type,a.username AS holder,t.starts_at,t.expires_at,t.outcome AS state FROM political_office_terms t LEFT JOIN site_accounts a ON a.id=t.user_id ORDER BY t.starts_at DESC,t.id DESC'} + deeds:{store:'central',sql:'SELECT t.id,t.office AS type,t.faction,a.username AS holder,t.starts_at,t.expires_at,t.outcome AS state FROM political_office_terms t LEFT JOIN site_accounts a ON a.id=t.user_id ORDER BY t.starts_at DESC,t.id DESC'} }; // Explicit projections intentionally omit codes, sealed material, signing keys, // private applications, payment accounts and full audit payloads. diff --git a/website/tests/jarvis-management.test.mjs b/website/tests/jarvis-management.test.mjs index 9e7d182d..1e7965aa 100644 --- a/website/tests/jarvis-management.test.mjs +++ b/website/tests/jarvis-management.test.mjs @@ -8,3 +8,6 @@ async function setup(){const db=new BankFixture();for(const sql of [...organisat test('management register requires authenticated management authority and rejects writes and identity overrides',async()=>{const f=await setup();try{f.signed(false);assert.equal((await f.call()).status,401);f.signed(true);f.permitted(false);assert.equal((await f.call()).status,403);f.permitted(true);assert.equal((await f.call('','POST')).status,405);for(const query of ['?section=keys&userId=other','?section=keys§ion=history','?page=0','?page=1.5','?page=10001'])assert.equal((await f.call(query)).status,400);}finally{f.db.close();}}); test('key register exposes explicit safe metadata only, with bounded pagination',async()=>{const f=await setup();try{const response=await f.call('?section=keys&page=1');assert.equal(response.status,200);const data=await response.json();assert.equal(data.records[0].recipient,'Citizen');assert.equal(data.records[0].type,'clan-founding');assert.equal(data.hasMore,false);const serialized=JSON.stringify(data);assert.ok(!serialized.includes('SECRET'));assert.ok(!serialized.includes('secret-hash'));assert.ok(!serialized.includes('code_sealed'));assert.equal((await f.call('?section=does-not-exist')).status,404);}finally{f.db.close();}}); test('missing section schema reports unavailable instead of claiming empty success; seasons contains only public edition',async()=>{const f=await setup();try{assert.equal((await f.call('?section=deeds')).status,503);const data=await (await f.call('?section=seasons')).json();assert.deepEqual(data.edition,{stage:'alpha',version:'1.0.1.1',season:'S01'});assert.equal((await f.call('?section=listings')).status,200);}finally{f.db.close();}}); + + +test('deed register retains public faction metadata so shared House office types remain distinguishable',async()=>{const f=await setup();try{await f.db.query('CREATE TABLE political_office_terms(id TEXT PRIMARY KEY,office TEXT,faction TEXT,user_id TEXT,starts_at INTEGER,expires_at INTEGER,outcome TEXT)');await f.db.query("INSERT INTO political_office_terms VALUES('term','house_leader','atreides','owner',1,2,'winner')");const response=await f.call('?section=deeds');assert.equal(response.status,200);const data=await response.json();assert.equal(data.records[0].faction,'atreides');assert.equal(data.records[0].holder,'Citizen');assert.equal(data.records[0].type,'house_leader');}finally{f.db.close();}}); diff --git a/website/tests/jarvis-register-presentation.test.mjs b/website/tests/jarvis-register-presentation.test.mjs new file mode 100644 index 00000000..a0607337 --- /dev/null +++ b/website/tests/jarvis-register-presentation.test.mjs @@ -0,0 +1,6 @@ +import test from 'node:test';import assert from 'node:assert/strict';import {existsSync} from 'node:fs'; +import {registerPresentation} from '../control-panel/public/cp-v2/cp-v2-register-presentation.mjs'; +import {KEY_TYPES} from '../node/organisation-key-policy.mjs'; +import {ELECTIONS} from '../control-panel/public/political-catalog.mjs'; +test('each registered key type resolves to existing artwork and a readable label',()=>{for(const type of Object.keys(KEY_TYPES)){const p=registerPresentation('keys',{type});assert.ok(p.label);const art=['silver','gold'].includes(p.art)?'organisation-deed-keys-v1.png':p.art;assert.ok(existsSync(new URL('../web/assets/'+art,import.meta.url)),type+' artwork');}assert.equal(registerPresentation('keys',{type:'entity-state'}).art,'esk-key-v1.png');}); +test('House deeds retain faction-specific seals rather than guessing from a shared office name',()=>{for(const e of ELECTIONS.filter(e=>e.kind==='house')){const p=registerPresentation('deeds',{type:'house_leader',faction:e.faction});assert.equal(p.art,'seals/'+e.seal);assert.equal(p.label,e.label);}const missing=registerPresentation('deeds',{type:'house_leader'});assert.match(missing.label,/not recorded/);assert.equal(missing.art,'seals/office-landsraad.png');assert.equal(registerPresentation('deeds',{type:'emperor',faction:'imperium'}).art,'seals/emperor-v1.png');});