first commit
This commit is contained in:
commit
b7b0f253ce
85 files changed
+7560
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { saveEntity } from "@/actions/entities";
|
||||
import { EntityForm } from "@/components/entity-form";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { KIND_BY_SLUG } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
|
||||
export default async function NewEntityPage({ params }: { params: Promise<{ bookId: string; kind: string }> }) {
|
||||
const { bookId, kind: slug } = await params;
|
||||
await requireBook(bookId);
|
||||
const info = KIND_BY_SLUG.get(slug);
|
||||
if (!info) notFound();
|
||||
const { t, locale } = await getT();
|
||||
const { fields } = await getTemplate(bookId, info.kind, locale);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t(`kind.${info.kind}.new`)} pretitle={t(`kind.${info.kind}.other`)} />
|
||||
<PageBody>
|
||||
<EntityForm
|
||||
action={saveEntity}
|
||||
bookId={bookId}
|
||||
kind={info.kind}
|
||||
fields={fields}
|
||||
cancelHref={`/books/${bookId}/e/${slug}`}
|
||||
t={t}
|
||||
/>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { IconPlus, IconSearch } from "@tabler/icons-react";
|
||||
import { kindIcons } from "@/components/kind-icons";
|
||||
import { EmptyState, PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { fileUrl } from "@/lib/files";
|
||||
import { KIND_BY_SLUG } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export default async function EntityListPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string; kind: string }>;
|
||||
searchParams: Promise<{ q?: string; tag?: string }>;
|
||||
}) {
|
||||
const { bookId, kind: slug } = await params;
|
||||
const { q, tag } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const info = KIND_BY_SLUG.get(slug);
|
||||
if (!info) notFound();
|
||||
const { t } = await getT();
|
||||
const Icon = kindIcons[info.kind];
|
||||
|
||||
const entities = await prisma.entity.findMany({
|
||||
where: {
|
||||
bookId,
|
||||
kind: info.kind,
|
||||
...(q
|
||||
? {
|
||||
OR: [
|
||||
{ name: { contains: q, mode: "insensitive" } },
|
||||
{ summary: { contains: q, mode: "insensitive" } },
|
||||
{ code: { contains: q, mode: "insensitive" } },
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
...(tag ? { tags: { has: tag } } : {}),
|
||||
},
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
|
||||
const base = `/books/${bookId}/e/${slug}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={t(`kind.${info.kind}.other`)}
|
||||
actions={
|
||||
<Link href={`${base}/new`} className="btn btn-primary">
|
||||
<IconPlus size={18} className="me-1" />
|
||||
{t(`kind.${info.kind}.new`)}
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
<div className="card">
|
||||
<div className="card-body border-bottom py-3">
|
||||
<form className="d-flex gap-2 align-items-center">
|
||||
<div className="input-icon flex-grow-1">
|
||||
<span className="input-icon-addon">
|
||||
<IconSearch size={18} />
|
||||
</span>
|
||||
<input name="q" defaultValue={q} className="form-control" placeholder={t("entity.search")} />
|
||||
</div>
|
||||
{tag ? <input type="hidden" name="tag" value={tag} /> : null}
|
||||
<button className="btn" type="submit">
|
||||
{t("common.search")}
|
||||
</button>
|
||||
</form>
|
||||
{tag ? (
|
||||
<div className="mt-2">
|
||||
<Link href={base} className="badge bg-primary-lt text-decoration-none">
|
||||
{t("entity.filterTag", { tag })} ×
|
||||
</Link>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{entities.length === 0 ? (
|
||||
<div className="card-body">
|
||||
<EmptyState>{q || tag ? t("common.noResults") : t("entity.empty")}</EmptyState>
|
||||
</div>
|
||||
) : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<tbody>
|
||||
{entities.map((entity) => {
|
||||
const image = fileUrl(entity.imageFile);
|
||||
return (
|
||||
<tr key={entity.id}>
|
||||
<td className="w-1">
|
||||
{image ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={image} alt="" className="bm-thumb" />
|
||||
) : (
|
||||
<span className={`avatar bg-${info.color}-lt`}>
|
||||
<Icon size={20} />
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<Link href={`/books/${bookId}/entity/${entity.id}`} className="fw-bold bm-table-link">
|
||||
{entity.name}
|
||||
</Link>
|
||||
{entity.code ? <span className="badge ms-2">{entity.code}</span> : null}
|
||||
{entity.summary ? (
|
||||
<div className="text-secondary text-truncate" style={{ maxWidth: "36rem" }}>
|
||||
{entity.summary}
|
||||
</div>
|
||||
) : null}
|
||||
</td>
|
||||
<td>
|
||||
{entity.tags.map((tagName) => (
|
||||
<Link
|
||||
key={tagName}
|
||||
href={`${base}?tag=${encodeURIComponent(tagName)}`}
|
||||
className="badge bg-azure-lt me-1 text-decoration-none"
|
||||
>
|
||||
{tagName}
|
||||
</Link>
|
||||
))}
|
||||
</td>
|
||||
<td className="text-end w-1">
|
||||
<Link href={`/books/${bookId}/entity/${entity.id}/edit`} className="btn btn-sm">
|
||||
{t("common.edit")}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { saveEntity } from "@/actions/entities";
|
||||
import { EntityForm } from "@/components/entity-form";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { requireEntity } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
|
||||
export default async function EditEntityPage({ params }: { params: Promise<{ bookId: string; entityId: string }> }) {
|
||||
const { bookId, entityId } = await params;
|
||||
const entity = await requireEntity(bookId, entityId);
|
||||
const { t, locale } = await getT();
|
||||
const { fields } = await getTemplate(bookId, entity.kind, locale);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t("entity.editTitle", { name: entity.name })} pretitle={t(`kind.${entity.kind}.one`)} />
|
||||
<PageBody>
|
||||
<EntityForm
|
||||
action={saveEntity}
|
||||
bookId={bookId}
|
||||
kind={entity.kind}
|
||||
entity={entity}
|
||||
fields={fields}
|
||||
cancelHref={`/books/${bookId}/entity/${entity.id}`}
|
||||
t={t}
|
||||
/>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,366 @@
|
||||
import Link from "next/link";
|
||||
import { IconMapPin, IconPencil, IconTrash, IconX } from "@tabler/icons-react";
|
||||
import { deleteEntity } from "@/actions/entities";
|
||||
import { deleteRelation } from "@/actions/relations";
|
||||
import { ConfirmSubmit } from "@/components/confirm-submit";
|
||||
import { kindIcons } from "@/components/kind-icons";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { RelationForm } from "@/components/relation-form";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { fileUrl } from "@/lib/files";
|
||||
import { KIND_INFO, WORKPLACE_KINDS } from "@/lib/kinds";
|
||||
import { requireEntity } from "@/lib/session";
|
||||
import { formatFieldValue, getTemplate, type FieldDef } from "@/lib/templates";
|
||||
|
||||
type Group = { section?: string; items: { field: FieldDef; value: string }[] };
|
||||
|
||||
function groupFields(fields: FieldDef[], data: Record<string, unknown>): Group[] {
|
||||
const groups: Group[] = [];
|
||||
let current: Group = { items: [] };
|
||||
for (const field of fields) {
|
||||
if (field.section) {
|
||||
if (current.items.length > 0) groups.push(current);
|
||||
current = { section: field.section, items: [] };
|
||||
}
|
||||
const value = formatFieldValue(field, data[field.key]);
|
||||
if (value) current.items.push({ field, value });
|
||||
}
|
||||
if (current.items.length > 0) groups.push(current);
|
||||
return groups;
|
||||
}
|
||||
|
||||
export default async function EntityPage({ params }: { params: Promise<{ bookId: string; entityId: string }> }) {
|
||||
const { bookId, entityId } = await params;
|
||||
const base = await requireEntity(bookId, entityId);
|
||||
const { t, locale } = await getT();
|
||||
|
||||
const [entity, template, allEntities, maps] = await Promise.all([
|
||||
prisma.entity.findUniqueOrThrow({
|
||||
where: { id: base.id },
|
||||
include: {
|
||||
outgoing: { include: { to: true, members: { include: { entity: true } } }, orderBy: { createdAt: "asc" } },
|
||||
incoming: { include: { from: true, members: { include: { entity: true } } }, orderBy: { createdAt: "asc" } },
|
||||
memberOf: {
|
||||
include: { relation: { include: { from: true, to: true, members: { include: { entity: true } } } } },
|
||||
},
|
||||
markers: { include: { map: true } },
|
||||
shifts: { include: { workplace: true }, orderBy: [{ weekday: "asc" }, { startTime: "asc" }] },
|
||||
hostedShifts: { include: { person: true }, orderBy: [{ weekday: "asc" }, { startTime: "asc" }] },
|
||||
},
|
||||
}),
|
||||
getTemplate(bookId, base.kind, locale),
|
||||
prisma.entity.findMany({
|
||||
where: { bookId },
|
||||
select: { id: true, name: true, kind: true },
|
||||
orderBy: { name: "asc" },
|
||||
}),
|
||||
prisma.bookMap.findMany({ where: { bookId }, orderBy: { name: "asc" } }),
|
||||
]);
|
||||
|
||||
const info = KIND_INFO[entity.kind];
|
||||
const Icon = kindIcons[entity.kind];
|
||||
const image = fileUrl(entity.imageFile);
|
||||
const groups = groupFields(template.fields, (entity.data ?? {}) as Record<string, unknown>);
|
||||
const isWorkplace = WORKPLACE_KINDS.includes(entity.kind);
|
||||
type Person = { id: string; name: string };
|
||||
type RelationItem = {
|
||||
id: string;
|
||||
type: string;
|
||||
description: string | null;
|
||||
// outgoing/incoming: vanlig relation sedd från den här posten. group: posten är med i en grupp.
|
||||
layout: "outgoing" | "incoming" | "group";
|
||||
others: Person[];
|
||||
createdAt: Date;
|
||||
};
|
||||
const relationItems: RelationItem[] = [
|
||||
...entity.outgoing.map((r): RelationItem => {
|
||||
const group = r.members.length > 0;
|
||||
return {
|
||||
id: r.id,
|
||||
type: r.type,
|
||||
description: r.description,
|
||||
layout: group ? "group" : "outgoing",
|
||||
others: [r.to, ...r.members.map((m) => m.entity)],
|
||||
createdAt: r.createdAt,
|
||||
};
|
||||
}),
|
||||
...entity.incoming.map((r): RelationItem => {
|
||||
const group = r.members.length > 0;
|
||||
return {
|
||||
id: r.id,
|
||||
type: r.type,
|
||||
description: r.description,
|
||||
layout: group ? "group" : "incoming",
|
||||
others: [r.from, ...r.members.map((m) => m.entity)],
|
||||
createdAt: r.createdAt,
|
||||
};
|
||||
}),
|
||||
...entity.memberOf.map(({ relation: r }): RelationItem => ({
|
||||
id: r.id,
|
||||
type: r.type,
|
||||
description: r.description,
|
||||
layout: "group",
|
||||
others: [r.from, r.to, ...r.members.map((m) => m.entity).filter((e) => e.id !== entity.id)],
|
||||
createdAt: r.createdAt,
|
||||
})),
|
||||
].sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
||||
const hasRelations = relationItems.length > 0;
|
||||
const entityHref = (id: string) => `/books/${bookId}/entity/${id}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
pretitle={
|
||||
<Link href={`/books/${bookId}/e/${info.slug}`} className="text-reset">
|
||||
{t(`kind.${entity.kind}.other`)}
|
||||
</Link>
|
||||
}
|
||||
title={
|
||||
<span className="d-flex align-items-center gap-2">
|
||||
<Icon size={26} className={`text-${info.color}`} />
|
||||
{entity.name}
|
||||
{entity.code ? <span className="badge fs-5 ms-1">{entity.code}</span> : null}
|
||||
</span>
|
||||
}
|
||||
actions={
|
||||
<>
|
||||
<Link href={`${entityHref(entity.id)}/edit`} className="btn">
|
||||
<IconPencil size={18} className="me-1" />
|
||||
{t("common.edit")}
|
||||
</Link>
|
||||
<form action={deleteEntity}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={entity.id} />
|
||||
<ConfirmSubmit className="btn btn-outline-danger">
|
||||
<IconTrash size={18} className="me-1" />
|
||||
{t("common.delete")}
|
||||
</ConfirmSubmit>
|
||||
</form>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
<div className="row row-cards">
|
||||
<div className="col-lg-8">
|
||||
{entity.tags.length > 0 || entity.summary ? (
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
{entity.tags.length > 0 ? (
|
||||
<div className="mb-2">
|
||||
{entity.tags.map((tag) => (
|
||||
<Link
|
||||
key={tag}
|
||||
href={`/books/${bookId}/e/${info.slug}?tag=${encodeURIComponent(tag)}`}
|
||||
className="badge bg-azure-lt me-1 text-decoration-none"
|
||||
>
|
||||
{tag}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{entity.summary ? <div className="bm-prewrap">{entity.summary}</div> : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.details")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{groups.length === 0 ? (
|
||||
<div className="text-secondary">{t("entity.noDetails")}</div>
|
||||
) : (
|
||||
groups.map((group, i) => (
|
||||
<div key={i} className={i > 0 ? "mt-4" : ""}>
|
||||
{group.section ? <h4 className="subheader border-bottom pb-2 mb-3">{group.section}</h4> : null}
|
||||
<dl className="mb-0">
|
||||
{group.items.map(({ field, value }) => (
|
||||
<div className="row mb-2" key={field.key}>
|
||||
<dt className="col-sm-4 text-secondary fw-normal">{field.label}</dt>
|
||||
<dd className={`col-sm-8 mb-0 ${field.type === "textarea" ? "bm-prewrap" : ""}`}>
|
||||
{field.type === "url" ? (
|
||||
<a href={value} target="_blank" rel="noopener noreferrer nofollow">
|
||||
{value}
|
||||
</a>
|
||||
) : (
|
||||
value
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
{image ? (
|
||||
<div className="card mb-3">
|
||||
<div className="card-body p-2">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={image} alt={entity.name} className="bm-portrait" />
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.relations")}</h3>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{!hasRelations ? <div className="list-group-item text-secondary">{t("entity.noRelations")}</div> : null}
|
||||
{relationItems.map((item) => (
|
||||
<div className="list-group-item d-flex align-items-center gap-2" key={item.id}>
|
||||
<div className="flex-fill min-w-0">
|
||||
{item.layout === "outgoing" ? (
|
||||
<>
|
||||
<Link href={`/books/${bookId}/relations/${item.id}`} className="text-secondary">
|
||||
{item.type}
|
||||
</Link>{" "}
|
||||
<EntityLinks bookId={bookId} entities={item.others} />
|
||||
</>
|
||||
) : item.layout === "incoming" ? (
|
||||
<>
|
||||
<EntityLinks bookId={bookId} entities={item.others} />{" "}
|
||||
<Link href={`/books/${bookId}/relations/${item.id}`} className="text-secondary">
|
||||
{item.type}
|
||||
</Link>{" "}
|
||||
{entity.name}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Link href={`/books/${bookId}/relations/${item.id}`} className="text-secondary">
|
||||
{item.type}:
|
||||
</Link>{" "}
|
||||
<EntityLinks bookId={bookId} entities={item.others} />
|
||||
</>
|
||||
)}
|
||||
{item.description ? <div className="text-secondary small">{item.description}</div> : null}
|
||||
</div>
|
||||
<RemoveRelation bookId={bookId} id={item.id} label={t("common.delete")} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="card-body border-top">
|
||||
<RelationForm bookId={bookId} entities={allEntities} fixedFromId={entity.id} t={t} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{entity.kind === "CHARACTER" ? (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.schedule")}</h3>
|
||||
<div className="card-actions">
|
||||
<Link href={`/books/${bookId}/schedules?person=${entity.id}`} className="btn btn-sm">
|
||||
{t("nav.schedules")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{entity.shifts.length === 0 ? <div className="list-group-item text-secondary">{t("entity.noShifts")}</div> : null}
|
||||
{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.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(" · ")}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{isWorkplace ? (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.workers")}</h3>
|
||||
<div className="card-actions">
|
||||
<Link href={`/books/${bookId}/schedules?workplace=${entity.id}`} className="btn btn-sm">
|
||||
{t("nav.schedules")}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{entity.hostedShifts.length === 0 ? <div className="list-group-item text-secondary">{t("entity.noWorkers")}</div> : null}
|
||||
{entity.hostedShifts.map((s) => (
|
||||
<div className="list-group-item" key={s.id}>
|
||||
<Link href={entityHref(s.person.id)} className="fw-bold">
|
||||
{s.person.name}
|
||||
</Link>
|
||||
<div className="text-secondary small">
|
||||
{t(`day.short.${s.weekday}`)} {s.startTime}–{s.endTime}
|
||||
{s.label ? ` · ${s.label}` : ""}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.onMap")}</h3>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{entity.markers.length === 0 ? <div className="list-group-item text-secondary">{t("entity.noMarkers")}</div> : null}
|
||||
{entity.markers.map((m) => (
|
||||
<Link
|
||||
key={m.id}
|
||||
href={`/books/${bookId}/maps/${m.mapId}?marker=${m.id}`}
|
||||
className="list-group-item list-group-item-action d-flex align-items-center gap-2"
|
||||
>
|
||||
<IconMapPin size={18} />
|
||||
<span>{m.map.name}</span>
|
||||
<span className="text-secondary">· {m.label}</span>
|
||||
</Link>
|
||||
))}
|
||||
{maps.map((map) => (
|
||||
<Link
|
||||
key={map.id}
|
||||
href={`/books/${bookId}/maps/${map.id}?place=${entity.id}`}
|
||||
className="list-group-item list-group-item-action text-primary"
|
||||
>
|
||||
{t("entity.placeOnMap")}: {map.name}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function RemoveRelation({ bookId, id, label }: { bookId: string; id: string; label: string }) {
|
||||
return (
|
||||
<form action={deleteRelation}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={id} />
|
||||
<button type="submit" className="btn btn-icon btn-sm btn-ghost-secondary" title={label} aria-label={label}>
|
||||
<IconX size={16} />
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function EntityLinks({ bookId, entities }: { bookId: string; entities: { id: string; name: string }[] }) {
|
||||
return (
|
||||
<>
|
||||
{entities.map((e, i) => (
|
||||
<span key={e.id}>
|
||||
{i > 0 ? ", " : ""}
|
||||
<Link href={`/books/${bookId}/entity/${e.id}`} className="fw-bold">
|
||||
{e.name}
|
||||
</Link>
|
||||
</span>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Shell } from "@/components/shell";
|
||||
import { requireBook, requireUser } from "@/lib/session";
|
||||
|
||||
export default async function BookLayout({
|
||||
children,
|
||||
params,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
params: Promise<{ bookId: string }>;
|
||||
}) {
|
||||
const { bookId } = await params;
|
||||
const user = await requireUser();
|
||||
const book = await requireBook(bookId);
|
||||
return (
|
||||
<Shell user={user} book={{ id: book.id, title: book.title }}>
|
||||
{children}
|
||||
</Shell>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { deleteMap, renameMap } from "@/actions/maps";
|
||||
import { ConfirmSubmit } from "@/components/confirm-submit";
|
||||
import { MapLoader } from "@/components/map-loader";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { fileUrl } from "@/lib/files";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
// Standard är OpenStreetMaps publika tjänster. Byt via miljövariabler vid tyngre användning.
|
||||
const TILE_URL = process.env.MAP_TILE_URL ?? "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
|
||||
const TILE_ATTRIBUTION = process.env.MAP_TILE_ATTRIBUTION ?? "© OpenStreetMap-bidragsgivare";
|
||||
const GEOCODER_URL = process.env.MAP_GEOCODER_URL ?? "https://nominatim.openstreetmap.org/search";
|
||||
|
||||
export default async function MapPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string; mapId: string }>;
|
||||
searchParams: Promise<{ place?: string; marker?: string }>;
|
||||
}) {
|
||||
const { bookId, mapId } = await params;
|
||||
const { place, marker } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
const [map, entities] = await Promise.all([
|
||||
prisma.bookMap.findFirst({ where: { id: mapId, bookId }, include: { markers: { orderBy: { createdAt: "asc" } } } }),
|
||||
prisma.entity.findMany({ where: { bookId }, select: { id: true, name: true, kind: true }, orderBy: { name: "asc" } }),
|
||||
]);
|
||||
if (!map) notFound();
|
||||
|
||||
const center: [number, number] | null =
|
||||
map.centerLat !== null && map.centerLng !== null ? [map.centerLat, map.centerLng] : null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={map.name} pretitle={t("map.title")} />
|
||||
<PageBody>
|
||||
<MapLoader
|
||||
bookId={bookId}
|
||||
mapId={map.id}
|
||||
kind={map.kind}
|
||||
imageUrl={fileUrl(map.imageFile)}
|
||||
center={center}
|
||||
zoom={map.zoom}
|
||||
markers={map.markers.map((m) => ({
|
||||
id: m.id,
|
||||
label: m.label,
|
||||
note: m.note,
|
||||
color: m.color,
|
||||
lat: m.lat,
|
||||
lng: m.lng,
|
||||
entityId: m.entityId,
|
||||
}))}
|
||||
entities={entities}
|
||||
tileUrl={TILE_URL}
|
||||
tileAttribution={TILE_ATTRIBUTION}
|
||||
geocoderUrl={GEOCODER_URL}
|
||||
preselectEntityId={entities.some((e) => e.id === place) ? (place ?? null) : null}
|
||||
initialMarkerId={marker ?? null}
|
||||
/>
|
||||
|
||||
<div className="card mt-4">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("map.settings")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
<div className="col-md-6">
|
||||
<form action={renameMap} className="input-group">
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="mapId" value={map.id} />
|
||||
<input name="name" className="form-control" defaultValue={map.name} required maxLength={200} aria-label={t("map.rename")} />
|
||||
<button type="submit" className="btn">
|
||||
{t("map.rename")}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div className="col-md-6 d-flex align-items-center gap-3">
|
||||
<form action={deleteMap}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="mapId" value={map.id} />
|
||||
<ConfirmSubmit className="btn btn-outline-danger">{t("map.deleteMap")}</ConfirmSubmit>
|
||||
</form>
|
||||
<span className="text-secondary small">{t("map.deleteMapHelp")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import Link from "next/link";
|
||||
import { IconMap2, IconPhoto } from "@tabler/icons-react";
|
||||
import { createMap } from "@/actions/maps";
|
||||
import { EmptyState, PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export const metadata = { title: "Kartor" };
|
||||
|
||||
export default async function MapsPage({ params }: { params: Promise<{ bookId: string }> }) {
|
||||
const { bookId } = await params;
|
||||
await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
const maps = await prisma.bookMap.findMany({
|
||||
where: { bookId },
|
||||
orderBy: { createdAt: "asc" },
|
||||
include: { _count: { select: { markers: true } } },
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t("map.title")} />
|
||||
<PageBody>
|
||||
<div className="row row-cards">
|
||||
<div className="col-lg-8">
|
||||
{maps.length === 0 ? (
|
||||
<EmptyState>{t("map.empty")}</EmptyState>
|
||||
) : (
|
||||
<div className="row row-cards">
|
||||
{maps.map((map) => (
|
||||
<div className="col-md-6" key={map.id}>
|
||||
<Link href={`/books/${bookId}/maps/${map.id}`} className="card card-link card-link-pop h-100">
|
||||
<div className="card-body d-flex align-items-center gap-3">
|
||||
<span className={`avatar ${map.kind === "GEO" ? "bg-green-lt" : "bg-purple-lt"}`}>
|
||||
{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="text-secondary">
|
||||
{t(`map.kind.${map.kind}`)} · {t("map.markerCount", { n: map._count.markers })}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
<form action={createMap} className="card">
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("map.new")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="mb-3">
|
||||
<label className="form-label required">{t("common.name")}</label>
|
||||
<input name="name" className="form-control" required maxLength={200} />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label className="form-label">{t("common.type")}</label>
|
||||
<select name="kind" className="form-select" defaultValue="GEO">
|
||||
<option value="GEO">{t("map.kind.GEO")}</option>
|
||||
<option value="IMAGE">{t("map.kind.IMAGE")}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="mb-0">
|
||||
<label className="form-label">{t("map.image")}</label>
|
||||
<input type="file" name="image" className="form-control" accept="image/png,image/jpeg,image/webp,image/gif" />
|
||||
<div className="form-hint">{t("map.imageHelp")}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer text-end">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("common.create")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import Link from "next/link";
|
||||
import { IconPlus } from "@tabler/icons-react";
|
||||
import { kindIcons } from "@/components/kind-icons";
|
||||
import { EmptyState, PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { KIND_INFO, KINDS } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export default async function BookDashboard({ params }: { params: Promise<{ bookId: string }> }) {
|
||||
const { bookId } = await params;
|
||||
const book = await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
const [counts, recent] = await Promise.all([
|
||||
prisma.entity.groupBy({ by: ["kind"], where: { bookId }, _count: true }),
|
||||
prisma.entity.findMany({ where: { bookId }, orderBy: { updatedAt: "desc" }, take: 8 }),
|
||||
]);
|
||||
const countOf = Object.fromEntries(counts.map((c) => [c.kind, c._count]));
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={book.title}
|
||||
pretitle={[book.subtitle, book.genre].filter(Boolean).join(" · ") || undefined}
|
||||
/>
|
||||
<PageBody>
|
||||
{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 }) => {
|
||||
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>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("dashboard.recent")}</h3>
|
||||
</div>
|
||||
{recent.length === 0 ? (
|
||||
<div className="card-body">
|
||||
<EmptyState>{t("dashboard.emptyRecent")}</EmptyState>
|
||||
</div>
|
||||
) : (
|
||||
<div className="list-group list-group-flush">
|
||||
{recent.map((entity) => {
|
||||
const Icon = kindIcons[entity.kind];
|
||||
return (
|
||||
<Link
|
||||
key={entity.id}
|
||||
href={`/books/${bookId}/entity/${entity.id}`}
|
||||
className="list-group-item list-group-item-action d-flex align-items-center gap-3"
|
||||
>
|
||||
<span className={`avatar avatar-sm bg-${KIND_INFO[entity.kind].color}-lt`}>
|
||||
<Icon size={16} />
|
||||
</span>
|
||||
<span className="fw-bold">{entity.name}</span>
|
||||
<span className="text-secondary">{t(`kind.${entity.kind}.one`)}</span>
|
||||
<span className="ms-auto text-secondary small">{entity.updatedAt.toLocaleDateString()}</span>
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Fragment } from "react";
|
||||
import { IconTrash } from "@tabler/icons-react";
|
||||
import { deleteRelation, saveRelation } from "@/actions/relations";
|
||||
import { ConfirmSubmit } from "@/components/confirm-submit";
|
||||
import { EntitySelect } from "@/components/entity-select";
|
||||
import { FieldInput } from "@/components/entity-form";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
|
||||
export default async function RelationPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string; relationId: string }>;
|
||||
searchParams: Promise<{ saved?: string }>;
|
||||
}) {
|
||||
const { bookId, relationId } = await params;
|
||||
const { saved } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const { t, locale } = await getT();
|
||||
|
||||
const relation = await prisma.relation.findFirst({
|
||||
where: { id: relationId, bookId },
|
||||
include: { from: true, to: true, members: { include: { entity: true } } },
|
||||
});
|
||||
if (!relation) notFound();
|
||||
const candidates = await prisma.entity.findMany({
|
||||
where: { bookId, id: { notIn: [relation.fromId, relation.toId] } },
|
||||
select: { id: true, name: true, kind: true },
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
const memberEntities = relation.members.map((m) => m.entity);
|
||||
const isGroup = memberEntities.length > 0;
|
||||
const { fields } = await getTemplate(bookId, "RELATION", locale);
|
||||
const data = (relation.data ?? {}) as Record<string, unknown>;
|
||||
const suggestions = t("relation.suggestions").split(",");
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
pretitle={
|
||||
<Link href={`/books/${bookId}/relations`} className="text-reset">
|
||||
{t("relation.title")}
|
||||
</Link>
|
||||
}
|
||||
title={
|
||||
isGroup ? (
|
||||
<span>
|
||||
{[relation.from, relation.to, ...memberEntities].map((e, i) => (
|
||||
<span key={e.id}>
|
||||
{i > 0 ? ", " : ""}
|
||||
<Link href={`/books/${bookId}/entity/${e.id}`} className="text-reset">
|
||||
{e.name}
|
||||
</Link>
|
||||
</span>
|
||||
))}
|
||||
<span className="text-secondary fw-normal"> · {relation.type}</span>
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
<Link href={`/books/${bookId}/entity/${relation.fromId}`} className="text-reset">
|
||||
{relation.from.name}
|
||||
</Link>
|
||||
<span className="text-secondary fw-normal"> · {relation.type} · </span>
|
||||
<Link href={`/books/${bookId}/entity/${relation.toId}`} className="text-reset">
|
||||
{relation.to.name}
|
||||
</Link>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
actions={
|
||||
<form action={deleteRelation}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={relation.id} />
|
||||
<input type="hidden" name="redirect" value="list" />
|
||||
<ConfirmSubmit className="btn btn-outline-danger">
|
||||
<IconTrash size={18} className="me-1" />
|
||||
{t("common.delete")}
|
||||
</ConfirmSubmit>
|
||||
</form>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
{saved ? <div className="alert alert-success">{t("common.saved")}</div> : null}
|
||||
<form action={saveRelation}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={relation.id} />
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
<div className="col-md-6">
|
||||
<label className="form-label required">{t("relation.type")}</label>
|
||||
<input name="type" className="form-control" list="relation-types" required maxLength={100} defaultValue={relation.type} />
|
||||
<datalist id="relation-types">
|
||||
{suggestions.map((s) => (
|
||||
<option key={s} value={s} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("common.note")}</label>
|
||||
<input name="description" className="form-control" maxLength={2000} defaultValue={relation.description ?? ""} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-label">{t("relation.members")}</label>
|
||||
<EntitySelect
|
||||
name="memberIds"
|
||||
entities={candidates}
|
||||
t={t}
|
||||
multiple
|
||||
defaultValues={memberEntities.map((e) => e.id)}
|
||||
/>
|
||||
<div className="form-hint">{t("relation.membersHelp")}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{fields.length > 0 ? (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("entity.details")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
{fields.map((field) => (
|
||||
<Fragment key={field.key}>
|
||||
{field.section ? (
|
||||
<div className="col-12">
|
||||
<h4 className="subheader border-bottom pb-2 mb-0 mt-2">{field.section}</h4>
|
||||
</div>
|
||||
) : null}
|
||||
<div className={field.type === "textarea" ? "col-12" : "col-md-6"}>
|
||||
{field.type !== "checkbox" ? <label className="form-label">{field.label}</label> : null}
|
||||
<FieldInput field={field} value={data[field.key]} />
|
||||
</div>
|
||||
</Fragment>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="d-flex justify-content-end gap-2">
|
||||
<Link href={`/books/${bookId}/relations`} className="btn">
|
||||
{t("common.back")}
|
||||
</Link>
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("common.save")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import Link from "next/link";
|
||||
import { IconX } from "@tabler/icons-react";
|
||||
import { deleteRelation } from "@/actions/relations";
|
||||
import { EntitySelect } from "@/components/entity-select";
|
||||
import { EmptyState, PageBody, PageHeader } from "@/components/page";
|
||||
import { RelationForm } from "@/components/relation-form";
|
||||
import { RelationGraph } from "@/components/relation-graph";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export const metadata = { title: "Relationer" };
|
||||
|
||||
export default async function RelationsPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string }>;
|
||||
searchParams: Promise<{ entity?: string }>;
|
||||
}) {
|
||||
const { bookId } = await params;
|
||||
const { entity: entityFilter } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
const [entities, relations] = await Promise.all([
|
||||
prisma.entity.findMany({ where: { bookId }, select: { id: true, name: true, kind: true }, orderBy: { name: "asc" } }),
|
||||
prisma.relation.findMany({
|
||||
where: {
|
||||
bookId,
|
||||
...(entityFilter
|
||||
? { OR: [{ fromId: entityFilter }, { toId: entityFilter }, { members: { some: { entityId: entityFilter } } }] }
|
||||
: {}),
|
||||
},
|
||||
include: { from: true, to: true, members: { include: { entity: true } } },
|
||||
orderBy: { createdAt: "asc" },
|
||||
}),
|
||||
]);
|
||||
|
||||
const nodeMap = new Map<string, { id: string; name: string; kind: (typeof entities)[number]["kind"] }>();
|
||||
for (const r of relations) {
|
||||
nodeMap.set(r.from.id, r.from);
|
||||
nodeMap.set(r.to.id, r.to);
|
||||
for (const m of r.members) nodeMap.set(m.entity.id, m.entity);
|
||||
}
|
||||
const nodes = [...nodeMap.values()];
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t("relation.title")} />
|
||||
<PageBody>
|
||||
<div className="row row-cards">
|
||||
<div className="col-lg-8">
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("relation.diagram")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{relations.length === 0 ? (
|
||||
<EmptyState>{t("relation.empty")}</EmptyState>
|
||||
) : nodes.length > 40 ? null : (
|
||||
<RelationGraph
|
||||
bookId={bookId}
|
||||
nodes={nodes}
|
||||
edges={relations.map((r) => ({
|
||||
id: r.id,
|
||||
type: r.type,
|
||||
participantIds: [r.fromId, r.toId, ...r.members.map((m) => m.entityId)],
|
||||
}))}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("relation.all")}</h3>
|
||||
<div className="card-actions">
|
||||
<form className="d-flex gap-2">
|
||||
<EntitySelect
|
||||
name="entity"
|
||||
entities={entities}
|
||||
t={t}
|
||||
defaultValue={entityFilter}
|
||||
emptyLabel={t("relation.filter")}
|
||||
className="form-select form-select-sm"
|
||||
/>
|
||||
<button className="btn btn-sm" type="submit">
|
||||
{t("common.search")}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{relations.length === 0 ? null : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<tbody>
|
||||
{relations.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td>
|
||||
<Link href={`/books/${bookId}/entity/${r.fromId}`} className="fw-bold">
|
||||
{r.from.name}
|
||||
</Link>
|
||||
</td>
|
||||
<td>
|
||||
<Link href={`/books/${bookId}/relations/${r.id}`} className="text-secondary" title={t("common.edit")}>
|
||||
{r.type}
|
||||
</Link>
|
||||
</td>
|
||||
<td>
|
||||
{[r.to, ...r.members.map((m) => m.entity)].map((e, i) => (
|
||||
<span key={e.id}>
|
||||
{i > 0 ? ", " : ""}
|
||||
<Link href={`/books/${bookId}/entity/${e.id}`} className="fw-bold">
|
||||
{e.name}
|
||||
</Link>
|
||||
</span>
|
||||
))}
|
||||
</td>
|
||||
<td className="text-secondary">{r.description}</td>
|
||||
<td className="w-1">
|
||||
<form action={deleteRelation}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={r.id} />
|
||||
<button type="submit" className="btn btn-icon btn-sm btn-ghost-secondary" aria-label={t("common.delete")} title={t("common.delete")}>
|
||||
<IconX size={16} />
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("relation.add")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<RelationForm bookId={bookId} entities={entities} t={t} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
import Link from "next/link";
|
||||
import { IconX } from "@tabler/icons-react";
|
||||
import { addShifts, deleteShift } from "@/actions/shifts";
|
||||
import { EntitySelect } from "@/components/entity-select";
|
||||
import { EmptyState, PageBody, PageHeader } from "@/components/page";
|
||||
import type { TFunction } from "@/i18n/core";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { WORKPLACE_KINDS } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export const metadata = { title: "Scheman" };
|
||||
|
||||
const DAYS = [0, 1, 2, 3, 4, 5, 6];
|
||||
|
||||
type ShiftRow = {
|
||||
id: string;
|
||||
weekday: number;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
weeks: "ALL" | "ODD" | "EVEN";
|
||||
label: string | null;
|
||||
person: { id: string; name: string };
|
||||
workplace: { id: string; name: string } | null;
|
||||
};
|
||||
|
||||
function ShiftChip({
|
||||
shift,
|
||||
bookId,
|
||||
t,
|
||||
showPerson,
|
||||
}: {
|
||||
shift: ShiftRow;
|
||||
bookId: string;
|
||||
t: TFunction;
|
||||
showPerson?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div className="d-flex align-items-start gap-1 border rounded px-2 py-1 mb-1">
|
||||
<div className="flex-fill min-w-0 small">
|
||||
<div className="fw-bold">
|
||||
{showPerson ? (
|
||||
<Link href={`/books/${bookId}/entity/${shift.person.id}`} className="text-reset">
|
||||
{shift.person.name}
|
||||
</Link>
|
||||
) : (
|
||||
<>
|
||||
{shift.startTime}–{shift.endTime}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-secondary">
|
||||
{showPerson ? `${shift.startTime}–${shift.endTime}` : null}
|
||||
{[
|
||||
shift.workplace?.name,
|
||||
shift.label,
|
||||
shift.weeks !== "ALL" ? t(`schedule.weeks.${shift.weeks}`) : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.map((part, i) => (
|
||||
<span key={i}>
|
||||
{showPerson || i > 0 ? " · " : ""}
|
||||
{part}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<form action={deleteShift}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="id" value={shift.id} />
|
||||
<button type="submit" className="btn btn-icon btn-sm btn-ghost-secondary" title={t("common.delete")} aria-label={t("common.delete")}>
|
||||
<IconX size={14} />
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default async function SchedulesPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string }>;
|
||||
searchParams: Promise<{ view?: string; range?: string; person?: string; workplace?: string }>;
|
||||
}) {
|
||||
const { bookId } = await params;
|
||||
const { view = "person", range: rangeParam, person, workplace } = await searchParams;
|
||||
const range = rangeParam === "night" ? "night" : "day";
|
||||
await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
const [people, workplaces, shifts] = await Promise.all([
|
||||
prisma.entity.findMany({
|
||||
where: { bookId, kind: { in: ["CHARACTER"] } },
|
||||
select: { id: true, name: true, kind: true },
|
||||
orderBy: { name: "asc" },
|
||||
}),
|
||||
prisma.entity.findMany({
|
||||
where: { bookId, kind: { in: WORKPLACE_KINDS } },
|
||||
select: { id: true, name: true, kind: true },
|
||||
orderBy: { name: "asc" },
|
||||
}),
|
||||
prisma.shift.findMany({
|
||||
where: {
|
||||
bookId,
|
||||
...(person ? { personId: person } : {}),
|
||||
...(workplace ? { workplaceId: workplace } : {}),
|
||||
},
|
||||
include: { person: { select: { id: true, name: true } }, workplace: { select: { id: true, name: true } } },
|
||||
orderBy: [{ startTime: "asc" }],
|
||||
}),
|
||||
]);
|
||||
|
||||
const byDay = view === "day";
|
||||
const byGrid = view === "grid";
|
||||
const queryFor = (v: string, r: string = range) => {
|
||||
const q = new URLSearchParams({ view: v });
|
||||
if (v === "grid") q.set("range", r);
|
||||
if (person) q.set("person", person);
|
||||
if (workplace) q.set("workplace", workplace);
|
||||
return `?${q}`;
|
||||
};
|
||||
|
||||
// Timrutnät som i dag- och nattscheman: dag 06–18, natt 18–06. Natten hör till dagen den började.
|
||||
const gridHours = range === "day" ? [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] : [18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5];
|
||||
const toHours = (time: string) => {
|
||||
const [h, m] = time.split(":").map(Number);
|
||||
return h + m / 60;
|
||||
};
|
||||
const covers = (s: (typeof shifts)[number], column: number, hour: number) => {
|
||||
const slot = range === "night" && hour < 6 ? (column + 1) * 24 + hour : column * 24 + hour;
|
||||
const start = s.weekday * 24 + toHours(s.startTime);
|
||||
let end = s.weekday * 24 + toHours(s.endTime);
|
||||
if (end <= start) end += 24;
|
||||
return [slot - 168, slot, slot + 168].some((a) => start < a + 1 && end > a);
|
||||
};
|
||||
|
||||
// Rader per person, i kolumnordning efter namn
|
||||
const personRows = people
|
||||
.map((p) => ({ person: p, shifts: shifts.filter((s) => s.personId === p.id) }))
|
||||
.filter((row) => row.shifts.length > 0);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={t("schedule.title")}
|
||||
actions={
|
||||
<>
|
||||
{byGrid ? (
|
||||
<div className="btn-group">
|
||||
<Link href={queryFor("grid", "day")} className={`btn ${range === "day" ? "active" : ""}`}>
|
||||
{t("schedule.rangeDay")}
|
||||
</Link>
|
||||
<Link href={queryFor("grid", "night")} className={`btn ${range === "night" ? "active" : ""}`}>
|
||||
{t("schedule.rangeNight")}
|
||||
</Link>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="btn-group">
|
||||
<Link href={queryFor("person")} className={`btn ${!byDay && !byGrid ? "active" : ""}`}>
|
||||
{t("schedule.viewPerson")}
|
||||
</Link>
|
||||
<Link href={queryFor("day")} className={`btn ${byDay ? "active" : ""}`}>
|
||||
{t("schedule.viewDay")}
|
||||
</Link>
|
||||
<Link href={queryFor("grid")} className={`btn ${byGrid ? "active" : ""}`}>
|
||||
{t("schedule.viewGrid")}
|
||||
</Link>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<PageBody>
|
||||
<div className="row row-cards">
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-body py-3">
|
||||
<form className="row g-2 align-items-center">
|
||||
<input type="hidden" name="view" value={view} />
|
||||
{byGrid ? <input type="hidden" name="range" value={range} /> : null}
|
||||
<div className="col-md-5">
|
||||
<EntitySelect
|
||||
name="person"
|
||||
entities={people}
|
||||
t={t}
|
||||
defaultValue={person}
|
||||
emptyLabel={t("schedule.filterPerson")}
|
||||
className="form-select form-select-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-5">
|
||||
<EntitySelect
|
||||
name="workplace"
|
||||
entities={workplaces}
|
||||
t={t}
|
||||
defaultValue={workplace}
|
||||
emptyLabel={t("schedule.filterWorkplace")}
|
||||
className="form-select form-select-sm"
|
||||
/>
|
||||
</div>
|
||||
<div className="col-md-2 d-flex gap-2">
|
||||
<button className="btn btn-sm" type="submit">
|
||||
{t("common.search")}
|
||||
</button>
|
||||
{person || workplace ? (
|
||||
<Link href={`?view=${view}`} className="btn btn-sm btn-ghost-secondary">
|
||||
{t("common.clear")}
|
||||
</Link>
|
||||
) : null}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
{shifts.length === 0 ? (
|
||||
<div className="card-body">
|
||||
<EmptyState>{t("schedule.empty")}</EmptyState>
|
||||
</div>
|
||||
) : byGrid ? (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-bordered card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="w-1" />
|
||||
{DAYS.map((d) => (
|
||||
<th key={d} className="bm-week-cell">
|
||||
{t(`day.short.${d}`)}
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{gridHours.map((hour) => (
|
||||
<tr key={hour}>
|
||||
<td className="text-secondary text-nowrap">{String(hour).padStart(2, "0")}:00</td>
|
||||
{DAYS.map((d) => {
|
||||
const here = shifts.filter((s) => covers(s, d, hour));
|
||||
return (
|
||||
<td key={d} className="bm-week-cell py-1">
|
||||
{here.map((s) => (
|
||||
<Link
|
||||
key={s.id}
|
||||
href={`/books/${bookId}/entity/${s.person.id}`}
|
||||
className="badge bg-blue-lt me-1 mb-1 text-decoration-none"
|
||||
title={[s.workplace?.name, `${s.startTime}–${s.endTime}`, s.label].filter(Boolean).join(" · ")}
|
||||
>
|
||||
{s.person.name}
|
||||
</Link>
|
||||
))}
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : byDay ? (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
{DAYS.map((d) => (
|
||||
<th key={d} className="bm-week-cell">{t(`day.${d}`)}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
{DAYS.map((d) => (
|
||||
<td key={d} className="bm-week-cell">
|
||||
{shifts
|
||||
.filter((s) => s.weekday === d)
|
||||
.map((s) => (
|
||||
<ShiftChip key={s.id} shift={s} bookId={bookId} t={t} showPerson />
|
||||
))}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th />
|
||||
{DAYS.map((d) => (
|
||||
<th key={d} className="bm-week-cell">{t(`day.short.${d}`)}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{personRows.map(({ person: p, shifts: rowShifts }) => (
|
||||
<tr key={p.id}>
|
||||
<td className="fw-bold">
|
||||
<Link href={`/books/${bookId}/entity/${p.id}`} className="text-reset">
|
||||
{p.name}
|
||||
</Link>
|
||||
</td>
|
||||
{DAYS.map((d) => (
|
||||
<td key={d} className="bm-week-cell">
|
||||
{rowShifts
|
||||
.filter((s) => s.weekday === d)
|
||||
.map((s) => (
|
||||
<ShiftChip key={s.id} shift={s} bookId={bookId} t={t} />
|
||||
))}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-8">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("schedule.add")}</h3>
|
||||
</div>
|
||||
{people.length === 0 ? (
|
||||
<div className="card-body text-secondary">{t("schedule.noPeople")}</div>
|
||||
) : (
|
||||
<form action={addShifts}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
<div className="col-md-6">
|
||||
<label className="form-label required">{t("schedule.person")}</label>
|
||||
<EntitySelect name="personId" entities={people} t={t} required defaultValue={person} />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("schedule.workplace")}</label>
|
||||
<EntitySelect
|
||||
name="workplaceId"
|
||||
entities={workplaces}
|
||||
t={t}
|
||||
emptyLabel={t("schedule.noWorkplace")}
|
||||
defaultValue={workplace}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-label required">{t("schedule.days")}</label>
|
||||
<div className="d-flex flex-wrap gap-3">
|
||||
{DAYS.map((d) => (
|
||||
<label className="form-check" key={d}>
|
||||
<input type="checkbox" name="days" value={d} className="form-check-input" defaultChecked={d < 5} />
|
||||
<span className="form-check-label">{t(`day.${d}`)}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-6 col-md-3">
|
||||
<label className="form-label required">{t("schedule.start")}</label>
|
||||
<input type="time" name="startTime" className="form-control" required defaultValue="08:00" />
|
||||
</div>
|
||||
<div className="col-6 col-md-3">
|
||||
<label className="form-label required">{t("schedule.end")}</label>
|
||||
<input type="time" name="endTime" className="form-control" required defaultValue="16:00" />
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">{t("schedule.weeks")}</label>
|
||||
<select name="weeks" className="form-select" defaultValue="ALL">
|
||||
{(["ALL", "ODD", "EVEN"] as const).map((w) => (
|
||||
<option key={w} value={w}>
|
||||
{t(`schedule.weeks.${w}`)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label">{t("schedule.label")}</label>
|
||||
<input name="label" className="form-control" maxLength={100} placeholder={t("schedule.labelHelp")} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer text-end">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("common.add")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { IconDownload } from "@tabler/icons-react";
|
||||
import { deleteBook, updateBook } from "@/actions/books";
|
||||
import { ConfirmSubmit } from "@/components/confirm-submit";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
export const metadata = { title: "Bokinställningar" };
|
||||
|
||||
export default async function SettingsPage({ params }: { params: Promise<{ bookId: string }> }) {
|
||||
const { bookId } = await params;
|
||||
const book = await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t("settings.title")} />
|
||||
<PageBody>
|
||||
<div className="row row-cards">
|
||||
<div className="col-lg-8">
|
||||
<form action={updateBook} className="card">
|
||||
<input type="hidden" name="bookId" value={book.id} />
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
<div className="col-md-6">
|
||||
<label className="form-label required">{t("common.title")}</label>
|
||||
<input name="title" className="form-control" required maxLength={200} defaultValue={book.title} />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("books.subtitle")}</label>
|
||||
<input name="subtitle" className="form-control" maxLength={200} defaultValue={book.subtitle ?? ""} />
|
||||
</div>
|
||||
<div className="col-md-6">
|
||||
<label className="form-label">{t("books.genre")}</label>
|
||||
<input name="genre" className="form-control" maxLength={100} defaultValue={book.genre ?? ""} />
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-label">{t("common.description")}</label>
|
||||
<textarea name="description" className="form-control" rows={4} defaultValue={book.description ?? ""} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer text-end">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
{t("common.save")}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div className="col-lg-4">
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">{t("settings.exportHelp")}</p>
|
||||
<a className="btn" href={`/api/books/${book.id}/export`}>
|
||||
<IconDownload size={18} className="me-1" />
|
||||
{t("settings.export")}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card border-danger">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title text-danger">{t("settings.danger")}</h3>
|
||||
</div>
|
||||
<form action={deleteBook} className="card-body">
|
||||
<input type="hidden" name="bookId" value={book.id} />
|
||||
<p className="text-secondary">{t("settings.deleteBookHelp")}</p>
|
||||
<ConfirmSubmit>{t("settings.deleteBook")}</ConfirmSubmit>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { TemplateEditor } from "@/components/template-editor";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { templateKindFromSlug } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { getPresets, getTemplate } from "@/lib/templates";
|
||||
|
||||
export default async function TemplateEditPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string; kind: string }>;
|
||||
searchParams: Promise<{ error?: string; saved?: string }>;
|
||||
}) {
|
||||
const { bookId, kind: slug } = await params;
|
||||
const { error, saved } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const kind = templateKindFromSlug(slug);
|
||||
if (!kind) notFound();
|
||||
const { t, locale } = await getT();
|
||||
const { fields, custom } = await getTemplate(bookId, kind, locale);
|
||||
const presets = getPresets(kind, locale).map((p) => ({ ...p, label: t(`template.preset.${p.id}`) }));
|
||||
const kindLabel = kind === "RELATION" ? t("relation.one") : t(`kind.${kind}.one`);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={`${t("template.edit")}: ${kindLabel}`}
|
||||
pretitle={t("template.title")}
|
||||
actions={<span className={`badge ${custom ? "bg-green-lt" : ""}`}>{custom ? t("template.custom") : t("template.standard")}</span>}
|
||||
/>
|
||||
<PageBody>
|
||||
{error ? <div className="alert alert-danger">{t("template.invalid", { reason: error })}</div> : null}
|
||||
{saved ? <div className="alert alert-success">{t("common.saved")}</div> : null}
|
||||
<TemplateEditor bookId={bookId} kind={kind} initialFields={fields} custom={custom} presets={presets} />
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import Link from "next/link";
|
||||
import { IconChartDots3 } from "@tabler/icons-react";
|
||||
import { kindIcons } from "@/components/kind-icons";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { KINDS, templateSlug, type TemplateKind } from "@/lib/kinds";
|
||||
import { requireBook } from "@/lib/session";
|
||||
import { getTemplate } from "@/lib/templates";
|
||||
|
||||
export const metadata = { title: "Mallar" };
|
||||
|
||||
export default async function TemplatesPage({ params }: { params: Promise<{ bookId: string }> }) {
|
||||
const { bookId } = await params;
|
||||
await requireBook(bookId);
|
||||
const { t, locale } = await getT();
|
||||
|
||||
const kinds: { kind: TemplateKind; color: string }[] = [
|
||||
...KINDS.map(({ kind, color }) => ({ kind: kind as TemplateKind, color })),
|
||||
{ kind: "RELATION", color: "azure" },
|
||||
];
|
||||
const templates = await Promise.all(kinds.map(async (k) => ({ ...k, ...(await getTemplate(bookId, k.kind, locale)) })));
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={t("template.title")} />
|
||||
<PageBody>
|
||||
<p className="text-secondary">{t("template.intro")}</p>
|
||||
<div className="row row-cards">
|
||||
{templates.map(({ kind, color, fields, custom }) => {
|
||||
const Icon = kind === "RELATION" ? IconChartDots3 : kindIcons[kind];
|
||||
return (
|
||||
<div className="col-md-6 col-xl-4" key={kind}>
|
||||
<Link href={`/books/${bookId}/templates/${templateSlug(kind)}`} className="card card-link card-link-pop h-100">
|
||||
<div className="card-body d-flex align-items-center gap-3">
|
||||
<span className={`avatar bg-${color}-lt`}>
|
||||
<Icon size={22} />
|
||||
</span>
|
||||
<div>
|
||||
<div className="fw-bold">{kind === "RELATION" ? t("relation.one") : t(`kind.${kind}.one`)}</div>
|
||||
<div className="text-secondary">{t("template.fields", { n: fields.length })}</div>
|
||||
</div>
|
||||
<span className={`badge ms-auto ${custom ? "bg-green-lt" : ""}`}>
|
||||
{custom ? t("template.custom") : t("template.standard")}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user