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>
256 lines
9.3 KiB
JavaScript
256 lines
9.3 KiB
JavaScript
/* The Job boards section of Sources: one query on one board per row, on
|
|
* Jobindex or Adzuna. The UI says "job board" for what the API and the CLI
|
|
* call a search (`/api/searches`, `app searches`); company boards and the
|
|
* prune by region are companies.js's section, since a board is a company's
|
|
* own, not a query's.
|
|
*
|
|
* The list comes from `/api/sources`, and every action is a fetch through
|
|
* `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";
|
|
|
|
const { api, count, debounce } = window;
|
|
const $ = (sel, root = document) => root.querySelector(sel);
|
|
|
|
/** @type {{searches: object[], adzuna_key: boolean}} */
|
|
let data = { searches: [], adzuna_key: false };
|
|
|
|
/** "DK 120 · EU 4 · unknown 2", the three biggest. */
|
|
function countries(source) {
|
|
const shown = source.countries.slice(0, 3)
|
|
.map(([code, n]) => `${code || "unknown"} ${n}`);
|
|
if (source.countries.length > 3) shown.push("…");
|
|
return shown.join(" · ");
|
|
}
|
|
|
|
function onSwitch(source, rerender) {
|
|
const box = document.createElement("input");
|
|
box.type = "checkbox";
|
|
box.checked = source.on;
|
|
box.setAttribute("aria-label", `Run ${source.label}`);
|
|
box.addEventListener("change", async () => {
|
|
box.disabled = true;
|
|
try {
|
|
const result = await api(`/api/sources/${source.id}/switch`,
|
|
{ method: "POST", body: { on: box.checked } });
|
|
Object.assign(source, result.source);
|
|
if (!box.checked && result.closed) {
|
|
window.toast.info(`${source.label}: ${count(result.closed, "open role")} closed.`);
|
|
}
|
|
} catch (err) {
|
|
box.checked = !box.checked;
|
|
}
|
|
box.disabled = false;
|
|
rerender();
|
|
});
|
|
return box;
|
|
}
|
|
|
|
async function load() {
|
|
data = await api("/api/sources");
|
|
}
|
|
|
|
// ---------------------------------------------------------------- searches
|
|
|
|
function renderSearches() {
|
|
const body = $("#searches-list");
|
|
body.replaceChildren();
|
|
for (const source of data.searches) {
|
|
const row = document.createElement("div");
|
|
row.className = "srow";
|
|
if (!source.on) row.dataset.muted = "true";
|
|
|
|
const name = document.createElement("span");
|
|
name.className = "name";
|
|
const label = document.createElement("span");
|
|
label.textContent = source.label;
|
|
const provider = document.createElement("span");
|
|
provider.className = "badge";
|
|
provider.textContent = source.provider;
|
|
name.append(label, provider);
|
|
row.appendChild(name);
|
|
row.appendChild(onSwitch(source, renderSearches));
|
|
|
|
const q = (source.params && source.params.q) || "";
|
|
const sub = document.createElement("span");
|
|
sub.className = "sub";
|
|
const parts = [q, `${source.open_roles} open`];
|
|
if (source.countries.length) parts.push(countries(source));
|
|
sub.append(parts.join(" · "), " ");
|
|
const edit = document.createElement("button");
|
|
edit.type = "button";
|
|
edit.className = "linky";
|
|
edit.textContent = "Edit";
|
|
edit.addEventListener("click", () => fillSearchForm(source));
|
|
const remove = document.createElement("button");
|
|
remove.type = "button";
|
|
remove.className = "linky";
|
|
remove.textContent = "Remove";
|
|
remove.addEventListener("click", () => removeSearch(source));
|
|
sub.append(edit, " ", remove);
|
|
row.appendChild(sub);
|
|
|
|
body.appendChild(row);
|
|
}
|
|
const open = data.searches.reduce((sum, s) => sum + s.open_roles, 0);
|
|
$("#searches-count").textContent = data.searches.length
|
|
? `${count(data.searches.length, "job board")}, ${count(open, "open role")}`
|
|
: "No job boards yet. Add one above; the starter ones in config.yaml import on the first pull.";
|
|
}
|
|
|
|
function showProvider() {
|
|
const provider = $("#s-provider").value;
|
|
for (const node of document.querySelectorAll("#search-form [data-provider]")) {
|
|
node.hidden = node.dataset.provider !== provider;
|
|
}
|
|
$("#adzuna-key").hidden = provider !== "adzuna" || data.adzuna_key;
|
|
}
|
|
|
|
function fillSearchForm(source) {
|
|
const p = (source && source.params) || {};
|
|
$("#search-form-title").textContent = source ? `Edit ${source.label}` : "New job board";
|
|
$("#s-provider").value = source ? source.provider : "jobindex";
|
|
$("#s-name").value = source ? source.label : "";
|
|
$("#s-name").readOnly = Boolean(source);
|
|
$("#s-provider").disabled = Boolean(source);
|
|
$("#s-q").value = p.q || "";
|
|
$("#s-area").value = String(p.area || (source ? 0 : 1));
|
|
$("#s-country").value = p.country || "de";
|
|
$("#s-where").value = p.where || "";
|
|
$("#s-pages").value = String(p.pages || 10);
|
|
$("#search-status").textContent = "";
|
|
$("#search-sample").replaceChildren();
|
|
showProvider();
|
|
if (source) $("#search-form").scrollIntoView({ behavior: "smooth", block: "start" });
|
|
}
|
|
|
|
function searchBody() {
|
|
return {
|
|
provider: $("#s-provider").value,
|
|
name: $("#s-name").value.trim(),
|
|
q: $("#s-q").value.trim(),
|
|
area: Number($("#s-area").value) || 0,
|
|
country: $("#s-country").value,
|
|
where: $("#s-where").value.trim(),
|
|
pages: Number($("#s-pages").value) || 0,
|
|
};
|
|
}
|
|
|
|
function found(result) {
|
|
const all = result.complete ? "every match" : "the page limit cut it short";
|
|
return `Found ${count(result.found, "role")} (${all}).`;
|
|
}
|
|
|
|
async function trySearch() {
|
|
const status = $("#search-status");
|
|
const button = $("#s-try");
|
|
button.disabled = true;
|
|
status.textContent = "Searching…";
|
|
$("#search-sample").replaceChildren();
|
|
try {
|
|
const result = await api("/api/searches/try", { method: "POST", body: searchBody() });
|
|
status.textContent = `${found(result)} The newest ${Math.min(result.found, 10)}:`;
|
|
const list = $("#search-sample");
|
|
for (const row of result.sample) {
|
|
const li = document.createElement("li");
|
|
const link = document.createElement("a");
|
|
link.href = row.url;
|
|
link.target = "_blank";
|
|
link.rel = "noopener";
|
|
link.textContent = row.title;
|
|
li.append(link, ` — ${[row.company, row.place].filter(Boolean).join(", ")}`);
|
|
list.appendChild(li);
|
|
}
|
|
} catch (err) {
|
|
status.textContent = "";
|
|
}
|
|
button.disabled = false;
|
|
}
|
|
|
|
async function saveSearch(event) {
|
|
event.preventDefault();
|
|
const status = $("#search-status");
|
|
const button = $("#search-form button[type=submit]");
|
|
button.disabled = true;
|
|
status.textContent = "Running it once before saving…";
|
|
try {
|
|
const result = await api("/api/searches", { method: "POST", body: searchBody() });
|
|
await load();
|
|
renderSearches();
|
|
fillSearchForm(null);
|
|
status.textContent = `Saved ${result.source.label}. ${found(result)} `
|
|
+ "Its roles arrive with the next pull.";
|
|
} catch (err) {
|
|
status.textContent = "";
|
|
}
|
|
button.disabled = false;
|
|
}
|
|
|
|
async function removeSearch(source) {
|
|
if (!window.confirm(`Remove ${source.label}? Its ${count(source.open_roles, "open role")} close.`)) {
|
|
return;
|
|
}
|
|
try {
|
|
await api(`/api/searches/${source.id}`, { method: "DELETE" });
|
|
data.searches = data.searches.filter((s) => s.id !== source.id);
|
|
renderSearches();
|
|
} catch (err) {
|
|
/* already toasted */
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------ 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 () => {
|
|
if (!$("#searches-list")) return;
|
|
try {
|
|
await load();
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
renderSearches();
|
|
fillSearchForm(null);
|
|
$("#s-provider").addEventListener("change", showProvider);
|
|
$("#s-try").addEventListener("click", trySearch);
|
|
$("#search-form").addEventListener("submit", saveSearch);
|
|
$("#s-new").addEventListener("click", () => fillSearchForm(null));
|
|
});
|
|
})();
|