Two tabs and a cog: settings shell, one ranking, a script per page, the phone frame

The top bar is Roles and Applications plus health's cog. Behind the cog,
/settings/{ranking,searches,companies,pulls,messages,account} share one row
of sub-tabs, an underlined row on a desktop and pills on a phone. The old
paths answer 301 with their query string.

Ranking edits the first enabled agent, or creates one, with the intent,
the weights and the gates under Advanced. The order menu on Roles reads
Newest and Best match with one enabled agent, and names them with several.
config.yaml keeps the Copenhagen starter; the other two are commented
examples in config.example.yaml.

roles.js is split into roles.js, applications.js, ranking.js and
companies.js; count, cell, debounce, the company list and the affinity
control live once in app.js. app.css gets the phone frame after health and
newsdesk: one-row bar, edge-to-edge panels, 44px targets and 16px fields on
a coarse pointer, hover only where there is one, safe areas. The app is
installable from a manifest and roledesk-coloured icons. Every lede touched
is written for the person using the app.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-25 21:29:06 +02:00
1 parent 8c4bc3112a
commit 7d31cca394
34 files changed
+848 -565

No files matched your search

+91 -1
View File
@@ -12,6 +12,11 @@
*
* `body` may be a plain object; it is JSON-encoded with the header set, since
* forgetting the header is the failure that looks like a server bug.
*
* Beside `api` on `window`, the few helpers more than one page script uses:
* `count`, `cell`, `debounce`, and the company list with its affinity control
* (`loadCompanies`, `companies`, `affinityControl`, `setAffinity`). One copy
* each, since two copies of a helper is one of them being fixed.
*/
(function () {
@@ -69,5 +74,90 @@
window.toast.error(String(detail));
});
window.api = api;
// ----------------------------------------------------------------- helpers
/** `count(3, "role")` is "3 roles"; `many` for an irregular plural. */
function count(n, one, many) {
return `${n} ${n === 1 ? one : many || `${one}s`}`;
}
/** A `<td>` with its column name in `data-label`, which the phone layout
prints above the value once the table's head is hidden. */
function cell(tr, label, content) {
const td = document.createElement("td");
td.dataset.label = label;
if (typeof content === "string") td.textContent = content;
else td.appendChild(content);
tr.appendChild(td);
return td;
}
function debounce(fn, ms) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), ms);
};
}
// --------------------------------------------------------------- companies
/** @type {Map<string, object>} company_key -> row from /api/companies. One
Map, refilled in place, so a script holding it sees every reload. */
const companies = new Map();
async function loadCompanies() {
const rows = await api("/api/companies");
companies.clear();
for (const c of rows) companies.set(c.key, c);
return companies;
}
const AFFINITY_LEVELS = [
{ value: -1, label: "Mute" },
{ value: 0, label: "Neutral" },
{ value: 1, label: "Like" },
{ value: 2, label: "Favourite" },
];
/* The four buttons. `onChange` runs after the server accepted the change,
so each page decides what a change means for it: the role list refetches,
since muting changes which roles come back, and the company table redraws. */
function affinityControl(companyKey, current, onChange) {
const span = document.createElement("span");
span.className = "affinity";
span.setAttribute("role", "group");
span.setAttribute("aria-label", "Company affinity");
for (const level of AFFINITY_LEVELS) {
const button = document.createElement("button");
button.type = "button";
button.dataset.value = String(level.value);
button.textContent = level.label[0];
button.title = level.label;
button.setAttribute("aria-label", level.label);
button.setAttribute("aria-pressed", String(level.value === current));
button.addEventListener("click", () => setAffinity(companyKey, level.value, onChange));
span.appendChild(button);
}
return span;
}
async function setAffinity(companyKey, affinity, onChange) {
if (!companyKey) return;
let updated;
try {
updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
method: "POST", body: { affinity },
});
} catch (err) {
return;
}
const company = companies.get(companyKey);
if (company) company.affinity = updated.affinity;
if (onChange) await onChange();
}
Object.assign(window, {
api, count, cell, debounce, companies, loadCompanies, affinityControl, setAffinity,
});
})();