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:
1 parent
0b65494cf5
commit
8a0e93f559
32 files changed
+664
-48
No files matched your search
+10
-4
@@ -6,6 +6,7 @@ import { prisma } from "@/lib/db";
|
||||
import { deleteImage, isUpload, saveImage } from "@/lib/files";
|
||||
import { optStr, parseTags, revalidateBook, str } from "@/lib/form";
|
||||
import { KIND_INFO, parseKind } from "@/lib/kinds";
|
||||
import { nextEntityCode } from "@/lib/ids";
|
||||
import { requireBook, requireEntity } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
import { getLocale } from "@/i18n/server";
|
||||
@@ -52,16 +53,21 @@ export async function saveEntity(formData: FormData) {
|
||||
|
||||
const values = {
|
||||
name,
|
||||
code: optStr(formData, "code", 50),
|
||||
summary: optStr(formData, "summary"),
|
||||
tags: parseTags(str(formData, "tags", 1000)),
|
||||
data: data as Prisma.InputJsonObject,
|
||||
imageFile,
|
||||
};
|
||||
|
||||
const saved = existing
|
||||
? await prisma.entity.update({ where: { id: existing.id }, data: values })
|
||||
: await prisma.entity.create({ data: { ...values, bookId: book.id, kind } });
|
||||
// ID skapas automatiskt vid första sparningen och ändras aldrig därefter
|
||||
const saved = await prisma.$transaction(async (tx) => {
|
||||
if (existing) {
|
||||
const code = existing.code ?? (await nextEntityCode(book.id, kind, tx));
|
||||
return tx.entity.update({ where: { id: existing.id }, data: { ...values, code } });
|
||||
}
|
||||
const code = await nextEntityCode(book.id, kind, tx);
|
||||
return tx.entity.create({ data: { ...values, code, bookId: book.id, kind } });
|
||||
});
|
||||
|
||||
revalidateBook(book.id);
|
||||
redirect(`/books/${book.id}/entity/${saved.id}`);
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@ import { prisma } from "@/lib/db";
|
||||
import { deleteImage, isUpload, saveImage } from "@/lib/files";
|
||||
import { revalidateBook, str } from "@/lib/form";
|
||||
import { MARKER_COLORS } from "@/lib/kinds";
|
||||
import { nextMapCode, nextMarkerCode } from "@/lib/ids";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
async function requireMap(bookId: string, mapId: string) {
|
||||
@@ -27,7 +28,8 @@ export async function createMap(formData: FormData) {
|
||||
imageFile = await saveImage(upload);
|
||||
}
|
||||
|
||||
const map = await prisma.bookMap.create({ data: { bookId: book.id, name, kind, imageFile } });
|
||||
const code = await nextMapCode(book.id, kind);
|
||||
const map = await prisma.bookMap.create({ data: { bookId: book.id, code, name, kind, imageFile } });
|
||||
revalidateBook(book.id);
|
||||
redirect(`/books/${book.id}/maps/${map.id}`);
|
||||
}
|
||||
@@ -89,7 +91,8 @@ async function cleanMarker(bookId: string, input: MarkerInput) {
|
||||
|
||||
export async function createMarker(bookId: string, mapId: string, input: MarkerInput) {
|
||||
const { book, map } = await requireMap(bookId, mapId);
|
||||
await prisma.marker.create({ data: { ...(await cleanMarker(book.id, input)), mapId: map.id } });
|
||||
const data = await cleanMarker(book.id, input);
|
||||
await prisma.marker.create({ data: { ...data, code: await nextMarkerCode(book.id), mapId: map.id } });
|
||||
revalidateBook(book.id);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { Prisma } from "@prisma/client";
|
||||
import { redirect } from "next/navigation";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { optStr, revalidateBook, str } from "@/lib/form";
|
||||
import { nextRelationCode } from "@/lib/ids";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
import { getLocale } from "@/i18n/server";
|
||||
@@ -28,15 +29,18 @@ export async function addRelation(formData: FormData) {
|
||||
if (count !== 2) return;
|
||||
|
||||
const memberIds = await cleanMemberIds(book.id, formData, [fromId, toId]);
|
||||
await prisma.relation.create({
|
||||
await prisma.$transaction(async (tx) => {
|
||||
await tx.relation.create({
|
||||
data: {
|
||||
bookId: book.id,
|
||||
code: await nextRelationCode(book.id, tx),
|
||||
fromId,
|
||||
toId,
|
||||
type,
|
||||
description: optStr(formData, "description", 2000),
|
||||
members: { create: memberIds.map((entityId) => ({ entityId })) },
|
||||
},
|
||||
});
|
||||
});
|
||||
revalidateBook(book.id);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import type { WeekPattern } from "@prisma/client";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { optStr, revalidateBook, str } from "@/lib/form";
|
||||
import { nextScheduleCode } from "@/lib/ids";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||
@@ -25,6 +26,13 @@ export async function addShifts(formData: FormData) {
|
||||
const found = await prisma.entity.count({ where: { bookId: book.id, id: { in: ids } } });
|
||||
if (found !== ids.length) return;
|
||||
|
||||
// En persons pass hos samma arbetsplats hör till samma schema och delar Schema-ID
|
||||
const existing = await prisma.shift.findFirst({
|
||||
where: { bookId: book.id, personId, workplaceId, scheduleCode: { not: null } },
|
||||
select: { scheduleCode: true },
|
||||
});
|
||||
const scheduleCode = existing?.scheduleCode ?? (await nextScheduleCode(book.id));
|
||||
|
||||
const label = optStr(formData, "label", 100);
|
||||
await prisma.shift.createMany({
|
||||
data: days.map((weekday) => ({
|
||||
@@ -36,6 +44,7 @@ export async function addShifts(formData: FormData) {
|
||||
endTime,
|
||||
weeks,
|
||||
label,
|
||||
scheduleCode,
|
||||
})),
|
||||
});
|
||||
revalidateBook(book.id);
|
||||
|
||||
@@ -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) => (
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}>
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -79,8 +79,7 @@ export function EntityForm({
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("common.code")}</label>
|
||||
<input name="code" className="form-control" maxLength={50} defaultValue={entity?.code ?? ""} />
|
||||
<div className="form-hint">{t("common.codeHelp")}</div>
|
||||
<input className="form-control" value={entity?.code ?? ""} placeholder={t("common.codeAuto")} readOnly disabled />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("common.tags")}</label>
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import {
|
||||
IconBookmark,
|
||||
IconBuildingSkyscraper,
|
||||
IconBuildingStore,
|
||||
IconCar,
|
||||
IconDeviceMobile,
|
||||
IconFlask,
|
||||
IconHome,
|
||||
IconMapPin,
|
||||
IconMovie,
|
||||
IconPaw,
|
||||
IconRuler2,
|
||||
IconSchool,
|
||||
IconUser,
|
||||
IconWorld,
|
||||
type Icon,
|
||||
} from "@tabler/icons-react";
|
||||
import type { EntityKind } from "@prisma/client";
|
||||
@@ -20,4 +26,10 @@ export const kindIcons: Record<EntityKind, Icon> = {
|
||||
PREMISES: IconBuildingStore,
|
||||
EDUCATION: IconSchool,
|
||||
SCENARIO: IconMovie,
|
||||
VEHICLE: IconCar,
|
||||
SKETCH: IconRuler2,
|
||||
RESEARCH: IconFlask,
|
||||
REFERENCE: IconBookmark,
|
||||
APP: IconDeviceMobile,
|
||||
WEBSITE: IconWorld,
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import { KINDS, MARKER_COLORS } from "@/lib/kinds";
|
||||
|
||||
export type MarkerDTO = {
|
||||
id: string;
|
||||
code: string | null;
|
||||
label: string;
|
||||
note: string | null;
|
||||
color: string;
|
||||
@@ -372,6 +373,11 @@ export default function MapView(props: MapViewProps) {
|
||||
<form onSubmit={submitDraft} className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{draft.id ? t("map.editMarker") : t("map.newMarker")}</h3>
|
||||
{draft.id ? (
|
||||
<div className="card-actions">
|
||||
<span className="badge">{markers.find((m) => m.id === draft.id)?.code}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="mb-3">
|
||||
@@ -473,6 +479,7 @@ export default function MapView(props: MapViewProps) {
|
||||
|
||||
</span>
|
||||
<span className="flex-fill text-start">
|
||||
{m.code ? <span className="badge me-2">{m.code}</span> : null}
|
||||
{m.label}
|
||||
{m.entityId ? <span className="text-secondary"> · {entityName(m.entityId)}</span> : null}
|
||||
</span>
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
IconCalendarWeek,
|
||||
IconChartDots3,
|
||||
IconLayoutDashboard,
|
||||
IconListDetails,
|
||||
IconLogout,
|
||||
IconMap2,
|
||||
IconSettings,
|
||||
@@ -80,7 +81,7 @@ export async function Shell({ user, book, children }: ShellProps) {
|
||||
<li className="nav-item mt-2">
|
||||
<div className="nav-link text-uppercase small text-secondary disabled">{t("nav.world")}</div>
|
||||
</li>
|
||||
{KINDS.map(({ kind, slug }) => {
|
||||
{KINDS.filter((k) => k.group === "world").map(({ kind, slug }) => {
|
||||
const Icon = kindIcons[kind];
|
||||
return (
|
||||
<NavLink key={kind} href={`${base}/e/${slug}`} icon={<Icon size={20} />}>
|
||||
@@ -89,6 +90,21 @@ export async function Shell({ user, book, children }: ShellProps) {
|
||||
);
|
||||
})}
|
||||
|
||||
<li className="nav-item mt-2">
|
||||
<div className="nav-link text-uppercase small text-secondary disabled">{t("nav.register")}</div>
|
||||
</li>
|
||||
{KINDS.filter((k) => k.group === "register").map(({ kind, slug }) => {
|
||||
const Icon = kindIcons[kind];
|
||||
return (
|
||||
<NavLink key={kind} href={`${base}/e/${slug}`} icon={<Icon size={20} />}>
|
||||
{t(`kind.${kind}.other`)}
|
||||
</NavLink>
|
||||
);
|
||||
})}
|
||||
<NavLink href={`${base}/register`} icon={<IconListDetails size={20} />}>
|
||||
{t("nav.idRegister")}
|
||||
</NavLink>
|
||||
|
||||
<li className="nav-item mt-2">
|
||||
<div className="nav-link text-uppercase small text-secondary disabled">{t("nav.planning")}</div>
|
||||
</li>
|
||||
|
||||
+34
-2
@@ -4,8 +4,7 @@ export const en: Record<keyof typeof sv, string> = {
|
||||
"app.name": "Story Planner",
|
||||
|
||||
"common.save": "Save",
|
||||
"common.code": "ID / code",
|
||||
"common.codeHelp": "Optional, e.g. K001. For cross-referencing between documents.",
|
||||
"common.code": "ID",
|
||||
"common.saved": "Saved.",
|
||||
"common.cancel": "Cancel",
|
||||
"common.delete": "Delete",
|
||||
@@ -99,6 +98,39 @@ export const en: Record<keyof typeof sv, string> = {
|
||||
"kind.PET.one": "Pet",
|
||||
"kind.PET.other": "Pets",
|
||||
"kind.PET.new": "New pet",
|
||||
"kind.VEHICLE.one": "Vehicle",
|
||||
"kind.VEHICLE.other": "Vehicles",
|
||||
"kind.VEHICLE.new": "New vehicle",
|
||||
"kind.SKETCH.one": "Sketch",
|
||||
"kind.SKETCH.other": "Sketches",
|
||||
"kind.SKETCH.new": "New sketch",
|
||||
"kind.RESEARCH.one": "Research",
|
||||
"kind.RESEARCH.other": "Research",
|
||||
"kind.RESEARCH.new": "New research",
|
||||
"kind.REFERENCE.one": "Reference",
|
||||
"kind.REFERENCE.other": "References",
|
||||
"kind.REFERENCE.new": "New reference",
|
||||
"kind.APP.one": "App",
|
||||
"kind.APP.other": "Apps",
|
||||
"kind.APP.new": "New app",
|
||||
"kind.WEBSITE.one": "Website",
|
||||
"kind.WEBSITE.other": "Websites",
|
||||
"kind.WEBSITE.new": "New website",
|
||||
"nav.register": "Registers",
|
||||
"nav.idRegister": "ID register",
|
||||
"dashboard.registers": "Registers",
|
||||
"common.codeAuto": "Created automatically when the item is saved.",
|
||||
"register.title": "ID register",
|
||||
"register.intro": "All IDs in the book in one place. IDs are created automatically and used to cross-reference between documents.",
|
||||
"register.search": "Search ID or name…",
|
||||
"register.type": "Type",
|
||||
"register.id": "ID",
|
||||
"register.name": "Name",
|
||||
"register.empty": "No IDs match.",
|
||||
"register.relation": "Relationship",
|
||||
"register.map": "Map",
|
||||
"register.marker": "Placement",
|
||||
"register.schedule": "Schedule",
|
||||
|
||||
"entity.search": "Search by name or summary…",
|
||||
"entity.empty": "Nothing here yet. Create the first one!",
|
||||
|
||||
+34
-2
@@ -2,8 +2,7 @@ export const sv = {
|
||||
"app.name": "Bokplanerare",
|
||||
|
||||
"common.save": "Spara",
|
||||
"common.code": "ID / kod",
|
||||
"common.codeHelp": "Valfritt, t.ex. K001. För att hänvisa mellan dokument.",
|
||||
"common.code": "ID",
|
||||
"common.saved": "Sparat.",
|
||||
"common.cancel": "Avbryt",
|
||||
"common.delete": "Ta bort",
|
||||
@@ -97,6 +96,39 @@ export const sv = {
|
||||
"kind.PET.one": "Husdjur",
|
||||
"kind.PET.other": "Husdjur",
|
||||
"kind.PET.new": "Nytt husdjur",
|
||||
"kind.VEHICLE.one": "Fordon",
|
||||
"kind.VEHICLE.other": "Fordon",
|
||||
"kind.VEHICLE.new": "Nytt fordon",
|
||||
"kind.SKETCH.one": "Skiss",
|
||||
"kind.SKETCH.other": "Skisser",
|
||||
"kind.SKETCH.new": "Ny skiss",
|
||||
"kind.RESEARCH.one": "Research",
|
||||
"kind.RESEARCH.other": "Research",
|
||||
"kind.RESEARCH.new": "Ny research",
|
||||
"kind.REFERENCE.one": "Referens",
|
||||
"kind.REFERENCE.other": "Referenser",
|
||||
"kind.REFERENCE.new": "Ny referens",
|
||||
"kind.APP.one": "App",
|
||||
"kind.APP.other": "Appar",
|
||||
"kind.APP.new": "Ny app",
|
||||
"kind.WEBSITE.one": "Hemsida",
|
||||
"kind.WEBSITE.other": "Hemsidor",
|
||||
"kind.WEBSITE.new": "Ny hemsida",
|
||||
"nav.register": "Register",
|
||||
"nav.idRegister": "ID-register",
|
||||
"dashboard.registers": "Register",
|
||||
"common.codeAuto": "Skapas automatiskt när posten sparas.",
|
||||
"register.title": "ID-register",
|
||||
"register.intro": "Alla ID i boken samlade på ett ställe. ID skapas automatiskt och används som referens mellan dokument.",
|
||||
"register.search": "Sök ID eller namn…",
|
||||
"register.type": "Typ",
|
||||
"register.id": "ID",
|
||||
"register.name": "Namn",
|
||||
"register.empty": "Inga ID matchar.",
|
||||
"register.relation": "Relation",
|
||||
"register.map": "Karta",
|
||||
"register.marker": "Placering",
|
||||
"register.schedule": "Schema",
|
||||
|
||||
"entity.search": "Sök på namn eller sammanfattning…",
|
||||
"entity.empty": "Inget här ännu. Skapa det första!",
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { EntityKind, Prisma, PrismaClient } from "@prisma/client";
|
||||
import { prisma } from "./db";
|
||||
|
||||
type Db = PrismaClient | Prisma.TransactionClient;
|
||||
|
||||
// ID-schema enligt författarens idöversikt. Siffrorna räknas upp löpande per bok och typ.
|
||||
// Plats och Scenario saknas i översikten, deras prefix är förslag (ändra här vid behov).
|
||||
// Appar och Hemsidor har inget ID.
|
||||
export const ENTITY_PREFIX: Partial<Record<EntityKind, string>> = {
|
||||
CHARACTER: "KI", // Karaktärs ID
|
||||
COMPANY: "FI", // Företag ID
|
||||
HOME: "BI", // Bostads ID
|
||||
PET: "DI", // Djur ID
|
||||
PREMISES: "LI", // Lokal ID
|
||||
EDUCATION: "UI", // Utbildnings ID
|
||||
VEHICLE: "FD", // Fordons ID
|
||||
RESEARCH: "RI", // Research ID
|
||||
REFERENCE: "RD", // Referens ID
|
||||
SKETCH: "SI", // Skiss ID
|
||||
PLACE: "PLI", // Plats ID (förslag)
|
||||
SCENARIO: "SNI", // Scenario ID (förslag)
|
||||
};
|
||||
|
||||
export const RELATION_PREFIX = "REI"; // Relations ID
|
||||
export const MARKER_PREFIX = "PI"; // Placerings ID
|
||||
export const SCHEDULE_PREFIX = "SCI"; // Schema ID
|
||||
export const MAP_PREFIX = "KD"; // Kart ID: KD-R_0001 (riktig karta) eller KD-E_0001 (egen kartbild)
|
||||
|
||||
export function mapLetter(kind: "GEO" | "IMAGE"): "R" | "E" {
|
||||
return kind === "GEO" ? "R" : "E";
|
||||
}
|
||||
|
||||
const pad = (n: number) => String(n).padStart(4, "0");
|
||||
|
||||
/** Nästa löpande nummer för en räknare (atomärt). */
|
||||
async function nextNumber(db: Db, bookId: string, key: string): Promise<number> {
|
||||
const row = await db.idCounter.upsert({
|
||||
where: { bookId_key: { bookId, key } },
|
||||
create: { bookId, key, next: 1 },
|
||||
update: { next: { increment: 1 } },
|
||||
});
|
||||
return row.next;
|
||||
}
|
||||
|
||||
/** T.ex. KI-0001. Ger null för typer utan ID. */
|
||||
export async function nextEntityCode(bookId: string, kind: EntityKind, db: Db = prisma): Promise<string | null> {
|
||||
const prefix = ENTITY_PREFIX[kind];
|
||||
if (!prefix) return null;
|
||||
return `${prefix}-${pad(await nextNumber(db, bookId, prefix))}`;
|
||||
}
|
||||
|
||||
export async function nextRelationCode(bookId: string, db: Db = prisma): Promise<string> {
|
||||
return `${RELATION_PREFIX}-${pad(await nextNumber(db, bookId, RELATION_PREFIX))}`;
|
||||
}
|
||||
|
||||
export async function nextMarkerCode(bookId: string, db: Db = prisma): Promise<string> {
|
||||
return `${MARKER_PREFIX}-${pad(await nextNumber(db, bookId, MARKER_PREFIX))}`;
|
||||
}
|
||||
|
||||
export async function nextScheduleCode(bookId: string, db: Db = prisma): Promise<string> {
|
||||
return `${SCHEDULE_PREFIX}-${pad(await nextNumber(db, bookId, SCHEDULE_PREFIX))}`;
|
||||
}
|
||||
|
||||
/** T.ex. KD-R_0001. Bokstaven anger kartans typ och räknas separat. */
|
||||
export async function nextMapCode(bookId: string, kind: "GEO" | "IMAGE", db: Db = prisma): Promise<string> {
|
||||
const letter = mapLetter(kind);
|
||||
const key = `${MAP_PREFIX}-${letter}`;
|
||||
return `${key}_${pad(await nextNumber(db, bookId, key))}`;
|
||||
}
|
||||
+16
-8
@@ -4,18 +4,26 @@ export type KindInfo = {
|
||||
kind: EntityKind;
|
||||
slug: string;
|
||||
color: string;
|
||||
// world = berättelsens värld, register = stödregister (fordon, research, skisser ...)
|
||||
group: "world" | "register";
|
||||
};
|
||||
|
||||
// Ordningen styr menyer och översikt.
|
||||
export const KINDS: KindInfo[] = [
|
||||
{ kind: "CHARACTER", slug: "characters", color: "blue" },
|
||||
{ kind: "PET", slug: "pets", color: "orange" },
|
||||
{ kind: "HOME", slug: "homes", color: "green" },
|
||||
{ kind: "PLACE", slug: "places", color: "red" },
|
||||
{ kind: "COMPANY", slug: "companies", color: "purple" },
|
||||
{ kind: "PREMISES", slug: "premises", color: "teal" },
|
||||
{ kind: "EDUCATION", slug: "education", color: "cyan" },
|
||||
{ kind: "SCENARIO", slug: "scenarios", color: "pink" },
|
||||
{ kind: "CHARACTER", slug: "characters", color: "blue", group: "world" },
|
||||
{ kind: "PET", slug: "pets", color: "orange", group: "world" },
|
||||
{ kind: "HOME", slug: "homes", color: "green", group: "world" },
|
||||
{ kind: "PLACE", slug: "places", color: "red", group: "world" },
|
||||
{ kind: "COMPANY", slug: "companies", color: "purple", group: "world" },
|
||||
{ kind: "PREMISES", slug: "premises", color: "teal", group: "world" },
|
||||
{ kind: "EDUCATION", slug: "education", color: "cyan", group: "world" },
|
||||
{ kind: "SCENARIO", slug: "scenarios", color: "pink", group: "world" },
|
||||
{ kind: "VEHICLE", slug: "vehicles", color: "indigo", group: "register" },
|
||||
{ kind: "SKETCH", slug: "sketches", color: "azure", group: "register" },
|
||||
{ kind: "RESEARCH", slug: "research", color: "lime", group: "register" },
|
||||
{ kind: "REFERENCE", slug: "references", color: "yellow", group: "register" },
|
||||
{ kind: "APP", slug: "apps", color: "dark", group: "register" },
|
||||
{ kind: "WEBSITE", slug: "websites", color: "secondary", group: "register" },
|
||||
];
|
||||
|
||||
export const KIND_BY_SLUG = new Map(KINDS.map((k) => [k.slug, k]));
|
||||
|
||||
@@ -206,6 +206,30 @@ const SPECS: Record<TemplateKind, Spec[]> = {
|
||||
area("impactAfter", ["Hur påverkas karaktärerna efter scenariot", "How the characters are affected afterwards"]),
|
||||
area("notes", ["Övrig information", "Other information"]),
|
||||
],
|
||||
VEHICLE: [
|
||||
f("model", ["Märke och modell", "Make and model"], "text", ["Grunduppgifter", "Basics"]),
|
||||
pick("fuel", ["Drivmedel", "Fuel"], ["Bensin", "Diesel", "El"], ["Petrol", "Diesel", "Electric"]),
|
||||
area("description", ["Beskrivning", "Description"]),
|
||||
NOTES,
|
||||
],
|
||||
SKETCH: [
|
||||
pick(
|
||||
"sketchType",
|
||||
["Typ av skiss", "Type of sketch"],
|
||||
["Planritning", "Miljöskiss", "Annat"],
|
||||
["Floor plan", "Environment sketch", "Other"],
|
||||
["Grunduppgifter", "Basics"],
|
||||
),
|
||||
area("description", ["Beskrivning", "Description"]),
|
||||
NOTES,
|
||||
],
|
||||
RESEARCH: [area("description", ["Beskrivning", "Description"], ["Research", "Research"])],
|
||||
REFERENCE: [
|
||||
f("link", ["Länk eller källa", "Link or source"], "url", ["Referens", "Reference"]),
|
||||
area("description", ["Beskrivning", "Description"]),
|
||||
],
|
||||
APP: [area("description", ["Beskrivning", "Description"], ["Applikation på telefonen", "Phone application"])],
|
||||
WEBSITE: [area("description", ["Beskrivning", "Description"], ["Hemsida", "Website"])],
|
||||
RELATION: [
|
||||
pick(
|
||||
"category",
|
||||
|
||||
Reference in new issue
Block a user