Viewing as leads the Roles rail; settings get a rail, agent cards, one Sources section at a time

A search agent is a persona, and every like or pass belongs to the one
being viewed. The rail now opens on Viewing as: a full-width chooser,
the name alone with one agent, a note with none, remembered in the URL
and localStorage. The vote buttons, the reader's affinity control, the
feed, the tag counts and the reader fetch all carry that agent; before,
votes sent none and every one landed on the default agent. Best first
and Newest first are back as the segmented control under Order,
independent of the agent. The rail selects no longer clip descenders:
Chrome ignores line-height on a select, so the fixed box is gone in
favour of padding and a min-height.

Settings render inside a sticky rail (Search agents; Sources with Job
boards, Company boards, Runs, Messages; Account), a strip under the
header on a phone, so Runs is one click away however long the company
list gets. Sources shows one section at a time, chosen by the fragment,
so the old redirects still land. Search agents are cards, newest first:
name, an On/Off switch with its word, the intent in full, the weights,
Edit in place, New agent on top, and a link to Roles as that agent.
Switching one on rescores it.

replace_scores writes nothing for an agent deleted while score was
running, instead of failing the run on the foreign key.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 15:05:55 +02:00
1 parent 063771d617
commit c4f2bcc0c9
20 files changed
+836 -326

No files matched your search

+203 -103
View File
@@ -1,9 +1,14 @@
/* The Search agents page: what Best match on the Roles tab is measured
* against, one agent at a time.
*
* The list is `/api/agents`; the form edits the agent picked from it, New
* clears it, Delete removes it. Votes, liked companies and scores are the
* agent's, so a delete takes them with it, and the confirm says so.
* Every agent from `/api/agents` is a card, newest first: its name, its
* switch, what it looks for, its weights, and a link to the Roles tab in its
* order. What it looks for is the paragraph, since that is what fit is
* measured against; the weights only share out the terms. Edit turns a card
* into the form from the page's `<template>`, in place, and New agent puts a
* blank card on top in the same state. One card edits at a time, so the
* form's ids stay unique. Votes, liked companies and scores are the agent's,
* so a delete takes them with it, and the confirm says so.
*
* Every request goes through `api()` from app.js, so a failure is one toast
* carrying the server's own sentence.
@@ -15,23 +20,69 @@
const $ = (sel, root = document) => root.querySelector(sel);
const DEFAULT_WEIGHTS = { fit: 0.6, recency: 0.2, affinity: 0.2, taste: 0.2 };
const NEW = "new";
/** @type {object[]} every agent, as the server lists them */
let agents = [];
/** @type {object | null} the agent the form edits, null for a new one */
let agent = null;
/** @type {number | "new" | null} the card in edit mode: an agent's id, NEW
* for the blank one on top, null for none */
let editing = null;
/** @type {HTMLElement | null} that card, kept across renders so a switch
* flipped on another card does not wipe what is being typed */
let editor = null;
/** @type {Map<number, HTMLElement>} each card's status line, kept across
* renders for the same reason: a "Scoring…" outlives the card it is on */
const statuses = new Map();
function byId(rows) {
return [...rows].sort((a, b) => a.id - b.id);
function newestFirst(rows) {
return [...rows].sort((a, b) => b.id - a.id);
}
// ---------------------------------------------------------------- the list
// What the Roles tab and the company list use when no agent is picked: the
// enabled one with the lowest id, else the lowest id (`Store.default_agent`).
function defaultAgent() {
const byId = [...agents].sort((a, b) => a.id - b.id);
return byId.find((a) => a.enabled) || byId[0] || null;
}
function el(tag, className, text) {
const node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined) node.textContent = text;
return node;
}
function link(href, text) {
const a = el("a", "", text);
a.href = href;
return a;
}
function statusOf(id) {
if (!statuses.has(id)) {
const line = el("p", "count agent-status");
line.setAttribute("role", "status");
statuses.set(id, line);
}
return statuses.get(id);
}
// ---------------------------------------------------------------- a card
// A switch with its state in words: a bare checkbox did not say what it
// switched. Switching one on scores it, since the pulls it sat out left it
// with no scores or stale ones.
function onSwitch(row) {
const box = document.createElement("input");
const label = el("label", "switch");
label.title = "On: scored with every pull and offered in the order menu on Roles.";
const box = el("input");
box.type = "checkbox";
box.setAttribute("role", "switch");
box.checked = Boolean(row.enabled);
box.setAttribute("aria-label", `Enable ${row.name}`);
box.setAttribute("aria-label", row.name);
const track = el("span", "switch-track");
track.setAttribute("aria-hidden", "true");
label.append(box, track, el("span", "switch-label", row.enabled ? "On" : "Off"));
box.addEventListener("change", async () => {
box.disabled = true;
try {
@@ -41,111 +92,162 @@
Object.assign(row, saved);
} catch (err) {
box.checked = !box.checked;
box.disabled = false;
return;
}
box.disabled = false;
render();
if (row.enabled) rescore(statusOf(row.id), row, "Switched on");
else statusOf(row.id).textContent = "Off: not scored, and not offered on Roles.";
});
return box;
return label;
}
function render() {
const body = $("#agents-list");
body.replaceChildren();
for (const row of byId(agents)) {
const div = document.createElement("div");
div.className = "crow";
if (!row.enabled) div.dataset.hidden = "true";
if (agent && agent.id === row.id) div.dataset.current = "true";
const name = document.createElement("span");
name.className = "name";
name.textContent = row.name;
div.appendChild(name);
div.appendChild(onSwitch(row));
function weightsLine(row) {
const w = Object.assign({}, DEFAULT_WEIGHTS, row.weights);
const gates = row.gates && row.gates.length ? ` · ${count(row.gates.length, "gate")}` : "";
return `fit ${w.fit} · newness ${w.recency} · companies ${w.affinity} · liked ${w.taste}${gates}`;
}
const sub = document.createElement("span");
sub.className = "sub";
const w = Object.assign({}, DEFAULT_WEIGHTS, row.weights);
sub.append(`fit ${w.fit} · newness ${w.recency} · companies ${w.affinity} · liked ${w.taste}`, " ");
const edit = document.createElement("button");
edit.type = "button";
edit.className = "linky";
edit.textContent = "Edit";
edit.addEventListener("click", () => fill(row));
const remove = document.createElement("button");
remove.type = "button";
remove.className = "linky";
remove.textContent = "Delete";
remove.addEventListener("click", () => removeAgent(row));
sub.append(edit, " ", remove);
div.appendChild(sub);
body.appendChild(div);
function card(row, fallback) {
const div = el("article", "agent-card");
if (!row.enabled) div.dataset.off = "true";
const head = el("div", "agent-card-head");
head.appendChild(el("h2", "agent-name", row.name));
if (fallback) {
const badge = el("span", "badge", "default");
badge.title = "What Roles and the company list use when no agent is picked.";
head.appendChild(badge);
}
$("#agents-count").textContent = agents.length
? count(agents.length, "search agent")
: "No search agents yet. Describe one below.";
head.appendChild(onSwitch(row));
div.appendChild(head);
const intent = (row.intent || "").trim();
div.appendChild(intent
? el("p", "agent-intent", intent)
: el("p", "agent-intent empty", "Nothing described yet, so fit has nothing to measure against. Edit says what this agent looks for."));
div.appendChild(el("p", "agent-weights", weightsLine(row)));
const actions = el("div", "agent-card-actions");
const edit = el("button", "secondary", "Edit");
edit.type = "button";
edit.addEventListener("click", () => open(row));
actions.appendChild(edit);
// An agent that is off is not in the order menu, so Roles would open in
// another agent's order: the link is only there while this one is on.
if (row.enabled) actions.appendChild(link(`/?agent=${row.id}`, "Open Roles as this agent →"));
const remove = el("button", "linky", "Delete");
remove.type = "button";
remove.addEventListener("click", () => removeAgent(row));
actions.appendChild(remove);
div.appendChild(actions);
div.appendChild(statusOf(row.id));
return div;
}
// ---------------------------------------------------------------- the form
function fill(row) {
agent = row;
function form(row) {
const div = el("article", "agent-card editing");
const f = $("#agent-form-template").content.querySelector("form").cloneNode(true);
const weights = Object.assign({}, DEFAULT_WEIGHTS, row ? row.weights : {});
$("#agent-form-title").textContent = row ? `Edit ${row.name}` : "New agent";
$("#a-name").value = row ? row.name : "";
$("#a-intent").value = row ? row.intent : "";
$("#a-gates").value = JSON.stringify(row ? row.gates : [], null, 2);
$("#a-fit").value = weights.fit;
$("#a-recency").value = weights.recency;
$("#a-affinity").value = weights.affinity;
$("#a-taste").value = weights.taste;
$("#a-delete").hidden = !row;
$("#agent-status").textContent = "";
render();
if (row) $("#agent-form").scrollIntoView({ behavior: "smooth", block: "start" });
$("#agent-form-title", f).textContent = row ? `Edit ${row.name}` : "New agent";
$("#a-name", f).value = row ? row.name : "";
$("#a-intent", f).value = row ? row.intent : "";
$("#a-gates", f).value = JSON.stringify(row ? row.gates : [], null, 2);
$("#a-fit", f).value = weights.fit;
$("#a-recency", f).value = weights.recency;
$("#a-affinity", f).value = weights.affinity;
$("#a-taste", f).value = weights.taste;
$("#a-delete", f).hidden = !row;
f.addEventListener("input", () => { f.dataset.dirty = "true"; });
f.addEventListener("submit", (event) => save(event, row));
$("#a-cancel", f).addEventListener("click", () => { close(); render(); });
$("#a-delete", f).addEventListener("click", () => row && removeAgent(row));
div.appendChild(f);
if (row) div.appendChild(statusOf(row.id));
return div;
}
async function save(event) {
// Put the open form away, asking first if it holds changes. False when the
// answer was to keep them.
function close() {
const f = editor && $("form", editor);
if (f && f.dataset.dirty && !window.confirm("Discard the changes to this agent?")) {
return false;
}
editing = null;
editor = null;
return true;
}
// Edit `row` in its own card, or a new agent in a blank card on top.
function open(row) {
const target = row ? row.id : NEW;
if (editing !== target) {
if (!close()) return;
editing = target;
editor = form(row);
render();
}
editor.scrollIntoView({ behavior: "smooth", block: "nearest" });
$("#a-name", editor).focus({ preventScroll: true });
}
function render() {
const cards = [];
if (editing === NEW) cards.push(editor);
const fallback = defaultAgent();
for (const row of newestFirst(agents)) {
cards.push(editing === row.id ? editor : card(row, agents.length > 1 && row === fallback));
}
$("#agents-list").replaceChildren(...cards);
$("#agents-count").textContent = agents.length
? count(agents.length, "search agent")
: "No search agents yet. New agent describes one.";
}
async function save(event, row) {
event.preventDefault();
const status = $("#agent-status");
const f = event.target;
let gates;
try {
gates = JSON.parse($("#a-gates").value || "[]");
gates = JSON.parse($("#a-gates", f).value || "[]");
} catch (err) {
window.toast.error(`Gates are not valid JSON: ${err.message}`);
return;
}
const body = {
name: $("#a-name").value.trim(),
intent: $("#a-intent").value,
name: $("#a-name", f).value.trim(),
intent: $("#a-intent", f).value,
gates,
weights: {
fit: Number($("#a-fit").value),
recency: Number($("#a-recency").value),
affinity: Number($("#a-affinity").value),
taste: Number($("#a-taste").value),
fit: Number($("#a-fit", f).value),
recency: Number($("#a-recency", f).value),
affinity: Number($("#a-affinity", f).value),
taste: Number($("#a-taste", f).value),
},
// Saving an agent means it is wanted, so a new one starts on; the
// list's checkbox is where an existing one is switched.
enabled: agent ? agent.enabled : true,
// card's switch is where an existing one is switched.
enabled: row ? row.enabled : true,
};
if (agent) body.id = agent.id;
const button = $("#agent-form button[type=submit]");
if (row) body.id = row.id;
const button = $("button[type=submit]", f);
button.disabled = true;
let saved;
try {
saved = await api("/api/agents", { method: "POST", body });
await load();
} catch (err) {
status.textContent = "";
button.disabled = false;
return;
}
agent = agents.find((a) => a.id === saved.id) || saved;
$("#agent-form-title").textContent = `Edit ${agent.name}`;
$("#a-delete").hidden = false;
// The newest is first, so a new agent's card stays where its form was.
editing = null;
editor = null;
render();
await rescore(status);
button.disabled = false;
const agent = agents.find((a) => a.id === saved.id) || saved;
await rescore(statusOf(agent.id), agent, "Saved");
}
async function removeAgent(row) {
@@ -158,19 +260,24 @@
return;
}
agents = agents.filter((a) => a.id !== row.id);
if (agent && agent.id === row.id) fill(null);
else render();
statuses.delete(row.id);
if (editing === row.id) {
editing = null;
editor = null;
}
render();
}
// Start the `score` job and wait for it, so "Saved and scored" means the
// Roles tab already orders by what was saved.
async function rescore(status) {
status.textContent = "Saved. Scoring…";
// Start the `score` job and wait for it, so "scored" means the Roles tab
// already orders by what was saved. `said` is what happened first.
async function rescore(status, agent, said) {
const runs = () => link("/settings/sources#runs", "follow it under Runs");
status.replaceChildren(`${said}. Scoring every open role; `, runs(), ".");
let job;
try {
job = await api("/api/jobs", { method: "POST", body: { kind: "score", payload: {} } });
} catch (err) {
status.textContent = "Saved, but scoring did not start.";
status.textContent = `${said}, but scoring did not start.`;
return;
}
for (let i = 0; i < 300; i += 1) {
@@ -185,22 +292,15 @@
if (busy) continue;
const done = snapshot.recent.find((j) => j.id === job.id);
if (done && done.state !== "done") {
status.textContent = `Saved. Scoring ${done.state}.`;
status.textContent = `${said}. Scoring ${done.state}.`;
if (done.error) window.toast.error(`Scoring ${done.state}: ${done.error}`);
return;
}
status.replaceChildren("Saved and scored. ");
const link = document.createElement("a");
link.href = `/?agent=${agent.id}`;
link.textContent = "See the best matches";
status.appendChild(link);
status.replaceChildren(`${said} and scored. `,
link(`/?agent=${agent.id}`, `Open Roles as ${agent.name} →`));
return;
}
status.replaceChildren("Saved. Scoring is still running; ");
const link = document.createElement("a");
link.href = "/settings/sources#runs";
link.textContent = "follow it under Runs";
status.append(link, ".");
status.replaceChildren(`${said}. Scoring is still running; `, runs(), ".");
}
// -------------------------------------------------------------------- init
@@ -211,17 +311,17 @@
document.addEventListener("DOMContentLoaded", async () => {
if (!$("#agents-list")) return;
$("#a-new").addEventListener("click", () => open(null));
try {
await load();
} catch (err) {
return;
}
// The default agent, the enabled one with the lowest id, is what the
// Roles tab and the company list fall back to, so it is what opens.
const first = byId(agents).find((a) => a.enabled) || byId(agents)[0] || null;
fill(first);
$("#agent-form").addEventListener("submit", save);
$("#a-new").addEventListener("click", () => fill(null));
$("#a-delete").addEventListener("click", () => agent && removeAgent(agent));
// With none yet, the page is the form for the first one.
if (!agents.length) {
editing = NEW;
editor = form(null);
}
render();
});
})();
+190 -60
View File
@@ -1,6 +1,6 @@
/* The whole stylesheet: the boilerplate's, with roledesk's palette in the
* custom properties (a quiet UI face and newsdesk's teal signal colour), the
* frame (a top bar of two tabs and a cog, the settings sub-tabs), roledesk's
* frame (a top bar of two tabs and a cog, the settings rail), roledesk's
* own pages, and at the bottom the phone: a width query for the layout and a
* pointer query for the sizes, after newsdesk and health. No build step.
*
@@ -122,35 +122,91 @@ a { color: var(--accent); }
}
.top nav a.active { background: var(--accent); color: var(--accent-fg); }
/* The settings sub-tabs, health's: an underlined row here, pills on a phone. */
.subtabs {
display: flex; gap: 4px; margin: 4px 0 14px;
border-bottom: 1px solid var(--line);
}
.subtabs a {
padding: 7px 12px;
color: var(--dim);
font-weight: 500;
text-decoration: none;
border-bottom: 2px solid transparent;
margin-bottom: -1px;
}
@media (hover: hover) {
.subtabs a:hover { color: var(--fg); }
}
.subtabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
/* == settings shell ======================================================= */
/* The rail beside every page under the cog (settings/_rail.html), in the
Roles rail's look: a small-caps heading, quiet rows, the current one tinted
with a bar down its edge. Rules of its own rather than `#rail`'s, because
that rail turns into an overlay when narrow and this one into a strip.
Sticky under the header, with its own scroll if it outgrows the screen, so
it stays beside a Company boards list sixty companies long. */
/* The jump row under the sub-tabs on Sources: one link per section, since
the page is three sections long. Each section clears the sticky bar when
the anchor lands. */
.jump { display: flex; gap: .25rem .75rem; flex-wrap: wrap; margin: -6px 0 10px; font-size: .9rem; }
.jump a { color: var(--dim); text-decoration: none; }
@media (hover: hover) {
.jump a:hover { color: var(--fg); text-decoration: underline; }
.settings-shell {
display: grid;
grid-template-columns: 13rem minmax(0, 1fr);
gap: 1.6rem;
max-width: 76rem; margin: 0 auto; padding: 0 1.1rem;
}
section[id] { scroll-margin-top: calc(var(--header-h, 3.5rem) + .5rem); }
.settings-shell > main {
max-width: none; min-width: 0; margin: 0;
padding: 1.5rem 0 calc(4rem + env(safe-area-inset-bottom));
}
.settings-rail {
position: sticky; top: var(--chrome); align-self: start;
max-height: calc(100vh - var(--chrome)); overflow-y: auto;
padding: 1.75rem 0 2rem;
}
.settings-rail h3 {
margin: 0 0 .45rem; padding: 0 .5rem;
font-size: .76rem; font-weight: 650; letter-spacing: .06em;
text-transform: uppercase; color: var(--faint);
}
.settings-rail nav, .rail-group { display: flex; flex-direction: column; gap: .1rem; }
.rail-link {
display: block; padding: .3rem .5rem; border-radius: 3px;
font-size: .9rem; color: var(--dim); text-decoration: none;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* A page's sections, indented under it. */
.rail-link.sub { padding-left: 1.5rem; font-size: .86rem; }
@media (hover: hover) {
.rail-link:hover { color: var(--fg); background: var(--panel); }
}
/* The current page, or on Sources the current section. The page a section
is on is only named in the accent, so one row at a time has the bar. */
.rail-link[aria-current] {
background: color-mix(in srgb, var(--accent) 14%, transparent);
color: var(--accent); font-weight: 600;
box-shadow: inset 3px 0 0 var(--accent);
}
.rail-link.parent[aria-current] { background: none; box-shadow: none; }
/* A section landed on by its fragment clears the header. */
section[id] { scroll-margin-top: calc(var(--chrome) + .5rem); }
.card h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
/* Narrow: one column, and the rail is a strip of chips across the top of the
content, pinned under the header and scrolled sideways, so a phone jumps
between sections without scrolling back up. Only the current page's
sections are in it, after a › on their page. */
@media (max-width: 60rem) {
.settings-shell { display: block; padding: 0; }
.settings-shell > main { padding-inline: 1.1rem; }
.settings-rail {
top: var(--chrome); z-index: 4;
max-height: none; overflow: auto hidden;
padding: .4rem .6rem;
background: var(--panel); border-bottom: 1px solid var(--line);
scrollbar-width: none;
}
.settings-rail::-webkit-scrollbar { display: none; }
.settings-rail h3 { display: none; }
.settings-rail nav { flex-direction: row; gap: .25rem; width: max-content; }
.rail-group { display: contents; }
.rail-group:not([data-current]) .sub { display: none; }
.rail-link, .rail-link.sub { padding: .3rem .75rem; border-radius: 999px; overflow: visible; }
.rail-link[aria-current] { box-shadow: none; }
.rail-link.parent[aria-current]::after { content: " ›"; color: var(--faint); }
section[id] { scroll-margin-top: calc(var(--chrome) + 3.25rem); }
}
@media (max-width: 640px) {
.settings-shell > main { padding: 10px 10px calc(3rem + env(safe-area-inset-bottom)); }
}
@media (pointer: coarse) {
.rail-link { display: inline-flex; align-items: center; min-height: 2.75rem; }
}
/* == end of settings shell ================================================ */
main {
max-width: 62rem;
margin: 0 auto;
@@ -515,9 +571,9 @@ kbd {
border-radius: 3px; padding: 0 .3em; margin-right: .1em; color: var(--dim);
}
/* Order and period. `.seg` is a block on its own here and the two halves
split the width, so the choice is one target each rather than two words
pushed against the edge. */
/* Order, and the period under it. `.seg` is a block on its own here and the
two halves split the width, so the choice is one target each rather than
two words pushed against the edge. */
.seg { display: flex; }
#sort { padding: 0 .3rem; }
#rail .seg button {
@@ -541,13 +597,42 @@ kbd {
display: block; margin: .7rem .3rem .25rem;
font-size: .78rem; color: var(--faint);
}
/* Sized by `min-height`, never by padding around one line. Chrome draws a
select's text at `line-height: normal` whatever the stylesheet says and
clips it to the content box, so a select that was padding around one line
box cut off the "g" wherever the face's glyphs reach below its own line
metrics, as Segoe UI Variable's do on Windows. A box taller than the line,
with the text centred in it, has room under the baseline in any face and
at any zoom. The text fields are set the same way so the column lines up. */
.rail-select, .rail-fields input[type="text"], .rail-fields select {
width: calc(100% - .6rem); margin: 0 .3rem;
padding: .25rem .4rem; font-size: .84rem;
min-height: 2rem; padding: .15rem .45rem;
font-size: .84rem; line-height: normal;
border: 1px solid var(--line); border-radius: 3px;
background: var(--panel); color: var(--fg);
}
#agent { margin-bottom: .1rem; }
/* Viewing as: the first thing in the rail, since it decides whose answer
every other control gets. The agent's name in the bold face, larger than
the filters, the full width, and ruled off from them. */
#rail .rail-viewing { padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
#rail .agent-pick {
display: block; width: calc(100% - .6rem); margin: 0 .3rem;
font-size: 1rem; font-weight: 650; color: var(--fg);
}
#rail select.agent-pick {
min-height: 2.6rem; padding: .2rem .5rem;
border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}
/* One agent is not a choice, so it is its name, not a select of one. */
#rail p.agent-pick {
padding: .45rem .6rem; line-height: 1.35; overflow-wrap: anywhere;
background: color-mix(in srgb, var(--accent) 10%, transparent);
box-shadow: inset 3px 0 0 var(--accent); border-radius: 3px;
}
.rail-viewing .rail-note { margin-top: 0; }
/* A link in a heading ("agents", "clear") is a word, not a second heading. */
#rail h3 .linky { text-transform: none; letter-spacing: 0; font-weight: 400; }
/* The filters that are not the everyday ones: folded, with a count on the
summary so a closed fold still says the list is narrowed. */
@@ -932,7 +1017,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
#rail .rail-row { align-items: center; min-height: 2.75rem; }
#rail .tag { padding: .45rem .8rem; }
#rail .seg button { min-height: 2.75rem; }
.rail-select, .rail-fields input[type="text"], .rail-fields select { min-height: 2.75rem; }
.rail-select, .rail-fields input[type="text"], .rail-fields select,
#rail select.agent-pick { min-height: 2.75rem; }
.rail-more > summary { padding-block: .7rem; }
.reader-bar { padding: .3rem .5rem; }
.reader-bar .judge button, .reader-bar .close, .reader-external { min-height: 2.75rem; min-width: 2.75rem; }
@@ -974,14 +1060,75 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
/* agents */
.agents { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.agent {
display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
/* The Search agents page: a card per agent (static/agents.js). What it looks
for is the card's body, in the reading face, since it is what fit is
measured against; the weights are a small line under it. */
.agents-head { display: flex; align-items: center; justify-content: space-between; gap: var(--gap); }
.agent-cards { display: flex; flex-direction: column; gap: .9rem; margin: .5rem 0 2rem; }
.agent-card {
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
padding: .5rem .75rem;
padding: 1rem 1.25rem;
}
.agent a { font-weight: 600; text-decoration: none; }
.agent-meta { color: var(--dim); font-size: .85rem; flex: 1 1 12rem; }
.agent-card.editing { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
/* One line however long the name: the name wraps inside its own box, and the
badge and the switch keep their width, level with its first line. */
.agent-card-head { display: flex; align-items: baseline; gap: .6rem; }
.agent-name { flex: 0 1 auto; min-width: 0; font-size: 1.2rem; font-weight: 700; margin: 0; overflow-wrap: anywhere; }
.agent-card-head .badge { flex: none; }
/* The switch keeps to the right, by an auto margin rather than a spacer. */
.agent-card-head .switch { flex: none; margin-left: auto; }
.agent-intent {
margin: .6rem 0 .4rem; max-width: 44rem;
font-family: var(--read); font-size: 1.02rem; line-height: 1.55;
white-space: pre-line; overflow-wrap: anywhere;
}
.agent-intent.empty { font-family: inherit; font-size: .9rem; color: var(--dim); font-style: italic; }
.agent-weights { margin: 0; font-size: .8rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.agent-card-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .8rem; }
.agent-card-actions a { font-size: .9rem; font-weight: 600; text-decoration: none; }
@media (hover: hover) {
.agent-card-actions a:hover { text-decoration: underline; }
}
.agent-card-actions .linky { margin-left: auto; }
.agent-card .agent-status { margin: .5rem 0 0; }
.agent-card .agent-status:empty { display: none; }
/* An agent that is off: the card stays readable, only quieter. */
.agent-card[data-off="true"] .agent-name,
.agent-card[data-off="true"] .agent-intent { color: var(--dim); }
/* In a card the form is the card's body, not a panel of its own. */
.agent-card .agent-form {
max-width: none; margin: 0; padding: 0;
background: none; border: 0; border-radius: 0;
}
.agent-card .agent-form h2 { font-size: 1.2rem; }
/* On and Off, said in words beside a track: a bare checkbox did not say what
it switched. The checkbox is still the control, only drawn over. */
.switch {
position: relative; display: inline-flex; align-items: center; gap: .45rem;
cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--dim);
user-select: none;
}
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch-track {
position: relative; flex: none; width: 2.2rem; height: 1.25rem;
border-radius: 999px; background: var(--line); transition: background 120ms;
}
.switch-track::after {
content: ""; position: absolute; top: .15rem; left: .15rem;
width: .95rem; height: .95rem; border-radius: 50%;
background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / .25);
transition: transform 120ms;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(.95rem); }
.switch input:checked ~ .switch-label { color: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled ~ * { opacity: .55; }
@media (pointer: coarse) {
.switch { min-height: 2.75rem; padding-left: .5rem; }
}
.agent-form {
display: flex; flex-direction: column; gap: .6rem; max-width: 44rem;
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
@@ -1057,8 +1204,6 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
gap: .4rem; font-size: .8rem; color: var(--dim);
}
.srow[data-muted="true"], .crow[data-hidden="true"] { opacity: .6; }
/* The agent the form is editing, on the Search agents list. */
.crow[data-current="true"] .name { color: var(--accent); }
.linky {
padding: 0; border: 0; background: none; font-size: .8rem;
@@ -1114,29 +1259,14 @@ table.list select { padding: .25rem .4rem; }
.top nav a { flex: 1 1 auto; text-align: center; padding: .6rem .4rem; white-space: nowrap; }
.top nav a.icon { flex: 0 0 auto; justify-content: center; padding-inline: .7rem; }
/* Three sub-tabs, one row of pills rather than the desktop's underlined
row; they wrap if a label needs it, since a scrolling strip does not
show that more are off the edge. */
.subtabs { flex-wrap: wrap; border-bottom: none; gap: 6px; }
.subtabs a {
flex: 1 1 30%;
padding: 7px 4px;
border-radius: 999px;
border-bottom: none;
margin-bottom: 0;
background: var(--panel);
text-align: center;
font-size: .85rem;
}
.subtabs a.active { background: var(--accent); color: var(--accent-fg); }
/* A panel runs to both edges of the screen: no side margin, border or
rounded corner, so the content keeps all but its own 10 pixels of the
width. The page background between two panels reads as a band. */
.card, .filters, .agent-form, .note {
.card, .filters, .agent-form, .agent-card, .note {
margin-inline: -10px; border-radius: 0; border-inline: 0;
}
.card { padding: .8rem 10px; }
.card, .agent-card { padding: .8rem 10px; }
.agent-card.editing { box-shadow: none; }
.row-between { flex-wrap: wrap; }
}
@@ -1153,8 +1283,8 @@ table.list select { padding: .25rem .4rem; }
not zoom back out when it loses it. */
input, select, textarea { font-size: 16px; }
button, .top nav a, .subtabs a { min-height: 2.75rem; }
.top nav a, .subtabs a { display: inline-flex; align-items: center; justify-content: center; }
button, .top nav a { min-height: 2.75rem; }
.top nav a { display: inline-flex; align-items: center; justify-content: center; }
.filters input[type="search"], .filters input[type="text"], .filters select,
.agent-form input, .source-form select { min-height: 2.75rem; }
.affinity button { min-width: 2.75rem; }
+23 -13
View File
@@ -14,15 +14,22 @@
* Both are optimistic: the button changes before the request and changes back
* if it fails. `api()` has already toasted the failure by then.
*
* A vote is a search agent's: `{agent}` names whose, and is sent with the POST
* and the DELETE. Without it the server's default agent takes the vote, which
* is right on a page that picks none. Save is not an agent's; it is the same
* application whoever is viewing.
*
* One role can have two sets of these on screen at once, its feed row's and
* the reader bar's, each bound to its own copy of the role. A change in one is
* echoed to every other set for the same uid (`echo`), which copies the vote
* and the read mark across and repaints it, so the row never shows a stance
* the reader has taken back. A vote marks the role read on the server, and the
* answer's `read_at` is copied onto the role with the vote.
* the reader has taken back. Only sets for the same agent are echoed to,
* since another agent can hold a different stance on the same role. A vote
* marks the role read on the server, and the answer's `read_at` is copied onto
* the role with the vote.
*
* await loadTracked();
* container.append(judgeButtons(role, (role) => row.classList.toggle(...)));
* container.append(judgeButtons(role, (role) => row.classList.toggle(...), { agent: 2 }));
*/
(function () {
"use strict";
@@ -44,10 +51,10 @@
next time a change is echoed. */
const groups = new Set();
function echo(from) {
function echo(from, agent) {
for (const group of groups) {
if (!group.star.isConnected) { groups.delete(group); continue; }
if (group.role === from || group.role.uid !== from.uid) continue;
if (group.role === from || group.role.uid !== from.uid || group.agent !== agent) continue;
group.role.vote = from.vote;
group.role.voted_at = from.voted_at;
if (from.read_at !== undefined) group.role.read_at = from.read_at;
@@ -72,8 +79,9 @@
/* The four buttons as a fragment, bound to `role`, which they read and
write in place (`role.vote`), so the caller's copy is always current.
`onChange(role)` runs after every change, optimistic or reverted: the
feed dims a passed row with it. */
function judgeButtons(role, onChange) {
feed dims a passed row with it. `agent` is whose vote, the server's
default agent when absent. */
function judgeButtons(role, onChange, { agent = null } = {}) {
const fragment = document.createDocumentFragment();
const votes = STANCES.map((s) => {
const b = button(s.cls, s.glyph);
@@ -106,12 +114,14 @@
const clearing = before === value;
role.vote = clearing ? null : value;
paint();
echo(role);
echo(role, agent);
const path = `/api/roles/${encodeURIComponent(role.uid)}/vote`;
const byDefault = agent == null;
try {
const updated = clearing
? await api(path, { method: "DELETE" })
: await api(path, { method: "POST", body: { value } });
? await api(byDefault ? path : `${path}?agent=${encodeURIComponent(agent)}`,
{ method: "DELETE" })
: await api(path, { method: "POST", body: byDefault ? { value } : { value, agent } });
role.vote = updated.vote;
role.voted_at = updated.voted_at;
if (updated.read_at !== undefined) role.read_at = updated.read_at;
@@ -119,7 +129,7 @@
role.vote = before;
}
paint();
echo(role);
echo(role, agent);
}
// One request at a time: a second tap while the first is in flight would
@@ -148,10 +158,10 @@
star.disabled = false;
}
paint();
echo(role);
echo(role, agent);
}
groups.add({ role, star, paint });
groups.add({ role, star, paint, agent });
paint();
return fragment;
}
+163 -71
View File
@@ -19,9 +19,25 @@
* back always means "out of the reader". The server answers `/roles/{uid}`
* with this same page, and `route` is the only thing that reads the path.
*
* The rail opens on Viewing as: the search agent the feed is seen as. An
* agent is a persona ("me as a candidate", "me as a hiring manager watching
* the market") with its own scores, votes and hidden companies, so every
* request that has an answer per agent names it: the feed, the tag counts,
* the role in the reader, the company list, each vote (judge.js's `{agent}`)
* and each company affinity. One is always picked while any is enabled: the
* one in `?agent=`, else the one this browser viewed last (localStorage),
* else the enabled one with the lowest id, which is the server's default too.
* Picking another reloads the feed and the counts under the reader, which
* stays open and is fetched again for that agent's vote.
*
* Order is Best first (`order=score`, the agent's score moved by its votes)
* or Newest first (`order=newest`), the same two whichever agent is viewed,
* and both carry the agent's votes and hidden companies.
*
* The filters are in the query string, replaced rather than pushed, so a
* reload or a link keeps them and the back button is not buried under them.
* `?company=` and `?agent=` are how the Companies and Ranking pages link in.
* `?company=` and `?agent=` are how the Companies and Search agents pages
* link in.
*
* The list is paged: 60 rows, then 60 more each time the end of the list comes
* within 600px of the screen, with the offset the rows already shown. Back to
@@ -47,10 +63,12 @@
const TEASER = 500;
/** How many rows and how far down, for coming back to this page. */
const KEPT = "roledesk.roles";
/** The agent last viewed as, so the next visit opens on the same persona. */
const VIEWING = "roledesk.agent";
const number = new Intl.NumberFormat("en");
// What the list is in the order of. Best first is the first enabled
// ranking's score, moved by the role's vote; Newest first is first seen.
// What the list is in the order of. Best first is the viewing agent's
// score, moved by its votes; Newest first is first seen.
const SORTS = { score: "Best first", time: "Newest first" };
// The named windows over `days`, which counts back from now.
@@ -76,7 +94,8 @@
q: "",
railOpen: !narrow.matches,
railAutoShut: false, // the reader folded the rail, so closing unfolds it
agents: [], // the enabled rankings, from /api/agents
agents: [], // the enabled search agents, from /api/agents, by id
agentsLoaded: false, // so "no agent" is not said before the answer
tags: [], // [{tag, count, unread}] from /api/filters
items: [], // the rows on screen, in order
total: 0, // how many roles the filters match in all
@@ -102,15 +121,10 @@
// ------------------------------------------------------------ the order
/** The ranking the list is ordered by, or null for Newest first. Best first
with no ranking enabled is Newest first; an `agent` from the URL that is
not an enabled ranking falls back to the first one. */
function rankedBy() {
if (state.filter.sort !== "score" || !state.agents.length) return null;
const chosen = state.agents.find((a) => a.id === state.filter.agent);
return (chosen || state.agents[0]).id;
}
const sortShown = () => (rankedBy() === null ? "time" : "score");
/** The order the list is in. Best first needs an agent to score by: with
none enabled the server answers newest first, and so does this. */
const sortShown = () =>
(state.filter.sort === "score" && state.filter.agent !== null ? "score" : "time");
function feedParams() {
const f = state.filter;
@@ -123,10 +137,10 @@
if (f.showMuted) p.set("show_muted", "true");
if (!f.showRead) p.set("include_read", "false");
f.tags.forEach((t) => p.append("tags", t));
const agent = rankedBy();
if (agent !== null) {
p.set("agent", String(agent));
if (f.gated) p.set("gated", "true");
if (f.agent !== null) {
p.set("agent", String(f.agent));
p.set("order", sortShown() === "score" ? "score" : "newest");
if (f.gated && sortShown() === "score") p.set("gated", "true");
}
return p;
}
@@ -149,10 +163,8 @@
f.gated = q.get("gated") === "true" || q.get("gated") === "1";
f.tags = new Set(q.getAll("tags"));
if (q.get("sort") === "time") f.sort = "time";
if (q.get("agent")) {
f.sort = "score";
f.agent = Number(q.get("agent"));
}
// Checked against the enabled agents once they are in (`chooseAgent`).
if (q.get("agent")) f.agent = Number(q.get("agent"));
if (f.company || f.place || f.function || f.remote || f.judged || f.showMuted || f.gated) {
$("#f-more").open = true;
}
@@ -162,12 +174,8 @@
adding one: a filter is a question, not a place. */
function writeUrl() {
const p = feedParams();
p.delete("agent");
p.delete("gated");
const f = state.filter;
if (f.sort === "time") p.set("sort", "time");
else if (f.agent !== null) p.set("agent", String(f.agent));
if (f.gated && f.sort === "score") p.set("gated", "true");
p.delete("order");
if (state.filter.sort === "time") p.set("sort", "time");
const query = p.toString();
const url = location.pathname + (query ? `?${query}` : "");
if (url !== location.pathname + location.search) history.replaceState(history.state, "", url);
@@ -226,15 +234,58 @@
}
async function loadAgents() {
state.agents = (await api("/api/agents")).filter((a) => a.enabled);
state.agents = (await api("/api/agents")).filter((a) => a.enabled)
.sort((a, b) => a.id - b.id);
state.agentsLoaded = true;
}
// The tag counts. Asked with `show_muted` only, the one filter the route
// takes, so picking a tag does not renumber the others.
function storedAgent() {
try { return Number(localStorage.getItem(VIEWING)) || null; } catch (err) { return null; }
}
function rememberAgent(id) {
try {
if (id === null) localStorage.removeItem(VIEWING);
else localStorage.setItem(VIEWING, String(id));
} catch (err) { /* private mode: the next visit opens on the default */ }
}
/** The agent to view as, among the enabled ones: the address's, else the
one this browser viewed last, else the lowest id. An agent disabled or
deleted since is passed over, not kept as a question nobody answers. */
function chooseAgent() {
const ids = state.agents.map((a) => a.id);
const wanted = [state.filter.agent, storedAgent()].find((id) => ids.includes(id));
state.filter.agent = wanted ?? (ids.length ? ids[0] : null);
rememberAgent(state.filter.agent);
writeUrl();
}
/* Another persona over the same roles: its scores, votes and hidden
companies, so the companies come first (they dim rows), then the feed
and the tag counts. The reader stays, fetched again for this agent's
vote; a filter closes it, an agent does not, since the role is still in
question, only the eyes on it changed. */
async function setAgent(id) {
if (id === state.filter.agent) return;
state.filter.agent = id;
rememberAgent(id);
writeUrl();
renderRail();
renderActive();
await loadCompanies(id).catch(() => {});
reload();
loadFilters().catch(() => {});
if (state.readingUid) refreshReader(state.readingUid);
}
// The tag counts. Asked with `show_muted` and the agent only, the filters
// the route takes, so picking a tag does not renumber the others.
let filtersRequest = 0;
async function loadFilters() {
const params = new URLSearchParams();
if (state.filter.showMuted) params.set("show_muted", "true");
if (state.filter.agent !== null) params.set("agent", String(state.filter.agent));
const request = ++filtersRequest;
const data = await api(`/api/filters?${params}`);
if (request !== filtersRequest) return;
@@ -257,8 +308,9 @@
renderActive();
}
// Who is viewing and in which order are not filters, so they stay.
function clearFilters() {
const kept = { agent: state.filter.agent };
const kept = { agent: state.filter.agent, sort: state.filter.sort };
state.filter = Object.assign(blankFilter(), kept);
setFilter({}, { counts: true });
}
@@ -297,33 +349,20 @@
const f = state.filter;
$("#show-read").setAttribute("aria-pressed", String(f.showRead));
// The order. One ranking, or none, is the segmented control; more than one
// is a select naming each, so none is lost.
const ranked = rankedBy();
const many = state.agents.length > 1;
$("#sort").hidden = many;
$("#agent").hidden = !many;
if (many) {
const select = $("#agent");
select.replaceChildren(...state.agents.map((a) => new Option(a.name, String(a.id))),
new Option(SORTS.time, ""));
select.value = ranked === null ? "" : String(ranked);
} else {
const none = !state.agents.length;
$("#sort").innerHTML = Object.entries(SORTS).map(([key, label]) => {
const off = key === "score" && none;
return `<button type="button" data-sort="${key}" aria-pressed="${sortShown() === key}"
${off ? `aria-disabled="true" title="No ranking is enabled. Settings, Ranking sets one up."`
: ""}>${label}</button>`;
}).join("");
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
b.onclick = () => {
if (b.getAttribute("aria-disabled") === "true") return;
setFilter({ sort: b.dataset.sort });
};
});
}
$("#show-gated").hidden = ranked === null;
renderAgent();
// The order, the same two whatever is viewed. Best first needs an agent
// to score by, so with none it is greyed and says why.
const none = state.agentsLoaded && !state.agents.length;
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
b.setAttribute("aria-pressed", String(sortShown() === b.dataset.sort));
const off = b.dataset.sort === "score" && none;
if (off) b.setAttribute("aria-disabled", "true");
else b.removeAttribute("aria-disabled");
b.title = off ? "No search agent is enabled, so nothing is scored." : "";
});
const ranked = sortShown() === "score";
$("#show-gated").hidden = !ranked;
$("#period").value = f.period;
@@ -354,13 +393,41 @@
setValue("f-show-muted", f.showMuted);
setValue("f-gated", f.gated);
const more = [f.company.trim(), f.place.trim(), f.function, f.remote, f.judged,
f.showMuted, ranked !== null && f.gated].filter(Boolean).length;
f.showMuted, ranked && f.gated].filter(Boolean).length;
$("#f-active").textContent = more ? ` · ${more}` : "";
document.body.dataset.rail = state.railOpen ? "open" : "shut";
$("#rail-toggle").setAttribute("aria-expanded", String(state.railOpen));
}
/* Viewing as: a select with two or more agents, the name with one, and
with none a sentence and the way to make one. Nothing until the agents
are in, so a page with agents never says it has none. */
function renderAgent() {
const agents = state.agents;
const select = $("#agent");
select.hidden = agents.length < 2;
$("#agent-one").hidden = agents.length !== 1;
$("#agent-none").hidden = !state.agentsLoaded || agents.length > 0;
if (agents.length > 1) {
// Rebuilt only when the agents changed, since the rail is drawn again on
// every filter and a rebuild shuts a select that is open.
const key = agents.map((a) => `${a.id}:${a.name}`).join("\n");
if (select.dataset.key !== key) {
select.dataset.key = key;
select.replaceChildren(...agents.map((a) => new Option(a.name, String(a.id))));
}
select.value = String(state.filter.agent);
// A long name is cut at the rail's edge; the whole of it is a hover away.
select.title = select.selectedOptions[0]?.text || "";
} else if (agents.length === 1) {
$("#agent-one").textContent = agents[0].name;
} else if (state.agentsLoaded) {
$("#agent-none").innerHTML = `No search agent is enabled, so nothing is ranked.
<a href="/settings/agents">Search agents</a> sets one up.`;
}
}
/* With the rail shut, which is every narrow screen, the burger is the only
thing left that can say a filter is on, so it says how many, in words: a
number in a circle reads as "new things" on the one control that means
@@ -368,7 +435,7 @@
function renderActive() {
const f = state.filter;
const on = [!f.showRead, f.period !== "all", f.company.trim(), f.place.trim(),
f.function, f.remote, f.judged, f.showMuted, rankedBy() !== null && f.gated]
f.function, f.remote, f.judged, f.showMuted, sortShown() === "score" && f.gated]
.filter(Boolean).length + f.tags.size;
const count = on === 1 ? "1 filter" : `${on} filters`;
$(".rail-toggle-label").textContent = on ? count : "Menu";
@@ -451,7 +518,8 @@
${text ? `<p class="excerpt">${esc(text)}</p>` : ""}
</div>
<div class="actions judge"></div>`;
el.querySelector(".actions").appendChild(judgeButtons(role, () => paintRow(el, role)));
el.querySelector(".actions").appendChild(
judgeButtons(role, () => paintRow(el, role), { agent: state.filter.agent }));
// Plain click reads it here; a modified or middle click still gets the
// real link, which is this same page with the role open.
el.querySelector(".headline").onclick = (e) => {
@@ -570,8 +638,19 @@
renderFeed();
rowAt(state.selected)?.scrollIntoView({ block: "nearest" });
markRead(uid);
await refreshReader(uid);
}
/** One role as the viewing agent sees it, which is what its vote is. */
function roleUrl(uid) {
const agent = state.filter.agent;
return `/api/roles/${encodeURIComponent(uid)}${agent === null ? "" : `?agent=${agent}`}`;
}
// The fetch behind the reader: on opening, and again when the agent changes.
async function refreshReader(uid) {
try {
const role = await api(`/api/roles/${encodeURIComponent(uid)}`);
const role = await api(roleUrl(uid));
if (state.readingUid !== uid) return; // moved on before this landed
state.reading = role;
renderReader();
@@ -704,7 +783,9 @@
state.selected >= state.items.length - 1 ? "disabled" : ""}>Next →</button>
</div>`;
if (r.uid) el.querySelector(".judge").appendChild(judgeButtons(r));
if (r.uid) {
el.querySelector(".judge").appendChild(judgeButtons(r, null, { agent: state.filter.agent }));
}
renderAffinity(el.querySelector(".affinity-slot"), r);
el.querySelector(".close").onclick = () => closeReader();
el.querySelector(".step-prev").onclick = () => move(-1);
@@ -727,7 +808,7 @@
slot.replaceChildren(affinityControl(r.company_key, company.affinity, () => {
renderAffinity(slot, r);
renderFeed();
}));
}, state.filter.agent));
}
/* The answer, into the role on screen and into its row, whose excerpt is
@@ -783,7 +864,7 @@
await new Promise((resolve) => setTimeout(resolve, 4000));
if (state.summarising !== uid) return;
let fresh;
try { fresh = await api(`/api/roles/${encodeURIComponent(uid)}`); } catch (err) { break; }
try { fresh = await api(roleUrl(uid)); } catch (err) { break; }
if (fresh.summary) { state.summarising = null; merge(fresh); return; }
}
if (state.summarising === uid) {
@@ -931,9 +1012,14 @@
$("#rail-toggle").addEventListener("click", toggleRail);
$("#scrim").addEventListener("click", toggleRail);
$("#show-read").addEventListener("click", () => setFilter({ showRead: !state.filter.showRead }));
$("#agent").addEventListener("change", (e) => {
const id = e.target.value;
setFilter(id ? { sort: "score", agent: Number(id) } : { sort: "time" });
$("#agent").addEventListener("change", (e) => setAgent(Number(e.target.value)));
$("#sort").innerHTML = Object.entries(SORTS).map(([key, label]) =>
`<button type="button" data-sort="${key}">${label}</button>`).join("");
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
b.onclick = () => {
if (b.getAttribute("aria-disabled") === "true") return;
setFilter({ sort: b.dataset.sort });
};
});
$("#period").innerHTML = Object.entries(PERIODS).map(([key, p]) =>
`<option value="${key}">${esc(p.label)}</option>`).join("");
@@ -973,11 +1059,14 @@
// Kept on the way out, whichever way that is, so back finds it.
window.addEventListener("pagehide", keep);
// Back from another tab without a reload (the back/forward cache): the
// rows are the ones left, but a vote or a star may have changed there.
// rows are the ones left, but a vote, a star or an agent may have changed
// there.
window.addEventListener("pageshow", async (e) => {
if (!e.persisted) return;
const y = window.scrollY;
await Promise.all([loadTracked(), loadCompanies()]).catch(() => {});
await loadAgents().then(chooseAgent).catch(() => {});
renderRail();
await Promise.all([loadTracked(), loadCompanies(state.filter.agent)]).catch(() => {});
await loadFeed({ keep: state.items.length });
if (state.readingUid) renderReader();
window.scrollTo(0, y);
@@ -991,8 +1080,11 @@
wire();
renderRail();
renderActive();
// The agent first: the companies, the feed and the counts are its.
try {
await Promise.all([loadCompanies(), loadTracked(), loadAgents()]);
await Promise.all([loadTracked(), loadAgents()]);
chooseAgent();
await loadCompanies(state.filter.agent);
} catch (err) {
return;
}
+34
View File
@@ -8,6 +8,9 @@
* `api()` from app.js, so a refusal (a query that finds nothing) is one
* toast with the server's own sentence. The catch blocks here only put a
* control back.
*
* It is also the page's first script, so it shows the one section of the
* four the URL fragment names and marks it in the settings rail.
*/
(function () {
"use strict";
@@ -202,6 +205,37 @@
}
}
// ------------------------------------------------------ one section shown
// Sources shows one section: the one the fragment names, or the first when
// there is none or it names none, so `/settings/sources#runs` (a rail link,
// an old path's 301, the Search agents page's "follow it under Runs") opens
// Runs. The rest are hidden, not removed, so their scripts still find their
// roots. It runs as the script loads rather than on DOMContentLoaded, so the
// page never paints all four first.
function showSection() {
const sections = [...document.querySelectorAll("section[data-section]")];
if (!sections.length) return;
const want = decodeURIComponent(location.hash.slice(1));
const shown = sections.find((s) => s.id === want) || sections[0];
for (const section of sections) section.hidden = section !== shown;
for (const link of document.querySelectorAll(".settings-rail a[data-section]")) {
if (link.dataset.section === shown.id) {
link.setAttribute("aria-current", "location");
link.scrollIntoView({ block: "nearest", inline: "nearest" });
} else {
link.removeAttribute("aria-current");
}
}
}
showSection();
// A switch starts the section at the top of the page, as opening it would.
window.addEventListener("hashchange", () => {
showSection();
window.scrollTo(0, 0);
});
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
+5 -1
View File
@@ -919,9 +919,13 @@ class Store:
"""`(uid, score, gated_reason)` for every role this agent scored,
replacing whatever it had: a role closed or muted since the last run
drops out rather than keeping a stale score. One transaction, so a
reader sees the old list or the new one."""
reader sees the old list or the new one. An agent deleted while its
run was scoring gets nothing written and 0 back: its rows are gone
with it, and an insert would only fail the foreign key."""
stamp = self.now()
with self.transaction() as conn:
if conn.execute("SELECT 1 FROM agents WHERE id=?", (agent_id,)).fetchone() is None:
return 0
conn.execute("DELETE FROM scores WHERE agent_id=?", (agent_id,))
conn.executemany(
"""INSERT INTO scores (uid, agent_id, score, gated_reason, scored_at)
+8 -7
View File
@@ -1,12 +1,13 @@
{# The frame every page is in. The top bar is `TABS` from app/web/pages.py
plus the cog, and the cog's sub-tabs are `SETTINGS` there: adding a page is
one entry in one of those lists, never a link here.
plus the cog, and the cog's pages are `SETTINGS` there, in the rail
settings/_rail.html draws: adding a page is one entry in one of those
lists, never a link here.
Three blocks let a page go past the default frame, which only the Roles
page does: `body_attrs` for attributes on `<body>`, `header_tools` for
controls between the brand and the tabs (its burger and search box), and
`page` to replace the centred `<main>` with a layout of its own (its rail,
feed and reader). A page setting `active_path` lights the tab for that path
Three blocks let a page go past the default frame: `body_attrs` for
attributes on `<body>`, `header_tools` for controls between the brand and
the tabs (the Roles page's burger and search box), and `page` to replace
the centred `<main>` with a layout of its own (the Roles page's rail, feed
and reader, and the settings rail in settings/_layout.html). A page setting `active_path` lights the tab for that path
rather than its own, which is how `/roles/{uid}` keeps Roles lit. #}
<!doctype html>
<html lang="en">
+17 -4
View File
@@ -8,6 +8,12 @@
renders only the select options, from `app.models` and
`plugins.ats.FUNCTIONS`, so they cannot drift from what the store accepts.
The rail opens on Viewing as: which search agent the feed is seen as.
An agent is a persona (a candidate, a hiring manager watching the market)
with its own scores, votes and hidden companies, so the order, the stance
on each row and every vote cast belong to the agent picked here. Order is
its own section below, the same two choices whichever agent is picked.
`/roles/{uid}` renders this same page with `role` set: the reader starts
open, so a phone lands on the role rather than on the list for as long as
the script takes. No `data-rail` on `<body>` until the script sets one:
@@ -33,6 +39,14 @@
<div class="shell">
<aside id="rail" aria-label="Filters">
<section class="rail-viewing" aria-labelledby="viewing-as">
{# One agent is its name, two or more a select, none a sentence with
the way to make one. The script shows whichever applies. #}
<h3 id="viewing-as">Viewing as <a class="linky" href="/settings/agents">agents</a></h3>
<select id="agent" class="rail-select agent-pick" aria-labelledby="viewing-as" hidden></select>
<p id="agent-one" class="agent-pick" hidden></p>
<p id="agent-none" class="rail-note" hidden></p>
</section>
<section>
<h3>Filters</h3>
<button type="button" class="rail-row" id="show-read" aria-pressed="true"
@@ -40,11 +54,10 @@
class="count" aria-hidden="true">👁</span></button>
</section>
<section>
<h3>Order and period</h3>
{# Best first and Newest first. With more than one ranking enabled the
segmented control gives way to the select, one entry per ranking. #}
<h3>Order</h3>
{# Best first is the viewing agent's score, Newest first is first seen;
both carry that agent's votes. #}
<div class="seg" id="sort" role="group" aria-label="Order"></div>
<select id="agent" class="rail-select" aria-label="Order" hidden></select>
<label class="rail-field" for="period">First seen</label>
<select id="period" class="rail-select"></select>
</section>
+13
View File
@@ -0,0 +1,13 @@
{% extends "base.html" %}
{# Every page under the cog: the settings rail beside the page's own content,
through base.html's `page` block, as the Roles page puts its rail beside
the feed. A settings page extends this and fills `content`. #}
{% block page %}
<div class="settings-shell">
{% include "settings/_rail.html" %}
<main>
{% block content %}{% endblock %}
</main>
</div>
{% endblock %}
+43
View File
@@ -0,0 +1,43 @@
{# The rail beside every settings page: `SETTINGS` from app/web/pages.py, each
page current by its own path, and under a page in `SECTIONS` its sections,
indented. Links, not buttons: a page is a page of its own and a section is
a fragment on it, so `/settings/sources#runs` opens Runs from anywhere.
Which section is current is the page script's to mark (sources.js), since
the server never sees the fragment.
The Roles rail's look without its overlay or its toggle: it is five links,
not a panel of filters. Below 60rem the same links are a strip across the
top of the content, pinned under the header, so a phone can still jump
between sections without scrolling back up. #}
<aside class="settings-rail" aria-label="Settings">
<h3>Settings</h3>
<nav>
{% for tab in SETTINGS %}
{% set current = request.url.path == tab.path %}
{% set sections = SECTIONS.get(tab.path, ()) %}
<div class="rail-group"{% if current %} data-current="true"{% endif %}>
<a class="rail-link{% if sections %} parent{% endif %}" href="{{ tab.path }}"
{% if current %}aria-current="page"{% endif %}>{{ tab.label }}</a>
{% for anchor, label in sections %}
<a class="rail-link sub" href="{{ tab.path }}#{{ anchor }}" data-section="{{ anchor }}">{{ label }}</a>
{% endfor %}
</div>
{% endfor %}
</nav>
</aside>
{# The header's height, for the rail pinned under it: 44px touch targets make
the header taller, and a rail pinned to a stale number slides under it.
roles.js measures the same on the Roles page. On a phone the current page
is scrolled into the strip, which a long label can push off its edge. #}
<script>
(function () {
"use strict";
const header = document.querySelector("header.top");
const measure = () =>
document.documentElement.style.setProperty("--chrome", `${header.offsetHeight}px`);
measure();
window.addEventListener("resize", measure);
const here = document.querySelector(".settings-rail a[aria-current=page]");
if (here) here.scrollIntoView({ block: "nearest", inline: "nearest" });
})();
</script>
-8
View File
@@ -1,8 +0,0 @@
{# The sub-tabs under the cog: `SETTINGS` from app/web/pages.py, each active by
its own path. Links, not a script: every sub-tab is a page of its own. #}
<nav class="subtabs" aria-label="Settings">
{% for tab in SETTINGS %}
<a href="{{ tab.path }}"
{% if request.url.path == tab.path %}class="active" aria-current="page"{% endif %}>{{ tab.label }}</a>
{% endfor %}
</nav>
+2 -4
View File
@@ -1,10 +1,8 @@
{% extends "base.html" %}
{% extends "settings/_layout.html" %}
{% block title %}Account — roledesk{% endblock %}
{% block content %}
<h1>Settings</h1>
{% include "settings/_tabs.html" %}
<h1>Account</h1>
<p class="lede">The one password, the devices signed in with it, and the passkeys that sign in without it.</p>
<section class="card">
+18 -16
View File
@@ -1,23 +1,24 @@
{% extends "base.html" %}
{% extends "settings/_layout.html" %}
{% block title %}Search agents — roledesk{% endblock %}
{# A list and a form: `static/agents.js` fills the list from `/api/agents`,
the form edits the picked agent, New clears it, Delete removes it with its
votes, liked companies and scores. #}
{# A card per agent: `static/agents.js` fills the list from `/api/agents`,
newest first. A card shows what the agent looks for, its switch and its
weights; Edit turns that card into the form below, in place, and New puts
a blank one on top. The form is a `<template>` because only one card edits
at a time, so its ids stay unique. #}
{% block content %}
<h1>Settings</h1>
{% include "settings/_tabs.html" %}
<h1>Search agents</h1>
<p class="lede">A search agent is what the Roles tab ranks by: describe the role, weigh the terms, and it scores every open role. Several agents rank the same roles differently, each with its own votes and liked companies; Viewing as on Roles picks one, and its votes are that agent's.</p>
<p class="lede">A search agent is what the Roles tab ranks by: describe the role, weigh the terms, and it scores every open role. Several agents rank the same roles differently, each with its own votes and liked companies; the order menu on Roles picks one.</p>
<p id="agents-count" class="count" role="status"></p>
<div id="agents-list" class="crows"></div>
<div class="agents-head">
<p id="agents-count" class="count" role="status"></p>
<button type="button" id="a-new">New agent</button>
</div>
<div id="agents-list" class="agent-cards"></div>
<template id="agent-form-template">
<form id="agent-form" class="agent-form" autocomplete="off">
<div class="row-between">
<h2 id="agent-form-title">New agent</h2>
<button type="button" id="a-new" class="secondary">New agent</button>
</div>
<h2 id="agent-form-title">New agent</h2>
<label>Name <input type="text" id="a-name" required placeholder="My search"></label>
<label>What you are looking for
<textarea id="a-intent" rows="7" placeholder="Senior backend engineer. Python and Go services, PostgreSQL, APIs on Kubernetes. Wants ownership of production systems in a product company."></textarea>
@@ -37,10 +38,11 @@
</details>
<div class="agent-actions">
<button type="submit">Save and score</button>
<button type="button" id="a-delete" class="secondary" hidden>Delete</button>
<button type="button" id="a-cancel" class="secondary">Cancel</button>
<button type="button" id="a-delete" class="secondary">Delete</button>
</div>
<p id="agent-status" class="count" role="status"></p>
</form>
</template>
{% endblock %}
{% block scripts %}
+18 -20
View File
@@ -1,24 +1,19 @@
{% extends "base.html" %}
{% extends "settings/_layout.html" %}
{% block title %}Sources — roledesk{% endblock %}
{# One page, three sections, one per plugin: the `search` plugin's job board
queries, the `ats` plugin's company boards, and the runs that read both,
with the message log at the end. Each section keeps the element ids it had
as a page of its own, so its script (sources.js, companies.js, jobs.js,
messages.js) is unchanged and finds its root or does nothing. #}
{# One page, four sections: the `search` plugin's job board queries, the
`ats` plugin's company boards, the runs that read both, and the message
log. One is shown at a time, the one the URL fragment names (`#runs`), or
Job boards without one; sources.js hides the rest and the rail picks one.
Hidden rather than separate pages, because each section keeps the element
ids it had as a page of its own and its script (sources.js, companies.js,
jobs.js, messages.js) is unchanged: it finds its root or does nothing. The
ids are `SECTIONS` in app/web/pages.py, which the rail links to. #}
{% block content %}
<h1>Settings</h1>
{% include "settings/_tabs.html" %}
<h1>Sources</h1>
<p class="lede">Sources are where roles come from: queries on job boards that span companies, and the boards of the companies you follow. Each section is one plugin; the runs read them all.</p>
<nav class="jump" aria-label="Sections">
<a href="#job-boards">Job boards</a>
<a href="#company-boards">Company boards</a>
<a href="#runs">Runs</a>
</nav>
<section class="card" id="job-boards">
<section class="card" id="job-boards" data-section>
<h2>Job boards</h2>
<p class="lede">A query on Jobindex or Adzuna finds roles at any company. Switching one off closes its roles until you switch it back on.</p>
@@ -64,7 +59,7 @@
<div id="searches-list" class="srows"></div>
</section>
<section class="card" id="company-boards">
<section class="card" id="company-boards" data-section>
<h2>Company boards</h2>
<p class="lede">Every company roledesk has seen, and how many of its roles are open. Switching a board off stops reading it and closes its roles; hiding a company keeps reading it but leaves its roles out of the list and unscored, and favourite or like lifts one instead, in Best match.</p>
@@ -126,7 +121,7 @@
</details>
</section>
<section class="card" id="runs">
<section class="card" id="runs" data-section>
<div class="row-between">
<h2>Runs</h2>
<button type="button" id="pull-now" class="secondary">Pull now</button>
@@ -159,8 +154,11 @@
</div>
</details>
<div class="row-between" id="messages">
<h3>Messages</h3>
</section>
<section class="card" id="messages" data-section>
<div class="row-between">
<h2>Messages</h2>
<button type="button" id="clear-all" class="secondary">Clear all</button>
</div>
<p class="lede">What the server said that nobody has cleared, newest first. A message goes when you clear it, or a fortnight after it was last said.</p>
+26 -10
View File
@@ -1,10 +1,12 @@
"""The pages: two tabs, a cog, and three settings pages behind it.
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the row of
sub-tabs under the cog at `/settings/<name>`: Search agents, Sources, Account.
`base.html` renders the first, `settings/_tabs.html` the second, every page
marks itself active by its own `path`, and adding one is one entry here plus
one template. `/settings` itself is Search agents.
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the rail
beside every page under the cog at `/settings/<name>`: Search agents,
Sources, Account. `base.html` renders the first, `settings/_rail.html` the
second, every page marks itself active by its own `path`, and adding one is
one entry here plus one template. `SECTIONS` is the rows the rail indents
under a page that is shown one section at a time, which is only Sources.
`/settings` itself is Search agents.
Every page is a shell. Each is filled and driven by its own script under
`static/` from the JSON routes in `web/api.py`; the Runs section of Sources
@@ -14,10 +16,11 @@ one page, so a link to a role and the role opened from the feed are the same
screen. What the server renders is only what a select needs to offer, so the
options cannot drift from what the store accepts.
Sources is one page in three sections, one per plugin: job boards (the
`search` plugin's queries), company boards (`ats`) and the runs that read
them, with the message log at the end. Its scripts are the ones the sections
had as pages of their own, each guarding on its own root element.
Sources is one page in four sections: job boards (the `search` plugin's
queries), company boards (`ats`), the runs that read them, and the message
log. One is shown at a time, the one the URL fragment names; the others stay
in the page, hidden, so each section's script (the ones they had as pages of
their own, each guarding on its own root element) keeps working.
Every path a page has had before (`/agents`, `/companies`, `/sources`,
`/jobs`, `/schedules`, `/messages`, `/account`, and the six sub-tabs the
@@ -70,13 +73,25 @@ TABS: tuple[Tab, ...] = (
Tab("/applications", "Applications", "applications.html"),
)
#: The sub-tabs under the cog, in order; `settings/_tabs.html` renders them.
#: The pages under the cog, in order; `settings/_rail.html` renders them.
SETTINGS: tuple[Tab, ...] = (
Tab("/settings/agents", "Search agents", "settings/agents.html"),
Tab("/settings/sources", "Sources", "settings/sources.html"),
Tab("/settings/account", "Account", "settings/account.html"),
)
#: `anchor, label` for each section of a settings page that shows one at a
#: time, keyed by the page's path. The anchor is the section's element id and
#: the fragment that picks it; the first is what the page opens on without one.
SECTIONS: dict[str, tuple[tuple[str, str], ...]] = {
"/settings/sources": (
("job-boards", "Job boards"),
("company-boards", "Company boards"),
("runs", "Runs"),
("messages", "Messages"),
),
}
#: Where each page that used to be a tab or a sub-tab lives now. The fragment
#: is the section on the merged page; a browser keeps it across the 301.
MOVED: dict[str, str] = {
@@ -117,6 +132,7 @@ def asset(path: str) -> str:
templates = Jinja2Templates(directory=str(TEMPLATE_DIR))
templates.env.globals["TABS"] = TABS
templates.env.globals["SETTINGS"] = SETTINGS
templates.env.globals["SECTIONS"] = SECTIONS
templates.env.globals["asset"] = asset
#: Out of the OpenAPI schema: these are pages.