io zuordnung; signal liste mit eas; links; csv ausgabe
This commit is contained in:
1 parent
13bbd26ce5
commit
f769ff7cc0
20 files changed
+594
-115
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { formatComponentName } from "@/lib/componentName";
|
||||
import { Sites } from "@/_config/sites";
|
||||
import { api_units } from "@/actions/rk2/api-units";
|
||||
|
||||
@@ -34,7 +35,7 @@ export default async function PageUnits() {
|
||||
{unit.type}
|
||||
</div>
|
||||
<div className="w-40">
|
||||
{unit.components?.map((comp) => <div key={comp.id}><div>{comp.name}</div></div>)}
|
||||
{unit.components?.map((comp) => <div key={comp.id}><div>{formatComponentName(comp)}</div></div>)}
|
||||
</div>
|
||||
<ListItemAction>
|
||||
<Button variant={"secondary"} size={"xs"} >
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
import { Sites } from "@/_config/sites";
|
||||
import { formatComponentName } from "@/lib/componentName";
|
||||
import Link from "next/link";
|
||||
import { api_anlage_getSelected } from "@/actions/rk/api-anlage";
|
||||
import { api_component_byId } from "@/actions/rk2/api-component";
|
||||
import { componentTypeDefinitions } from "@/actions/rk2/api-compTypes";
|
||||
import { api_units_byId } from "@/actions/rk2/api-units";
|
||||
import { api_groups } from "@/actions/rk2/api-groups";
|
||||
import { api_signalsByComp } from "@/actions/rk2/api-signals";
|
||||
import { api_ios } from "@/actions/rk2/api-ios";
|
||||
import ComponentSignals from "@/components/rk2/signals/componentSignals";
|
||||
import { SignalForm } from "@/components/rk2/signals/signalForm";
|
||||
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
||||
import { Link } from "lucide-react";
|
||||
import Breadcrumbs from "@/components/ui/navigation/breadcrumbs";
|
||||
|
||||
type Props = {
|
||||
params: Promise<{
|
||||
componentId: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default async function PageSignalsEdit({ params }: Props) {
|
||||
|
||||
const { componentId } = await params;
|
||||
const resultComponentOfId = await api_component_byId(componentId);
|
||||
const currentAnlage= await api_anlage_getSelected();
|
||||
const componentTypes = componentTypeDefinitions;
|
||||
|
||||
if(!resultComponentOfId) return <div>Keine Daten</div>
|
||||
return (
|
||||
<div className="">
|
||||
<Link href={Sites.main.url}>{Sites.main.name}</Link>
|
||||
<Link href={Sites.procon.url}>{Sites.procon.name}</Link>
|
||||
<div className="flex flex-col m-4 w-300 ">
|
||||
|
||||
<SignalForm componente={resultComponentOfId.data.component} ></SignalForm>
|
||||
|
||||
{true &&
|
||||
<Card positons={"start"}>
|
||||
<CardHeader variant={"danger"} >Debug</CardHeader>
|
||||
<CardContent className="ps-8">
|
||||
{componentId}
|
||||
<pre>{JSON.stringify(resultComponentOfId, null, 2)}</pre>
|
||||
|
||||
</CardContent>
|
||||
</Card>
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
export default async function PageSignalsEdit({ params }: { params: Promise<{ componentId: string }> }) {
|
||||
const { componentId } = await params;
|
||||
const result = await api_component_byId(componentId);
|
||||
if (!result.success) return <div className="m-4"><p role="alert">Komponente konnte nicht geladen werden.</p><Link href="/rk2/signals">Zur Signalübersicht</Link></div>;
|
||||
const { component, unitId } = result.data;
|
||||
const [anlage, unitResult, groups, signals, ios] = await Promise.all([
|
||||
api_anlage_getSelected(), api_units_byId(unitId), api_groups(), api_signalsByComp(componentId), api_ios(),
|
||||
]);
|
||||
if (!unitResult.success) return <p className="m-4" role="alert">Unit konnte nicht geladen werden.</p>;
|
||||
const unit = unitResult.data;
|
||||
if (unit.anlageId !== anlage.id) return <p className="m-4" role="alert">Die Komponente gehört nicht zur ausgewählten Anlage.</p>;
|
||||
const groupNames: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
let group = groups.find((item) => item.id === unit.groupId);
|
||||
while (group && !seen.has(group.id)) {
|
||||
seen.add(group.id);
|
||||
groupNames.unshift(`${group.nr} ${group.name}`.trim());
|
||||
group = groups.find((item) => item.id === group?.parentId);
|
||||
}
|
||||
return <div className="m-4">
|
||||
<Breadcrumbs items={[
|
||||
{ label: 'Signale', href: '/rk2/signals' },
|
||||
{ label: `${anlage.anlageNr} ${anlage.name}` },
|
||||
{ label: groupNames.join(' / ') || 'Ohne Gruppe' },
|
||||
{ label: unit.name, href: `/rk2/units/edit/${encodeURIComponent(unit.id)}` },
|
||||
{ label: formatComponentName(component) },
|
||||
]} />
|
||||
<h1 className="my-4 text-xl font-semibold">Signale: {unit.name} / {formatComponentName(component)}</h1>
|
||||
<Link className="mb-4 mr-4 inline-block underline" href={`/rk2/units/edit/${encodeURIComponent(unitId)}?componentId=${encodeURIComponent(componentId)}`}>Zurück zur Komponente {formatComponentName(component)}</Link>
|
||||
<Link className="mb-4 inline-block underline" href={`/rk2/signals/assignment?unitId=${encodeURIComponent(unitId)}`}>IOs zuordnen</Link>
|
||||
<ComponentSignals component={component} signals={signals} ios={ios} anlageId={anlage.id} />
|
||||
<h2 className="mb-2 font-semibold">Neues Signal</h2>
|
||||
<SignalForm componente={component} />
|
||||
</div>;
|
||||
}
|
||||
@@ -6,12 +6,13 @@ import { api_ios } from "@/actions/rk2/api-ios";
|
||||
import Breadcrumbs from "@/components/ui/navigation/breadcrumbs";
|
||||
import SignalIoAssignment from "@/components/rk2/signals/signalIoAssignment";
|
||||
|
||||
export default async function AssignmentPage() {
|
||||
export default async function AssignmentPage({ searchParams }: { searchParams: Promise<{ unitId?: string }> }) {
|
||||
const { unitId } = await searchParams;
|
||||
const anlage = await api_anlage_getSelected();
|
||||
const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]);
|
||||
return <div className="m-4">
|
||||
<Breadcrumbs items={[{ label: 'Signale', href: '/rk2/signals' }, { label: 'IO-Zuordnung' }, { label: `${anlage.anlageNr} ${anlage.name}` }]} />
|
||||
<SignalIoAssignment groups={groups} units={units.filter((unit) => unit.anlageId === anlage.id)}
|
||||
signals={signals} ios={ios.filter((io) => io.anlageId === anlage.id)} anlageId={anlage.id} />
|
||||
<SignalIoAssignment key={`${anlage.id}:${unitId ?? ''}`} groups={groups} units={units.filter((unit) => unit.anlageId === anlage.id)}
|
||||
signals={signals} ios={ios.filter((io) => io.anlageId === anlage.id)} anlageId={anlage.id} initialUnitId={unitId} />
|
||||
</div>;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import Link from "next/link";
|
||||
import AssignmentsTable, { type AssignmentRow } from "@/components/rk2/signals/assignmentsTable";
|
||||
import { api_anlage_getSelected } from "@/actions/rk/api-anlage";
|
||||
import { api_groups } from "@/actions/rk2/api-groups";
|
||||
import { api_units } from "@/actions/rk2/api-units";
|
||||
import { api_signals } from "@/actions/rk2/api-signals";
|
||||
import { api_ios } from "@/actions/rk2/api-ios";
|
||||
import Breadcrumbs from "@/components/ui/navigation/breadcrumbs";
|
||||
import { formatComponentName } from "@/lib/componentName";
|
||||
import { eaName } from "@/lib/ioEaExport";
|
||||
|
||||
export default async function AssignmentsPage() {
|
||||
const anlage = await api_anlage_getSelected();
|
||||
const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]);
|
||||
const groupMap = new Map(groups.map((group) => [group.id, group]));
|
||||
const ioMap = new Map(ios.filter((io) => io.anlageId === anlage.id).map((io) => [io.id, io]));
|
||||
const componentMap = new Map(units.filter((unit) => unit.anlageId === anlage.id).flatMap((unit) =>
|
||||
unit.components.map((component) => [component.id, { unit, component }] as const)));
|
||||
|
||||
const groupPath = (id?: string) => {
|
||||
const names: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
let group = id ? groupMap.get(id) : undefined;
|
||||
while (group && !seen.has(group.id)) {
|
||||
seen.add(group.id);
|
||||
names.unshift(group.name);
|
||||
group = group.parentId ? groupMap.get(group.parentId) : undefined;
|
||||
}
|
||||
return names;
|
||||
};
|
||||
|
||||
const rows: AssignmentRow[] = signals.filter((signal) => signal.anlageId === anlage.id && signal.ioId).map((signal) => {
|
||||
const context = signal.componentId ? componentMap.get(signal.componentId) : undefined;
|
||||
const io = ioMap.get(signal.ioId!);
|
||||
return {
|
||||
id: signal.id,
|
||||
group: context ? groupPath(context.unit.groupId).join('.') || 'Ohne Gruppe' : 'Zuordnung zu Unit fehlt',
|
||||
exportName: context ? eaName(context.unit, context.component, signal.name) : '',
|
||||
variableTable: context ? groupPath(context.unit.groupId)[1] ?? '' : '',
|
||||
exportComment: [context?.unit.bmk, io?.seiteName, io?.functionText].filter(Boolean).join(' '),
|
||||
bmk: context?.unit.bmk ?? '',
|
||||
unit: context?.unit.name ?? 'Nicht verfügbar',
|
||||
unitId: context?.unit.id,
|
||||
component: context ? formatComponentName(context.component) : 'Nicht verfügbar',
|
||||
componentId: context?.component.id,
|
||||
signal: signal.name,
|
||||
type: io?.adrType ?? 'IO nicht verfügbar',
|
||||
byte: io?.adrByte,
|
||||
bit: io?.adrBit,
|
||||
functionText: io?.functionText ?? '',
|
||||
};
|
||||
});
|
||||
|
||||
return <div className="m-4">
|
||||
<Breadcrumbs items={[{ label: 'Signale', href: '/rk2/signals' }, { label: 'Alle Zuordnungen' }, { label: `${anlage.anlageNr} ${anlage.name}` }]} />
|
||||
<h1 className="my-4 text-xl font-semibold">IO-Zuordnungen ({rows.length})</h1>
|
||||
<Link className="mb-4 inline-block underline" href="/rk2/signals/assignment">Zuordnungen bearbeiten</Link>
|
||||
<AssignmentsTable rows={rows} />
|
||||
</div>;
|
||||
}
|
||||
@@ -24,6 +24,9 @@ export default async function PageSignale() {
|
||||
|
||||
<div className="flex flex-col m-4 w-170 ">
|
||||
<List variant={"default"} size={"lg"} >
|
||||
<ListItem hover={true}>
|
||||
<Link href="/rk2/signals/assignments">Alle IO-Zuordnungen</Link>
|
||||
</ListItem>
|
||||
<ListItem hover={true}>
|
||||
<Link href="/rk2/signals/assignment">IO-Zuordnung</Link>
|
||||
</ListItem>
|
||||
|
||||
@@ -11,6 +11,7 @@ import { componentDefaults, componentTypeDefinitions } from "@/actions/rk2/api-c
|
||||
import Breadcrumbs from "@/components/ui/navigation/breadcrumbs";
|
||||
|
||||
type Props = {
|
||||
searchParams: Promise<{ componentId?: string; from?: string }>;
|
||||
params: Promise<{
|
||||
id: string;
|
||||
}>;
|
||||
@@ -18,7 +19,8 @@ type Props = {
|
||||
|
||||
|
||||
|
||||
export default async function PageUnitsEdit({ params }: Props) {
|
||||
export default async function PageUnitsEdit({ params, searchParams }: Props) {
|
||||
const { componentId, from } = await searchParams;
|
||||
|
||||
const { id } = await params;
|
||||
const resultFindUnitById = await api_units_byId(id);
|
||||
@@ -32,13 +34,14 @@ export default async function PageUnitsEdit({ params }: Props) {
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
{from === 'io-assignment' && <Link className="m-4 inline-block underline" href="/rk2/signals/assignment">Zurück zur IO-Zuordnung</Link>}
|
||||
<div>
|
||||
<Breadcrumbs items={breadcrumb}/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col m-4 w-300 ">
|
||||
|
||||
<UnitEdit anlage={currentAnlage} groups={groups} selectedUnit={resultFindUnitById.data} componentTypes={componentTypes} componentDefaults={cd}></UnitEdit>
|
||||
<UnitEdit anlage={currentAnlage} groups={groups} selectedUnit={resultFindUnitById.data} componentTypes={componentTypes} componentDefaults={cd} initialComponentId={componentId}></UnitEdit>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatComponentName } from "@/lib/componentName";
|
||||
import { Sites } from "@/_config/sites";
|
||||
import { api_units } from "@/actions/rk2/api-units";
|
||||
import { api_anlage_getSelected } from "@/actions/rk/api-anlage";
|
||||
@@ -56,7 +57,7 @@ export default async function PageUnits() {
|
||||
<ListItemDescription className="ps-50 pt-1 flex gap-2">
|
||||
{unit.components?.map((comp) => <div key={comp.id}>
|
||||
{comp.prefix && comp.prefix}
|
||||
{comp.name}
|
||||
{formatComponentName(comp)}
|
||||
{comp.postfix && comp.postfix}
|
||||
{comp.index && comp.index>0 ? comp.index:""}
|
||||
</div>)}
|
||||
|
||||
Reference in new issue
Block a user