Downgrade and chase connections from the NOC dashboard (#336)
The Connections tab now has the POP panel's shrink buttons next to the upgrades: a downgrade to the next smaller port for transit, PNIs and IX ports, one LAG member less (also for NNIs), and Chase it for a PNI that is on order or waiting for a bigger port. Same actions and conditions as the panel; the NOC pop-out window runs them in the game. Fixes #336
This commit is contained in:
parent
e2b3615a19
commit
c52e7c7747
4 changed files with 94 additions and 3 deletions
|
|
@ -8,6 +8,7 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
- Alien waves you list on a fiber yourself now stay listed. With the capacity market selling for you, the broker used to cut your listing down to what its settings allowed the next day, or take it off altogether when the route's demand was below your minimum. Your own listing now stays put, and the broker adds what its settings allow on top (#340).
|
||||
- The Connections list in the NOC dashboard no longer stays blank when you sort it by load or show only NNI ports while a fabric port runs at 400G. A 400G fabric port is the fastest there is, so the list now offers it one more LAG member instead of a faster port that does not exist.
|
||||
- The Connections tab of the NOC dashboard can now shrink connections as well as grow them. Next to the upgrades, transit ports, PNIs and exchange ports get a downgrade to the next smaller port and a button to drop one LAG member, and a PNI that is still on order can be chased from the list, just like from the POP panel (#336).
|
||||
|
||||
## [3.4.0] — 2026-11-10
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,18 @@ function connUp(r){if(r.mine)return '';const nx=t=>PORT[t+1]&&portShown(t+1)?t+1
|
|||
if(i>=0){const c=NNI[i].mo*n;h+=btn(n>1?tr('common.upgrade_all_to_port_cost_mo',{port:NNI[i].n,cost:fmt$(c),mo:fmt$(c)}):tr('common.upgrade_port_price_mo',{port:NNI[i].n,price:fmt$(c)}),'buyNni',{city,prov,tier:i},'sm',S.cash<c||!portOk(city,i));}
|
||||
if(n<LAG_MAX)h+=btn(tr('common.lag_member_price',{price:portMo(NNI[pt.tier].mo)}),'lagNni',{city,prov,d:1},'sm',S.cash<NNI[pt.tier].mo||!portOk(city,pt.tier));}
|
||||
return h;}
|
||||
// Shrink a connection from the list, or chase a PNI order: the same buttons and conditions as the POP panel (#336).
|
||||
function connDown(r){if(r.mine)return '';const dn=(port,price,act,args)=>btn(tr('link_panels.downgrade_port_price',{port,price}),act,args,'ghost sm'),less=(act,args)=>btn(tr('common.member'),act,{...args,d:-1},'ghost sm');let h='';
|
||||
if(r.k==='t'){const t=S.transit.find(x=>x.id===r.id);if(!t)return '';const n=t.n||1;
|
||||
if(t.tier>0)h+=dn(PORT[t.tier-1].n,portMo(PORT[t.tier-1].tmo*n),'downT',{id:t.id});if(n>1)h+=less('lagT',{id:t.id});}
|
||||
else if(r.k==='p'){const p=S.pni.find(x=>x.id===r.id);if(!p)return '';const n=p.n||1,chase=btn(tr('common.chase_it'),'pniChase',{id:p.id},'ghost sm');
|
||||
if(!pniOn(p))return chase;
|
||||
if(p.up)h+=chase;else if(!p.g1&&p.tier>pniMin(p.net)&&!msfNope(p.net,p.city))h+=dn(PORT[p.tier-1].n,portMo(PORT[p.tier-1].pni*n),'downP',{id:p.id});
|
||||
if(n>1)h+=less('lagP',{id:p.id});}
|
||||
else if(r.k==='ix'){const c=r.id,n=(S.ixn||{})[c]||1;
|
||||
if(n>1)h+=less('lagIx',{city:c});if(S.ixp[c]>0)h+=dn(PORT[S.ixp[c]-1].n,portMo(ixPortMo(c,S.ixp[c]-1)*n),'downIx',{city:c});}
|
||||
else if(r.k==='nni'){const [city,prov]=r.id.split('|'),pt=nniPort(city,prov);if(pt&&(pt.n||1)>1)h+=less('lagNni',{city,prov});}
|
||||
return h;}
|
||||
function connX(r){if(r.mine)return '';const on=UI.confirm==='cc:'+r.k+':'+r.id;
|
||||
return btn(on?(r.k==='ix'?tr('common.really_leave'):r.k==='t'?tr('common.really_cancel'):tr('common.really_remove')):r.k==='ix'?tr('common.leave_ix'):r.k==='t'?tr('common.cancel'):r.k==='c'&&r.n>1?tr('common.box_6ee3'):r.k==='nni'?tr('common.remove_port'):tr('common.remove'),'connCancel',{k:r.k,id:r.id},on?'red sm':'ghost sm');}
|
||||
function connMatch(r,F){return (!F.k||r.k===F.k)&&(!F.city||r.city===F.city)&&(!F.net||r.net===F.net||(r.nets&&r.nets.includes(F.net)));}
|
||||
|
|
@ -47,11 +59,11 @@ function connSection(){const all=conns(),F=UI.cf||{};
|
|||
const tc=rows.reduce((a,r)=>a+r.cap,0),tu=rows.reduce((a,r)=>a+r.use,0),tm=rows.reduce((a,r)=>a+r.mo,0);
|
||||
if(isPhone()){const st=(r)=>r.down?` <span class="tag restrictive">${tr('common.down')}</span>`:r.low?` <span class="tag st">${tr('common.backup')}</span>`:'';
|
||||
h+=`<div class="seg" style="margin-bottom:4px">${[['k',tr('common.type')],['city',tr('common.where')],['use',tr('common.in_use')],['mo',tr('common.per_month')]].map(([k,l])=>btn(l+(sk===k?(dir>0?' ▲':' ▼'):''),'connSort',{k},sk===k?'pink sm':'ghost sm')).join('')}</div>`;
|
||||
h+=rows.slice(0,listN('conn')).map(r=>{const u=r.cap?r.use/r.cap:0,N=r.net&&NET[r.net];return `<div class="row"${r.down?' style="opacity:.55"':''}>${N?logo(N):`<span class="logo" style="--c:${CONN_COL[r.k]}">${r.k==='nni'?'NNI':'IX'}</span>`}<div class="grow"><div class="nm">${esc(r.name)} <span class="tag" style="background:${CONN_COL[r.k]}">${tr(CONN_K[r.k])}</span>${st(r)}</div><div class="meta">${esc(CITY[r.city].name)} · ${esc(r.port)} · ${tr('common.price_mo',{price:fmt$(r.mo)})}${r.note?' · '+esc(r.note):''}</div><div class="kv"><span>${tr('common.in_use')}</span><b>${fmtG(r.use)} / ${fmtCap(Math.round(r.cap))}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>${r.mine?'':`<div class="btns">${connUp(r)}${connX(r)}</div>`}</div>${btn(tr('common.open'),'goConn',{city:r.city,k:r.k},'ghost sm')}</div>`;}).join('');
|
||||
h+=rows.slice(0,listN('conn')).map(r=>{const u=r.cap?r.use/r.cap:0,N=r.net&&NET[r.net];return `<div class="row"${r.down?' style="opacity:.55"':''}>${N?logo(N):`<span class="logo" style="--c:${CONN_COL[r.k]}">${r.k==='nni'?'NNI':'IX'}</span>`}<div class="grow"><div class="nm">${esc(r.name)} <span class="tag" style="background:${CONN_COL[r.k]}">${tr(CONN_K[r.k])}</span>${st(r)}</div><div class="meta">${esc(CITY[r.city].name)} · ${esc(r.port)} · ${tr('common.price_mo',{price:fmt$(r.mo)})}${r.note?' · '+esc(r.note):''}</div><div class="kv"><span>${tr('common.in_use')}</span><b>${fmtG(r.use)} / ${fmtCap(Math.round(r.cap))}</b></div><div class="bar ${barCls(u)}"><i style="width:${Math.min(100,u*100)}%"></i></div>${r.mine?'':`<div class="btns">${connUp(r)}${connDown(r)}${connX(r)}</div>`}</div>${btn(tr('common.open'),'goConn',{city:r.city,k:r.k},'ghost sm')}</div>`;}).join('');
|
||||
return h+listMore('conn',rows.length,n=>trn('connections.n_more_connection',n))+`<div class="kv" style="margin-top:6px"><span><b>${trn('connections.n_connection',rows.length)}</b></span><b>${fmtG(tu)} / ${fmtCap(Math.round(tc))} · ${tr('common.price_mo',{price:fmt$(tm)})}</b></div></div>`;}
|
||||
const th=(k,l,c)=>`<th class="${c||''}">${k?`<button class="thb" data-act="connSort" data-args="${esc(JSON.stringify({k}))}">${l}${sk===k?(dir>0?' ▲':' ▼'):''}</button>`:l}</th>`;
|
||||
h+=`<div class="tscroll"><table class="tbl"><thead><tr>${th('k',tr('common.type'))}${th('city',tr('common.where'))}${th('name',tr('common.with'))}${th('',tr('common.port'))}${th('use',tr('common.in_use'),'r')}${th('mo',tr('common.per_month'),'r')}<th></th></tr></thead><tbody>`;
|
||||
h+=rows.slice(0,listN('conn')).map(r=>{const u=r.cap?r.use/r.cap:0,N=r.net&&NET[r.net];return `<tr${r.down?' style="opacity:.55"':''}><td><span class="tag" style="background:${CONN_COL[r.k]}">${tr(CONN_K[r.k])}</span></td><td>${esc(CITY[r.city].name)}</td><td><span style="display:inline-flex;align-items:center;gap:6px">${N?logo(N):''}<span><b>${esc(r.name)}</b>${r.note?`<br><span class="meta">${esc(r.note)}</span>`:''}</span></span></td><td>${esc(r.port)}${r.down?` <span class="tag restrictive">${tr('common.down')}</span>`:r.low?` <span class="tag st">${tr('common.backup')}</span>`:''}</td><td class="r">${fmtG(r.use)} / ${fmtCap(Math.round(r.cap))}<div class="bar ${barCls(u)}" style="margin-top:3px"><i style="width:${Math.min(100,u*100)}%"></i></div></td><td class="r">${fmt$(r.mo)}</td><td><div style="display:flex;flex-wrap:wrap;gap:6px;min-width:220px">${btn(tr('common.open'),'goConn',{city:r.city,k:r.k},'ghost sm')}${connUp(r)}${connX(r)}</div></td></tr>`;}).join('');
|
||||
h+=rows.slice(0,listN('conn')).map(r=>{const u=r.cap?r.use/r.cap:0,N=r.net&&NET[r.net];return `<tr${r.down?' style="opacity:.55"':''}><td><span class="tag" style="background:${CONN_COL[r.k]}">${tr(CONN_K[r.k])}</span></td><td>${esc(CITY[r.city].name)}</td><td><span style="display:inline-flex;align-items:center;gap:6px">${N?logo(N):''}<span><b>${esc(r.name)}</b>${r.note?`<br><span class="meta">${esc(r.note)}</span>`:''}</span></span></td><td>${esc(r.port)}${r.down?` <span class="tag restrictive">${tr('common.down')}</span>`:r.low?` <span class="tag st">${tr('common.backup')}</span>`:''}</td><td class="r">${fmtG(r.use)} / ${fmtCap(Math.round(r.cap))}<div class="bar ${barCls(u)}" style="margin-top:3px"><i style="width:${Math.min(100,u*100)}%"></i></div></td><td class="r">${fmt$(r.mo)}</td><td><div style="display:flex;flex-wrap:wrap;gap:6px;min-width:220px">${btn(tr('common.open'),'goConn',{city:r.city,k:r.k},'ghost sm')}${connUp(r)}${connDown(r)}${connX(r)}</div></td></tr>`;}).join('');
|
||||
h+=`</tbody><tfoot><tr><td colspan="4"><b>${trn('connections.n_connection',rows.length)}</b></td><td class="r"><b>${fmtG(tu)} / ${fmtCap(Math.round(tc))}</b></td><td class="r"><b>${fmt$(tm)}</b></td><td></td></tr></tfoot></table></div>${listMore('conn',rows.length,n=>trn('connections.n_more_connection',n))}</div>`;
|
||||
return h;}
|
||||
// Where you connect to one network, as buttons that jump to the POP (Networks tab).
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
const NOC_HB=3000,NOC_LOST=10000,NOC_GAP=1000;
|
||||
// What a click in the window does: changes only its own view, or runs in the game. Every button the dashboard draws is in one list.
|
||||
const NOC_LOCAL=['chartToggle','connCity','connF','connNet','connSort','custCity','custF','custSort','dashClose','dashSort','dashTab','listMore','popsReg','popsSort'];
|
||||
const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','goConn','lagIx','lagNni','lagP','lagT','leaseSwap','mktCfg','mktHold','mktRoute','netFocus','opsOpen','pni','pniAllOpen','popGo'];
|
||||
const NOC_GO=['buyIx','buyNni','buyTransit','cache','connCancel','custGo','dashLink','downIx','downP','downT','goConn','lagIx','lagNni','lagP','lagT','leaseSwap','mktCfg','mktHold','mktRoute','netFocus','opsOpen','pni','pniAllOpen','pniChase','popGo'];
|
||||
const NOC={win:false,id:null,ctl:null,st:null,stId:null,peer:false,until:0,dirty:false,sent:0,speed:1,hid:false,yoAt:0,gone:false};
|
||||
{const id=RW_IN?null:new URLSearchParams(location.search).get('noc');if(slotOkId(id)){NOC.win=true;NOC.id=id;}}
|
||||
if(!RW_IN)try{if(typeof BroadcastChannel==='function'){NOC.ctl=new BroadcastChannel('sot-noc');NOC.ctl.onmessage=e=>{const m=e.data;if(!m||typeof m!=='object'||!slotOkId(m.id))return;if(NOC.win)nocWinMsg(m);else nocGameMsg(m);};}}catch(e){}
|
||||
|
|
|
|||
78
tests/dashboard-connections.test.js
Normal file
78
tests/dashboard-connections.test.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
// #336: the NOC dashboard's connection list can shrink connections too (a smaller port, one LAG member fewer) and
|
||||
// chase a PNI that is on order, with the same buttons and rules as the POP panel.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// A transit LAG, a live PNI LAG, a PNI on order and an IX LAG, all in Frankfurt, set up directly so nothing is left to luck.
|
||||
const setup = () => {
|
||||
const r = load();
|
||||
r.ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e9;S.lvl=6;S.offers=[];S.nextFail=S.nextEvent=1e6;if(!S.pops.fra)ACT.buildPop({city:'fra'})");
|
||||
r.ev(`(()=>{const free=NETS.filter(n=>n.type!=='t1'&&n.type!=='cdn'&&n.pops.includes('fra')&&!msfNope(n.id,'fra')).map(n=>n.id);
|
||||
S.transit=[{id:'t1',city:'fra',net:'cog',tier:2,n:2}];
|
||||
S.pni=[{id:'p1',city:'fra',net:free[0],tier:2,n:2,ready:0,site:'a',sacrif:false},{id:'p2',city:'fra',net:free[1],tier:1,n:1,ready:S.day+60,site:'a',sacrif:false}];
|
||||
const x=ixIdsIn('fra')[0];S.ixp={[x]:2};S.ixn={[x]:2};window.__ix=x;compute();})()`);
|
||||
return r;
|
||||
};
|
||||
const open = (ev, phone) => ev(`window.innerWidth=${phone ? 390 : 1280};UI.dtab='conn';ACT.connOpen()`);
|
||||
// Every button in the list as act + args, to compare with what the POP panel offers.
|
||||
const acts = (ev, sel) => JSON.parse(ev(`JSON.stringify([...document.querySelectorAll('${sel} [data-act]')].map(b=>b.dataset.act+' '+b.dataset.args))`));
|
||||
const has = (list, act, args) => list.includes(`${act} ${JSON.stringify(args)}`);
|
||||
|
||||
for (const phone of [false, true]) {
|
||||
test(`#336 the connection list offers downgrades and a chase (${phone ? 'phone' : 'desktop'})`, () => {
|
||||
const { ev, errors } = setup();
|
||||
open(ev, phone);
|
||||
const ix = ev('window.__ix'), a = acts(ev, '#connSec');
|
||||
assert.ok(has(a, 'downT', { id: 't1' }) && has(a, 'lagT', { id: 't1', d: -1 }), 'transit: smaller port, one member fewer');
|
||||
assert.ok(has(a, 'downP', { id: 'p1' }) && has(a, 'lagP', { id: 'p1', d: -1 }), 'PNI: smaller port, one member fewer');
|
||||
assert.ok(has(a, 'pniChase', { id: 'p2' }), 'a PNI on order can be chased');
|
||||
assert.ok(!has(a, 'pniChase', { id: 'p1' }) && !has(a, 'downP', { id: 'p2' }), 'no chase for a live PNI, no downgrade for one on order');
|
||||
assert.ok(has(a, 'downIx', { city: ix }) && has(a, 'lagIx', { city: ix, d: -1 }), 'IX: smaller port, one member fewer');
|
||||
assert.match(ev("document.getElementById('connSec').textContent"), /Downgrade 100G/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
|
||||
test('#336 the buttons in the list do what the POP panel buttons do', () => {
|
||||
const { ev, errors } = setup();
|
||||
const ix = ev('window.__ix');
|
||||
open(ev, false);
|
||||
const click = (act, args) => {
|
||||
const ok = ev(`(()=>{const b=[...document.querySelectorAll('#connSec [data-act]')].find(b=>b.dataset.act===${JSON.stringify(act)}&&b.dataset.args===${JSON.stringify(JSON.stringify(args))});if(!b)return false;b.click();return true})()`);
|
||||
assert.ok(ok, `${act} ${JSON.stringify(args)} is in the list`);
|
||||
open(ev, false);
|
||||
};
|
||||
click('downT', { id: 't1' });
|
||||
assert.equal(ev("S.transit[0].tier"), 1);
|
||||
click('lagT', { id: 't1', d: -1 });
|
||||
assert.equal(ev("S.transit[0].n||1"), 1);
|
||||
click('downP', { id: 'p1' });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p1').tier"), 1);
|
||||
click('lagP', { id: 'p1', d: -1 });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p1').n||1"), 1);
|
||||
click('downIx', { city: ix });
|
||||
assert.equal(ev(`S.ixp['${ix}']`), 1);
|
||||
click('lagIx', { city: ix, d: -1 });
|
||||
assert.equal(ev(`(S.ixn||{})['${ix}']||1`), 1);
|
||||
// A chase that lands takes a month off the wait, as from the POP panel.
|
||||
const ready = ev("S.pni.find(p=>p.id==='p2').ready");
|
||||
ev("Math.random=()=>0");
|
||||
click('pniChase', { id: 'p2' });
|
||||
assert.equal(ev("S.pni.find(p=>p.id==='p2').ready"), Math.max(ev('S.day') + 1, ready - 30));
|
||||
// No more members to take away: those buttons go away.
|
||||
const a = acts(ev, '#connSec');
|
||||
assert.ok(!has(a, 'lagT', { id: 't1', d: -1 }) && !has(a, 'lagP', { id: 'p1', d: -1 }) && !has(a, 'lagIx', { city: ix, d: -1 }));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('#336 the list offers the same downgrades as the POP panel', () => {
|
||||
const { ev, errors } = setup();
|
||||
open(ev, false);
|
||||
const dash = acts(ev, '#connSec').filter(x => /^(downT|lagT|downIx|lagIx) /.test(x) && !x.includes('"d":1'));
|
||||
ev("UI.sel={type:'city',id:'fra'};UI.tab='up';renderPanel()");
|
||||
const panel = acts(ev, '#panelBody').filter(x => /^(downT|lagT) /.test(x) && !x.includes('"d":1'));
|
||||
assert.ok(panel.length >= 2, `the POP panel shows the transit downgrades: ${panel}`);
|
||||
for (const x of panel) assert.ok(dash.includes(x), `${x} is in the list too`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue