The Roles tab is news's feed row: the title opens /roles/{uid}, company,
place and age under it, the badges, a one-line excerpt (summary, else the
description's opening), and ▲ ● ▼ ★ on the right, under the text at 640px.
The company affinity control leaves the row. A passed role and a hidden
company's are dimmed and stay. The filter bar is one row: order, search and
a Filters <details> holding the rest, with a judged select and "Show hidden
companies". The list loads 60 and appends on an IntersectionObserver
sentinel; back from a read page restores the filters, rows and scroll.
GET /api/roles takes offset, defaults to 60 and answers {items, total}.
judged= is a WHERE on roles.vote. Under a ranking the served score and the
order are the stored score moved by the vote (x0.5 pass, x1.2 like, capped
at 1), so a vote shows at once without a rescore. POST and DELETE
/api/roles/{uid}/vote set and clear it; pressing the pressed stance clears.
★ saves; pressed again it calls DELETE /api/applications/{id}, which drops
the application while it is still saved and answers 409 after. save_role no
longer writes the placeholder next step.
The read page (role.html, role.js) is news's reader: a bar with back,
▲ ● ▼ ★ and ↗, the company with its affinity control, place, badges, salary,
summary, the text (fetched posting, else description) and the link out.
It offers Fetch the posting for a teaser and Summarise without a summary,
against the /text and /summarise routes B4 adds. The vote and star buttons
are judge.js, shared by the feed and the reader.
Applications: titles open the read page, the Next column is gone, a Saved
column instead, and the lede says what the page is for.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
187 lines
6.8 KiB
Python
187 lines
6.8 KiB
Python
"""The pages: two tabs, a cog, and six settings pages behind it.
|
|
|
|
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the row of
|
|
sub-tabs under the cog at `/settings/<name>`: the setup pages first (Ranking,
|
|
Searches, Companies), the system ones after (Pulls, Messages, Account).
|
|
`base.html` renders the first, `settings/_tabs.html` the second, every page
|
|
marks itself active by its own `path`, and adding one is one entry here plus
|
|
one template. `/settings` itself is Ranking.
|
|
|
|
Every page is a shell. Each is filled and driven by its own script under
|
|
`static/` from the JSON routes in `web/api.py`; Pulls 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.
|
|
|
|
The pages that were tabs before the settings shell (`/agents`, `/companies`,
|
|
`/sources`, `/jobs`, `/schedules`, `/messages`, `/account`) answer 301 to
|
|
their new place, query string kept, so a bookmark still lands.
|
|
|
|
`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`. The
|
|
Jobindex areas and Adzuna countries on the Searches page come from
|
|
`plugins.search` for the same reason.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from collections.abc import Callable
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter, HTTPException, Request
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from app.models import REMOTE, STATUSES
|
|
from app.web.deps import StoreDep
|
|
|
|
_ROOT = Path(__file__).resolve().parents[2]
|
|
if str(_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(_ROOT))
|
|
|
|
from plugins.ats import FUNCTIONS # noqa: E402
|
|
from plugins.search import ADZUNA_COUNTRIES, JOBINDEX_AREAS # noqa: E402
|
|
|
|
TEMPLATE_DIR = Path(__file__).resolve().parent.parent / "templates"
|
|
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Tab:
|
|
path: str
|
|
label: str
|
|
template: str
|
|
|
|
|
|
#: The top bar, in order. One list; `base.html` is its only reader.
|
|
TABS: tuple[Tab, ...] = (
|
|
Tab("/", "Roles", "roles.html"),
|
|
Tab("/applications", "Applications", "applications.html"),
|
|
)
|
|
|
|
#: The sub-tabs under the cog, in order; `settings/_tabs.html` renders them.
|
|
SETTINGS: tuple[Tab, ...] = (
|
|
Tab("/settings/ranking", "Ranking", "settings/ranking.html"),
|
|
Tab("/settings/searches", "Searches", "settings/searches.html"),
|
|
Tab("/settings/companies", "Companies", "settings/companies.html"),
|
|
Tab("/settings/pulls", "Pulls", "settings/pulls.html"),
|
|
Tab("/settings/messages", "Messages", "settings/messages.html"),
|
|
Tab("/settings/account", "Account", "settings/account.html"),
|
|
)
|
|
|
|
#: Where each page that used to be a tab lives now.
|
|
MOVED: dict[str, str] = {
|
|
"/agents": "/settings/ranking",
|
|
"/companies": "/settings/companies",
|
|
"/sources": "/settings/searches",
|
|
"/jobs": "/settings/pulls",
|
|
"/schedules": "/settings/pulls",
|
|
"/messages": "/settings/messages",
|
|
"/account": "/settings/account",
|
|
}
|
|
|
|
#: `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]
|
|
AREA_OPTIONS = list(JOBINDEX_AREAS.items())
|
|
COUNTRY_OPTIONS = [(c, c.upper()) for c in sorted(ADZUNA_COUNTRIES)]
|
|
|
|
|
|
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["SETTINGS"] = SETTINGS
|
|
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 roles(request: Request) -> HTMLResponse:
|
|
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
|
|
remote_options=REMOTE_OPTIONS)
|
|
|
|
|
|
@router.get("/roles/{uid}", response_class=HTMLResponse)
|
|
def role(request: Request, uid: str, store: StoreDep) -> HTMLResponse:
|
|
"""The read page of one role. A shell like the others, filled by
|
|
`role.js`; the lookup here only makes an unknown uid a 404 page rather
|
|
than an empty one."""
|
|
if store.role(uid) is None:
|
|
raise HTTPException(404, f"no such role: {uid}")
|
|
return page(request, "role.html", uid=uid)
|
|
|
|
|
|
@router.get("/applications", response_class=HTMLResponse)
|
|
def applications(request: Request) -> HTMLResponse:
|
|
return page(request, "applications.html", status_options=STATUS_OPTIONS)
|
|
|
|
|
|
@router.get("/settings", response_class=RedirectResponse)
|
|
def settings() -> RedirectResponse:
|
|
return RedirectResponse(SETTINGS[0].path, status_code=302)
|
|
|
|
|
|
@router.get("/settings/ranking", response_class=HTMLResponse)
|
|
def ranking(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/ranking.html")
|
|
|
|
|
|
@router.get("/settings/searches", response_class=HTMLResponse)
|
|
def searches(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/searches.html", areas=AREA_OPTIONS,
|
|
countries=COUNTRY_OPTIONS)
|
|
|
|
|
|
@router.get("/settings/companies", response_class=HTMLResponse)
|
|
def companies(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/companies.html")
|
|
|
|
|
|
@router.get("/settings/pulls", response_class=HTMLResponse)
|
|
def pulls(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/pulls.html")
|
|
|
|
|
|
@router.get("/settings/messages", response_class=HTMLResponse)
|
|
def messages(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/messages.html")
|
|
|
|
|
|
@router.get("/settings/account", response_class=HTMLResponse)
|
|
def account(request: Request) -> HTMLResponse:
|
|
return page(request, "settings/account.html")
|
|
|
|
|
|
def _moved(to: str) -> Callable[[Request], RedirectResponse]:
|
|
"""A 301 to `to`, carrying the query string, so `/agents?x=1` keeps it."""
|
|
def redirect(request: Request) -> RedirectResponse:
|
|
query = request.url.query
|
|
return RedirectResponse(f"{to}?{query}" if query else to, status_code=301)
|
|
return redirect
|
|
|
|
|
|
for _old, _new in MOVED.items():
|
|
router.add_api_route(_old, _moved(_new), methods=["GET"],
|
|
response_class=RedirectResponse)
|