Automatiska ID, nya registertyper och ID-register

- Löpande ID per bok och typ enligt idöversikten (KI, FI, BI, DI, LI, UI, FD, RI,
  RD, SI, REI, PI, SCI, KD-R_/KD-E_), prefix samlade i src/lib/ids.ts
- Nya typer: Fordon, Skiss, Research, Referens, Appar, Hemsidor (grupp Register)
- Sida med ID-register med sök och filter
- Migration 0003_auto_ids med backfill av befintliga poster
- ID visas i listor, postsidor, kartpanel och scheman
- README och Register/-mallar

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-22 22:31:50 +02:00
1 parent 0b65494cf5
commit 8a0e93f559
32 files changed
+664 -48

No files matched your search

@@ -266,6 +266,7 @@ export default async function EntityPage({ params }: { params: Promise<{ bookId:
{entity.shifts.map((s) => (
<div className="list-group-item" key={s.id}>
<span className="fw-bold">{t(`day.short.${s.weekday}`)}</span> {s.startTime}–{s.endTime}
{s.scheduleCode ? <span className="badge ms-1">{s.scheduleCode}</span> : null}
{s.weeks !== "ALL" ? <span className="badge ms-1">{t(`schedule.weeks.${s.weeks}`)}</span> : null}
<div className="text-secondary small">
{[s.workplace?.name, s.label].filter(Boolean).join(" · ")}
@@ -318,6 +319,7 @@ export default async function EntityPage({ params }: { params: Promise<{ bookId:
<IconMapPin size={18} />
<span>{m.map.name}</span>
<span className="text-secondary">· {m.label}</span>
{m.code ? <span className="badge ms-auto">{m.code}</span> : null}
</Link>
))}
{maps.map((map) => (
+10 -1
View File
@@ -36,7 +36,15 @@ export default async function MapPage({
return (
<>
<PageHeader title={map.name} pretitle={t("map.title")} />
<PageHeader
title={map.name}
pretitle={
<>
{t("map.title")}
{map.code ? <span className="badge ms-2">{map.code}</span> : null}
</>
}
/>
<PageBody>
<MapLoader
bookId={bookId}
@@ -47,6 +55,7 @@ export default async function MapPage({
zoom={map.zoom}
markers={map.markers.map((m) => ({
id: m.id,
code: m.code,
label: m.label,
note: m.note,
color: m.color,
+4 -1
View File
@@ -36,7 +36,10 @@ export default async function MapsPage({ params }: { params: Promise<{ bookId: s
{map.kind === "GEO" ? <IconMap2 size={22} /> : <IconPhoto size={22} />}
</span>
<div className="min-w-0">
<div className="fw-bold text-truncate">{map.name}</div>
<div className="fw-bold text-truncate">
{map.name}
{map.code ? <span className="badge ms-2">{map.code}</span> : null}
</div>
<div className="text-secondary">
{t(`map.kind.${map.kind}`)} · {t("map.markerCount", { n: map._count.markers })}
</div>
+39 -1
View File
@@ -28,7 +28,45 @@ export default async function BookDashboard({ params }: { params: Promise<{ book
{book.description ? <p className="text-secondary bm-prewrap mb-4">{book.description}</p> : null}
<div className="row row-cards mb-4">
{KINDS.map(({ kind, slug, color }) => {
{KINDS.filter((k) => k.group === "world").map(({ kind, slug, color }) => {
const Icon = kindIcons[kind];
return (
<div className="col-6 col-md-4 col-xl-3" key={kind}>
<div className="card card-sm">
<div className="card-body">
<div className="row align-items-center">
<div className="col-auto">
<span className={`avatar bg-${color}-lt`}>
<Icon size={22} />
</span>
</div>
<div className="col">
<Link href={`/books/${bookId}/e/${slug}`} className="fw-bold text-reset stretched-link">
{t(`kind.${kind}.other`)}
</Link>
<div className="text-secondary">{countOf[kind] ?? 0}</div>
</div>
<div className="col-auto position-relative" style={{ zIndex: 2 }}>
<Link
href={`/books/${bookId}/e/${slug}/new`}
className="btn btn-icon btn-sm btn-ghost-secondary"
title={t(`kind.${kind}.new`)}
aria-label={t(`kind.${kind}.new`)}
>
<IconPlus size={18} />
</Link>
</div>
</div>
</div>
</div>
</div>
);
})}
</div>
<h3 className="subheader mb-2">{t("dashboard.registers")}</h3>
<div className="row row-cards mb-4">
{KINDS.filter((k) => k.group === "register").map(({ kind, slug, color }) => {
const Icon = kindIcons[kind];
return (
<div className="col-6 col-md-4 col-xl-3" key={kind}>
+175
View File
@@ -0,0 +1,175 @@
import Link from "next/link";
import { IconSearch } from "@tabler/icons-react";
import { EmptyState, PageBody, PageHeader } from "@/components/page";
import { getT } from "@/i18n/server";
import { prisma } from "@/lib/db";
import { ENTITY_PREFIX } from "@/lib/ids";
import { KINDS } from "@/lib/kinds";
import { requireBook } from "@/lib/session";
export const metadata = { title: "ID-register" };
type Row = { code: string; type: string; typeLabel: string; name: string; href: string; detail?: string };
const SPECIAL_TYPES = ["relation", "map", "marker", "schedule"] as const;
export default async function RegisterPage({
params,
searchParams,
}: {
params: Promise<{ bookId: string }>;
searchParams: Promise<{ q?: string; type?: string }>;
}) {
const { bookId } = await params;
const { q = "", type = "" } = await searchParams;
await requireBook(bookId);
const { t } = await getT();
const [entities, relations, maps, markers, shifts] = await Promise.all([
prisma.entity.findMany({ where: { bookId, code: { not: null } }, select: { id: true, code: true, name: true, kind: true } }),
prisma.relation.findMany({
where: { bookId, code: { not: null } },
include: { from: { select: { name: true } }, to: { select: { name: true } } },
}),
prisma.bookMap.findMany({ where: { bookId, code: { not: null } }, select: { id: true, code: true, name: true } }),
prisma.marker.findMany({
where: { map: { bookId }, code: { not: null } },
include: { map: { select: { id: true, name: true } } },
}),
prisma.shift.findMany({
where: { bookId, scheduleCode: { not: null } },
include: { person: { select: { id: true, name: true } }, workplace: { select: { name: true } } },
}),
]);
const rows: Row[] = [
...entities.map((e) => ({
code: e.code!,
type: e.kind,
typeLabel: t(`kind.${e.kind}.one`),
name: e.name,
href: `/books/${bookId}/entity/${e.id}`,
})),
...relations.map((r) => ({
code: r.code!,
type: "relation",
typeLabel: t("register.relation"),
name: `${r.from.name} – ${r.to.name}`,
detail: r.type,
href: `/books/${bookId}/relations/${r.id}`,
})),
...maps.map((m) => ({
code: m.code!,
type: "map",
typeLabel: t("register.map"),
name: m.name,
href: `/books/${bookId}/maps/${m.id}`,
})),
...markers.map((m) => ({
code: m.code!,
type: "marker",
typeLabel: t("register.marker"),
name: m.label,
detail: m.map.name,
href: `/books/${bookId}/maps/${m.map.id}?marker=${m.id}`,
})),
];
// Ett schema-ID gäller en persons alla pass hos samma arbetsplats
const schedules = new Map<string, Row>();
for (const s of shifts) {
if (schedules.has(s.scheduleCode!)) continue;
schedules.set(s.scheduleCode!, {
code: s.scheduleCode!,
type: "schedule",
typeLabel: t("register.schedule"),
name: s.person.name,
detail: s.workplace?.name,
href: `/books/${bookId}/schedules?person=${s.person.id}`,
});
}
rows.push(...schedules.values());
const needle = q.trim().toLowerCase();
const visible = rows
.filter((r) => (!type || r.type === type) && (!needle || `${r.code} ${r.name} ${r.detail ?? ""}`.toLowerCase().includes(needle)))
.sort((a, b) => a.code.localeCompare(b.code, "sv", { numeric: true }));
const typeOptions = [
...KINDS.filter((k) => ENTITY_PREFIX[k.kind]).map((k) => ({ value: k.kind as string, label: t(`kind.${k.kind}.other`) })),
...SPECIAL_TYPES.map((s) => ({ value: s as string, label: t(`register.${s}`) })),
];
return (
<>
<PageHeader title={t("register.title")} />
<PageBody>
<p className="text-secondary">{t("register.intro")}</p>
<div className="card">
<div className="card-body border-bottom py-3">
<form className="row g-2">
<div className="col-md-6">
<div className="input-icon">
<span className="input-icon-addon">
<IconSearch size={18} />
</span>
<input name="q" defaultValue={q} className="form-control" placeholder={t("register.search")} />
</div>
</div>
<div className="col-md-4">
<select name="type" className="form-select" defaultValue={type}>
<option value="">{t("common.all")}</option>
{typeOptions.map((o) => (
<option key={o.value} value={o.value}>
{o.label}
</option>
))}
</select>
</div>
<div className="col-md-2">
<button className="btn w-100" type="submit">
{t("common.search")}
</button>
</div>
</form>
</div>
{visible.length === 0 ? (
<div className="card-body">
<EmptyState>{t("register.empty")}</EmptyState>
</div>
) : (
<div className="table-responsive">
<table className="table table-vcenter card-table">
<thead>
<tr>
<th>{t("register.id")}</th>
<th>{t("register.type")}</th>
<th>{t("register.name")}</th>
</tr>
</thead>
<tbody>
{visible.map((r) => (
<tr key={`${r.type}-${r.code}`}>
<td className="text-nowrap">
<span className="badge bg-azure-lt">{r.code}</span>
</td>
<td className="text-secondary">{r.typeLabel}</td>
<td>
<Link href={r.href} className="fw-bold bm-table-link">
{r.name}
</Link>
{r.detail ? <span className="text-secondary"> · {r.detail}</span> : null}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</PageBody>
</>
);
}
@@ -46,8 +46,10 @@ export default async function RelationPage({
pretitle={
<Link href={`/books/${bookId}/relations`} className="text-reset">
{t("relation.title")}
{relation.code ? <span className="badge ms-2">{relation.code}</span> : null}
</Link>
}
title={
isGroup ? (
<span>
@@ -106,6 +106,7 @@ export default async function RelationsPage({
<Link href={`/books/${bookId}/relations/${r.id}`} className="text-secondary" title={t("common.edit")}>
{r.type}
</Link>
{r.code ? <span className="badge ms-2">{r.code}</span> : null}
</td>
<td>
{[r.to, ...r.members.map((m) => m.entity)].map((e, i) => (
@@ -301,6 +301,13 @@ export default async function SchedulesPage({
<Link href={`/books/${bookId}/entity/${p.id}`} className="text-reset">
{p.name}
</Link>
<div className="mt-1">
{[...new Set(rowShifts.map((s) => s.scheduleCode).filter(Boolean))].map((code) => (
<span key={code} className="badge me-1">
{code}
</span>
))}
</div>
</td>
{DAYS.map((d) => (
<td key={d} className="bm-week-cell">