Open the job board form in place of its row, and add Platsbanken to it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-09-29 16:11:59 +02:00
1 parent b6afe24eaa
commit 6c63139343
2 files changed
+125 -56

No files matched your search

+102 -49
View File
@@ -1,8 +1,13 @@
/* 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
* Jobindex, Adzuna or Platsbanken. The UI says "job board" for what the API and the CLI
* call a search (`/api/searches`, `app searches`); company boards are
* companies.js's section, since a board is a company's own, not a query's.
*
* Edit turns a row into the form from the page's `<template>`, in place, and
* New job board puts a blank form on top of the list, as agents.js does for
* its cards. One form is open at a time, so its ids stay unique; Save and
* Cancel put it away.
*
* 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
@@ -19,6 +24,13 @@
/** @type {{searches: object[], adzuna_key: boolean}} */
let data = { searches: [], adzuna_key: false };
const NEW = "new";
/** @type {number | "new" | null} the row in edit mode: a source's id, NEW
* for the blank form on top, null for none */
let editing = null;
/** @type {HTMLFormElement | null} that form, kept across renders so a
* switch flipped on another row does not wipe what is being typed */
let editor = null;
/** "DK 120 · EU 4 · unknown 2", the three biggest. */
function countries(source) {
@@ -70,7 +82,12 @@
function renderSearches() {
const body = $("#searches-list");
body.replaceChildren();
if (editing === NEW) body.appendChild(editor);
for (const source of data.searches) {
if (editing === source.id) {
body.appendChild(editor);
continue;
}
const row = document.createElement("div");
row.className = "srow";
if (!source.on) row.dataset.muted = "true";
@@ -96,7 +113,7 @@
edit.type = "button";
edit.className = "linky";
edit.textContent = "Edit";
edit.addEventListener("click", () => fillSearchForm(source));
edit.addEventListener("click", () => openForm(source));
const remove = document.createElement("button");
remove.type = "button";
remove.className = "linky";
@@ -110,44 +127,76 @@
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.";
: "No job boards yet. New job board adds one; 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]")) {
function showProvider(f) {
const provider = $("#s-provider", f).value;
for (const node of f.querySelectorAll("[data-provider]")) {
node.hidden = node.dataset.provider !== provider;
}
$("#adzuna-key").hidden = provider !== "adzuna" || data.adzuna_key;
$("#adzuna-key", f).hidden = provider !== "adzuna" || data.adzuna_key;
}
function fillSearchForm(source) {
function form(source) {
const f = $("#search-form-template").content.querySelector("form").cloneNode(true);
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" });
$("#search-form-title", f).textContent = source ? `Edit ${source.label}` : "New job board";
$("#s-provider", f).value = source ? source.provider : "jobindex";
$("#s-name", f).value = source ? source.label : "";
$("#s-name", f).readOnly = Boolean(source);
$("#s-provider", f).disabled = Boolean(source);
$("#s-q", f).value = p.q || "";
$("#s-area", f).value = String(p.area || (source ? 0 : 1));
$("#s-country", f).value = p.country || "de";
$("#s-where", f).value = p.where || "";
$("#s-region", f).value = p.region || "";
$("#s-pages", f).value = String(p.pages || 10);
showProvider(f);
f.addEventListener("input", () => { f.dataset.dirty = "true"; });
$("#s-provider", f).addEventListener("change", () => showProvider(f));
$("#s-try", f).addEventListener("click", () => trySearch(f));
$("#s-cancel", f).addEventListener("click", () => { if (close()) renderSearches(); });
f.addEventListener("submit", saveSearch);
return f;
}
function searchBody() {
// 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 job board?")) {
return false;
}
editing = null;
editor = null;
return true;
}
// Edit `source` in place of its row, or a new job board on top of the list.
function openForm(source) {
const target = source ? source.id : NEW;
if (editing !== target) {
if (!close()) return;
editing = target;
editor = form(source);
$("#searches-answer").textContent = "";
renderSearches();
}
editor.scrollIntoView({ behavior: "smooth", block: "nearest" });
$("#s-q", editor).focus({ preventScroll: true });
}
function searchBody(f) {
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,
provider: $("#s-provider", f).value,
name: $("#s-name", f).value.trim(),
q: $("#s-q", f).value.trim(),
area: Number($("#s-area", f).value) || 0,
country: $("#s-country", f).value,
where: $("#s-where", f).value.trim(),
region: $("#s-region", f).value,
pages: Number($("#s-pages", f).value) || 0,
};
}
@@ -156,16 +205,16 @@
return `Found ${count(result.found, "role")} (${all}).`;
}
async function trySearch() {
const status = $("#search-status");
const button = $("#s-try");
async function trySearch(f) {
const status = $("#search-status", f);
const button = $("#s-try", f);
button.disabled = true;
status.textContent = "Searching…";
$("#search-sample").replaceChildren();
$("#search-sample", f).replaceChildren();
try {
const result = await api("/api/searches/try", { method: "POST", body: searchBody() });
const result = await api("/api/searches/try", { method: "POST", body: searchBody(f) });
status.textContent = `${found(result)} The newest ${Math.min(result.found, 10)}:`;
const list = $("#search-sample");
const list = $("#search-sample", f);
for (const row of result.sample) {
const li = document.createElement("li");
const url = safeUrl(row.url);
@@ -190,21 +239,25 @@
async function saveSearch(event) {
event.preventDefault();
const status = $("#search-status");
const button = $("#search-form button[type=submit]");
const f = event.target;
const status = $("#search-status", f);
const button = $("button[type=submit]", f);
button.disabled = true;
status.textContent = "Running it once before saving…";
let result;
try {
const result = await api("/api/searches", { method: "POST", body: searchBody() });
result = await api("/api/searches", { method: "POST", body: searchBody(f) });
await load();
renderSearches();
fillSearchForm(null);
status.textContent = `Saved ${result.source.label}. ${found(result)} `
+ "Reading now, or with the pull right after.";
} catch (err) {
status.textContent = "";
button.disabled = false;
return;
}
button.disabled = false;
editing = null;
editor = null;
renderSearches();
$("#searches-answer").textContent = `Saved ${result.source.label}. ${found(result)} `
+ "Reading now, or with the pull right after.";
}
async function removeSearch(source) {
@@ -214,6 +267,10 @@
try {
await api(`/api/searches/${source.id}`, { method: "DELETE" });
data.searches = data.searches.filter((s) => s.id !== source.id);
if (editing === source.id) {
editing = null;
editor = null;
}
renderSearches();
} catch (err) {
/* already toasted */
@@ -266,10 +323,6 @@
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));
$("#s-add").addEventListener("click", () => openForm(null));
});
})();
+23 -7
View File
@@ -14,10 +14,22 @@
<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>
{# The Job boards form is a `<template>` because only one edits at a time, so
its ids stay unique: sources.js puts it in place of a row on Edit, and on
top of the list on New, as agents.js does for the Search agents cards. #}
<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>
<p class="lede">A query on Jobindex, Adzuna or Platsbanken finds roles at any company. Switching one off closes its roles until you switch it back on.</p>
<div class="agents-head">
<p id="searches-count" class="count" role="status"></p>
<button type="button" id="s-add">New job board</button>
</div>
<p id="searches-answer" class="count" role="status"></p>
<div id="searches-list" class="srows"></div>
</section>
<template id="search-form-template">
<form id="search-form" class="agent-form source-form" autocomplete="off">
<h3 id="search-form-title">New job board</h3>
<div class="form-row">
@@ -25,13 +37,15 @@
<select id="s-provider">
<option value="jobindex">Jobindex (Denmark)</option>
<option value="adzuna">Adzuna (UK and EU)</option>
<option value="platsbanken">Platsbanken (Sweden)</option>
</select></label>
<label>Name <input type="text" id="s-name" required placeholder="Copenhagen backend"></label>
</div>
<label>Query
<input type="text" id="s-q" required spellcheck="false">
<span class="hint" data-provider="jobindex">Jobindex syntax: words are OR, <code>"a b"</code> is a phrase, <code>+word</code> is required.</span>
<span class="hint" data-provider="adzuna" hidden>Every word must appear.</span></label>
<span class="hint" data-provider="adzuna" hidden>Every word must appear.</span>
<span class="hint" data-provider="platsbanken" hidden>Free text; every word counts towards the match.</span></label>
<div class="form-row">
<label data-provider="jobindex">Area
<select id="s-area">
@@ -42,6 +56,11 @@
{% for value, label in countries %}<option value="{{ value }}">{{ label }}</option>{% endfor %}
</select></label>
<label data-provider="adzuna" hidden>Place <input type="text" id="s-where" placeholder="Berlin"></label>
<label data-provider="platsbanken" hidden>Region
<select id="s-region">
<option value="">All of Sweden</option>
{% for value, label in regions %}<option value="{{ value }}">{{ label }}</option>{% endfor %}
</select></label>
<label>Pages
<input type="number" id="s-pages" min="1" max="10" value="10">
<span class="hint">per pull, up to 10</span></label>
@@ -50,15 +69,12 @@
<div class="agent-actions">
<button type="button" id="s-try" class="secondary">Try it</button>
<button type="submit">Save</button>
<button type="button" id="s-new" class="secondary">New</button>
<button type="button" id="s-cancel" class="secondary">Cancel</button>
</div>
<p id="search-status" class="count" role="status"></p>
<ol id="search-sample" class="sample"></ol>
</form>
<p id="searches-count" class="count" role="status"></p>
<div id="searches-list" class="srows"></div>
</section>
</template>
<section class="card" id="company-boards" data-section>
<h2>Company boards</h2>