Companies and Searches: follow, hide not mute, prune moved, one row style

Companies gets a Follow-a-company form, a combined affinity/on-off filter,
and one .srow-style row per company (name, board or "from searches", open
roles, on/off switch, affinity). The prune-by-region tool moves here from
Searches, folded under the list in a <details>. The lede states the
difference between switching a board off (stops reading it, closes its
roles) and hiding a company (keeps reading it, keeps its roles out of the
list and unscored).

affinityControl becomes three icon toggles (favourite, like, hidden) instead
of four letter buttons with a neutral one; pressing the pressed icon clears
back to neutral. "Hidden" is the word everywhere the UI names affinity -1;
the code keeps mute/hide_muted. CompanyOut carries each company's board
subscription id and on-state, so the Companies page needs only
/api/companies, not a second fetch of /api/sources. Setting a company's
affinity now enqueues a score job, deduped by the queue to one run.

Searches keeps only the search form and list, in the same row style;
company boards and the prune tool left with it, and "Pull now" left for
Pulls (package B3).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-25 22:02:28 +02:00
1 parent 7d31cca394
commit 55248555e9
8 files changed
+419 -318

No files matched your search

+34 -161
View File
@@ -1,21 +1,20 @@
/* The Searches page under Settings: saved searches, and for now the company
* boards and the prune by region as well.
/* The Searches page under Settings: saved searches only. Company boards and
* the prune by region moved to Companies, since a board is a company's own,
* not a search's.
*
* The template is a shell; the lists come from /api/sources and every action
* is a fetch through `api()` from app.js, so a refusal (a search that finds
* nothing, a board that does not answer) is one toast with the server's own
* sentence. The catch blocks here only put a control back.
* The list comes from `/api/sources`, and every action is a fetch through
* `api()` from app.js, so a refusal (a search that finds nothing) is one
* toast with the server's own sentence. The catch blocks here only put a
* control back.
*/
(function () {
"use strict";
const { api, count, cell, debounce } = window;
const { api, count, debounce } = window;
const $ = (sel, root = document) => root.querySelector(sel);
/** @type {{searches: object[], boards: object[], adzuna_key: boolean}} */
let data = { searches: [], boards: [], adzuna_key: false };
/** @type {object[]} the boards the last prune preview named */
let pruneBoards = [];
/** @type {{searches: object[], adzuna_key: boolean}} */
let data = { searches: [], adzuna_key: false };
/** "DK 120 · EU 4 · unknown 2", the three biggest. */
function countries(source) {
@@ -25,19 +24,11 @@
return shown.join(" · ");
}
function query(source) {
const p = source.params || {};
const where = source.provider === "adzuna"
? [p.country && p.country.toUpperCase(), p.where].filter(Boolean).join(", ")
: (p.area ? $(`#s-area option[value="${p.area}"]`)?.textContent : "All of Denmark");
return `${p.q || ""}${where ? ` — ${where}` : ""}`;
}
function onSwitch(source, rerender) {
const box = document.createElement("input");
box.type = "checkbox";
box.checked = source.on;
box.setAttribute("aria-label", `Pull ${source.label}`);
box.setAttribute("aria-label", `Run ${source.label}`);
box.addEventListener("change", async () => {
box.disabled = true;
try {
@@ -66,35 +57,41 @@
const body = $("#searches-list");
body.replaceChildren();
for (const source of data.searches) {
const tr = document.createElement("tr");
if (!source.on) tr.classList.add("muted");
const row = document.createElement("div");
row.className = "srow";
if (!source.on) row.dataset.muted = "true";
const name = document.createElement("span");
name.textContent = source.label;
name.className = "name";
const label = document.createElement("span");
label.textContent = source.label;
const provider = document.createElement("span");
provider.className = "badge";
provider.textContent = source.provider;
const title = document.createElement("span");
title.append(name, " ", provider);
cell(tr, "Search", title);
cell(tr, "Query", query(source)).className = "mono small";
cell(tr, "Open roles", String(source.open_roles)).className = "num";
cell(tr, "Countries", countries(source)).className = "small";
cell(tr, "On", onSwitch(source, renderSearches));
const actions = document.createElement("span");
actions.className = "row-actions";
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 = "secondary";
edit.className = "linky";
edit.textContent = "Edit";
edit.addEventListener("click", () => fillSearchForm(source));
const remove = document.createElement("button");
remove.type = "button";
remove.className = "secondary";
remove.className = "linky";
remove.textContent = "Remove";
remove.addEventListener("click", () => removeSearch(source));
actions.append(edit, remove);
cell(tr, "", actions);
body.appendChild(tr);
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
@@ -203,123 +200,6 @@
}
}
// ------------------------------------------------------------------ boards
function renderBoards() {
const q = $("#b-q").value.trim().toLowerCase();
const on = $("#b-on").value;
const rows = data.boards
.filter((b) => !q || b.label.toLowerCase().includes(q) || b.target.includes(q))
.filter((b) => !on || (on === "on") === b.on)
.sort((a, b) => Number(b.on) - Number(a.on) || b.open_roles - a.open_roles
|| a.label.localeCompare(b.label));
const body = $("#boards-list");
body.replaceChildren();
for (const board of rows) {
const tr = document.createElement("tr");
if (!board.on) tr.classList.add("muted");
const link = document.createElement("a");
link.href = `/?company=${encodeURIComponent(board.label)}`;
link.title = "This company's open roles";
link.textContent = board.label;
cell(tr, "Company", link);
cell(tr, "Board", board.target).className = "mono small";
cell(tr, "Open roles", String(board.open_roles)).className = "num";
cell(tr, "Countries", countries(board)).className = "small";
cell(tr, "On", onSwitch(board, renderBoards));
body.appendChild(tr);
}
const onCount = data.boards.filter((b) => b.on).length;
$("#boards-count").textContent =
`${count(data.boards.length, "board")}, ${onCount} on. Showing ${rows.length}.`;
}
async function addBoard(event) {
event.preventDefault();
const status = $("#board-status");
const button = $("#board-form button[type=submit]");
button.disabled = true;
status.textContent = "Reading the board once before following it…";
try {
const result = await api("/api/boards", {
method: "POST",
body: { board: $("#b-board").value.trim(), name: $("#b-name").value.trim() },
});
data.boards.push(result.source);
renderBoards();
$("#board-form").reset();
status.textContent = `Following ${result.source.label}: `
+ `${count(result.found, "role")} listed. They arrive with the next pull.`;
} catch (err) {
status.textContent = "";
}
button.disabled = false;
}
// ------------------------------------------------------------------- prune
async function previewPrune(event) {
event.preventDefault();
const status = $("#prune-status");
const list = $("#prune-list");
const region = $("#p-region").value.trim();
list.replaceChildren();
$("#p-apply").disabled = true;
status.textContent = "Checking every board…";
try {
const result = await api(`/api/prune?region=${encodeURIComponent(region)}`);
pruneBoards = result.boards;
const roles = pruneBoards.reduce((sum, b) => sum + b.open_roles, 0);
status.textContent = pruneBoards.length
? `${count(pruneBoards.length, "board")} with no open role in ${region}, `
+ `${count(roles, "open role")} between them:`
: `Every board that is on has a role in ${region}.`;
for (const board of pruneBoards) {
const li = document.createElement("li");
li.textContent = `${board.label} (${board.target}), ${count(board.open_roles, "open role")}`;
list.appendChild(li);
}
$("#p-apply").disabled = pruneBoards.length === 0;
} catch (err) {
status.textContent = "";
}
}
async function applyPrune() {
const region = $("#p-region").value.trim();
if (!window.confirm(`Switch off ${count(pruneBoards.length, "board")} and close their roles? `
+ "Each can be switched back on in the list above.")) return;
$("#p-apply").disabled = true;
try {
const result = await api("/api/prune", { method: "POST", body: { region } });
$("#prune-status").textContent = `Switched off ${count(result.pruned, "board")}, `
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
$("#prune-list").replaceChildren();
await load();
renderBoards();
} catch (err) {
$("#p-apply").disabled = false;
}
}
// -------------------------------------------------------------------- pull
async function pullNow() {
const button = $("#pull-now");
button.disabled = true;
try {
await api("/api/jobs", { method: "POST", body: { kind: "pull", payload: {} } });
$("#pull-status").replaceChildren("Pull started. ");
const link = document.createElement("a");
link.href = "/settings/pulls";
link.textContent = "Follow it under Pulls";
$("#pull-status").appendChild(link);
} catch (err) {
/* already toasted */
}
button.disabled = false;
}
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
@@ -330,17 +210,10 @@
return;
}
renderSearches();
renderBoards();
fillSearchForm(null);
$("#s-provider").addEventListener("change", showProvider);
$("#s-try").addEventListener("click", trySearch);
$("#search-form").addEventListener("submit", saveSearch);
$("#s-new").addEventListener("click", () => fillSearchForm(null));
$("#b-q").addEventListener("input", debounce(renderBoards, 150));
$("#b-on").addEventListener("change", renderBoards);
$("#board-form").addEventListener("submit", addBoard);
$("#prune-form").addEventListener("submit", previewPrune);
$("#p-apply").addEventListener("click", applyPrune);
$("#pull-now").addEventListener("click", pullNow);
});
})();