panel: Allowance shows what's left; Remaining becomes Dues
The Members table's Allowance column printed the uniform $15 balance, which is the total, not what the member still has. It now computes max(balance - spend, 0) client-side from the two served fields (no series summed in the browser), keeps its allowance-only class so it still hides in All-time mode, and reads "Allowance left" with a title saying it is a budget, not OC dues. The Remaining column (allowance + credits - spend, a credit figure) is replaced by Dues: the member's current Open Collective contribution level, rendered $10/mo / $120/yr and '—' when the portal has no readable level. Dues sorts by dues_amount with unknowns last, and carries no balance-col, so it stays visible in both modes. tests/check-page-js.sh now stubs classList/parentElement so a harness can observe the mode toggle; admin-panel-dues-harness.js pins the subtraction, floor, dues text, null handling, sort and 10-cell column count in both modes; tests/test_member_table_columns.py pins the header/row alignment.
This commit is contained in:
1 parent
3c3fb0b921
commit
2ae9868966
4 files changed
+264
-7
No files matched your search
+42
-7
@@ -465,8 +465,7 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
.range-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
|
||||
.range-btn { cursor: pointer; border: 1px solid var(--border); background: #fff; color: var(--muted); border-radius: 8px; font-size: 12px; font-weight: 600; padding: 5px 12px; }
|
||||
.range-btn.active { background: var(--green-mid); color: #fff; border-color: var(--green-mid); }
|
||||
.members-all-time .balance-col.allowance-only,
|
||||
.members-all-time .balance-col.remaining-only { display: none; }
|
||||
.members-all-time .balance-col.allowance-only { display: none; }
|
||||
.members-all-time .credits-col-head .mode-note::after,
|
||||
.table-scroll { overflow-x: auto; border-radius: 12px; }
|
||||
.table-scroll table { min-width: 980px; }
|
||||
@@ -517,10 +516,10 @@ PAGE_HTML = """<!DOCTYPE html>
|
||||
<th class="sortable" onclick="sortMembers('active')">Status<span class="arrow" id="arrow-members-active"></span></th>
|
||||
<th class="sortable" onclick="sortMembers('activated')">Activated<span class="arrow" id="arrow-members-activated"></span></th>
|
||||
<th class="sortable" onclick="sortMembers('manual')">Source<span class="arrow" id="arrow-members-manual"></span></th>
|
||||
<th class="sortable balance-col allowance-only" onclick="sortMembers('balance')">Allowance<span class="arrow" id="arrow-members-balance"></span></th>
|
||||
<th class="sortable balance-col allowance-only" onclick="sortMembers('allowance_left')" title="Uniform monthly allowance ($15) minus what the member has spent this cycle — what they can still spend. This is a budget, not their Open Collective dues.">Allowance left<span class="arrow" id="arrow-members-allowance_left"></span></th>
|
||||
<th class="sortable balance-col credits-col-head" onclick="sortMembers('credit_balance')">Credits<span class="mode-note"></span><span class="arrow" id="arrow-members-credit_balance"></span></th>
|
||||
<th class="sortable" onclick="sortMembers('spend')"><span id="spend-mode-label">Spend</span><span class="arrow" id="arrow-members-spend"></span></th>
|
||||
<th class="sortable balance-col remaining-only" onclick="sortMembers('remaining')">Remaining<span class="arrow" id="arrow-members-remaining"></span></th>
|
||||
<th class="sortable" onclick="sortMembers('dues_amount')" title="What the member currently pays on Open Collective — their dues level (e.g. $10/mo). Blank when OC shows no live recurring contribution.">Dues<span class="arrow" id="arrow-members-dues_amount"></span></th>
|
||||
<th class="sortable balance-col" onclick="sortMembers('reset_at')">Reset<span class="arrow" id="arrow-members-reset_at"></span></th>
|
||||
<th>Adjust</th>
|
||||
</tr>
|
||||
@@ -968,7 +967,10 @@ function setMemberMode(mode) {
|
||||
// must not claim a mode the reader is not in — it said "All-time spend" while
|
||||
// the table was in balance mode (ntnsndr, 2026-11-13). Just "Spend".
|
||||
if (adminLabel) adminLabel.textContent = 'Spend';
|
||||
// Balance-only columns (Allowance/Credits/Remaining/Reset) hide in all-time mode
|
||||
// Balance-only columns (Allowance left/Credits/Reset) hide in all-time mode.
|
||||
// Dues is NOT balance-derived — it is the member's current OC subscription
|
||||
// level, so it stays visible in both modes (and its header/cells never carry
|
||||
// balance-col, which keeps header and row cells in step).
|
||||
$('table-members').parentElement.classList.toggle('members-all-time', mode === 'all');
|
||||
const adminTable = document.getElementById('table-admins');
|
||||
if (adminTable) adminTable.parentElement.classList.toggle('admins-all-time', mode === 'all');
|
||||
@@ -985,6 +987,31 @@ function memberSpend(m) {
|
||||
return memberMode === 'all' ? (m.all_time_spend ?? m.spend ?? 0) : (m.spend ?? 0);
|
||||
}
|
||||
|
||||
// Allowance left: what the member can still spend from the uniform monthly
|
||||
// allowance. ONE subtraction of two served fields — never a series summed in
|
||||
// the browser. Floored at zero so an overdrawn cycle reads $0.00, not negative.
|
||||
function allowanceLeft(m) {
|
||||
return Math.max(Number(m.balance ?? 0) - memberSpend(m), 0);
|
||||
}
|
||||
|
||||
// Dues: the member's CURRENT Open Collective contribution level, e.g. $10/mo.
|
||||
// The portal persists dues_amount/dues_frequency from the OC orders its
|
||||
// reconciliation matched. null means "no live recurring contribution we could
|
||||
// read" and renders '—' — never the allowance, never a guessed tier.
|
||||
function duesCell(m) {
|
||||
const raw = m.dues_amount;
|
||||
const amt = (raw === null || raw === undefined) ? null : Number(raw);
|
||||
if (amt === null || !isFinite(amt)) return '<span style="color:var(--muted)">—</span>';
|
||||
const per = { MONTHLY: 'mo', YEARLY: 'yr', ONETIME: 'once' }[String(m.dues_frequency || '').toUpperCase()];
|
||||
const money = '$' + (Number.isInteger(amt) ? String(amt) : amt.toFixed(2));
|
||||
return '<span class="num">' + esc(per ? money + '/' + per : money) + '</span>';
|
||||
}
|
||||
|
||||
function duesSortValue(m) {
|
||||
const raw = m.dues_amount;
|
||||
return (raw === null || raw === undefined) ? null : Number(raw);
|
||||
}
|
||||
|
||||
function sortModels(key) {
|
||||
modelSort = { key, dir: modelSort.key === key ? -modelSort.dir : -1 };
|
||||
clearArrows('models', modelSort);
|
||||
@@ -1000,6 +1027,14 @@ function renderMembers() {
|
||||
const rows = [...membersData].sort((a, b) => {
|
||||
let va = a[memberSort.key], vb = b[memberSort.key];
|
||||
if (memberSort.key === 'spend') { va = memberSpend(a); vb = memberSpend(b); }
|
||||
if (memberSort.key === 'allowance_left') { va = allowanceLeft(a); vb = allowanceLeft(b); }
|
||||
if (memberSort.key === 'dues_amount') {
|
||||
va = duesSortValue(a); vb = duesSortValue(b);
|
||||
// Members with no readable dues sort LAST in either direction — they are
|
||||
// not a $0 subscription, they are unknown.
|
||||
if ((va === null) !== (vb === null)) return va === null ? 1 : -1;
|
||||
va = va ?? 0; vb = vb ?? 0;
|
||||
}
|
||||
if (memberSort.key === 'active' || memberSort.key === 'activated') { va = va ? 1 : 0; vb = vb ? 1 : 0; }
|
||||
if (typeof va === 'string' || typeof vb === 'string') {
|
||||
return String(va ?? '').localeCompare(String(vb ?? '')) * memberSort.dir;
|
||||
@@ -1059,10 +1094,10 @@ function renderMembers() {
|
||||
'<td>' + statusCell + '</td>' +
|
||||
'<td>' + act + '</td>' +
|
||||
'<td>' + src + '</td>' +
|
||||
'<td class="num balance-col allowance-only">' + fmt(m.balance) + '</td>' +
|
||||
'<td class="num balance-col allowance-only" title="Allowance left: $15 uniform monthly allowance minus spend this cycle">' + fmt(allowanceLeft(m)) + '</td>' +
|
||||
'<td class="num balance-col">' + creditsCell + '</td>' +
|
||||
'<td class="num">' + fmt(memberSpend(m)) + '</td>' +
|
||||
'<td class="num balance-col remaining-col remaining-only">' + fmt(m.remaining) + '</td>' +
|
||||
'<td class="num">' + duesCell(m) + '</td>' +
|
||||
'<td class="balance-col">' + esc(reset) + '</td>' +
|
||||
'<td><div class="adjust">' +
|
||||
'<input id="add-' + i(m.email) + '" placeholder="+$" />' +
|
||||
|
||||
Reference in new issue
Block a user