Wire the app like the boilerplate: door, queue, schedules, eight tabs
app/main.py assembles it in the boilerplate's order, auth.connect first, then the queue with the scheduler and the pages. TABS is Roles, Applications, Agents, Companies, Jobs, Schedules, Messages and Account: the alpha page's three views become templates on the boilerplate's base.html, driven by static/roles.js (the old app.js) through api() and toasts.js, over the unchanged JSON routes. Companies lists every board with its open roles and the affinity control. A 422 is one sentence, so a toast never reads [object Object]. Config takes the boilerplate's shape: APP_CONFIG or config.yaml, a missing file is the defaults, an unknown key is an error. roles.yaml is gone; config.yaml is the committed default and carries the starter agents. pull is now a job that asks for the pull cascade, because a schedule enqueues a job kind; its default schedule, every 6h, is declared beside it in app/jobs/cascade.py. pull_batch's targets are keyword-only so the Jobs tab offers no batch button. `app worker` is the boilerplate's; `app job` still drains a queue of its own and fires no schedules. test_coupling holds pipeline, auth and desk apart (desk may import pipeline) and plugins to desk; test_architecture keeps app's layers, now with main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
24508dd6fc
commit
59a301c351
42 files changed
+2407
-998
No files matched your search
+7
-3
@@ -1,7 +1,11 @@
|
||||
"""The web face. One door: `create_app` and `serve`."""
|
||||
"""The web face: the tabs, the JSON routes behind them, and the Jinja
|
||||
environment. The queue brings its own routes and elements (`pipeline.web`),
|
||||
auth the login page and `<auth-account>` (`auth`); `app.main` puts them
|
||||
together. One door for all of it."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.web.app import create_app, serve
|
||||
from app.web.api import router as api_router
|
||||
from app.web.pages import STATIC_DIR, TABS, router as pages_router, templates
|
||||
|
||||
__all__ = ["create_app", "serve"]
|
||||
__all__ = ["STATIC_DIR", "TABS", "api_router", "pages_router", "templates"]
|
||||
+5
-3
@@ -1,7 +1,9 @@
|
||||
"""The JSON routes the page uses: roles, companies, applications, agents.
|
||||
"""The JSON routes the tabs use: roles, companies, applications, agents.
|
||||
|
||||
`/api/jobs*`, `/_jobs/jobs.js` and `/ws/jobs` are `pipeline.web`'s, mounted by
|
||||
`connect` in `app.py`. This is roledesk's own API, over the same store.
|
||||
`/api/jobs*`, `/api/schedules*`, `/api/notices` and `/ws/jobs` are
|
||||
`pipeline.web`'s and `/api/account*` is `auth`'s, both wired in `app/main.py`.
|
||||
This is roledesk's own API, over the same store. Every refusal is
|
||||
`{"detail": "<sentence>"}`, which `api()` in `static/app.js` turns into a toast.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
"""The application factory: the queue's routes and socket from
|
||||
`pipeline.web.connect`, roledesk's own JSON API, and the one page."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from pipeline import Jobs
|
||||
from pipeline.web import connect
|
||||
from app import config as config_mod
|
||||
from app import jobs
|
||||
from app.storage import Store
|
||||
from app.web.api import router as api_router
|
||||
from app.web.pages import router as pages_router
|
||||
|
||||
WEB = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def create_app(config_path: str | None = None) -> FastAPI:
|
||||
config = config_mod.load(config_path)
|
||||
# `Store` first, so the file is at the current schema before the queue
|
||||
# adds its own table to it.
|
||||
store = Store(config.database)
|
||||
jobs.seed_agents(config, store)
|
||||
app = FastAPI(title="roledesk", docs_url="/api/docs")
|
||||
connect(app, Jobs(config.database), config, store,
|
||||
workers=config.workers.model_dump(),
|
||||
bootstrap=jobs.BOOTSTRAP, bootstrap_arg=config.path or "")
|
||||
app.state.config = config
|
||||
app.state.store = store
|
||||
app.include_router(api_router)
|
||||
app.include_router(pages_router)
|
||||
app.mount("/static", StaticFiles(directory=WEB / "static"), name="static")
|
||||
return app
|
||||
|
||||
|
||||
def serve(host: str, port: int, config_path: str | None) -> int:
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(create_app(config_path), host=host, port=port)
|
||||
return 0
|
||||
+99
-19
@@ -1,17 +1,24 @@
|
||||
"""The one page. Everything under `/api` and `/_jobs` is JSON; this route
|
||||
hands the browser an empty shell — the filter bar, the section headers, the
|
||||
`<select>` options a plugin's vocabulary decides — and `static/app.js` fills
|
||||
it and drives every action from there.
|
||||
"""The tabs: eight pages, declared once.
|
||||
|
||||
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are
|
||||
the classifier's vocabulary, and this reaches `plugins/` the same way
|
||||
`app.cli` already does, since a plugin is app-agnostic and never reaches
|
||||
back into `app`.
|
||||
`TABS` is the whole navigation. `base.html` renders it, every page marks
|
||||
itself active by its own `path`, and adding a tab is one entry here plus one
|
||||
template.
|
||||
|
||||
Every page is a shell. Roles, Applications, Agents and Companies are filled
|
||||
and driven by `static/roles.js` from the JSON routes in `web/api.py`; Jobs,
|
||||
Schedules and Account are shells around the modules' own elements. What the
|
||||
server renders is only what a select needs to offer, so the options cannot
|
||||
drift from what the store accepts.
|
||||
|
||||
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are the
|
||||
classifier's vocabulary, and this reaches `plugins/` the same way `app.cli`
|
||||
does, since a plugin is app-agnostic and never reaches back into `app`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, Request
|
||||
@@ -26,22 +33,95 @@ if str(_ROOT) not in sys.path:
|
||||
|
||||
from plugins.ats import FUNCTIONS # noqa: E402
|
||||
|
||||
WEB = Path(__file__).resolve().parent
|
||||
templates = Jinja2Templates(directory=WEB / "templates")
|
||||
TEMPLATE_DIR = Path(__file__).resolve().parent.parent / "templates"
|
||||
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
||||
|
||||
router = APIRouter(tags=["pages"])
|
||||
|
||||
#: `value, label` for each function select option. `FUNCTIONS` is already the
|
||||
#: value a role's `function` column holds; only the label is dressed up.
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class Tab:
|
||||
path: str
|
||||
label: str
|
||||
template: str
|
||||
|
||||
|
||||
#: The navigation, in order. One list; `base.html` is its only reader.
|
||||
TABS: tuple[Tab, ...] = (
|
||||
Tab("/", "Roles", "roles.html"),
|
||||
Tab("/applications", "Applications", "applications.html"),
|
||||
Tab("/agents", "Agents", "agents.html"),
|
||||
Tab("/companies", "Companies", "companies.html"),
|
||||
Tab("/jobs", "Jobs", "jobs.html"),
|
||||
Tab("/schedules", "Schedules", "schedules.html"),
|
||||
Tab("/messages", "Messages", "messages.html"),
|
||||
Tab("/account", "Account", "account.html"),
|
||||
)
|
||||
|
||||
#: `value, label` for each select option. `FUNCTIONS` is already the value a
|
||||
#: role's `function` column holds; only the label is dressed up.
|
||||
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
|
||||
REMOTE_OPTIONS = [(r, r.capitalize()) for r in REMOTE if r]
|
||||
STATUS_OPTIONS = [(s, s.capitalize()) for s in STATUSES]
|
||||
|
||||
|
||||
def asset(path: str) -> str:
|
||||
"""A static URL stamped with the file's modification time, so a changed
|
||||
file is a different URL and a cached stale copy is never the answer."""
|
||||
name = path.lstrip("/")
|
||||
try:
|
||||
stamp = int((STATIC_DIR / name).stat().st_mtime)
|
||||
except OSError:
|
||||
return f"/static/{name}"
|
||||
return f"/static/{name}?v={stamp}"
|
||||
|
||||
|
||||
templates = Jinja2Templates(directory=str(TEMPLATE_DIR))
|
||||
templates.env.globals["TABS"] = TABS
|
||||
templates.env.globals["asset"] = asset
|
||||
|
||||
#: Out of the OpenAPI schema: these are pages.
|
||||
router = APIRouter(include_in_schema=False)
|
||||
|
||||
|
||||
def page(request: Request, name: str, **context: object) -> HTMLResponse:
|
||||
return templates.TemplateResponse(request, name, context)
|
||||
|
||||
|
||||
@router.get("/", response_class=HTMLResponse)
|
||||
def index(request: Request) -> HTMLResponse:
|
||||
return templates.TemplateResponse(request, "index.html", {
|
||||
"functions": FUNCTION_OPTIONS,
|
||||
"remote_options": REMOTE_OPTIONS,
|
||||
"status_options": STATUS_OPTIONS,
|
||||
})
|
||||
def roles(request: Request) -> HTMLResponse:
|
||||
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
|
||||
remote_options=REMOTE_OPTIONS)
|
||||
|
||||
|
||||
@router.get("/applications", response_class=HTMLResponse)
|
||||
def applications(request: Request) -> HTMLResponse:
|
||||
return page(request, "applications.html", status_options=STATUS_OPTIONS)
|
||||
|
||||
|
||||
@router.get("/agents", response_class=HTMLResponse)
|
||||
def agents(request: Request) -> HTMLResponse:
|
||||
return page(request, "agents.html")
|
||||
|
||||
|
||||
@router.get("/companies", response_class=HTMLResponse)
|
||||
def companies(request: Request) -> HTMLResponse:
|
||||
return page(request, "companies.html")
|
||||
|
||||
|
||||
@router.get("/jobs", response_class=HTMLResponse)
|
||||
def jobs(request: Request) -> HTMLResponse:
|
||||
return page(request, "jobs.html")
|
||||
|
||||
|
||||
@router.get("/schedules", response_class=HTMLResponse)
|
||||
def schedules(request: Request) -> HTMLResponse:
|
||||
return page(request, "schedules.html")
|
||||
|
||||
|
||||
@router.get("/messages", response_class=HTMLResponse)
|
||||
def messages(request: Request) -> HTMLResponse:
|
||||
return page(request, "messages.html")
|
||||
|
||||
|
||||
@router.get("/account", response_class=HTMLResponse)
|
||||
def account(request: Request) -> HTMLResponse:
|
||||
return page(request, "account.html")
|
||||
@@ -1,227 +0,0 @@
|
||||
/* roledesk — an alpha to look at real ads, not the final reader. The palette
|
||||
and type stack borrow newsdesk's visual language (news/newsdesk/web/static
|
||||
/app.css): a quiet UI face and a teal signal colour, nothing ported beyond
|
||||
that — no reader, no auth, no passkeys. */
|
||||
|
||||
:root {
|
||||
--bg: #eceff1;
|
||||
--panel: #ffffff;
|
||||
--ink: #1a2027;
|
||||
--muted: #505c67;
|
||||
--faint: #6d7883;
|
||||
--rule: #d6dbdf;
|
||||
--signal: #14655b;
|
||||
--signal-weak: #a9c4bf;
|
||||
--mute: #96382c;
|
||||
--focus: #1b4f8f;
|
||||
|
||||
--ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto,
|
||||
"Helvetica Neue", Arial, sans-serif;
|
||||
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--bg: #14181c;
|
||||
--panel: #1b2126;
|
||||
--ink: #e3e7ea;
|
||||
--muted: #a8b2ba;
|
||||
--faint: #8b959d;
|
||||
--rule: #2a3238;
|
||||
--signal: #4fb3a3;
|
||||
--signal-weak: #35544f;
|
||||
--mute: #cd6a5b;
|
||||
--focus: #6ea8e8;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body { max-width: 100%; overflow-x: hidden; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
font-family: var(--ui);
|
||||
line-height: 1.45;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
button, input, select { font: inherit; color: inherit; }
|
||||
|
||||
a { color: var(--signal); }
|
||||
|
||||
/* ---------------------------------------------------------------- chrome */
|
||||
|
||||
header {
|
||||
position: sticky; top: 0; z-index: 10;
|
||||
display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
|
||||
padding: .7rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.wordmark { font-weight: 640; letter-spacing: -.01em; font-size: 1.1rem; }
|
||||
.wordmark span { color: var(--signal); }
|
||||
|
||||
.tabs { display: flex; gap: .25rem; }
|
||||
|
||||
.tab {
|
||||
background: none; border: 1px solid transparent; border-radius: .3rem;
|
||||
padding: .35rem .75rem; cursor: pointer; color: var(--muted);
|
||||
}
|
||||
.tab[aria-pressed="true"] { color: var(--ink); background: var(--bg); border-color: var(--rule); }
|
||||
|
||||
/* --------------------------------------------------------------- filters */
|
||||
|
||||
.filters {
|
||||
display: flex; flex-wrap: wrap; gap: .5rem;
|
||||
padding: .75rem 1rem;
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--rule);
|
||||
}
|
||||
|
||||
.filters input[type="search"], .filters input[type="text"], .filters select {
|
||||
padding: .4rem .55rem;
|
||||
border: 1px solid var(--rule); border-radius: .3rem;
|
||||
background: var(--bg); color: var(--ink);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.filters input[type="search"] { flex: 1 1 12rem; }
|
||||
.filters input[type="text"] { flex: 1 1 8rem; }
|
||||
|
||||
.show-muted {
|
||||
display: flex; align-items: center; gap: .35rem;
|
||||
color: var(--muted); font-size: .9rem; white-space: nowrap;
|
||||
}
|
||||
|
||||
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
|
||||
outline: 2px solid var(--focus); outline-offset: 1px;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ views */
|
||||
|
||||
.view { padding: 0 1rem 1.5rem; }
|
||||
|
||||
.count { color: var(--faint); font-size: .85rem; margin: .75rem 0 .5rem; }
|
||||
|
||||
/* ------------------------------------------------------------------- roles */
|
||||
|
||||
.roles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
|
||||
|
||||
.role {
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: .5rem;
|
||||
padding: .6rem .8rem;
|
||||
display: flex; flex-direction: column; gap: .35rem;
|
||||
}
|
||||
|
||||
.role-main {
|
||||
display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem;
|
||||
}
|
||||
|
||||
.role-title { font-weight: 600; text-decoration: none; }
|
||||
.role-title:hover { text-decoration: underline; }
|
||||
|
||||
.role-company { color: var(--muted); }
|
||||
|
||||
.role-meta {
|
||||
display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
|
||||
color: var(--faint); font-size: .85rem;
|
||||
}
|
||||
|
||||
.badge {
|
||||
border: 1px solid var(--rule); border-radius: 1rem;
|
||||
padding: .05rem .55rem; font-size: .78rem;
|
||||
}
|
||||
.role-remote.badge:empty, .role-function.badge:empty { display: none; }
|
||||
|
||||
.role-age { margin-left: auto; }
|
||||
|
||||
.affinity { display: inline-flex; gap: .15rem; margin-left: auto; }
|
||||
.affinity button {
|
||||
background: none; border: 1px solid var(--rule); border-radius: .3rem;
|
||||
padding: .1rem .4rem; cursor: pointer; color: var(--muted); font-size: .85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.affinity button[aria-pressed="true"] { color: #fff; background: var(--signal); border-color: var(--signal); }
|
||||
.affinity button[data-value="-1"][aria-pressed="true"] { background: var(--mute); border-color: var(--mute); }
|
||||
|
||||
.save {
|
||||
align-self: flex-start;
|
||||
background: var(--signal); color: #fff; border: 1px solid var(--signal);
|
||||
border-radius: .3rem; padding: .3rem .8rem; cursor: pointer; font-weight: 600;
|
||||
}
|
||||
.save[disabled] {
|
||||
background: var(--bg); color: var(--muted); border-color: var(--rule); cursor: default;
|
||||
}
|
||||
|
||||
.role.muted { opacity: .55; }
|
||||
.role.gated { opacity: .7; }
|
||||
.show-muted[hidden] { display: none; }
|
||||
.role-score.badge:empty { display: none; }
|
||||
.role-score.badge { color: var(--signal); border-color: var(--signal-weak); font-variant-numeric: tabular-nums; }
|
||||
.role-gated { color: var(--mute); font-size: .85rem; }
|
||||
|
||||
/* ---------------------------------------------------------------- agents */
|
||||
|
||||
.agents { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
|
||||
.agent {
|
||||
display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .5rem .75rem;
|
||||
}
|
||||
.agent-meta { color: var(--faint); font-size: .85rem; flex: 1 1 12rem; }
|
||||
.agent-form {
|
||||
display: flex; flex-direction: column; gap: .6rem; max-width: 44rem;
|
||||
background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: .75rem 1rem;
|
||||
}
|
||||
.agent-form h2 { 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"] {
|
||||
font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--rule);
|
||||
border-radius: 4px; padding: .35rem .5rem; width: 100%;
|
||||
}
|
||||
.agent-form textarea { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85rem; }
|
||||
.agent-form .hint { color: var(--faint); font-size: .8rem; overflow-wrap: anywhere; }
|
||||
.weights { display: flex; gap: .75rem; flex-wrap: wrap; border: 1px solid var(--rule); border-radius: 4px; }
|
||||
.weights label { flex: 1 1 6rem; }
|
||||
.agent-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
|
||||
.agent-actions button, .agent button {
|
||||
background: var(--bg); border: 1px solid var(--rule); border-radius: 4px; padding: .3rem .8rem; cursor: pointer;
|
||||
}
|
||||
.agent-actions button.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
|
||||
|
||||
/* ------------------------------------------------------------ applications */
|
||||
|
||||
.applications { width: 100%; border-collapse: collapse; background: var(--panel); }
|
||||
.applications th, .applications td {
|
||||
text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--rule);
|
||||
font-size: .9rem;
|
||||
}
|
||||
.applications select { padding: .25rem .4rem; }
|
||||
|
||||
/* Below tablet width, a table stops being a table: each row becomes a card,
|
||||
its cells stacked, so nothing scrolls sideways to be read. */
|
||||
@media (max-width: 640px) {
|
||||
.applications thead { display: none; }
|
||||
.applications, .applications tbody, .applications tr, .applications td { display: block; width: 100%; }
|
||||
.applications tr { margin-bottom: .6rem; border: 1px solid var(--rule); border-radius: .4rem; }
|
||||
.applications td { border-bottom: none; }
|
||||
.applications td::before {
|
||||
content: attr(data-label);
|
||||
display: block; font-size: .72rem; color: var(--faint); margin-bottom: .1rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------- jobs */
|
||||
|
||||
#jobs { padding: 1rem; border-top: 1px solid var(--rule); }
|
||||
#jobs h2 { font-size: .95rem; color: var(--muted); margin: 0 0 .6rem; }
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.role-age { margin-left: 0; }
|
||||
.affinity { margin-left: 0; }
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
// roledesk's page: the filter bar, the role list, the tracker, the search
|
||||
// agents, and the tab switch between them. The template renders an empty shell (see index.html);
|
||||
// everything on screen comes from the API, and every action — Save, an
|
||||
// affinity click, a status change — is a fetch from here, not a form post.
|
||||
"use strict";
|
||||
|
||||
const ROLES_URL = "/api/roles";
|
||||
|
||||
/** @type {Map<string, object>} company_key -> company row from /api/companies */
|
||||
let companies = new Map();
|
||||
/** @type {Map<string, object>} role_uid -> application row, for roles that are already tracked */
|
||||
let trackedByRole = new Map();
|
||||
/** @type {object[]} the last /api/roles response, already muted-filtered by the server */
|
||||
let roles = [];
|
||||
/** @type {object[]} every search agent, from /api/agents */
|
||||
let agents = [];
|
||||
|
||||
const $ = (sel, root = document) => root.querySelector(sel);
|
||||
const $$ = (sel, root = document) => Array.from(root.querySelectorAll(sel));
|
||||
|
||||
function debounce(fn, ms) {
|
||||
let timer;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => fn(...args), ms);
|
||||
};
|
||||
}
|
||||
|
||||
async function api(path, options) {
|
||||
const res = await fetch(path, options);
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => ({}));
|
||||
throw new Error(body.detail || `${path}: ${res.status}`);
|
||||
}
|
||||
return res.status === 204 ? null : res.json();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ tabs
|
||||
|
||||
function initTabs() {
|
||||
$$(".tab").forEach((tab) => {
|
||||
tab.addEventListener("click", () => {
|
||||
$$(".tab").forEach((t) => t.setAttribute("aria-pressed", String(t === tab)));
|
||||
const name = tab.dataset.tab;
|
||||
$("#roles-view").hidden = name !== "roles";
|
||||
$("#applications-view").hidden = name !== "applications";
|
||||
$("#agents-view").hidden = name !== "agents";
|
||||
if (name === "applications") loadApplications();
|
||||
if (name === "agents") loadAgents();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- roles
|
||||
|
||||
function filterParams() {
|
||||
const params = new URLSearchParams();
|
||||
const q = $("#f-q").value.trim();
|
||||
const company = $("#f-company").value.trim();
|
||||
const place = $("#f-place").value.trim();
|
||||
const fn = $("#f-function").value;
|
||||
const remote = $("#f-remote").value;
|
||||
const days = $("#f-days").value;
|
||||
if (q) params.set("q", q);
|
||||
if (company) params.set("company", company);
|
||||
if (place) params.set("place", place);
|
||||
if (fn) params.set("function", fn);
|
||||
if (remote) params.set("remote", remote);
|
||||
if (days) params.set("days", days);
|
||||
if ($("#f-show-muted").checked) params.set("show_muted", "true");
|
||||
const agent = $("#f-agent").value;
|
||||
if (agent) {
|
||||
params.set("agent", agent);
|
||||
if ($("#f-gated").checked) params.set("gated", "1");
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
async function loadRoles() {
|
||||
const params = filterParams();
|
||||
roles = await api(`${ROLES_URL}?${params.toString()}`);
|
||||
renderRoles();
|
||||
}
|
||||
|
||||
function relativeAge(iso) {
|
||||
const then = new Date(iso);
|
||||
const minutes = Math.max(0, Math.floor((Date.now() - then.getTime()) / 60000));
|
||||
if (minutes < 60) return `${minutes} min ago`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} h ago`;
|
||||
const days = Math.floor(hours / 24);
|
||||
return `${days} d ago`;
|
||||
}
|
||||
|
||||
function renderRoles() {
|
||||
const list = $("#roles-list");
|
||||
const template = $("#role-row");
|
||||
list.replaceChildren();
|
||||
|
||||
for (const role of roles) {
|
||||
const node = template.content.cloneNode(true);
|
||||
const li = node.querySelector(".role");
|
||||
const company = companies.get(role.company_key);
|
||||
|
||||
if (company && company.affinity === -1) li.classList.add("muted");
|
||||
|
||||
const titleLink = node.querySelector(".role-title");
|
||||
titleLink.textContent = role.title || "(untitled)";
|
||||
titleLink.href = role.original_url || "#";
|
||||
|
||||
node.querySelector(".role-company").textContent = role.company || "";
|
||||
node.querySelector(".role-place").textContent = role.place || "";
|
||||
node.querySelector(".role-remote").textContent = role.remote || "";
|
||||
node.querySelector(".role-function").textContent = role.function || "";
|
||||
node.querySelector(".role-age").textContent = relativeAge(role.first_seen);
|
||||
if (role.score !== null && role.score !== undefined) {
|
||||
const badge = node.querySelector(".role-score");
|
||||
badge.textContent = role.gated_reason ? "gated" : role.score.toFixed(2);
|
||||
badge.title = "Score for the selected agent";
|
||||
node.querySelector(".role-gated").textContent = role.gated_reason || "";
|
||||
if (role.gated_reason) li.classList.add("gated");
|
||||
}
|
||||
|
||||
node.querySelector(".affinity").replaceWith(
|
||||
affinityControl(role.company_key, company ? company.affinity : 0));
|
||||
|
||||
const saveButton = node.querySelector(".save");
|
||||
setSaveButton(saveButton, role.uid);
|
||||
saveButton.addEventListener("click", () => saveRole(role.uid, saveButton));
|
||||
|
||||
list.appendChild(node);
|
||||
}
|
||||
|
||||
$("#roles-count").textContent = `${roles.length} role${roles.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function setSaveButton(button, uid) {
|
||||
const saved = trackedByRole.has(uid);
|
||||
button.textContent = saved ? "Saved" : "Save";
|
||||
button.disabled = saved;
|
||||
}
|
||||
|
||||
async function saveRole(uid, button) {
|
||||
button.disabled = true;
|
||||
button.textContent = "Saving…";
|
||||
try {
|
||||
const application = await api("/api/applications", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ role_uid: uid, status: "saved" }),
|
||||
});
|
||||
trackedByRole.set(uid, application);
|
||||
setSaveButton(button, uid);
|
||||
} catch (err) {
|
||||
button.disabled = false;
|
||||
button.textContent = "Save";
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- affinity
|
||||
|
||||
const AFFINITY_LEVELS = [
|
||||
{ value: -1, label: "Mute" },
|
||||
{ value: 0, label: "Neutral" },
|
||||
{ value: 1, label: "Like" },
|
||||
{ value: 2, label: "Favourite" },
|
||||
];
|
||||
|
||||
function affinityControl(companyKey, current) {
|
||||
const span = document.createElement("span");
|
||||
span.className = "affinity";
|
||||
span.setAttribute("role", "group");
|
||||
span.setAttribute("aria-label", "Company affinity");
|
||||
for (const level of AFFINITY_LEVELS) {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.dataset.value = String(level.value);
|
||||
button.textContent = level.label[0];
|
||||
button.title = level.label;
|
||||
button.setAttribute("aria-label", level.label);
|
||||
button.setAttribute("aria-pressed", String(level.value === current));
|
||||
button.addEventListener("click", () => setAffinity(companyKey, level.value));
|
||||
span.appendChild(button);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
async function setAffinity(companyKey, affinity) {
|
||||
if (!companyKey) return;
|
||||
try {
|
||||
const updated = await api(`/api/companies/${encodeURIComponent(companyKey)}/affinity`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ affinity }),
|
||||
});
|
||||
const company = companies.get(companyKey);
|
||||
if (company) company.affinity = updated.affinity;
|
||||
// Muting or unmuting changes which roles the server hands back, so the
|
||||
// list is refetched rather than just re-rendered from what is on hand.
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ applications
|
||||
|
||||
// `ROLEDESK_STATUSES` is set by index.html from the same `STATUSES` tuple
|
||||
// the store validates against, so this list can never drift from what a
|
||||
// `POST .../status` will actually accept.
|
||||
function statusSelect(current) {
|
||||
const select = document.createElement("select");
|
||||
for (const status of window.ROLEDESK_STATUSES) {
|
||||
const option = document.createElement("option");
|
||||
option.value = status;
|
||||
option.textContent = status[0].toUpperCase() + status.slice(1);
|
||||
option.selected = status === current;
|
||||
select.appendChild(option);
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
async function loadApplications() {
|
||||
const applications = await api("/api/applications");
|
||||
trackedByRole = new Map(applications.filter((a) => a.role_uid).map((a) => [a.role_uid, a]));
|
||||
renderApplications(applications);
|
||||
}
|
||||
|
||||
function renderApplications(applications) {
|
||||
const body = $("#applications-list");
|
||||
body.replaceChildren();
|
||||
for (const application of applications) {
|
||||
const tr = document.createElement("tr");
|
||||
|
||||
const roleTd = document.createElement("td");
|
||||
roleTd.dataset.label = "Role";
|
||||
roleTd.textContent = application.role_title || "(untitled)";
|
||||
tr.appendChild(roleTd);
|
||||
|
||||
const companyTd = document.createElement("td");
|
||||
companyTd.dataset.label = "Company";
|
||||
const company = companies.get(application.company_key);
|
||||
companyTd.textContent = company ? company.name : application.company_key;
|
||||
tr.appendChild(companyTd);
|
||||
|
||||
const statusTd = document.createElement("td");
|
||||
statusTd.dataset.label = "Status";
|
||||
const select = statusSelect(application.status);
|
||||
select.addEventListener("change", () => setStatus(application.id, select.value));
|
||||
statusTd.appendChild(select);
|
||||
tr.appendChild(statusTd);
|
||||
|
||||
const nextTd = document.createElement("td");
|
||||
nextTd.dataset.label = "Next";
|
||||
nextTd.textContent = [application.next_action, application.next_date]
|
||||
.filter(Boolean).join(" · ");
|
||||
tr.appendChild(nextTd);
|
||||
|
||||
body.appendChild(tr);
|
||||
}
|
||||
$("#applications-count").textContent =
|
||||
`${applications.length} tracked application${applications.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
async function setStatus(id, status) {
|
||||
try {
|
||||
await api(`/api/applications/${encodeURIComponent(id)}/status`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
await loadApplications();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- agents
|
||||
|
||||
async function loadAgents() {
|
||||
agents = await api("/api/agents");
|
||||
renderAgentSelect();
|
||||
renderAgents();
|
||||
}
|
||||
|
||||
// The filter bar's order: "Newest", or one agent's score. Keeps the current
|
||||
// choice when the list is refreshed, unless that agent is gone.
|
||||
function renderAgentSelect() {
|
||||
const select = $("#f-agent");
|
||||
const current = select.value;
|
||||
select.replaceChildren(new Option("Newest", ""));
|
||||
for (const agent of agents) {
|
||||
const label = agent.enabled ? agent.name : `${agent.name} (off)`;
|
||||
select.appendChild(new Option(label, String(agent.id)));
|
||||
}
|
||||
select.value = agents.some((a) => String(a.id) === current) ? current : "";
|
||||
$("#show-gated").hidden = !select.value;
|
||||
}
|
||||
|
||||
function renderAgents() {
|
||||
const list = $("#agents-list");
|
||||
list.replaceChildren();
|
||||
for (const agent of agents) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "agent";
|
||||
const name = document.createElement("strong");
|
||||
name.textContent = agent.name;
|
||||
const meta = document.createElement("span");
|
||||
meta.className = "agent-meta";
|
||||
const gates = agent.gates.map((g) => `${g.mode} ${g.field}`).join(", ") || "no gates";
|
||||
meta.textContent = `${agent.enabled ? "" : "off · "}${gates}`;
|
||||
const edit = document.createElement("button");
|
||||
edit.type = "button";
|
||||
edit.textContent = "Edit";
|
||||
edit.addEventListener("click", () => fillAgentForm(agent));
|
||||
li.append(name, meta, edit);
|
||||
list.appendChild(li);
|
||||
}
|
||||
$("#agents-count").textContent = `${agents.length} agent${agents.length === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
function fillAgentForm(agent) {
|
||||
$("#agent-form-title").textContent = agent ? `Edit ${agent.name}` : "New agent";
|
||||
$("#a-id").value = agent ? String(agent.id) : "";
|
||||
$("#a-name").value = agent ? agent.name : "";
|
||||
$("#a-intent").value = agent ? agent.intent : "";
|
||||
$("#a-gates").value = JSON.stringify(agent ? agent.gates : [], null, 2);
|
||||
const weights = agent ? agent.weights : { fit: 0.6, recency: 0.2, affinity: 0.2 };
|
||||
$("#a-fit").value = weights.fit;
|
||||
$("#a-recency").value = weights.recency;
|
||||
$("#a-affinity").value = weights.affinity;
|
||||
$("#a-enabled").checked = agent ? agent.enabled : true;
|
||||
$("#a-delete").hidden = !agent;
|
||||
$("#agent-status").textContent = "";
|
||||
}
|
||||
|
||||
async function saveAgent(event) {
|
||||
event.preventDefault();
|
||||
const status = $("#agent-status");
|
||||
let gates;
|
||||
try {
|
||||
gates = JSON.parse($("#a-gates").value || "[]");
|
||||
} catch (err) {
|
||||
status.textContent = `Gates are not valid JSON: ${err.message}`;
|
||||
return;
|
||||
}
|
||||
const id = $("#a-id").value;
|
||||
const body = {
|
||||
name: $("#a-name").value.trim(),
|
||||
intent: $("#a-intent").value,
|
||||
gates,
|
||||
weights: {
|
||||
fit: Number($("#a-fit").value),
|
||||
recency: Number($("#a-recency").value),
|
||||
affinity: Number($("#a-affinity").value),
|
||||
},
|
||||
enabled: $("#a-enabled").checked,
|
||||
};
|
||||
if (id) body.id = Number(id);
|
||||
try {
|
||||
const saved = await api("/api/agents", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
await loadAgents();
|
||||
fillAgentForm(saved);
|
||||
await rescore(status);
|
||||
} catch (err) {
|
||||
status.textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteAgent() {
|
||||
const id = $("#a-id").value;
|
||||
if (!id || !confirm("Delete this agent and its scores?")) return;
|
||||
try {
|
||||
await api(`/api/agents/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
fillAgentForm(null);
|
||||
await loadAgents();
|
||||
await loadRoles();
|
||||
} catch (err) {
|
||||
$("#agent-status").textContent = err.message;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the `score` job and refetch the roles once it has finished, so the
|
||||
// order on the Roles tab is the saved agent's.
|
||||
async function rescore(status) {
|
||||
status.textContent = "Saved. Scoring…";
|
||||
const job = await api("/api/jobs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ kind: "score", payload: {} }),
|
||||
});
|
||||
for (let i = 0; i < 300; i += 1) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const snapshot = await api("/api/jobs");
|
||||
const busy = [...snapshot.running, ...snapshot.queued].some((j) => j.id === job.id);
|
||||
if (!busy) {
|
||||
const done = snapshot.recent.find((j) => j.id === job.id);
|
||||
status.textContent = done && done.state !== "done"
|
||||
? `Scoring ${done.state}: ${done.error || ""}`
|
||||
: "Saved and scored.";
|
||||
await loadRoles();
|
||||
return;
|
||||
}
|
||||
}
|
||||
status.textContent = "Saved. Scoring is still running; see Jobs below.";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- init
|
||||
|
||||
async function loadCompanies() {
|
||||
const rows = await api("/api/companies");
|
||||
companies = new Map(rows.map((c) => [c.key, c]));
|
||||
}
|
||||
|
||||
async function init() {
|
||||
initTabs();
|
||||
await Promise.all([loadCompanies(), loadApplications(), loadAgents()]);
|
||||
await loadRoles();
|
||||
|
||||
const refetch = debounce(loadRoles, 300);
|
||||
$("#f-q").addEventListener("input", refetch);
|
||||
$("#f-company").addEventListener("input", refetch);
|
||||
$("#f-place").addEventListener("input", refetch);
|
||||
$("#f-function").addEventListener("change", loadRoles);
|
||||
$("#f-remote").addEventListener("change", loadRoles);
|
||||
$("#f-days").addEventListener("change", loadRoles);
|
||||
$("#f-show-muted").addEventListener("change", loadRoles);
|
||||
$("#f-agent").addEventListener("change", () => {
|
||||
$("#show-gated").hidden = !$("#f-agent").value;
|
||||
loadRoles();
|
||||
});
|
||||
$("#f-gated").addEventListener("change", loadRoles);
|
||||
$("#agent-form").addEventListener("submit", saveAgent);
|
||||
$("#a-new").addEventListener("click", () => fillAgentForm(null));
|
||||
$("#a-delete").addEventListener("click", deleteAgent);
|
||||
$("#filters").addEventListener("submit", (e) => e.preventDefault());
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
@@ -1,128 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>roledesk</title>
|
||||
<link rel="stylesheet" href="/static/app.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<span class="wordmark">role<span>desk</span></span>
|
||||
<nav class="tabs" id="tabs">
|
||||
<button type="button" class="tab" data-tab="roles" aria-pressed="true">Roles</button>
|
||||
<button type="button" class="tab" data-tab="applications" aria-pressed="false">Applications</button>
|
||||
<button type="button" class="tab" data-tab="agents" aria-pressed="false">Agents</button>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section id="roles-view" class="view">
|
||||
<form id="filters" class="filters" autocomplete="off">
|
||||
<select id="f-agent" aria-label="Order">
|
||||
<option value="">Newest</option>
|
||||
</select>
|
||||
<input type="search" id="f-q" placeholder="Search titles" aria-label="Search titles">
|
||||
<input type="text" id="f-company" placeholder="Company" aria-label="Company">
|
||||
<input type="text" id="f-place" placeholder="Place" aria-label="Place">
|
||||
<select id="f-function" aria-label="Function">
|
||||
<option value="">Any function</option>
|
||||
{% for value, label in functions %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-remote" aria-label="Remote">
|
||||
<option value="">Any remote</option>
|
||||
{% for value, label in remote_options %}
|
||||
<option value="{{ value }}">{{ label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<select id="f-days" aria-label="New in">
|
||||
<option value="">Any time</option>
|
||||
<option value="1">New in 1 day</option>
|
||||
<option value="3">New in 3 days</option>
|
||||
<option value="7">New in 7 days</option>
|
||||
<option value="30">New in 30 days</option>
|
||||
</select>
|
||||
<label class="show-muted">
|
||||
<input type="checkbox" id="f-show-muted"> Show muted
|
||||
</label>
|
||||
<label class="show-muted" id="show-gated" hidden>
|
||||
<input type="checkbox" id="f-gated"> Show gated
|
||||
</label>
|
||||
</form>
|
||||
|
||||
<p id="roles-count" class="count" role="status"></p>
|
||||
<ul id="roles-list" class="roles"></ul>
|
||||
</section>
|
||||
|
||||
<section id="applications-view" class="view" hidden>
|
||||
<p id="applications-count" class="count" role="status"></p>
|
||||
<table class="applications">
|
||||
<thead>
|
||||
<tr><th>Role</th><th>Company</th><th>Status</th><th>Next</th></tr>
|
||||
</thead>
|
||||
<tbody id="applications-list"></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<section id="agents-view" class="view" hidden>
|
||||
<p id="agents-count" class="count" role="status"></p>
|
||||
<ul id="agents-list" class="agents"></ul>
|
||||
<form id="agent-form" class="agent-form" autocomplete="off">
|
||||
<h2 id="agent-form-title">New agent</h2>
|
||||
<input type="hidden" id="a-id">
|
||||
<label>Name <input type="text" id="a-name" required></label>
|
||||
<label>Intent <span class="hint">a CV paragraph, or what this search is for</span>
|
||||
<textarea id="a-intent" rows="5"></textarea></label>
|
||||
<label>Gates <span class="hint">JSON: [{"field": "place", "values": ["Berlin"], "mode": "require"}, {"field": "remote", "values": ["remote"], "mode": "prefer", "weight": 0.2}]</span>
|
||||
<textarea id="a-gates" rows="5" spellcheck="false">[]</textarea></label>
|
||||
<fieldset class="weights">
|
||||
<legend>Weights</legend>
|
||||
<label>Fit <input type="number" id="a-fit" min="0" step="0.05" value="0.6"></label>
|
||||
<label>Recency <input type="number" id="a-recency" min="0" step="0.05" value="0.2"></label>
|
||||
<label>Affinity <input type="number" id="a-affinity" min="0" step="0.05" value="0.2"></label>
|
||||
</fieldset>
|
||||
<label class="inline"><input type="checkbox" id="a-enabled" checked> Enabled</label>
|
||||
<div class="agent-actions">
|
||||
<button type="submit" class="primary">Save and score</button>
|
||||
<button type="button" id="a-new">New</button>
|
||||
<button type="button" id="a-delete" hidden>Delete</button>
|
||||
</div>
|
||||
<p id="agent-status" class="count" role="status"></p>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section id="jobs">
|
||||
<h2>Jobs</h2>
|
||||
<script type="module" src="/_jobs/jobs.js"></script>
|
||||
<desk-jobs></desk-jobs>
|
||||
</section>
|
||||
|
||||
<template id="role-row">
|
||||
<li class="role">
|
||||
<div class="role-main">
|
||||
<a class="role-title" target="_blank" rel="noopener"></a>
|
||||
<span class="role-company"></span>
|
||||
<span class="affinity" role="group"></span>
|
||||
</div>
|
||||
<div class="role-meta">
|
||||
<span class="role-place"></span>
|
||||
<span class="role-remote badge"></span>
|
||||
<span class="role-function badge"></span>
|
||||
<span class="role-score badge"></span>
|
||||
<span class="role-gated"></span>
|
||||
<span class="role-age"></span>
|
||||
</div>
|
||||
<button type="button" class="save"></button>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// The tracker's status vocabulary, from the same `STATUSES` tuple the
|
||||
// store validates a status change against — see app/web/pages.py.
|
||||
window.ROLEDESK_STATUSES = {{ status_options | map(attribute=0) | list | tojson }};
|
||||
</script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user