Merge the Roles feed: rail note on the fetch gate, Show gated in every order, saved filters per agent, the company strip naming the gate's parts (wp-feed)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
553042f1fc
4 files changed
+402
-28
No files matched your search
@@ -660,6 +660,47 @@ kbd {
|
||||
.rail-legacy .tag { max-width: 100%; overflow-wrap: anywhere; text-align: left; }
|
||||
.rail-legacy .chip-x { margin-left: .35rem; color: var(--faint); }
|
||||
|
||||
/* Saved filters: newsdesk's `#active` pills (`newsdesk/web/static/app.css`),
|
||||
in the accent's outline. Here a pill applies and its own × beside it
|
||||
deletes, so the two halves are one rounded shape split by a rule. The
|
||||
pill of the filter on screen is filled, as a picked tag is. */
|
||||
.saved-list { display: flex; flex-wrap: wrap; gap: .3rem; padding: 0 .3rem; }
|
||||
.saved-list .rail-note { margin: 0; }
|
||||
.saved { display: inline-flex; max-width: 100%; }
|
||||
#rail .saved button:not(.linky) {
|
||||
border: 1px solid var(--accent-weak); color: var(--accent);
|
||||
font-size: .82rem; padding: .12rem .55rem;
|
||||
}
|
||||
#rail .saved .pill:not(.linky) {
|
||||
min-width: 0; border-radius: 999px 0 0 999px;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
#rail .saved .pill-x:not(.linky) {
|
||||
margin-left: -1px; padding-inline: .45rem;
|
||||
border-radius: 0 999px 999px 0; color: var(--faint);
|
||||
}
|
||||
@media (hover: hover) {
|
||||
#rail .saved .pill:not(.linky):hover { background: var(--panel); }
|
||||
#rail .saved .pill-x:not(.linky):hover { color: var(--error); background: var(--panel); }
|
||||
}
|
||||
#rail .saved .pill[aria-pressed="true"]:not(.linky) {
|
||||
color: var(--panel); background: var(--accent); border-color: var(--accent);
|
||||
}
|
||||
/* The name field and its Save: one line under the pills, the field taking
|
||||
what Save and cancel leave. */
|
||||
.save-form { display: flex; align-items: center; gap: .35rem; padding: .45rem .3rem 0; }
|
||||
.save-form[hidden] { display: none; }
|
||||
.save-form input {
|
||||
flex: 1; min-width: 0; min-height: 2rem; padding: .15rem .45rem;
|
||||
font: inherit; font-size: .84rem; line-height: normal;
|
||||
border: 1px solid var(--line); border-radius: 3px;
|
||||
background: var(--panel); color: var(--fg);
|
||||
}
|
||||
#rail .save-form button[type="submit"] {
|
||||
border-color: var(--line); color: var(--fg); background: var(--panel);
|
||||
}
|
||||
#saved-note { margin-top: .4rem; }
|
||||
|
||||
/* -- the feed -- */
|
||||
|
||||
.shell > #list {
|
||||
@@ -1113,6 +1154,15 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
|
||||
.actions button { padding: .5rem .7rem; font-size: 1.15rem; }
|
||||
#rail .rail-row { align-items: center; min-height: 2.75rem; }
|
||||
#rail button.tag:not(.linky) { padding: .45rem .8rem; }
|
||||
#rail .saved button:not(.linky) { min-height: 2.75rem; padding: .35rem .8rem; }
|
||||
#rail .saved .pill-x:not(.linky) { min-width: 2.75rem; }
|
||||
/* Under 16px, iOS Safari zooms the page when a field takes focus
|
||||
(newsdesk's touch block). */
|
||||
.save-form input { min-height: 2.75rem; font-size: 16px; }
|
||||
#rail .save-form button { min-height: 2.75rem; }
|
||||
/* "save" in the heading is a word, so its tap band is padding given
|
||||
back by a negative margin, as a company name's in a row. */
|
||||
#save-open { padding: .6rem .4rem; margin: -.6rem -.4rem; }
|
||||
#rail .seg button { min-height: 2.75rem; }
|
||||
.rail-select, .rail-fields input[type="text"], .rail-fields select,
|
||||
#rail select.agent-pick { min-height: 2.75rem; }
|
||||
|
||||
+243
-24
@@ -32,12 +32,21 @@
|
||||
* 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 Agent match (`order=score`, the agent's score moved by its votes),
|
||||
* Newest (`order=newest`) or CV match (`order=cv`, the roles the
|
||||
* Order is Agent match (`order=score`, the agent's final score moved by its
|
||||
* votes), Newest (`order=newest`) or CV match (`order=cv`, the roles the
|
||||
* agent's `judge` read against its CV first, by that total), the same three
|
||||
* whichever agent is viewed, and all carry the agent's votes and hidden
|
||||
* companies. CV match needs a CV: an agent without one is shown Agent
|
||||
* match, as an agentless page is shown Newest.
|
||||
* match, as an agentless page is shown Newest. Every order keeps to the
|
||||
* roles the agent's fetch gate passes, which a note under Viewing as says;
|
||||
* Show gated (`gated=true`) adds the ones it rejects, with the reason.
|
||||
*
|
||||
* Saved filters belong to the viewing agent (`/api/agents/{id}/filters`):
|
||||
* pills in the rail, newsdesk's `#active` row, each the query string
|
||||
* `addressFor` writes without the agent. A click reads it into the filter
|
||||
* as a company link is read (`readUrl`) and pushes; × deletes it; Save
|
||||
* names the filters on screen in a field of its own. No editing: a change
|
||||
* is saved under a new name.
|
||||
*
|
||||
* The filters are in the query string, so a reload or a link keeps them, and
|
||||
* each one set is a history entry, so back takes it off again: a tag, the
|
||||
@@ -165,7 +174,7 @@
|
||||
counted. */
|
||||
function filtersOn(f = state.filter, { more = false } = {}) {
|
||||
const folded = [f.company.trim(), f.place.trim(), f.function, f.remote, f.pay, f.judged,
|
||||
f.showMuted, f.closing, ranked() && f.gated].filter(Boolean).length
|
||||
f.showMuted, f.closing, f.agent !== null && f.gated].filter(Boolean).length
|
||||
+ f.companyKeys.length + f.places.length
|
||||
+ [f.levelFrom, f.levelTo, f.track].filter(Boolean).length;
|
||||
if (more) return folded;
|
||||
@@ -191,6 +200,7 @@
|
||||
listY: 0, // where the page was scrolled when the reader replaced the feed
|
||||
feedError: false, // the feed's own fetch failed; the empty state offers a retry
|
||||
facets: null, // {seniority, pay} counts from /api/roles/facets for this filter
|
||||
saved: [], // the viewing agent's saved filters, [{id, name, query}] by name
|
||||
};
|
||||
|
||||
// The chips' text, by company key and by place token: what a pick said,
|
||||
@@ -228,9 +238,6 @@
|
||||
return sort === "cv" && hasCv() ? "cv" : "score";
|
||||
}
|
||||
|
||||
/** Whether the list is in a score order, where a gated role can be shown. */
|
||||
const ranked = () => sortShown() !== "time";
|
||||
|
||||
/** Whether a bound or a track is set, which is what "no level" asks about. */
|
||||
const seniorityOn = (f = state.filter) => Boolean(f.levelFrom || f.levelTo || f.track);
|
||||
|
||||
@@ -257,7 +264,8 @@
|
||||
if (f.agent !== null) {
|
||||
p.set("agent", String(f.agent));
|
||||
p.set("order", ORDERS[sortShown()]);
|
||||
if (f.gated && ranked()) p.set("gated", "true");
|
||||
// Every order keeps to the fetch gate, so each can show what it rejects.
|
||||
if (f.gated) p.set("gated", "true");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -302,9 +310,10 @@
|
||||
|
||||
/* The chip text of place tokens read from the address, which carries only
|
||||
the token. A token the server does not know is dropped from the filter
|
||||
and the address, rather than sent to /api/roles for a 422. Nothing is
|
||||
asked when every token already has its text. */
|
||||
async function labelPlaces() {
|
||||
and, unless `write` is false, the address, rather than sent to
|
||||
/api/roles for a 422. Nothing is asked when every token already has
|
||||
its text. */
|
||||
async function labelPlaces({ write = true } = {}) {
|
||||
const missing = state.filter.places.filter((t) => !placeLabels.has(t));
|
||||
if (!missing.length) return;
|
||||
const p = new URLSearchParams();
|
||||
@@ -319,7 +328,7 @@
|
||||
const kept = state.filter.places.filter((t) => placeLabels.has(t) || !missing.includes(t));
|
||||
if (kept.length !== state.filter.places.length) {
|
||||
state.filter.places = kept;
|
||||
writeUrl();
|
||||
if (write) writeUrl();
|
||||
}
|
||||
renderRail();
|
||||
}
|
||||
@@ -498,6 +507,7 @@
|
||||
writeUrl();
|
||||
renderRail();
|
||||
renderActive();
|
||||
agentSaved();
|
||||
await loadCompanies(id).catch(() => {});
|
||||
reload();
|
||||
loadFilters().catch(() => {});
|
||||
@@ -599,6 +609,13 @@
|
||||
>${esc(role.company)}</a>`;
|
||||
}
|
||||
|
||||
/* Who is viewing changed: its saved filters in, the last agent's field and
|
||||
message gone. */
|
||||
function agentSaved() {
|
||||
closeSaveForm();
|
||||
loadSaved().catch(() => {});
|
||||
}
|
||||
|
||||
/* A plain click lists the company's roles in place, the list its link
|
||||
leads to, and pushes, so back is the list it left; a modified or middle
|
||||
click is the browser's, and opens the link. The link is written again
|
||||
@@ -669,7 +686,7 @@
|
||||
else b.removeAttribute("aria-disabled");
|
||||
b.title = why[b.dataset.sort] || "";
|
||||
});
|
||||
$("#show-gated").hidden = !ranked();
|
||||
$("#show-gated").hidden = f.agent === null;
|
||||
|
||||
$("#period").value = f.period;
|
||||
|
||||
@@ -701,6 +718,7 @@
|
||||
setValue("f-closing", f.closing);
|
||||
setValue("f-gated", f.gated);
|
||||
renderFacets();
|
||||
renderSaved();
|
||||
const more = filtersOn(f, { more: true });
|
||||
$("#f-active").textContent = more ? ` · ${more}` : "";
|
||||
|
||||
@@ -829,6 +847,12 @@
|
||||
const select = $("#agent");
|
||||
select.hidden = !agents.length;
|
||||
$("#agent-none").hidden = !state.agentsLoaded || agents.length > 0;
|
||||
// Every order keeps to the agent's fetch gate; Show gated says it widened.
|
||||
const gate = $("#agent-gate");
|
||||
gate.hidden = state.filter.agent === null;
|
||||
gate.textContent = state.filter.gated
|
||||
? "Filtered by this agent's fetch gate, and Show gated adds the roles it rejects."
|
||||
: "Already filtered by this agent's fetch gate: region, places and role.";
|
||||
if (agents.length) {
|
||||
// Rebuilt only when the agents changed, since the rail is drawn again on
|
||||
// every filter and a rebuild shuts a select that is open.
|
||||
@@ -846,6 +870,169 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- saved filters
|
||||
|
||||
/** The filter on screen as a saved filter's query: the query string
|
||||
`addressFor` writes, without the agent (`POST /api/agents/{id}/filters`). */
|
||||
function savedQuery(f = state.filter, q = state.q) {
|
||||
const p = new URLSearchParams(addressFor("", f, q).replace(/^\?/, ""));
|
||||
p.delete("agent");
|
||||
return p.toString();
|
||||
}
|
||||
|
||||
/** Whether two queries say the same, whatever the order of their parts. */
|
||||
function sameQuery(a, b) {
|
||||
const sorted = (query) => {
|
||||
const p = new URLSearchParams(query);
|
||||
p.sort();
|
||||
return p.toString();
|
||||
};
|
||||
return sorted(a) === sorted(b);
|
||||
}
|
||||
|
||||
// The viewing agent's saved filters, the newest answer only; none without
|
||||
// an agent, when the section is hidden.
|
||||
let savedRequest = 0;
|
||||
async function loadSaved() {
|
||||
const agent = state.filter.agent;
|
||||
const request = ++savedRequest;
|
||||
let rows = [];
|
||||
if (agent !== null) {
|
||||
try {
|
||||
rows = await api(`/api/agents/${agent}/filters`);
|
||||
} catch (err) {
|
||||
rows = []; // toasted; the section says none is saved
|
||||
}
|
||||
}
|
||||
if (request !== savedRequest) return;
|
||||
state.saved = rows;
|
||||
renderSaved();
|
||||
}
|
||||
|
||||
/* The pills, rebuilt only when the list changed, since the rail is drawn
|
||||
on every filter and a rebuild drops the focus of the pill just pressed.
|
||||
The pill whose query is the filter on screen is pressed. */
|
||||
function renderSaved() {
|
||||
const section = $("#saved");
|
||||
section.hidden = state.filter.agent === null;
|
||||
if (section.hidden) return;
|
||||
const list = $("#saved-list");
|
||||
const key = JSON.stringify([state.filter.agent, state.saved.map((x) => [x.id, x.name])]);
|
||||
if (list.dataset.key !== key) {
|
||||
list.dataset.key = key;
|
||||
list.innerHTML = state.saved.length
|
||||
? state.saved.map((x) => `<span class="saved">`
|
||||
+ `<button type="button" class="pill" data-apply="${x.id}" title="Apply “${esc(x.name)}”"
|
||||
>${esc(x.name)}</button>`
|
||||
+ `<button type="button" class="pill-x" data-delete="${x.id}" title="Delete “${esc(x.name)}”"
|
||||
aria-label="Delete the saved filter ${esc(x.name)}">×</button></span>`).join("")
|
||||
: `<p class="rail-note">None saved for this agent yet.</p>`;
|
||||
list.querySelectorAll("[data-apply]").forEach((b) => {
|
||||
b.onclick = () => applySaved(Number(b.dataset.apply));
|
||||
});
|
||||
list.querySelectorAll("[data-delete]").forEach((b) => {
|
||||
b.onclick = () => deleteSaved(Number(b.dataset.delete));
|
||||
});
|
||||
}
|
||||
const current = savedQuery();
|
||||
list.querySelectorAll("[data-apply]").forEach((b) => {
|
||||
const x = state.saved.find((y) => y.id === Number(b.dataset.apply));
|
||||
b.setAttribute("aria-pressed", String(Boolean(x) && sameQuery(x.query, current)));
|
||||
});
|
||||
}
|
||||
|
||||
/* A saved filter onto the page, the way a company link is followed
|
||||
(`companyClick`): its query read into the filter and the search, the
|
||||
agent kept, and the list pushed, so back is the filter it replaced. Its
|
||||
order is read too, since `addressFor` wrote it. Place tokens are named
|
||||
first, a token no longer known dropped rather than sent for a 422. On a
|
||||
phone the rail is put away, since the list is what was asked for. */
|
||||
async function applySaved(id) {
|
||||
const saved = state.saved.find((x) => x.id === id);
|
||||
if (!saved) return;
|
||||
const muted = state.filter.showMuted;
|
||||
const query = new URLSearchParams(saved.query);
|
||||
readUrl(`?${saved.query}`, { view: false });
|
||||
const sort = query.get("sort");
|
||||
state.filter.sort = sort === "time" || sort === "cv" ? sort : "score";
|
||||
$("#search").value = state.q;
|
||||
companyChips?.clear();
|
||||
placeChips?.clear();
|
||||
await labelPlaces({ write: false });
|
||||
if (filtersOn(state.filter, { more: true })) $("#f-more").open = true;
|
||||
if (overlayRail() && state.railOpen) toggleRail();
|
||||
setFilter({}, { counts: muted !== state.filter.showMuted });
|
||||
}
|
||||
|
||||
async function deleteSaved(id) {
|
||||
const saved = state.saved.find((x) => x.id === id);
|
||||
if (!saved) return;
|
||||
try {
|
||||
await api(`/api/filters/${id}`, { method: "DELETE" });
|
||||
} catch (err) {
|
||||
if (err.status !== 404) return; // toasted; a 404 is gone already
|
||||
}
|
||||
state.saved = state.saved.filter((x) => x.id !== id);
|
||||
renderSaved();
|
||||
savedSay(`Deleted “${saved.name}”.`);
|
||||
}
|
||||
|
||||
/* The name field: opened by "save", shut by cancel, Escape, a save or
|
||||
another agent. */
|
||||
function openSaveForm() {
|
||||
$("#save-form").hidden = false;
|
||||
$("#save-open").setAttribute("aria-expanded", "true");
|
||||
$("#save-name").value = "";
|
||||
savedSay("");
|
||||
$("#save-name").focus();
|
||||
}
|
||||
|
||||
function closeSaveForm() {
|
||||
$("#save-form").hidden = true;
|
||||
$("#save-open").setAttribute("aria-expanded", "false");
|
||||
}
|
||||
|
||||
let savedSaid = 0;
|
||||
/** A short line under the pills, gone after a few seconds. */
|
||||
function savedSay(text) {
|
||||
const note = $("#saved-note");
|
||||
note.textContent = text;
|
||||
note.hidden = !text;
|
||||
clearTimeout(savedSaid);
|
||||
if (text) savedSaid = setTimeout(() => { note.hidden = true; }, 5000);
|
||||
}
|
||||
|
||||
/* The filters on screen under the name typed. A name the agent already
|
||||
has, whatever its case, is said under the field rather than sent; the
|
||||
server's 409, for a name saved meanwhile elsewhere, is said there too. */
|
||||
async function saveFilter(e) {
|
||||
e.preventDefault();
|
||||
const agent = state.filter.agent;
|
||||
if (agent === null) return;
|
||||
const name = $("#save-name").value.trim();
|
||||
if (!name) {
|
||||
savedSay("Give it a name.");
|
||||
return;
|
||||
}
|
||||
const taken = (n) => `“${n}” is already saved. Pick another name.`;
|
||||
if (state.saved.some((x) => x.name.toLowerCase() === name.toLowerCase())) {
|
||||
savedSay(taken(name));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await api(`/api/agents/${agent}/filters`, {
|
||||
method: "POST", body: { name, query: savedQuery() },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.status === 409) savedSay(taken(name));
|
||||
return;
|
||||
}
|
||||
if (agent !== state.filter.agent) return;
|
||||
closeSaveForm();
|
||||
await loadSaved();
|
||||
savedSay(`Saved as “${name}”.`);
|
||||
}
|
||||
|
||||
/* 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
|
||||
@@ -1091,7 +1278,7 @@
|
||||
${badges(role)}
|
||||
<span title="Posted">${ago(role.posted_at)}</span>
|
||||
${role.gated_reason
|
||||
? `<span class="gated" title="Kept out of the ranking">${esc(role.gated_reason)}</span>`
|
||||
? `<span class="gated" title="Rejected by this agent's fetch gate">${esc(role.gated_reason)}</span>`
|
||||
: ""}
|
||||
${tagChips(role.tags)}
|
||||
</div>
|
||||
@@ -1192,10 +1379,11 @@
|
||||
|
||||
/* With exactly one company filtered, which is where its name leads, a
|
||||
strip over the feed says whose roles these are and carries what is done
|
||||
with a company from here: its careers page, and its ⊘ ▲ ★ for the viewing
|
||||
agent, which is where a company is starred from. Built again only for
|
||||
another company or agent, since the feed is drawn on every page; the
|
||||
count and the affinity are patched. */
|
||||
with a company from here: its careers page, its ⊘ ▲ ★ for the viewing
|
||||
agent, which is where a company is starred from, and its two overrides,
|
||||
under them which parts of the fetch gate apply to it (`gateNote`). Built
|
||||
again only for another company or agent, since the feed is drawn on
|
||||
every page; the count, the affinity and the overrides are patched. */
|
||||
function renderStrip() {
|
||||
const el = $("#company-strip");
|
||||
const key = state.filter.companyKeys.length === 1 ? state.filter.companyKeys[0] : null;
|
||||
@@ -1234,18 +1422,40 @@
|
||||
(updated) => affinityChanged(key, company, updated), state.filter.agent));
|
||||
// The two overrides need a company row, which a first stance makes.
|
||||
if (company) slot.append(" ", overridesControl(key, company, renderStrip));
|
||||
// What ★ does, before; what it did, after.
|
||||
el.querySelector(".strip-note").textContent = affinity === 2
|
||||
? "★ Favourite: roles from every place the agent's required gates allow are listed. "
|
||||
+ "All countries fetches them from a big board."
|
||||
: "★ Favourite also lists this company's roles outside your places, as far as the "
|
||||
+ "agent's required gates allow. All countries fetches them from a big board.";
|
||||
const note = el.querySelector(".strip-note");
|
||||
note.textContent = gateNote(company);
|
||||
note.hidden = !note.textContent;
|
||||
}
|
||||
const n = state.total;
|
||||
el.querySelector(".strip-count").textContent = state.loaded
|
||||
? `${number.format(n)} ${n === 1 ? "role matches" : "roles match"}` : "";
|
||||
}
|
||||
|
||||
/* Which parts of the viewing agent's fetch gate apply to a company's
|
||||
roles: All countries lifts the place part (the Where lines), All roles
|
||||
the role part (fetch terms, titles to leave out); the region always
|
||||
holds. A favourite only ranks higher, so it is not named here. Nothing
|
||||
with no agent, when no fetch gate applies. */
|
||||
function gateNote(company) {
|
||||
if (state.filter.agent === null) return "";
|
||||
const countries = Boolean(company?.all_countries);
|
||||
const roles = Boolean(company?.all_roles);
|
||||
if (countries && roles) {
|
||||
return "All countries and All roles: every role in the agent's region, "
|
||||
+ "not filtered by place or by role.";
|
||||
}
|
||||
if (countries) {
|
||||
return "All countries: every role in the agent's region, not filtered by place. "
|
||||
+ "The agent's fetch terms and titles to leave out still apply.";
|
||||
}
|
||||
if (roles) {
|
||||
return "All roles: not filtered by role, no fetch terms and no titles left out. "
|
||||
+ "The agent's places still apply.";
|
||||
}
|
||||
return "The roles this agent's fetch gate passes: its region, places and role. "
|
||||
+ "All countries lifts the places for this company, All roles the role.";
|
||||
}
|
||||
|
||||
/* A company seen only through a search has no row until its first change
|
||||
creates one, so the list is reloaded then. A change dims or undims its
|
||||
rows at once; where they rank waits on the `score` it queued, whose id
|
||||
@@ -1834,6 +2044,13 @@
|
||||
`<option value="${key}">${esc(p.label)}</option>`).join("");
|
||||
$("#period").addEventListener("change", (e) => setFilter({ period: e.target.value }));
|
||||
$("#clear-tags").addEventListener("click", () => { state.filter.tags.clear(); setFilter({}); });
|
||||
$("#save-open").addEventListener("click",
|
||||
() => ($("#save-form").hidden ? openSaveForm() : closeSaveForm()));
|
||||
$("#save-cancel").addEventListener("click", closeSaveForm);
|
||||
$("#save-form").addEventListener("submit", saveFilter);
|
||||
$("#save-name").addEventListener("keydown", (e) => {
|
||||
if (e.key === "Escape") closeSaveForm();
|
||||
});
|
||||
|
||||
// A pick or a removal is a filter set, pushed; the text typed to find
|
||||
// it is the chip input's own and never reaches the address.
|
||||
@@ -1926,6 +2143,7 @@
|
||||
const y = window.scrollY;
|
||||
await loadAgents().then(chooseAgent).catch(() => {});
|
||||
renderRail();
|
||||
loadSaved().catch(() => {});
|
||||
await Promise.all([loadTracked(), loadCompanies(state.filter.agent)]).catch(() => {});
|
||||
await loadFeed({ keep: state.items.length });
|
||||
if (state.readingUid) renderReader();
|
||||
@@ -1963,6 +2181,7 @@
|
||||
renderRail();
|
||||
renderActive();
|
||||
loadFilters().catch(() => {});
|
||||
loadSaved().catch(() => {});
|
||||
// The feed's first request went out with whatever agent `readUrl` had
|
||||
// (often none): reload for the score and votes once the real one is
|
||||
// known, and either way bring the reader's affinity control and judge
|
||||
|
||||
@@ -46,6 +46,25 @@
|
||||
<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-none" class="rail-note" hidden></p>
|
||||
{# Every order keeps to the agent's fetch gate (docs/architecture.md,
|
||||
"5 Feed"), so the filters below only narrow what it passed. #}
|
||||
<p id="agent-gate" class="rail-note" hidden></p>
|
||||
</section>
|
||||
{# The agent's saved filters (`/api/agents/{id}/filters`), newsdesk's
|
||||
`#active` pills: a click applies one, × deletes it. Save names the
|
||||
filters on screen in a field of its own; there is no editing, a change
|
||||
is saved as a new one. Hidden with no agent. #}
|
||||
<section id="saved" aria-labelledby="saved-title" hidden>
|
||||
<h3 id="saved-title">Saved filters <button type="button" class="linky" id="save-open"
|
||||
aria-controls="save-form" aria-expanded="false">save</button></h3>
|
||||
<div id="saved-list" class="saved-list"></div>
|
||||
<form id="save-form" class="save-form" hidden>
|
||||
<input type="text" id="save-name" maxlength="80" autocomplete="off"
|
||||
placeholder="Name" aria-label="Name of the saved filter">
|
||||
<button type="submit">Save</button>
|
||||
<button type="button" class="linky" id="save-cancel">cancel</button>
|
||||
</form>
|
||||
<p class="rail-note" id="saved-note" role="status" hidden></p>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Filters</h3>
|
||||
@@ -55,9 +74,9 @@
|
||||
</section>
|
||||
<section>
|
||||
<h3>Order</h3>
|
||||
{# Agent match is the viewing agent's score, Newest is first seen,
|
||||
CV match the agent's `judge` total against its CV; all carry
|
||||
that agent's votes. #}
|
||||
{# Agent match is the viewing agent's final score, Newest is first
|
||||
seen, CV match the agent's `judge` total against its CV; all carry
|
||||
that agent's votes and keep to its fetch gate. #}
|
||||
<div class="seg" id="sort" role="group" aria-label="Order"></div>
|
||||
<label class="rail-field" for="period">First seen</label>
|
||||
<select id="period" class="rail-select"></select>
|
||||
@@ -133,7 +152,10 @@
|
||||
<label class="check">
|
||||
<input type="checkbox" id="f-show-muted"> Show hidden companies
|
||||
</label>
|
||||
<label class="check" id="show-gated" hidden>
|
||||
{# The roles the agent's fetch gate rejects, each with the reason,
|
||||
in any order; offered only with an agent. #}
|
||||
<label class="check" id="show-gated" hidden
|
||||
title="Also list the roles this agent's fetch gate rejects, with the reason">
|
||||
<input type="checkbox" id="f-gated"> Show gated
|
||||
</label>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""The Roles page's part of the ranking flow (docs/architecture.md, "5 Feed"):
|
||||
the note that the feed keeps to the agent's fetch gate, the saved filters in
|
||||
the rail and the routes they call, as `static/roles.js` uses them. A temp
|
||||
database and FastAPI's TestClient; no browser."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.config import Config, ServerConfig
|
||||
from app.main import create_app
|
||||
from app.storage import Store
|
||||
|
||||
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path: Path) -> FastAPI:
|
||||
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
||||
database=tmp_path / "roledesk.db"))
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(app: FastAPI) -> Store:
|
||||
return app.state.store
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app: FastAPI) -> Iterator[TestClient]:
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
|
||||
|
||||
def test_the_rail_says_the_feed_keeps_to_the_fetch_gate_and_offers_saved_filters(
|
||||
client: TestClient) -> None:
|
||||
page = client.get("/").text
|
||||
assert 'id="agent-gate"' in page
|
||||
for name in ("saved", "saved-list", "save-open", "save-form", "save-name", "saved-note"):
|
||||
assert f'id="{name}"' in page
|
||||
script = (STATIC / "roles.js").read_text()
|
||||
assert "Already filtered by this agent's fetch gate" in script
|
||||
# The name is asked in the page, never by a browser prompt.
|
||||
assert "prompt(" not in script
|
||||
|
||||
|
||||
def test_no_text_says_a_favourite_skips_the_places() -> None:
|
||||
script = (STATIC / "roles.js").read_text()
|
||||
for stale in ("outside your places", "Kept out of the ranking", "required gates allow"):
|
||||
assert stale not in script
|
||||
|
||||
|
||||
def test_a_saved_filter_round_trips_the_query_roles_js_writes(
|
||||
client: TestClient, store: Store) -> None:
|
||||
agent = store.save_agent("Wolf")
|
||||
query = "q=engineer&remote=remote&places=country%3ADK&gated=true&sort=time"
|
||||
|
||||
made = client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": "Remote engineers", "query": query})
|
||||
assert made.status_code == 201
|
||||
assert made.json()["query"] == query
|
||||
|
||||
listed = client.get(f"/api/agents/{agent.id}/filters").json()
|
||||
assert [(f["name"], f["query"]) for f in listed] == [("Remote engineers", query)]
|
||||
|
||||
# Case does not make a second name; the page says the 409 under the field.
|
||||
twice = client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": "remote ENGINEERS", "query": ""})
|
||||
assert twice.status_code == 409 and twice.json()["detail"]
|
||||
assert client.post(f"/api/agents/{agent.id}/filters",
|
||||
json={"name": " ", "query": ""}).status_code == 422
|
||||
assert client.get("/api/agents/999/filters").status_code == 404
|
||||
|
||||
gone = client.delete(f"/api/filters/{made.json()['id']}")
|
||||
assert gone.status_code == 204
|
||||
# A second delete, from a page that had not heard of the first, is a 404
|
||||
# the page treats as done.
|
||||
assert client.delete(f"/api/filters/{made.json()['id']}").status_code == 404
|
||||
assert client.get(f"/api/agents/{agent.id}/filters").json() == []
|
||||
Reference in new issue
Block a user