Positions dashboard: show only the generations a position can be paid from

Marty: members were confused by generations far below them that their level
cannot reach. A position at level L catches upgrades from generations 1..L
(7 at most), so the pyramid, the list view, the generations list and the org
bar now stop there. Drilling into a card is only allowed where reachable
generations remain. Team size and qualified/earned totals are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-26 07:11:42 -05:00
parent d6fdabdcba
commit 1a06f50d9f
+13 -7
View File
@@ -35,7 +35,10 @@
function pathId(){const m=location.pathname.match(/^\/my\/(\d+)$/);if(m)return m[1];const q=new URLSearchParams(location.search).get('id');if(q&&/^\d+$/.test(q))return q;try{return localStorage.getItem('ctb.myId')||''}catch(e){return ''}}
const treeUI={byId:{},parent:{},homeId:0,rootId:0,mode:'pyramid',zoom:null,_applied:1};
const treeUI={byId:{},parent:{},depth:{},reach:7,homeId:0,rootId:0,mode:'pyramid',zoom:null,_applied:1};
// Marty 2026-09-26: show only the generations this position can be paid from. A member at
// level L catches upgrades from generations 1..L (7 at most); deeper ones only confused people.
const reachOf=d=>Math.max(1,Math.min(7,Number(d&&d.level)||1));
// Zoom the matrix so it fits small screens. treeUI.zoom: null = auto-fit (shrink
// to fit width, never enlarge), or a manual factor. Uses CSS `zoom` so the layout
// reflows cleanly (no leftover box, centering + scroll keep working).
@@ -62,7 +65,7 @@
if(fit)fit.addEventListener('click',()=>{treeUI.zoom=null;applyMatrixZoom()});
let t;window.addEventListener('resize',()=>{clearTimeout(t);t=setTimeout(()=>{if(treeUI.mode==='pyramid')applyMatrixZoom()},160)});
})();
function indexTree(n,par){if(!n)return;treeUI.byId[n.id]=n;if(par)treeUI.parent[n.id]=par.id;indexTree(n.left,n);indexTree(n.right,n)}
function indexTree(n,par){if(!n)return;treeUI.byId[n.id]=n;treeUI.depth[n.id]=par?treeUI.depth[par.id]+1:0;if(par)treeUI.parent[n.id]=par.id;indexTree(n.left,n);indexTree(n.right,n)}
function isSpill(n){return !!(n&&treeUI.parent[n.id]&&n.referrerId&&n.referrerId!==treeUI.parent[n.id])}
function card(n,focus){
if(!n)return '<div class="mtp-card mtp-open">open<br>slot</div>';
@@ -79,11 +82,13 @@
const rows=[[root]];
for(let g=1;g<4;g++)rows.push(rows[g-1].flatMap(n=>n?[n.left||null,n.right||null]:[null,null]));
if(!rows[3].some(Boolean))rows.pop();
const base=treeUI.depth[root.id]||0;
while(rows.length>1&&base+rows.length-1>treeUI.reach)rows.pop();
out.innerHTML=`<div class="mtp">${rows.map((r,i)=>`<div class="mtp-row">${r.map(n=>card(n,i===0)).join('')}</div>`).join('')}</div>`;
const path=[];let cur=treeUI.rootId;
while(cur){path.unshift(cur);if(cur===treeUI.homeId)break;cur=treeUI.parent[cur]}
nav.innerHTML=path.length>1?`<span class="micro" style="margin:0">Viewing:</span> `+path.map((id,i)=>i===path.length-1?`<strong class="mt-id">#${id}</strong>`:`<button class="btn btn-secondary btn-sm" data-tid="${id}">#${id}</button>`).join(' <span style="color:var(--muted)">›</span> ')+` <button class="btn btn-secondary btn-sm" data-tid="${treeUI.parent[treeUI.rootId]}">↑ Up one</button>`:'';
const wire=el=>el.querySelectorAll('[data-tid]').forEach(b=>b.addEventListener('click',()=>{const t=Number(b.dataset.tid);if(t&&treeUI.byId[t]){treeUI.rootId=t;renderTree()}}));
const wire=el=>el.querySelectorAll('[data-tid]').forEach(b=>b.addEventListener('click',()=>{const t=Number(b.dataset.tid);if(t&&treeUI.byId[t]&&(treeUI.depth[t]||0)<treeUI.reach){treeUI.rootId=t;renderTree()}}));
wire(out);wire(nav);
applyMatrixZoom();
}
@@ -95,7 +100,7 @@
if(!home){out.innerHTML='<div class="empty">Team view is still indexing — check back in a few minutes.</div>';return}
const node=(n,depth)=>{
if(!n)return '';
const ch=[n.left,n.right].filter(Boolean);
const ch=depth<treeUI.reach?[n.left,n.right].filter(Boolean):[];
const qmark=n.directCount>=2?'<span class="mtp-qmark" style="position:static;display:inline-grid;width:16px;height:16px;font-size:10px;vertical-align:middle">✓</span> ':'';
const badge=n.tier===2?'<span class="mt-badge mt-prem">P</span>':'<span class="mt-badge">S</span>';
const label=`${qmark}${badge} <span class="mt-id">#${n.id}</span> <span class="mt-meta">${esc(n.levelName)} · ${n.directCount}/2 directs · ${fmt(n.earnedPol)} POL${n.downCount?` · ⬇ ${n.downCount} below (${fmt(n.downPol)} POL)`:''}${isSpill(n)?` · <span style="color:var(--teal)">↧ spillover (ref #${n.referrerId})</span>`:''}</span>`;
@@ -118,7 +123,7 @@
const q=Object.values(treeUI.byId).filter(n=>n.id!==d.id&&n.directCount>=2).length;
el.innerHTML=`<div style="display:flex;gap:10px;flex-wrap:wrap;margin:0 0 14px">`+
`<div class="fact" style="flex:1;min-width:130px"><small>Your organization</small><strong style="font-size:22px;color:var(--gold)">${st.downCount.toLocaleString()} member${st.downCount===1?'':'s'}</strong></div>`+
`<div class="fact" style="flex:1;min-width:110px"><small>Generations deep</small><strong style="font-size:22px">${gens}</strong></div>`+
`<div class="fact" style="flex:1;min-width:110px"><small>Generations in your reach</small><strong style="font-size:22px">${Math.min(gens,reachOf(d))}</strong></div>`+
`<div class="fact" style="flex:1;min-width:110px"><small>Qualified below you</small><strong style="font-size:22px">${q}</strong></div>`+
`<div class="fact" style="flex:1;min-width:140px"><small>Earned below you</small><strong style="font-size:22px;color:var(--ok)">${fmt(st.downPol)} POL</strong></div>`+
(d.polUsd>0?`<div class="fact" style="flex:1;min-width:140px"><small>≈ US dollars (POL @ $${d.polUsd<0.1?d.polUsd.toFixed(4):d.polUsd.toFixed(2)})</small><strong style="font-size:22px;color:var(--ok)">$${(st.downPol*d.polUsd).toLocaleString(undefined,{maximumFractionDigits:0})}</strong></div>`:'')+
@@ -156,7 +161,7 @@
`<div class="fact"><small>Directs</small><strong>${d.directCount}/2${d.directCount>=2?' ✓ qualified':''}</strong></div>`+
`<div class="fact"><small>Team below you</small><strong>${d.subtree?`${d.subtree.downCount} member${d.subtree.downCount===1?'':'s'}`:'—'}</strong></div>`+
`<div class="fact"><small>Member since</small><strong>${date(d.joinedAt)}</strong></div>`;
treeUI.byId={};treeUI.parent={};treeUI.homeId=d.id;treeUI.rootId=d.id;
treeUI.byId={};treeUI.parent={};treeUI.depth={};treeUI.reach=reachOf(d);treeUI.homeId=d.id;treeUI.rootId=d.id;
indexTree(d.subtree,null);
renderOrgBar(d);
renderTree();
@@ -202,7 +207,8 @@
layer.forEach(n=>{if(n.left)next.push(n.left);if(n.right)next.push(n.right);});
if(!next.length)break;gens.push(next.length);layer=next;
}
const rows=gens.map((c,i)=>{
const reach=reachOf(d);
const rows=gens.slice(0,reach).map((c,i)=>{
const cap=Math.pow(2,i+1);
const pays=i<7?`pays you at their <strong style="color:var(--text)">${LEVELS[i+1]}</strong> upgrade`:'beyond the 8 pay levels';
return `<div style="display:flex;align-items:center;gap:10px;margin:5px 0;font-size:13px;flex-wrap:wrap"><span style="width:46px;color:var(--muted)">Gen ${i+1}</span><div class="progress-line" style="flex:1;min-width:90px;height:9px"><span style="width:${Math.min(100,Math.round(100*c/cap))}%"></span></div><span style="width:88px;text-align:right"><strong>${c}</strong><span style="color:var(--muted)">${cap<=1024?' of '+cap:''}</span></span><span class="micro" style="color:var(--muted);width:230px">${pays}</span></div>`;