procon aggregate
This commit is contained in:
1 parent
3bea468d23
commit
734aa81710
16 files changed
+656
-12
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
experimental: { serverActions: { bodySizeLimit: '10mb' } },
|
||||||
/* config options here */
|
/* config options here */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ export const componentTypeDefinitions: ComponentTypeDefinition[] = [
|
|||||||
label: "Antrieb",
|
label: "Antrieb",
|
||||||
|
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
key: "slave",
|
||||||
|
label: "Slave",
|
||||||
|
type: "boolean",
|
||||||
|
defaultValue: false,
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "linkslauf",
|
key: "linkslauf",
|
||||||
label: "Linkslauf",
|
label: "Linkslauf",
|
||||||
@@ -493,4 +500,4 @@ const componentProperties: Record<ComponentTypes, PropertyDefinition[]> = {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
'use server';
|
||||||
|
import { ProConViewAggregateData, ViewElement, ViewAggregateOverview } from '@/types/anlagen/procon-view-aggregate';
|
||||||
|
const url = 'http://localhost:3000/rk2/procon-view-aggregate/';
|
||||||
|
|
||||||
|
export async function api_viewAggregate_overview(): Promise<ViewAggregateOverview[]> {
|
||||||
|
const response = await fetch(url, { cache: 'no-store' });
|
||||||
|
if (!response.ok) throw new Error('Grafikübersicht konnte nicht geladen werden.');
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function api_viewAggregate(componentId: string): Promise<ProConViewAggregateData> {
|
||||||
|
const response = await fetch(url + encodeURIComponent(componentId), { cache: 'no-store' });
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response.json();
|
||||||
|
throw new Error(error.message ?? 'Grafiken konnten nicht geladen werden.');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function api_viewAggregate_save(componentId: string, anlageId: string, elemente: ViewElement[]) {
|
||||||
|
try {
|
||||||
|
const body = JSON.stringify({ anlageId, elemente });
|
||||||
|
if (new TextEncoder().encode(body).length > 9 * 1024 * 1024)
|
||||||
|
return { success: false, error: 'Die Grafiken sind zusammen zu groß (maximal 9 MB pro Speichervorgang).' };
|
||||||
|
const response = await fetch(url + encodeURIComponent(componentId), {
|
||||||
|
method: 'PUT', headers: { 'Content-Type': 'application/json' }, body,
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response.json();
|
||||||
|
return { success: false, error: Array.isArray(error.message) ? error.message.join(', ') : error.message ?? 'Speichern fehlgeschlagen.' };
|
||||||
|
}
|
||||||
|
return { success: true };
|
||||||
|
} catch {
|
||||||
|
return { success: false, error: 'Keine Verbindung zum Backend. Bitte erneut versuchen.' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import { VisuAggregateInput, VisuAggregateRow } from '@/types/anlagen/visu-aggregate';
|
||||||
|
|
||||||
|
const url = 'http://localhost:3000/rk2/visu-aggregate';
|
||||||
|
|
||||||
|
export async function api_visuAggregate(): Promise<VisuAggregateRow[]> {
|
||||||
|
const response = await fetch(url, { cache: 'no-store' });
|
||||||
|
if (!response.ok) throw new Error('VisuAggregate konnten nicht geladen werden.');
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function api_visuAggregate_save(componentId: string, data: VisuAggregateInput): Promise<{ success: boolean; error?: string }> {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url + '/' + encodeURIComponent(componentId), {
|
||||||
|
method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
return { success: false, error: Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Speichern fehlgeschlagen.' };
|
||||||
|
}
|
||||||
|
return { success: true };
|
||||||
|
} catch {
|
||||||
|
return { success: false, error: 'Keine Verbindung zum Backend. Bitte erneut versuchen.' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -36,6 +36,8 @@ export default function AnlageLayout({ children }: Props) {
|
|||||||
<h2 className="mb-4 font-semibold">Anlage</h2>
|
<h2 className="mb-4 font-semibold">Anlage</h2>
|
||||||
|
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-2">
|
||||||
|
<li><a href="/rk2/visu-aggregate">VisuAggregate</a></li>
|
||||||
|
<li><a href="/rk2/visu-aggregate/grafiken">Grafikübersicht</a></li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/rk2/groups">Groups</a>
|
<a href="/rk2/groups">Groups</a>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import Link from 'next/link';
|
||||||
|
import { api_viewAggregate } from '@/actions/rk2/api-procon-view-aggregate';
|
||||||
|
import ViewAggregateForm from '@/components/rk2/visu-aggregate/viewAggregateForm';
|
||||||
|
|
||||||
|
export default async function Page({ params }: { params: Promise<{ componentId: string }> }) {
|
||||||
|
const { componentId } = await params;
|
||||||
|
try {
|
||||||
|
const data = await api_viewAggregate(componentId);
|
||||||
|
return <div><Link href="/rk2/visu-aggregate" className="underline">Zurück zu VisuAggregate</Link>
|
||||||
|
<h1 className="my-4 text-xl font-semibold">Grafiken – {data.name}</h1>
|
||||||
|
<ViewAggregateForm componentId={componentId} initial={data} />
|
||||||
|
</div>;
|
||||||
|
} catch (error) {
|
||||||
|
return <div><Link href="/rk2/visu-aggregate" className="underline">Zurück zur Tabelle</Link>
|
||||||
|
<p role="alert" className="mt-4 text-red-600">{error instanceof Error ? error.message : 'Laden fehlgeschlagen'}</p></div>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export async function GET() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:3000/rk2/visu-aggregate/export', { cache: 'no-store' });
|
||||||
|
if (!response.ok) return new Response('Excel-Export fehlgeschlagen.', { status: 502 });
|
||||||
|
return new Response(response.body, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
|
'Content-Disposition': 'attachment; filename="VisuAggregate.xlsx"',
|
||||||
|
'Cache-Control': 'no-store',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return new Response('Keine Verbindung zum Backend.', { status: 502 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import Link from 'next/link';
|
||||||
|
import { api_viewAggregate_overview } from '@/actions/rk2/api-procon-view-aggregate';
|
||||||
|
|
||||||
|
export default async function GraphicsOverviewPage() {
|
||||||
|
let aggregates;
|
||||||
|
try { aggregates = await api_viewAggregate_overview(); }
|
||||||
|
catch { return <p role="alert">Die Grafikübersicht konnte nicht geladen werden. Bitte Backend-Verbindung und ausgewählte Anlage prüfen.</p>; }
|
||||||
|
const count = aggregates.reduce((sum, item) => sum + item.elemente.length, 0);
|
||||||
|
return <div>
|
||||||
|
<Link href="/rk2/visu-aggregate" className="text-sm underline">Zur VisuAggregate-Tabelle</Link>
|
||||||
|
<h1 className="my-3 text-xl font-semibold">Grafikübersicht</h1>
|
||||||
|
<p className="mb-4 text-sm text-gray-600">{count} Elemente in {aggregates.length} gespeicherten Aggregaten der ausgewählten Anlage. Angezeigt wird der gespeicherte Stand.</p>
|
||||||
|
{!aggregates.length && <p>Noch keine VisuAggregate gespeichert.</p>}
|
||||||
|
<div className="space-y-3">{aggregates.map(aggregate => <section key={aggregate.componentId} className="rounded border bg-white">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-2 bg-gray-50 p-2">
|
||||||
|
<div><h2 className="text-sm font-semibold">{aggregate.antriebId} · {aggregate.name}</h2><p className="text-xs text-gray-500">{aggregate.viewName || 'Kein View-Name'}</p></div>
|
||||||
|
<Link className="text-sm underline" href={`/rk2/visu-aggregate/${aggregate.componentId}/grafiken`}>Grafiken bearbeiten</Link>
|
||||||
|
</div>
|
||||||
|
{!aggregate.elemente.length ? <p className="p-2 text-xs text-gray-500">Noch keine Grafikelemente.</p> : <div className="overflow-x-auto">
|
||||||
|
<table className="w-full border-collapse text-left text-xs">
|
||||||
|
<thead><tr>{['Element', 'Typ', 'Breite', 'Höhe', 'X', 'Y', 'Z', 'Sichtbar', 'Zustände / Dateien'].map(label =>
|
||||||
|
<th key={label} className="border-b p-2" scope="col">{label}</th>)}</tr></thead>
|
||||||
|
<tbody>{aggregate.elemente.map(element => <tr key={element._id ?? element.key} className="align-top">
|
||||||
|
<th scope="row" className="border-b p-2 font-medium">{element.key}{element.name && <span className="block font-normal text-gray-500">{element.name}</span>}</th>
|
||||||
|
<td className="border-b p-2">{element.typ}</td>
|
||||||
|
{[element.width, element.height, element.posX, element.posY, element.zIndex].map((value, index) => <td key={index} className="border-b p-2">{value}</td>)}
|
||||||
|
<td className="border-b p-2">{element.show ? 'Ja' : 'Nein'}</td>
|
||||||
|
<td className="border-b p-2">{element.darstellung === 'standard' ? <span className="text-gray-500">Standardanzeige · keine XAML</span>
|
||||||
|
: !element.varianten.length ? <span className="text-gray-500">Keine Zustände</span>
|
||||||
|
: <ul className="space-y-1">{element.varianten.map(variant => <li key={variant.zustand}>
|
||||||
|
<span className={variant.xamlBase64 ? 'text-green-700' : 'text-gray-500'}>{variant.zustand} · {variant.xamlBase64 ? 'XAML vorhanden' : 'ohne XAML'}</span>
|
||||||
|
<span className="block break-all text-gray-500">{aggregate.viewName}_{element.key}_{variant.zustand}.xaml</span>
|
||||||
|
</li>)}</ul>}</td>
|
||||||
|
</tr>)}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>}
|
||||||
|
</section>)}</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { api_visuAggregate } from '@/actions/rk2/api-visu-aggregate';
|
||||||
|
import VisuAggregateTable from '@/components/rk2/visu-aggregate/visuAggregateTable';
|
||||||
|
import Breadcrumbs from '@/components/ui/navigation/breadcrumbs';
|
||||||
|
|
||||||
|
export default async function VisuAggregatePage() {
|
||||||
|
let rows;
|
||||||
|
try { rows = await api_visuAggregate(); }
|
||||||
|
catch {
|
||||||
|
return <div><h1 className="mb-4 text-xl font-semibold">VisuAggregate</h1>
|
||||||
|
<p role="alert">Die Tabelle konnte nicht geladen werden. Bitte die Backend-Verbindung und die ausgewählte Anlage prüfen und die Seite neu laden.</p></div>;
|
||||||
|
}
|
||||||
|
return <div>
|
||||||
|
<Breadcrumbs items={[{ label: 'Anlage', href: '/rk2' }, { label: 'VisuAggregate' }]} />
|
||||||
|
<h1 className="my-4 text-xl font-semibold">VisuAggregate</h1>
|
||||||
|
<p className="mb-4">Werte direkt in der Tabelle bearbeiten und je Zeile speichern. Weitere Spalten sind durch horizontales Scrollen erreichbar.</p>
|
||||||
|
<VisuAggregateTable rows={rows} />
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ export default async function PageShowDraw() {
|
|||||||
height="100%"
|
height="100%"
|
||||||
viewBox={`${0} ${0} ${1820} ${1120}`}
|
viewBox={`${0} ${0} ${1820} ${1120}`}
|
||||||
>
|
>
|
||||||
<rect x1={1} y1={0} width={1750} height={1500} fill="#fee0fe" stroke="#000" strokeWidth={1} />
|
<rect x1={1} y1={0} width={1750} height={1500} fill="#fee0fe" stroke="#000" strokeWidth={1} />
|
||||||
|
|
||||||
<SvgShow svg={data.svg} />
|
<SvgShow svg={data.svg} />
|
||||||
|
|
||||||
@@ -29,8 +29,11 @@ export default async function PageShowDraw() {
|
|||||||
<Card positons={"start"}>
|
<Card positons={"start"}>
|
||||||
<CardHeader variant={"danger"} >Debug</CardHeader>
|
<CardHeader variant={"danger"} >Debug</CardHeader>
|
||||||
<CardContent className="ps-8">
|
<CardContent className="ps-8">
|
||||||
<pre>{JSON.stringify(data, null, 2)}</pre>
|
|
||||||
|
<pre className="overflow-auto whitespace-pre rounded bg-gray-100 p-4 text-sm">
|
||||||
|
<code>{data.xamlBase64}</code>
|
||||||
|
<code>{"data.svg"}</code>
|
||||||
|
</pre>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,8 +93,10 @@ export function ComponentForm({ component, componentTypes, componentDefaults, on
|
|||||||
<div className="mt-6">
|
<div className="mt-6">
|
||||||
<div className="font-bold">Eigenschaften</div>
|
<div className="font-bold">Eigenschaften</div>
|
||||||
|
|
||||||
{compnentData.properties &&
|
{Object.entries({
|
||||||
Object.entries(compnentData.properties).map(([key, value]) => (
|
...(compnentData.type === "Antrieb" ? { slave: false } : {}),
|
||||||
|
...compnentData.properties,
|
||||||
|
}).map(([key, value]) => (
|
||||||
|
|
||||||
<PropertyField
|
<PropertyField
|
||||||
key={key}
|
key={key}
|
||||||
@@ -104,6 +106,9 @@ export function ComponentForm({ component, componentTypes, componentDefaults, on
|
|||||||
setPropValue={(name, value) => changePropertie(name, value)}
|
setPropValue={(name, value) => changePropertie(name, value)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
{compnentData.type === "Antrieb" && <p className="mt-2 text-xs text-gray-600">
|
||||||
|
Slave: Der Motor wird nicht separat angesteuert, sondern läuft parallel zu einem anderen Motor mit.
|
||||||
|
</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4">
|
||||||
|
|||||||
@@ -0,0 +1,218 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, type FormEvent } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Select } from '@/components/ui/select';
|
||||||
|
import Modal from '@/components/ui/Modal';
|
||||||
|
import { api_viewAggregate_save } from '@/actions/rk2/api-procon-view-aggregate';
|
||||||
|
import { ProConViewAggregateData, ViewElement } from '@/types/anlagen/procon-view-aggregate';
|
||||||
|
|
||||||
|
const standardTypes = ['anfahrzeit', 'betriebsart', 'text'] as const;
|
||||||
|
const measurements = [
|
||||||
|
{ key: 'width', label: 'Breite', min: 0 }, { key: 'height', label: 'Höhe', min: 0 },
|
||||||
|
{ key: 'posX', label: 'X', min: undefined }, { key: 'posY', label: 'Y', min: undefined },
|
||||||
|
{ key: 'zIndex', label: 'Ebene (Z)', min: undefined },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export default function ViewAggregateForm({ componentId, initial }: { componentId: string; initial: ProConViewAggregateData }) {
|
||||||
|
const [elements, setElements] = useState(initial.elemente);
|
||||||
|
const [newType, setNewType] = useState('main');
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
const [message, setMessage] = useState('');
|
||||||
|
const [error, setError] = useState('');
|
||||||
|
const busy = saving || uploading;
|
||||||
|
const [selected, setSelected] = useState<{ element: number; variant: number } | null>(null);
|
||||||
|
const [positionMode, setPositionMode] = useState<'absolute' | 'relative'>('absolute');
|
||||||
|
const main = elements.find(element => element.key === 'main');
|
||||||
|
|
||||||
|
function update(index: number, change: (element: ViewElement) => ViewElement) {
|
||||||
|
setElements(current => current.map((element, i) => i === index ? change(element) : element));
|
||||||
|
setMessage('Ungespeicherte Änderungen'); setError('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function add() {
|
||||||
|
const used = new Set(elements.map(element => element.key));
|
||||||
|
let key = newType, suffix = 1;
|
||||||
|
while (used.has(key)) key = newType + suffix++;
|
||||||
|
const basis = { key, name: key, width: 40, height: 40, posX: 0, posY: 0, zIndex: 0, show: true };
|
||||||
|
const element: ViewElement = standardTypes.includes(newType as typeof standardTypes[number])
|
||||||
|
? { ...basis, darstellung: 'standard', typ: newType as typeof standardTypes[number] }
|
||||||
|
: { ...basis, darstellung: 'xaml', typ: newType, varianten: [] };
|
||||||
|
setElements(current => [...current, element]);
|
||||||
|
setMessage('Ungespeicherte Änderungen'); setError('');
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDefaults() {
|
||||||
|
const defaults: ViewElement[] = [
|
||||||
|
{ key: 'main', name: '', darstellung: 'xaml', typ: 'main', width: 54, height: 54, posX: 0, posY: 0, zIndex: 0, show: true, varianten: [] },
|
||||||
|
...Array.from({ length: initial.anzahlMotoren }, (_, i): ViewElement => ({
|
||||||
|
key: i === 0 ? 'motor' : 'motor' + (i + 1), name: '', darstellung: 'xaml', typ: 'motor',
|
||||||
|
width: 20, height: 20, posX: 0, posY: 0, zIndex: 0, show: true, varianten: [],
|
||||||
|
})),
|
||||||
|
...standardTypes.map((typ): ViewElement => ({
|
||||||
|
key: typ, name: '', darstellung: 'standard', typ,
|
||||||
|
width: typ === 'anfahrzeit' ? 40 : typ === 'betriebsart' ? 32 : 30,
|
||||||
|
height: typ === 'anfahrzeit' ? 40 : typ === 'betriebsart' ? 32 : 30,
|
||||||
|
posX: 0, posY: 0, zIndex: 0, show: true,
|
||||||
|
})),
|
||||||
|
];
|
||||||
|
setElements(current => {
|
||||||
|
const keys = new Set(current.map(element => element.key));
|
||||||
|
return [...current, ...defaults.filter(element => !keys.has(element.key))];
|
||||||
|
});
|
||||||
|
setMessage('Default-Elemente ergänzt – noch nicht gespeichert'); setError('');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function upload(index: number, variant: number, file: File | undefined) {
|
||||||
|
if (!file) return;
|
||||||
|
if (!file.name.toLowerCase().endsWith('.xaml') || file.size > 1024 * 1024) {
|
||||||
|
setError('Bitte eine XAML-Datei mit maximal 1 MB auswählen.'); return;
|
||||||
|
}
|
||||||
|
setUploading(true); setError('');
|
||||||
|
try {
|
||||||
|
const xml = await file.text();
|
||||||
|
const parsed = new DOMParser().parseFromString(xml, 'application/xml');
|
||||||
|
if (parsed.querySelector('parsererror')) throw new Error('Die Datei enthält kein gültiges XML.');
|
||||||
|
const base64 = await new Promise<string>((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => resolve(String(reader.result).split(',')[1]);
|
||||||
|
reader.onerror = () => reject(new Error('Datei konnte nicht gelesen werden.'));
|
||||||
|
reader.readAsDataURL(new Blob([xml], { type: 'application/xml' }));
|
||||||
|
});
|
||||||
|
update(index, element => element.darstellung === 'xaml'
|
||||||
|
? { ...element, varianten: element.varianten.map((value, i) => i === variant ? { ...value, xamlBase64: base64 } : value) }
|
||||||
|
: element);
|
||||||
|
} catch (cause) { setError(cause instanceof Error ? cause.message : 'Upload fehlgeschlagen'); }
|
||||||
|
finally { setUploading(false); }
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(event: FormEvent) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (busy) return;
|
||||||
|
setSaving(true); setError(''); setMessage('');
|
||||||
|
try {
|
||||||
|
const result = await api_viewAggregate_save(componentId, initial.anlageId, elements);
|
||||||
|
if (result.success) setMessage('Gespeichert');
|
||||||
|
else setError(result.error ?? 'Speichern fehlgeschlagen');
|
||||||
|
} finally { setSaving(false); }
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedElement = selected ? elements[selected.element] : undefined;
|
||||||
|
const selectedVariant = selected && selectedElement?.darstellung === 'xaml' ? selectedElement.varianten[selected.variant] : undefined;
|
||||||
|
|
||||||
|
function addVariant(index: number) {
|
||||||
|
const element = elements[index];
|
||||||
|
if (element.darstellung !== 'xaml') return;
|
||||||
|
const used = new Set(element.varianten.map(item => item.zustand));
|
||||||
|
let state = ['active', 'inactive', 'error', 'inactivePos0', 'inactivePos1'].find(item => !used.has(item));
|
||||||
|
if (!state) { let nr = 1; while (used.has('zustand' + nr)) nr++; state = 'zustand' + nr; }
|
||||||
|
update(index, value => value.darstellung === 'xaml'
|
||||||
|
? { ...value, varianten: [...value.varianten, { zustand: state!, xamlBase64: '' }] } : value);
|
||||||
|
setSelected({ element: index, variant: element.varianten.length });
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>
|
||||||
|
<form onSubmit={save}>
|
||||||
|
<div className="sticky top-0 z-20 mb-2 flex flex-wrap items-center gap-2 rounded border bg-white p-2 text-xs">
|
||||||
|
<Button type="submit" size="sm" disabled={busy}>{saving ? 'Speichert …' : 'Grafiken speichern'}</Button>
|
||||||
|
<span>View: {initial.viewName || 'Noch kein View-Name vergeben'}</span>
|
||||||
|
<span role="status">{uploading ? 'Datei wird gelesen …' : message || (initial.persisted ? 'In DB gespeichert' : 'Noch nicht gespeichert')}</span>
|
||||||
|
</div>
|
||||||
|
{error && <p role="alert" className="mb-2 text-sm text-red-600">{error}</p>}
|
||||||
|
<fieldset disabled={busy}>
|
||||||
|
<div className="mb-2 flex flex-wrap items-center gap-2 text-xs">
|
||||||
|
<label htmlFor="position-mode">Positionen</label>
|
||||||
|
<Select id="position-mode" className="w-40" value={positionMode}
|
||||||
|
onChange={event => setPositionMode(event.target.value === 'relative' ? 'relative' : 'absolute')}>
|
||||||
|
<option value="absolute">Absolut</option>
|
||||||
|
<option value="relative" disabled={!main}>Relativ zu main</option>
|
||||||
|
</Select>
|
||||||
|
<span className="text-gray-500">main immer absolut · Speicherung immer absolut</span>
|
||||||
|
<label htmlFor="new-element">Neues Element</label>
|
||||||
|
<Select id="new-element" className="w-44" value={newType} onChange={event => setNewType(event.target.value)}>
|
||||||
|
<option value="main">Hauptelement (XAML)</option><option value="motor">Motor (XAML)</option>
|
||||||
|
<option value="pfeil">Pfeil (XAML)</option><option value="warnung">Warnung (XAML)</option>
|
||||||
|
<option value="sonstiges">Sonstiges (XAML)</option><option value="anfahrzeit">Anfahrzeit</option>
|
||||||
|
<option value="betriebsart">Betriebsart</option><option value="text">Text</option>
|
||||||
|
</Select>
|
||||||
|
<Button type="button" size="xs" variant="secondary" onClick={add}>Element hinzufügen</Button>
|
||||||
|
<Button type="button" size="xs" variant="secondary" onClick={addDefaults}>Default-Elemente</Button>
|
||||||
|
</div>
|
||||||
|
<div className="overflow-x-auto rounded border">
|
||||||
|
<table className="w-full border-collapse text-left text-xs">
|
||||||
|
<thead className="bg-gray-100"><tr>
|
||||||
|
{['Element', 'Breite', 'Höhe', positionMode === 'relative' && main ? 'X (rel.)' : 'X', positionMode === 'relative' && main ? 'Y (rel.)' : 'Y', 'Z', 'Sichtbar', 'Zustände', ''].map((label, i) =>
|
||||||
|
<th key={i} scope="col" className="border-b px-2 py-1">{label}</th>)}
|
||||||
|
</tr></thead>
|
||||||
|
<tbody>{elements.map((element, index) => <tr key={element._id ?? index} className="align-top hover:bg-gray-50">
|
||||||
|
<td className="w-48 border-b p-1">
|
||||||
|
<Input sizeVariant="xs" className="min-w-32" required pattern="[a-zA-Z0-9_-]+" aria-label={'Element ' + (index + 1)} value={element.key}
|
||||||
|
onChange={event => update(index, value => ({ ...value, key: event.target.value }))} />
|
||||||
|
<details className="mt-1 text-gray-500"><summary className="cursor-pointer">Details · {element.typ}</summary>
|
||||||
|
<label className="mt-1 block">Beschreibung<Input sizeVariant="xs" value={element.name}
|
||||||
|
onChange={event => update(index, value => ({ ...value, name: event.target.value }))} /></label>
|
||||||
|
{element.darstellung === 'xaml' && <label className="block">Elementtyp<Input sizeVariant="xs" required value={element.typ}
|
||||||
|
onChange={event => update(index, value => value.darstellung === 'xaml' ? { ...value, typ: event.target.value } : value)} /></label>}
|
||||||
|
</details>
|
||||||
|
</td>
|
||||||
|
{measurements.map(({ key, label, min }) => <td key={key} className="w-20 border-b p-1">
|
||||||
|
<Input className="w-18 min-w-16" sizeVariant="xs" required type="number" step={key === 'zIndex' ? '1' : 'any'} min={min}
|
||||||
|
aria-label={element.key + ': ' + label + (positionMode === 'relative' && main && element !== main && (key === 'posX' || key === 'posY') ? ' relativ zu main' : '')}
|
||||||
|
title={element === main && (key === 'posX' || key === 'posY') ? 'main: absolute Position' : undefined}
|
||||||
|
value={Number.isNaN(element[key]) ? '' : element[key] -
|
||||||
|
(positionMode === 'relative' && main && element !== main && (key === 'posX' || key === 'posY') ? main[key] : 0)}
|
||||||
|
onChange={event => update(index, value => ({ ...value, [key]: event.target.valueAsNumber +
|
||||||
|
(positionMode === 'relative' && main && element !== main && (key === 'posX' || key === 'posY') ? main[key] : 0) }))} />
|
||||||
|
</td>)}
|
||||||
|
<td className="border-b p-2 text-center"><input type="checkbox" aria-label={element.key + ': Sichtbar'} checked={element.show}
|
||||||
|
onChange={event => update(index, value => ({ ...value, show: event.target.checked }))} /></td>
|
||||||
|
<td className="border-b p-1">
|
||||||
|
{element.darstellung === 'standard' ? <span className="text-gray-400">Keine XAML</span> : <div className="flex flex-wrap gap-1">
|
||||||
|
{element.varianten.map((variant, variantIndex) => <Button key={variantIndex} type="button" size="xs" variant="secondary"
|
||||||
|
className={variant.xamlBase64 ? 'bg-green-100 text-green-800' : ''}
|
||||||
|
title={variant.xamlBase64 ? 'XAML vorhanden – Datei bearbeiten' : 'Ohne XAML – Datei auswählen'}
|
||||||
|
onClick={() => setSelected({ element: index, variant: variantIndex })}>{variant.zustand || 'Zustand'}</Button>)}
|
||||||
|
<Button type="button" size="xs" variant="ghost" onClick={() => addVariant(index)}>+ Zustand</Button>
|
||||||
|
</div>}
|
||||||
|
</td>
|
||||||
|
<td className="border-b p-1"><Button type="button" variant="ghost" size="xs" aria-label={element.key + ' entfernen'} onClick={() => {
|
||||||
|
if (!window.confirm('Element „' + element.key + '“ entfernen?')) return;
|
||||||
|
setElements(current => current.filter((_, i) => i !== index)); setMessage('Ungespeicherte Änderungen');
|
||||||
|
}}>Entfernen</Button></td>
|
||||||
|
</tr>)}</tbody>
|
||||||
|
</table>
|
||||||
|
{!elements.length && <p className="p-3 text-sm">Noch keine Elemente vorhanden.</p>}
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
{selected && selectedElement && selectedVariant && <Modal onClose={() => { if (!busy) setSelected(null); }}>
|
||||||
|
<form className="flex w-[min(28rem,80vw)] flex-col gap-3" onSubmit={event => { event.preventDefault(); if (!busy) setSelected(null); }}>
|
||||||
|
<h2 className="pr-6 text-base font-semibold">{selectedElement.key} · {selectedVariant.zustand || 'Zustand'}</h2>
|
||||||
|
<fieldset disabled={busy} className="space-y-3">
|
||||||
|
<label className="block text-sm">Zustand<Input autoFocus required pattern="[a-zA-Z0-9_-]+" list="xaml-states" value={selectedVariant.zustand}
|
||||||
|
onChange={event => update(selected.element, value => value.darstellung === 'xaml'
|
||||||
|
? { ...value, varianten: value.varianten.map((item, i) => i === selected.variant ? { ...item, zustand: event.target.value } : item) } : value)} /></label>
|
||||||
|
<label className="block text-sm">XAML-Datei (optional, max. 1 MB)<input className="mt-1 block w-full text-sm" type="file" accept=".xaml"
|
||||||
|
onChange={event => { const file = event.target.files?.[0]; event.target.value = ''; void upload(selected.element, selected.variant, file); }} /></label>
|
||||||
|
<p className="break-all text-xs text-gray-600">{initial.viewName || '(View fehlt)'}_{selectedElement.key}_{selectedVariant.zustand}.xaml</p>
|
||||||
|
<p role="status" className="text-xs">{uploading ? 'Datei wird gelesen …' : selectedVariant.xamlBase64 ? 'XAML vorhanden' : 'Ohne XAML-Datei'}</p>
|
||||||
|
{error && <p role="alert" className="text-sm text-red-600">{error}</p>}
|
||||||
|
<div className="flex flex-wrap gap-2">
|
||||||
|
<Button type="submit" size="sm">Fertig</Button>
|
||||||
|
{selectedVariant.xamlBase64 && <Button type="button" size="sm" variant="secondary" onClick={() => update(selected.element, value => value.darstellung === 'xaml'
|
||||||
|
? { ...value, varianten: value.varianten.map((item, i) => i === selected.variant ? { ...item, xamlBase64: '' } : item) } : value)}>Datei entfernen</Button>}
|
||||||
|
<Button type="button" size="sm" variant="danger" onClick={() => {
|
||||||
|
update(selected.element, value => value.darstellung === 'xaml'
|
||||||
|
? { ...value, varianten: value.varianten.filter((_, i) => i !== selected.variant) } : value);
|
||||||
|
setSelected(null);
|
||||||
|
}}>Zustand entfernen</Button>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-gray-500">Anschließend mit „Grafiken speichern“ in der Datenbank speichern.</p>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</Modal>}
|
||||||
|
<datalist id="xaml-states">{['active', 'inactive', 'error', 'inactivePos0', 'inactivePos1'].map(state => <option key={state} value={state} />)}</datalist>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useLayoutEffect, useRef, useState, type FormEvent, type KeyboardEvent } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { Select } from '@/components/ui/select';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { api_visuAggregate_save } from '@/actions/rk2/api-visu-aggregate';
|
||||||
|
import { VisuAggregateInput, VisuAggregateRow } from '@/types/anlagen/visu-aggregate';
|
||||||
|
|
||||||
|
const switches = [{ "key": "dauerlaeufer", "label": "Dauerläufer" }, { "key": "stellantrieb", "label": "Stellantrieb" }, { "key": "pulsantrieb", "label": "Pulsantrieb" }, { "key": "direktanlauf", "label": "Direktanlauf" }, { "key": "wendeschuetz", "label": "Wendeschütz" }, { "key": "sternDreieck", "label": "Stern-Dreieck" }, { "key": "fu", "label": "FU" }, { "key": "sanftanlauf", "label": "Sanftanlauf" }, { "key": "dzImpulsgeber", "label": "DZ Impulsgeber" }, { "key": "dzDauersignal", "label": "DZ Dauersignal" }, { "key": "schlupfueberwachung", "label": "Schlupfüberwachung" }, { "key": "endschalter1", "label": "Endschalter 1" }, { "key": "endschalter2", "label": "Endschalter 2" }, { "key": "endschalter3", "label": "Endschalter 3" }, { "key": "endschalter4", "label": "Endschalter 4" }] as const;
|
||||||
|
const texts = [
|
||||||
|
{ key: 'view', label: 'View' }, { key: 'antriebName', label: 'Antrieb Name' }, { key: 'bmk', label: 'BMK' },
|
||||||
|
{ key: 'hmiText3', label: 'HMI Text 3' }, { key: 'hmiText2', label: 'HMI Text 2' }, { key: 'hmiText1', label: 'HMI Text 1' },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
type BmkDefault = 'unit' | 'view';
|
||||||
|
|
||||||
|
function AggregateRow({ initial, bmkDefault }: { initial: VisuAggregateRow; bmkDefault: BmkDefault }) {
|
||||||
|
const [row, setRow] = useState(initial);
|
||||||
|
const [persisted, setPersisted] = useState(initial.persisted);
|
||||||
|
const [antriebId, setAntriebId] = useState(String(initial.antriebId ?? ''));
|
||||||
|
const [sensorId, setSensorId] = useState(String(initial.analogSensorId ?? ''));
|
||||||
|
const [motors, setMotors] = useState(String(initial.anzahlMotoren));
|
||||||
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [message, setMessage] = useState('');
|
||||||
|
const [failed, setFailed] = useState(false);
|
||||||
|
const formId = 'aggregate-' + initial.componentId;
|
||||||
|
const formRef = useRef<HTMLFormElement>(null);
|
||||||
|
const savedFocus = useRef<{
|
||||||
|
element: HTMLElement;
|
||||||
|
selection: { start: number; end: number; direction: 'forward' | 'backward' | 'none' } | null;
|
||||||
|
} | null>(null);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (saving || !savedFocus.current) return;
|
||||||
|
const { element, selection } = savedFocus.current;
|
||||||
|
savedFocus.current = null;
|
||||||
|
if (!element.isConnected ||
|
||||||
|
(document.activeElement !== document.body && document.activeElement !== element)) return;
|
||||||
|
element.focus({ preventScroll: true });
|
||||||
|
if (selection && element instanceof HTMLInputElement) {
|
||||||
|
element.setSelectionRange(selection.start, selection.end, selection.direction);
|
||||||
|
}
|
||||||
|
}, [saving]);
|
||||||
|
|
||||||
|
function handleKeyDown(event: KeyboardEvent<HTMLTableRowElement>) {
|
||||||
|
if (event.nativeEvent.isComposing) return;
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 's') {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!saving && !event.repeat) formRef.current?.requestSubmit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!event.altKey || event.ctrlKey || event.metaKey ||
|
||||||
|
(event.key !== 'ArrowDown' && event.key !== 'ArrowUp')) return;
|
||||||
|
event.preventDefault();
|
||||||
|
const target = event.target;
|
||||||
|
if (!(target instanceof HTMLElement)) return;
|
||||||
|
const cell = target.closest<HTMLTableCellElement>('td, th');
|
||||||
|
if (!cell) return;
|
||||||
|
const selector = 'input:not(:disabled), button:not(:disabled), select:not(:disabled), textarea:not(:disabled)';
|
||||||
|
const controls = Array.from(cell.querySelectorAll<HTMLElement>(selector));
|
||||||
|
const controlIndex = Math.max(0, controls.indexOf(target));
|
||||||
|
let next = event.key === 'ArrowDown' ? event.currentTarget.nextElementSibling : event.currentTarget.previousElementSibling;
|
||||||
|
while (next instanceof HTMLTableRowElement) {
|
||||||
|
const nextCell = next.cells[cell.cellIndex];
|
||||||
|
const nextControls = nextCell ? Array.from(nextCell.querySelectorAll<HTMLElement>(selector)) : [];
|
||||||
|
const control = nextControls[controlIndex] ?? nextControls[0];
|
||||||
|
if (control) {
|
||||||
|
control.focus({ preventScroll: true });
|
||||||
|
control.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
next = event.key === 'ArrowDown' ? next.nextElementSibling : next.previousElementSibling;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function change() { setMessage('Ungespeicherte Änderungen'); setFailed(false); }
|
||||||
|
|
||||||
|
async function save(event: FormEvent<HTMLFormElement>) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (saving) return;
|
||||||
|
const drive = Number(antriebId), sensor = sensorId.trim() === '' ? null : Number(sensorId), count = Number(motors);
|
||||||
|
if (!antriebId.trim() || !Number.isSafeInteger(drive) || !motors.trim() || !Number.isSafeInteger(count) || count < 1 ||
|
||||||
|
(sensor !== null && !Number.isSafeInteger(sensor))) {
|
||||||
|
setMessage('Bitte gültige Ganzzahlen eingeben; mindestens ein Motor.'); setFailed(true); return;
|
||||||
|
}
|
||||||
|
const active = document.activeElement;
|
||||||
|
if (active instanceof HTMLElement && event.currentTarget.closest('tr')?.contains(active)) {
|
||||||
|
savedFocus.current = {
|
||||||
|
element: active,
|
||||||
|
selection: active instanceof HTMLInputElement && active.selectionStart !== null && active.selectionEnd !== null
|
||||||
|
? { start: active.selectionStart, end: active.selectionEnd, direction: active.selectionDirection ?? 'none' }
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
setSaving(true); setMessage('');
|
||||||
|
try {
|
||||||
|
const data: VisuAggregateInput = { ...row, antriebId: drive, analogSensorId: sensor, anzahlMotoren: count, mengeId: null };
|
||||||
|
const result = await api_visuAggregate_save(row.componentId, data);
|
||||||
|
if (result.success) setPersisted(true);
|
||||||
|
setFailed(!result.success);
|
||||||
|
setMessage(result.success ? 'Gespeichert' : result.error ?? 'Speichern fehlgeschlagen');
|
||||||
|
} finally { setSaving(false); }
|
||||||
|
}
|
||||||
|
|
||||||
|
return <tr onKeyDown={handleKeyDown} className={persisted ? 'align-top bg-green-50/50' : 'align-top'}>
|
||||||
|
<th scope="row" className={`sticky left-0 z-10 min-w-56 border p-2 text-left font-normal ${persisted ? 'bg-green-50' : 'bg-white'}`}>
|
||||||
|
<div className="font-medium">{initial.componentLabel}</div>
|
||||||
|
{persisted && <Link className="mt-1 inline-block text-xs underline" href={`/rk2/visu-aggregate/${initial.componentId}/grafiken`}>Grafiken bearbeiten</Link>}
|
||||||
|
<div className={persisted ? 'mt-1 text-xs text-green-700' : 'mt-1 text-xs text-gray-500'}>
|
||||||
|
{persisted ? 'In DB gespeichert' : 'Noch nicht gespeichert'}
|
||||||
|
</div>
|
||||||
|
<form ref={formRef} id={formId} onSubmit={save} className="mt-2">
|
||||||
|
<Button type="submit" size="sm" disabled={saving}>{saving ? 'Speichert …' : 'Speichern'}</Button>
|
||||||
|
</form>
|
||||||
|
<p role={failed ? 'alert' : 'status'} className={failed ? 'mt-1 text-red-600' : 'mt-1 text-xs'}>{message}</p>
|
||||||
|
</th>
|
||||||
|
<td className="border p-2"><Input form={formId} aria-label={initial.componentLabel + ': Antrieb ID'} className="min-w-28" type="number" step="1" required disabled={saving}
|
||||||
|
value={antriebId} onChange={e => { setAntriebId(e.target.value); change(); }} /></td>
|
||||||
|
<td className="border p-2"><Input form={formId} aria-label={initial.componentLabel + ': AnalogSensor ID'} className="min-w-28" type="number" step="1" disabled={saving}
|
||||||
|
value={sensorId} onChange={e => { setSensorId(e.target.value); change(); }} /></td>
|
||||||
|
<td className="border p-2"><Input aria-label="Menge ID (vorerst leer)" value="" disabled className="min-w-24" /></td>
|
||||||
|
{texts.slice(0, 3).map(({ key, label }) => <td key={key} className="border p-2"><Input form={formId} className="min-w-44" aria-label={initial.componentLabel + ': ' + label}
|
||||||
|
value={row[key] ?? ''} disabled={saving} onChange={e => { setRow(current => ({ ...current, [key]: e.target.value })); change(); }} />
|
||||||
|
<Button type="button" size="sm" variant="secondary" className="mt-1" disabled={saving}
|
||||||
|
onClick={() => {
|
||||||
|
setRow(current => ({
|
||||||
|
...current, [key]: key === 'view' ? initial.defaultView
|
||||||
|
: key === 'antriebName' ? initial.defaultView.replaceAll('_', ' ')
|
||||||
|
: bmkDefault === 'view' ? current.view?.trim() ? current.view : initial.defaultView : initial.defaultBmk
|
||||||
|
}));
|
||||||
|
change();
|
||||||
|
}}>Default</Button>
|
||||||
|
</td>)}
|
||||||
|
{switches.slice(0, 8).map(({ key, label }) => checkbox(key, label))}
|
||||||
|
<td className="border p-2"><Input form={formId} aria-label={initial.componentLabel + ': Anzahl Motoren'} className="min-w-24" type="number" min="1" step="1" required disabled={saving}
|
||||||
|
value={motors} onChange={e => { setMotors(e.target.value); change(); }} /></td>
|
||||||
|
{switches.slice(8, 11).map(({ key, label }) => checkbox(key, label))}
|
||||||
|
{texts.slice(3).map(({ key, label }) => initial.slave ? <td key={key} className="border p-2" aria-label={label + ': entfällt bei Slave'} /> : <td key={key} className="border p-2"><Input form={formId} className="min-w-44" aria-label={initial.componentLabel + ': ' + label}
|
||||||
|
value={row[key] ?? ''} disabled={saving} onChange={e => { setRow(current => ({ ...current, [key]: e.target.value })); change(); }} /></td>)}
|
||||||
|
{switches.slice(11).map(({ key, label }) => checkbox(key, label))}
|
||||||
|
</tr>;
|
||||||
|
|
||||||
|
function checkbox(key: typeof switches[number]['key'], label: string) {
|
||||||
|
if (initial.slave && (key === 'dzImpulsgeber' || key === 'dzDauersignal')) {
|
||||||
|
return <td key={key} className="border p-2" aria-label={label + ': entfällt bei Slave'} />;
|
||||||
|
}
|
||||||
|
return <td key={key} className="border p-3 text-center"><input form={formId} type="checkbox" className="h-4 w-4" aria-label={initial.componentLabel + ': ' + label}
|
||||||
|
checked={row[key]} disabled={saving} onChange={e => { setRow(current => ({ ...current, [key]: e.target.checked })); change(); }} /></td>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function VisuAggregateTable({ rows }: { rows: VisuAggregateRow[] }) {
|
||||||
|
const [bmkDefault, setBmkDefault] = useState<BmkDefault>('unit');
|
||||||
|
const headers = ['Komponente / Aktion', 'Antrieb ID', 'AnalogSensor ID', 'Menge ID', ...texts.slice(0, 3).map(item => item.label),
|
||||||
|
...switches.slice(0, 8).map(item => item.label), 'Anzahl Motoren', ...switches.slice(8, 11).map(item => item.label),
|
||||||
|
...texts.slice(3).map(item => item.label), ...switches.slice(11).map(item => item.label)];
|
||||||
|
if (!rows.length) return <p>In der ausgewählten Anlage sind keine Komponenten vom Typ „Antrieb“ vorhanden.</p>;
|
||||||
|
return <div>
|
||||||
|
<div className="mb-4 flex flex-wrap items-center gap-3">
|
||||||
|
<Button asChild variant="secondary"><Link href="/rk2/visu-aggregate/grafiken">Grafikübersicht</Link></Button>
|
||||||
|
<Button asChild variant="secondary"><a href="/rk2/visu-aggregate/export" download>Excel herunterladen</a></Button>
|
||||||
|
<span className="text-xs text-gray-600">Exportiert gespeicherte Einträge. Änderungen vorher speichern.</span>
|
||||||
|
<label htmlFor="bmk-default" className="text-sm font-medium">BMK-Default</label>
|
||||||
|
<Select id="bmk-default" className="w-64" value={bmkDefault}
|
||||||
|
onChange={event => setBmkDefault(event.target.value === 'view' ? 'view' : 'unit')}>
|
||||||
|
<option value="unit">Unit-BMK</option>
|
||||||
|
<option value="view">View-ID</option>
|
||||||
|
</Select>
|
||||||
|
<p className="text-sm text-gray-600">Wird beim Klick auf „Default“ in der BMK-Spalte übernommen.</p>
|
||||||
|
</div>
|
||||||
|
<p className="mb-3 text-sm text-gray-600">
|
||||||
|
Alt + ↑ / ↓: gleiche Spalte in der vorherigen / nächsten Zeile. Strg + S (Mac: Cmd + S): aktuelle Zeile speichern.
|
||||||
|
</p>
|
||||||
|
<div className="max-h-[75vh] overflow-auto rounded border">
|
||||||
|
<table className="w-full border-separate border-spacing-0 text-sm">
|
||||||
|
<caption className="sr-only">VisuAggregate der ausgewählten Anlage – eine Zeile pro Antrieb-Komponente</caption>
|
||||||
|
<thead className="sticky top-0 z-20 bg-gray-100"><tr>{headers.map(label => <th scope="col" key={label} className="border p-2 text-left">{label}</th>)}</tr></thead>
|
||||||
|
<tbody>{rows.map(row => <AggregateRow key={row.componentId} initial={row} bmkDefault={bmkDefault} />)}</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -85,11 +85,7 @@ export function useComponent({ component, componentTypes, componentDefaults }: P
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
const changePropertie = (name: string, value: unknown) => {
|
const changePropertie = (name: string, value: unknown) => {
|
||||||
|
|
||||||
let newData = { ...data };
|
setData((cur) => ({ ...cur, properties: { ...cur.properties, [name]: value } }));
|
||||||
if (!newData.properties) return;
|
|
||||||
newData.properties[name] = value;
|
|
||||||
|
|
||||||
setData((cur) => ({ ...cur, properties: newData.properties }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -192,4 +188,4 @@ export function useComponent({ component, componentTypes, componentDefaults }: P
|
|||||||
changePropertie,
|
changePropertie,
|
||||||
setDefaultPropertie
|
setDefaultPropertie
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
export interface ViewElementBasis {
|
||||||
|
_id?: string;
|
||||||
|
key: string;
|
||||||
|
name: string;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
posX: number;
|
||||||
|
posY: number;
|
||||||
|
zIndex: number;
|
||||||
|
show: boolean;
|
||||||
|
}
|
||||||
|
export type ViewElement =
|
||||||
|
| (ViewElementBasis & { darstellung: 'xaml'; typ: string; varianten: { zustand: string; xamlBase64: string }[] })
|
||||||
|
| (ViewElementBasis & { darstellung: 'standard'; typ: 'anfahrzeit' | 'betriebsart' | 'text' });
|
||||||
|
|
||||||
|
export interface ProConViewAggregateData {
|
||||||
|
anlageId: string;
|
||||||
|
visuAggregateId: string;
|
||||||
|
viewName: string;
|
||||||
|
anzahlMotoren: number;
|
||||||
|
name: string;
|
||||||
|
persisted: boolean;
|
||||||
|
elemente: ViewElement[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ViewAggregateOverview {
|
||||||
|
componentId: string;
|
||||||
|
antriebId: number;
|
||||||
|
name: string;
|
||||||
|
viewName: string;
|
||||||
|
elemente: ViewElement[];
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
export interface VisuAggregateInput {
|
||||||
|
anlageId: string;
|
||||||
|
antriebId: number;
|
||||||
|
analogSensorId: number | null;
|
||||||
|
mengeId: null;
|
||||||
|
view: string | null;
|
||||||
|
anzahlMotoren: number;
|
||||||
|
antriebName: string;
|
||||||
|
bmk: string;
|
||||||
|
hmiText3: string;
|
||||||
|
hmiText2: string;
|
||||||
|
hmiText1: string;
|
||||||
|
dauerlaeufer: boolean;
|
||||||
|
stellantrieb: boolean;
|
||||||
|
pulsantrieb: boolean;
|
||||||
|
direktanlauf: boolean;
|
||||||
|
wendeschuetz: boolean;
|
||||||
|
sternDreieck: boolean;
|
||||||
|
fu: boolean;
|
||||||
|
sanftanlauf: boolean;
|
||||||
|
dzImpulsgeber: boolean;
|
||||||
|
dzDauersignal: boolean;
|
||||||
|
schlupfueberwachung: boolean;
|
||||||
|
endschalter1: boolean;
|
||||||
|
endschalter2: boolean;
|
||||||
|
endschalter3: boolean;
|
||||||
|
endschalter4: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VisuAggregateRow extends Omit<VisuAggregateInput, 'antriebId'> {
|
||||||
|
componentId: string;
|
||||||
|
componentLabel: string;
|
||||||
|
defaultView: string;
|
||||||
|
defaultBmk: string;
|
||||||
|
slave: boolean;
|
||||||
|
persisted: boolean;
|
||||||
|
antriebId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user