Merge branch 'wp2b-watchlist'

This commit is contained in:
Wolf committed 2026-09-29 19:37:36 +02:00
commit d06f0f3327
4 files changed
+317 -74

No files matched your search

+5 -1
View File
@@ -1130,7 +1130,8 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
.agent-form h2, .agent-form h3 { font-size: 1rem; margin: 0; }
.agent-form label { display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
.agent-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"] {
.agent-form input[type="text"], .agent-form textarea, .agent-form input[type="number"],
.agent-form input[type="url"] {
background: var(--bg); border: 1px solid var(--line);
border-radius: .3rem; padding: .35rem .5rem; width: 100%;
}
@@ -1253,6 +1254,9 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
}
.crow .board-edit input { flex: 1 1 8rem; min-width: 0; }
.crow .sub .failing { color: var(--warn); }
/* A Watchlist row's note, a line of its own: the owner's line breaks kept,
and a pasted URL broken rather than widening a phone's page. */
.crow .sub.notes { white-space: pre-line; overflow-wrap: anywhere; }
.linky {
padding: 0; border: 0; background: none; font-size: .8rem;
+256 -71
View File
@@ -2,13 +2,20 @@
* going through their careers pages by hand.
*
* The list is app.js's shared company list (`/api/companies`), narrowed to
* the rule the "Not readable yet" filter of Company boards uses (no board
* subscription, not from a search), plus every company whose board is
* failing. The rating (`watch`: null unrated, 1 yes, 0 no) is global, not a
* search agent's affinity, and is set with `POST .../watch`. Opening the
* careers page stamps `careers_opened_at` (`POST .../opened`), so the row can
* say when, and the On the list filter sorts what was opened longest ago
* first. The filter is remembered per browser, and opens on Unrated.
* the by-hand list (`by_hand`: no board shown, not known from a search only),
* plus every company whose board is failing. The rating (`watch`: null
* unrated, 1 yes, 0 no) is global, not a search agent's affinity, and is set
* with `POST .../watch`. Opening the careers page stamps `careers_opened_at`
* (`POST .../opened`), so the row can say when, and the On the list filter
* sorts what was opened longest ago first. The filter is remembered per
* browser, and opens on Unrated.
*
* New company and Edit are the Job boards form of Sources (sources.js): Edit
* turns a row into the form from the page's `<template>`, in place, New puts
* a blank one on top, one is open at a time, and Save and Cancel put it
* away. New is `POST /api/companies`, Edit a `PATCH` of the fields that
* changed, and Remove a `DELETE`; a refusal is `api()`'s toast with the
* server's sentence, and the catch blocks here only put a control back.
*/
(function () {
"use strict";
@@ -22,8 +29,13 @@
];
const DAY = 24 * 60 * 60 * 1000;
/** The key of the row whose careers link editor is open, or null. */
const NEW = "new";
/** @type {string | "new" | null} the row in edit mode: a company's key,
* NEW for the blank form on top, null for none */
let editing = null;
/** @type {HTMLFormElement | null} that form, kept across renders so a
* rating set on another row does not wipe what is being typed */
let editor = null;
function savedFilter() {
try {
@@ -38,10 +50,17 @@
try { localStorage.setItem(FILTER, value); } catch (err) { /* not remembered */ }
}
/** On the by-hand list: the server says so, or, from a server without
`by_hand`, no board and not known from a search only. */
function byHand(company) {
return "by_hand" in company
? Boolean(company.by_hand)
: company.subscription_id == null && !company.from_search;
}
/** The companies the tab is about, before any filter. */
function watched() {
return [...companies.values()].filter(
(c) => (c.subscription_id == null && !c.from_search) || c.failing_since);
return [...companies.values()].filter((c) => byHand(c) || c.failing_since);
}
function matchesFilter(company, filter) {
@@ -53,6 +72,24 @@
}
}
/** A `hand_reason` in words, from the options the page rendered into the
form: "no reader yet". "" for none given. */
function reasonWords(value) {
if (!value) return "";
const option = [...$("#company-form-template").content.querySelector("#cf-reason").options]
.find((o) => o.value === value);
const label = option ? option.textContent : value;
return label.charAt(0).toLowerCase() + label.slice(1);
}
function matchesQuery(company, q) {
return !q || company.name.toLowerCase().includes(q)
|| (company.board || company.ats || "").includes(q)
|| (company.country || "").toLowerCase() === q
|| (company.notes || "").toLowerCase().includes(q)
|| reasonWords(company.hand_reason).includes(q);
}
function ago(iso) {
if (!iso) return "not opened yet";
const days = Math.floor((Date.now() - new Date(iso).getTime()) / DAY);
@@ -100,13 +137,30 @@
return span;
}
function badge(text) {
const span = document.createElement("span");
span.className = "badge";
span.textContent = text;
return span;
}
function linky(text, onClick) {
const button = document.createElement("button");
button.type = "button";
button.className = "linky";
button.textContent = text;
button.addEventListener("click", () => onClick(button));
return button;
}
function subLine(company, rerender) {
const sub = document.createElement("span");
sub.className = "sub";
const badge = document.createElement("span");
badge.className = "badge";
badge.textContent = company.board || company.ats || "board not found";
sub.appendChild(badge);
// The host, then why the company is read by hand. Without a reason the
// row says what it did before there were reasons: "board not found".
const host = company.board || company.ats || (company.hand_reason ? "" : "board not found");
if (host) sub.appendChild(badge(host));
if (company.hand_reason) sub.appendChild(badge(reasonWords(company.hand_reason)));
const place = [company.city, (company.country || "").toUpperCase()].filter(Boolean).join(", ");
if (place) sub.append(` ${place}`);
if (company.failing_since) {
@@ -128,16 +182,9 @@
sub.appendChild(link);
sub.append(` · ${ago(company.careers_opened_at)} `);
}
const edit = document.createElement("button");
edit.type = "button";
edit.className = "linky";
edit.textContent = company.careers_url ? "Edit link" : "Add careers page";
edit.setAttribute("aria-expanded", String(editing === company.key));
edit.addEventListener("click", () => {
editing = editing === company.key ? null : company.key;
rerender();
});
sub.appendChild(edit);
// Edit is also how a link is set: the form opens on the careers page box.
sub.append(linky("Edit", () => openForm(company)), " ",
linky("Remove", (button) => removeCompany(company, button)));
return sub;
}
@@ -154,39 +201,23 @@
rerender();
}
function linkEditor(company, rerender) {
const form = document.createElement("form");
form.className = "board-edit";
form.autocomplete = "off";
const input = document.createElement("input");
input.type = "url";
input.spellcheck = false;
input.placeholder = "https://";
input.value = company.careers_url || "";
input.setAttribute("aria-label", `${company.name}'s careers page`);
const save = document.createElement("button");
save.type = "submit";
save.textContent = "Save";
const cancel = document.createElement("button");
cancel.type = "button";
cancel.className = "linky";
cancel.textContent = "Cancel";
cancel.addEventListener("click", () => { editing = null; rerender(); });
form.append(input, save, cancel);
form.addEventListener("submit", async (event) => {
event.preventDefault();
save.disabled = true;
try {
const updated = await api(`/api/companies/${encodeURIComponent(company.key)}/careers`,
{ method: "POST", body: { careers_url: input.value.trim() } });
company.careers_url = updated.careers_url;
editing = null;
rerender();
} catch (err) {
save.disabled = false;
}
});
return form;
function row(company) {
const row = document.createElement("div");
row.className = "crow";
row.dataset.key = company.key;
const name = document.createElement("span");
name.className = "name";
name.textContent = company.name;
row.appendChild(name);
row.appendChild(ratingControl(company, render));
row.appendChild(subLine(company, render));
if (company.notes) {
const note = document.createElement("span");
note.className = "sub notes";
note.textContent = company.notes;
row.appendChild(note);
}
return row;
}
/** The filter's options with their counts, kept on the chosen one. */
@@ -208,10 +239,9 @@
drawFilter(all);
const q = $("#w-q").value.trim().toLowerCase();
const filter = $("#w-filter").value;
const rows = all
.filter((c) => !q || c.name.toLowerCase().includes(q)
|| (c.board || c.ats || "").includes(q) || (c.country || "").toLowerCase() === q)
.filter((c) => matchesFilter(c, filter));
// The row being edited stays, whatever the filter says, so its form does.
const rows = all.filter((c) => c.key === editing
|| (matchesQuery(c, q) && matchesFilter(c, filter)));
// Overdue first on the list, never opened on top (the empty stamp sorts
// before any date); every other filter is by name.
rows.sort((a, b) => (filter === "yes"
@@ -219,21 +249,175 @@
|| a.name.localeCompare(b.name));
const body = $("#watchlist-list");
body.replaceChildren();
if (editing === NEW) body.appendChild(editor);
for (const company of rows) {
const row = document.createElement("div");
row.className = "crow";
const name = document.createElement("span");
name.className = "name";
name.textContent = company.name;
row.appendChild(name);
row.appendChild(ratingControl(company, render));
row.appendChild(subLine(company, render));
if (editing === company.key) row.appendChild(linkEditor(company, render));
body.appendChild(row);
body.appendChild(editing === company.key ? editor : row(company));
}
$("#watchlist-count").textContent = count(rows.length, "company", "companies");
}
// ---------------------------------------------------------------- the form
function form(company) {
const f = $("#company-form-template").content.querySelector("form").cloneNode(true);
$("#company-form-title", f).textContent = company ? `Edit ${company.name}` : "New company";
$("#cf-name", f).value = company ? company.name : "";
// A company with a board keeps its name: the board is found by it.
const kept = Boolean(company && company.subscription_id != null);
$("#cf-name", f).readOnly = kept;
$("#cf-name-hint", f).hidden = !kept;
$("#cf-url", f).value = company ? company.careers_url || "" : "";
$("#cf-reason", f).value = company ? company.hand_reason || "" : "added";
$("#cf-notes", f).value = company ? company.notes || "" : "";
f.addEventListener("input", () => { f.dataset.dirty = "true"; });
$("#cf-cancel", f).addEventListener("click", () => { if (close()) render(); });
f.addEventListener("submit", saveCompany);
return f;
}
// Put the open form away, asking first if it holds changes. False when the
// answer was to keep them.
function close() {
if (editor && editor.dataset.dirty
&& !window.confirm("Discard the changes to this company?")) {
return false;
}
editing = null;
editor = null;
return true;
}
// Edit `company` in place of its row, or a new one on top of the list.
function openForm(company) {
const want = company ? company.key : NEW;
if (editing !== want) {
if (!close()) return;
editing = want;
editor = form(company);
$("#watchlist-answer").replaceChildren();
render();
}
editor.scrollIntoView({ behavior: "smooth", block: "nearest" });
$(company ? "#cf-url" : "#cf-name", editor).focus({ preventScroll: true });
}
function formBody(f) {
return {
name: $("#cf-name", f).value.trim(),
careers_url: $("#cf-url", f).value.trim(),
hand_reason: $("#cf-reason", f).value,
notes: $("#cf-notes", f).value.trim(),
};
}
/** A new company is unrated: if the filter or the text would hide it, they
change to show it, since the owner just asked for it. */
function reveal(company) {
if (!matchesFilter(company, $("#w-filter").value)) {
$("#w-filter").value = "unrated";
saveFilter("unrated");
}
if (!matchesQuery(company, $("#w-q").value.trim().toLowerCase())) $("#w-q").value = "";
}
async function saveCompany(event) {
event.preventDefault();
const f = event.target;
const button = $("button[type=submit]", f);
const body = formBody(f);
const company = editing === NEW ? null : companies.get(editing);
// Only what changed, so a company with a board is not sent the name it
// may not change.
const patch = {};
if (company) {
for (const [field, value] of Object.entries(body)) {
if (value !== (company[field] || "")) patch[field] = value;
}
}
button.disabled = true;
let answer = company;
try {
if (!company) {
answer = await api("/api/companies", { method: "POST", body });
} else if (Object.keys(patch).length) {
answer = await api(`/api/companies/${encodeURIComponent(company.key)}`,
{ method: "PATCH", body: patch });
}
} catch (err) {
button.disabled = false;
if (!company && err.status === 409) await taken(body.name, err.detail);
return;
}
if (company) {
Object.assign(company, answer);
} else {
companies.set(answer.key, answer);
reveal(answer);
}
editing = null;
editor = null;
$("#watchlist-answer").textContent = `${company ? "Saved" : "Added"} ${answer.name}.`;
render();
const shown = $(`#watchlist-list [data-key="${CSS.escape(answer.key)}"]`);
if (shown) shown.scrollIntoView({ behavior: "smooth", block: "nearest" });
}
// New refused, since the key its name folds to is taken, which the toast
// said. If that company is on this list, offer to edit it instead; if not,
// say where it is. The server's sentence ends "as <key>.", which finds it
// when the name typed is not the one it has ("Acme GmbH" for "Acme").
async function taken(name, detail) {
try {
await loadCompanies();
} catch (err) {
return;
}
render();
const said = / as (\S+)\.$/.exec(detail || "");
const wanted = name.toLowerCase();
const existing = (said && companies.get(said[1]))
|| [...companies.values()].find((c) => c.name.toLowerCase() === wanted);
if (!existing) return;
if (byHand(existing) || existing.failing_since) {
if (window.confirm(`${existing.name} is on the Watchlist already. Edit it instead?`)) {
delete editor.dataset.dirty;
openForm(existing);
}
return;
}
const why = existing.board ? "the app reads its board" : "it is known from a job board search";
const link = document.createElement("a");
link.href = "/settings/sources#company-boards";
link.textContent = "Settings, Sources, Company boards";
$("#watchlist-answer").replaceChildren(
`${existing.name} is not on the Watchlist, since ${why}; it is under `, link, ".");
}
// ---------------------------------------------------------------- actions
async function removeCompany(company, button) {
if (!window.confirm(`Remove ${company.name}? Its rating, note and careers link go with it.`)) {
return;
}
button.disabled = true;
try {
// A company with a board or open roles is refused, and the toast says which.
await api(`/api/companies/${encodeURIComponent(company.key)}`, { method: "DELETE" });
} catch (err) {
button.disabled = false;
return;
}
companies.delete(company.key);
if (editing === company.key) {
editing = null;
editor = null;
}
$("#watchlist-answer").textContent = `Removed ${company.name}.`;
render();
}
// -------------------------------------------------------------------- init
document.addEventListener("DOMContentLoaded", async () => {
if (!$("#watchlist-list")) return;
try {
@@ -248,5 +432,6 @@
saveFilter($("#w-filter").value);
render();
});
$("#w-add").addEventListener("click", () => openForm(null));
});
})();
+40 -2
View File
@@ -1,19 +1,57 @@
{% extends "base.html" %}
{% block title %}Watchlist — roledesk{% endblock %}
{# The form is a `<template>` for the reason the Job boards one on Sources
is: one company is edited at a time, so its ids stay unique. watchlist.js
puts it in place of a row on Edit, and on top of the list on New. The
reason's options are `HAND_REASONS` of app/models.py, in the words a row's
badge uses; watchlist.js reads the words off them. #}
{% block content %}
<h1>Watchlist</h1>
<p class="lede">The companies roledesk knows but cannot read a board of, so their roles are not in Roles. Mark the ones worth checking by hand and open their careers page from here.</p>
<form class="filters" autocomplete="off" onsubmit="return false">
<input type="search" id="w-q" placeholder="Filter by name, host or country code" aria-label="Filter companies">
<input type="search" id="w-q" placeholder="Filter by name, host, country code, reason or note" aria-label="Filter companies">
{# The options and their counts are drawn by watchlist.js, which also
remembers the choice. #}
<select id="w-filter" aria-label="Show"></select>
</form>
<p id="watchlist-count" class="count" role="status"></p>
<div class="agents-head">
<p id="watchlist-count" class="count" role="status"></p>
<button type="button" id="w-add">New company</button>
</div>
<p id="watchlist-answer" class="count" role="status"></p>
<div id="watchlist-list" class="crows"></div>
<template id="company-form-template">
<form id="company-form" class="agent-form source-form" autocomplete="off">
<h3 id="company-form-title">New company</h3>
<div class="form-row">
<label>Name <input type="text" id="cf-name" required placeholder="Acme">
<span class="hint" id="cf-name-hint" hidden>Kept while it has a board, which is found by its name.</span></label>
<label>Reason
<select id="cf-reason">
<option value="unread">No reader yet</option>
<option value="robots">Site disallows reading</option>
<option value="blocked">Site blocks programs</option>
<option value="key">Needs a key</option>
<option value="group">Inside another company's board</option>
<option value="gone">No careers page</option>
<option value="added">Added by hand</option>
<option value="">Not given</option>
</select></label>
</div>
<label>Careers page
<input type="url" id="cf-url" pattern="https?://.+" placeholder="https://acme.com/careers" spellcheck="false">
<span class="hint">The page with its roles, which the row links to.</span></label>
<label>Note <textarea id="cf-notes" rows="3" placeholder="Where the roles are, what to search for"></textarea></label>
<div class="agent-actions">
<button type="submit">Save</button>
<button type="button" id="cf-cancel" class="secondary">Cancel</button>
</div>
</form>
</template>
{% endblock %}
{% block scripts %}
+16
View File
@@ -15,6 +15,7 @@ from fastapi.testclient import TestClient
from app.config import Config, ServerConfig
from app.main import create_app
from app.models import HAND_REASONS
from app.storage import Store
from desk.models import Item
@@ -96,6 +97,21 @@ def test_the_watchlist_is_the_third_tab_and_a_shell(client: TestClient) -> None:
assert nav.count('aria-current="page"') == 1
def test_the_watchlist_has_new_company_and_the_form_it_opens(client: TestClient) -> None:
page = client.get("/watchlist").text
assert '<button type="button" id="w-add">New company</button>' in page
assert 'id="watchlist-answer"' in page
template = page.split('<template id="company-form-template">', 1)[1].split("</template>", 1)[0]
for part in ('id="company-form"', 'id="cf-name" required', 'type="url" id="cf-url"',
'id="cf-reason"', 'id="cf-notes"', 'id="cf-cancel"', 'type="submit"'):
assert part in template, part
# The reason's options are the store's reasons, since a row's badge reads
# its words off them and a PATCH sends their values.
options = template.split('<select id="cf-reason">', 1)[1].split("</select>", 1)[0]
values = [v.split('"', 1)[0] for v in options.split('<option value="')[1:]]
assert sorted(values) == sorted(HAND_REASONS)
def test_the_read_page_of_its_own_is_gone(client: TestClient) -> None:
assert client.get("/static/role.js").status_code == 404
other = client.get("/applications").text