stand2026_10_06

This commit is contained in:
marco committed 2026-10-06 15:34:27 +02:00
1 parent 41f80ce947
commit 266f8c3b4f
199 files changed
+17061 -87

No files matched your search

+132
View File
@@ -0,0 +1,132 @@
"use client"
import { PropertyField } from "./propertyFields"
import { ComponentDefaults, ComponentResponse, ComponentType, ComponentTypeDefinition } from "@/types/anlagen/components"
import { Input } from "@/components/ui/input"
import { useComponent } from "@/hooks/rk2/useComponent"
import { Button } from "@/components/ui/button"
import { Label } from "@/components/ui/label"
import { Select } from "@/components/ui/select"
import { useSignal } from "@/hooks/rk2/useSignal"
import { Card, CardContent, CardHeader } from "@/components/ui/card"
interface Props {
component?: ComponentResponse
componentTypes: ComponentTypeDefinition[]
componentDefaults: ComponentDefaults[]
onClose?: () => void
}
export function ComponentForm({ component, componentTypes, componentDefaults, onClose }: Props) {
const { findCompType,
findCompPropertyType,
updateComponent,
compnentData,
setValue,
changePropertie,
setDefaultPropertie
} = useComponent({ component, componentTypes, componentDefaults });
const { signalByComp } = useSignal({ componenteId: component?.id })
const handleSaveChanges = async ()=>{
await updateComponent(compnentData.id, compnentData)
if(onClose) onClose();
}
if (!component) return <>{true &&
<Card positons={"start"}>
<CardHeader variant={"danger"} >Debug</CardHeader>
<CardContent className="ps-8">
<pre>{JSON.stringify(compnentData, null, 2)}</pre>
</CardContent>
</Card>
}</>
return (
<div style={{ border: "1px solid #ccc", padding: 16, marginBottom: 16, borderRadius: 8, }} >
{/*--- Component Basisdaten */}
<div className="flex gap-4">
<div className="flex flex-col w-100">
<Label size={"xs"} >Name</Label>
<Input sizeVariant={"xs"} type="text" value={compnentData.name} onChange={(e) => setValue('name', e.target.value)} />
</div>
<div className="w-30 flex flex-col">
<label className="ps-1 font-normal text-xs text-gray-600 "> {"Index"}</label>
<Input sizeVariant={"xs"} type="number" value={compnentData.index} onChange={(e) => setValue('index', Number(e.target.value))} />
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >Prefix</Label>
<Input sizeVariant={"xs"} type="text" value={compnentData.prefix} onChange={(e) => setValue('prefix', e.target.value)} />
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >Postfix</Label>
<Input sizeVariant={"xs"} type="text" value={compnentData.postfix} onChange={(e) => setValue('postfix', e.target.value)} />
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >Unit Typ</Label>
<Select sizeVariant={"xs"} value={compnentData.type} onChange={(e) => setValue('type', e.target.value)} >
{componentTypes.map((t) => <option key={t.type} value={t.type}>{t.label}</option>)}
</Select>
</div>
</div>
{/*--- Properties */}
<div className="mt-6">
<div className="font-bold">Eigenschaften</div>
{compnentData.properties &&
Object.entries(compnentData.properties).map(([key, value]) => (
<PropertyField
key={key}
name={key}
value={value}
propertyType={findCompPropertyType(key)}
setPropValue={(name, value) => changePropertie(name, value)}
/>
))}
</div>
<div className="flex gap-4">
<Button type="button" onClick={() => handleSaveChanges()}>Save</Button>
<Button type="button" onClick={() => setDefaultPropertie()}>Add default Props</Button>
</div>
{/* --- Signal IDs ----*/}
{signalByComp && signalByComp.map((s) => <div key={s.id}>
{s.name}
</div>)}
{true &&
<Card positons={"start"}>
<CardHeader variant={"danger"} >Debug</CardHeader>
<CardContent className="ps-8">
<pre>{JSON.stringify(compnentData, null, 2)}</pre>
</CardContent>
</Card>
}
</div>
)
}
/*
*/
@@ -0,0 +1,78 @@
import { Input } from "@/components/ui/input"
import { PropertyDefinition } from "@/types/anlagen/components"
interface PropertyFieldProps {
name: string
propertyType?: PropertyDefinition,
value: unknown,
setPropValue: (name:string,value:unknown)=>void
}
export function PropertyField({ name, value, propertyType,setPropValue }: PropertyFieldProps) {
if (!propertyType) return <div className="w-30">
{name} {value as string} {propertyType}
</div>
const handleChangeValue = (value:unknown,type:string)=>{
setPropValue(name,value);
}
switch (propertyType.type) {
case "text":
return (
<div className="w-30 flex flex-col">
<label className="ps-1 font-normal text-xs text-gray-600 "> {propertyType.label}</label>
<Input type="text" value={""+value} onChange={(e)=>handleChangeValue(e.target.value,"text")} />
</div>
)
case "number":
return (
<div className="w-30 flex flex-col">
<label className="ps-1 font-normal text-xs text-gray-600 "> {propertyType.label}</label>
<Input type="number" value={Number(value)} onChange={(e)=>handleChangeValue(e.target.value,"number")} />
</div>
)
case "boolean":
return (
<div className="w-30 flex flex-row gap-4">
<label className="w-20 ps-1 font-normal text-xs text-gray-600 ">
{propertyType.label}
</label>
<input type="checkbox" checked={value as boolean} onChange={(e)=>handleChangeValue(e.target.checked,"boolean")} />
</div>
)
case "select":
return (
<div>
<label> {propertyType.label} </label>
<select value={value as string} onChange={(e)=>handleChangeValue(e.target.value,"text")}>
<option value="">
Bitte auswählen
</option>
{propertyType.options?.map(
(option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
)
)}
</select>
</div>
)
default:
return null
}
}
+70
View File
@@ -0,0 +1,70 @@
"use client";
import { useEffect, useState } from "react";
import Modal from "@/components/ui/Modal";
import { Anlage } from "@/types/rk";
import { GroupResponse } from "@/types/anlagen/groups";
import { UnitResponse } from "@/types/anlagen/units";
import { useGroups } from "@/hooks/rk2/useGroups";
import { UnitCreateForm } from "./unit_createForm";
import { GroupSelect } from "../groups/groupSelect";
import { ComponentDefaults, ComponentTypeDefinition } from "@/types/anlagen/components";
interface Params {
anlage: Anlage,
groups: GroupResponse[],
selectedUnit?: UnitResponse,
componentTypes: ComponentTypeDefinition[]
componentDefaults: ComponentDefaults[]
}
export const UnitEdit = ({ anlage, groups, selectedUnit, componentTypes,componentDefaults }: Params) => {
const { getGroupById } = useGroups({ groups });
const [showSelectGroup, setShowSelectGroup] = useState(false);
const [selectedGroup, setSelectedGroup] = useState<GroupResponse>();
useEffect(() => {
if (selectedUnit && selectedUnit.groupId) {
const pGroup = getGroupById(selectedUnit.groupId)
setSelectedGroup(() => pGroup)
}
}, [selectedUnit])
useEffect(() => {
if (selectedGroup) {
const pGroup = getGroupById(selectedGroup.id)
setSelectedGroup(() => pGroup)
}
}, [selectedGroup])
const handlerGroupSelect = (group: GroupResponse) => {
setSelectedGroup(() => group);
setShowSelectGroup(false);
}
//groupIntial={selectedGroup} parentGroup={selectedGroup} onResetParent={() => setSelectedGroup(() => undefined)}
return (
<div className="" >
<UnitCreateForm anlage={anlage} selectedGroup={selectedGroup} onDisplaySelectGroup={() => setShowSelectGroup(true)} unitIntial={selectedUnit} componentTypes={componentTypes} componentDefaults={componentDefaults}/>
{showSelectGroup &&
<Modal onClose={() => setShowSelectGroup(false)} >
<GroupSelect groups={groups} onSelect={handlerGroupSelect} />
</Modal>
}
</div >
)
}
@@ -0,0 +1,280 @@
"use client";
import { useEffect, useState } from "react"
import { Anlage } from "@/types/rk";
import Toast from "@/components/ui/Toast";
import { UnitResponse } from "@/types/anlagen/units";
import { useUnit } from "@/hooks/rk2/useUnit";
import { api_units_create, api_units_update } from "@/actions/rk2/api-units";
import { ComponentForm } from "./componentForm";
import { GroupResponse } from "@/types/anlagen/groups";
import { Button } from "@/components/ui/button";
import { ComponentDefaults, ComponentResponse, ComponentTypeDefinition } from "@/types/anlagen/components";
import { useComponent } from "@/hooks/rk2/useComponent";
import { ComponentIcon, Divide, Save, TableOfContents } from "lucide-react";
import { Card, CardContent, CardFooder, CardHeader, CardTitle } from "@/components/ui/card";
import { List, ListItem, ListItemAction, ListItemContent, ListItemDescription, ListItemIcon, ListItemTitle } from "@/components/ui/list";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Select } from "@/components/ui/select";
interface Params {
anlage: Anlage,
unitIntial?: UnitResponse
selectedGroup?: GroupResponse
onDisplaySelectGroup: () => void
componentTypes: ComponentTypeDefinition[]
componentDefaults: ComponentDefaults[]
debug?: boolean
}
export const UnitCreateForm = ({ anlage, unitIntial, onDisplaySelectGroup, selectedGroup, componentTypes, componentDefaults, debug }: Params) => {
const [id, setId] = useState<string>();
const [selectedComponent, setSelectedComponent] = useState<ComponentResponse>();
const { emptyUnit, unitType, setValue, unitData, string_to_UnitType } = useUnit({ unit: unitIntial });
const { componentNames, findCompType, createComponent, removeComponent } = useComponent({ componentTypes, componentDefaults });
const [toast, setToast] = useState<string | null>(null);
useEffect(() => {
console.log('init');
if (unitIntial) {
const { id, ...rest } = unitIntial;
setId(id);
} else {
}
}, [unitIntial]);
//--- Parent Group hat sich geändert
useEffect(() => {
selectedGroup && setValue("groupId", selectedGroup.id);
}, [selectedGroup])
//--- Submit --> Create oder Update
const onSubmit = async () => {
const { id: id1, ...sendData } = unitData;
let response = id ? await api_units_update(id, sendData) : await api_units_create(sendData);
if (response.success) {
setId(response.data!.id);
setToast("Erfolgreich gespeichert!");
} else {
setToast("Fehler beim Speichern!");
}
}
const handlerAppendComponent = (type: string) => {
const comp = findCompType(type);
if (!comp || !id) return;
console.log(comp)
createComponent(id, { name: "", type: comp.type })
}
return (
<>
<div className="relative inline-block">
{toast && (
<Toast
message={toast}
onClose={() => setToast(null)}
/>
)}
</div>
<Card variant={"primary"}>
<CardHeader >Unit</CardHeader>
<CardContent className="ps-12 pt-4">
<div className="flex gap-4">
<div className="flex gap-1 items-center ">
<div className="text-xs">{selectedGroup ? selectedGroup.name : "noGroup"}</div>
<Button type="button" variant={"secondary"} size={"xs"} onClick={() => onDisplaySelectGroup()}><TableOfContents /></Button>
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >Prefix</Label>
<Input sizeVariant={"xs"} type="text" value={unitData.prefix} onChange={(e) => setValue('prefix', e.target.value)} />
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >BMK</Label>
<Input sizeVariant={"xs"} type="text" value={unitData.bmk} onChange={(e) => setValue('bmk', e.target.value)} />
</div>
<div className="flex flex-col w-150">
<Label size={"xs"} >Name</Label>
<Input sizeVariant={"xs"} type="text" value={unitData.name} onChange={(e) => setValue('name', e.target.value)} />
</div>
<div className="flex flex-col w-100">
<Label size={"xs"} >Postfix</Label>
<Input sizeVariant={"xs"} type="text" value={unitData.postfix} onChange={(e) => setValue('postfix', e.target.value)} />
</div>
<div className="flex flex-col w-150">
<Label size={"xs"} >Unit Typ</Label>
<Select sizeVariant={"xs"} value={unitData.type} onChange={(e) => setValue('type', string_to_UnitType(e.target.value))} >
{unitType.map((t) => <option key={t.id} value={t.id}>{t.value}</option>)}
</Select>
</div>
<Button type="button" size={"lg"} onClick={() => onSubmit()} ><Save /> </Button>
</div>
<div className="w-30 flex flex-row">
<Label size={"xs"} >Info</Label>
<Input sizeVariant={"xs"} type="text" value={unitData.info} onChange={(e) => setValue('info', e.target.value)} />
</div>
</CardContent>
<CardFooder></CardFooder>
</Card >
{selectedComponent && <div>
<Button onClick={() => setSelectedComponent(undefined)}>close</Button>
</div>
}
{/* Componente */}
{/*--- Show addable Components */}
{
!selectedComponent && <section className="flex gap-4">
{id &&
<Card className="w-60" variant={"primary"}>
<CardHeader variant={"ghost"}>Komponenten +</CardHeader>
<List variant="transparent" border={"none"} divide={false} size={"sm"}>
{componentNames.map((comp) => (
<ListItem className="" key={comp.id}>
<Button onClick={() => handlerAppendComponent(comp.id)} type="button" key={comp.id} variant={"select"} size={"xs"} >{comp.name}</Button>
</ListItem>
))}
</List>
</Card >
}
{/*--- Show Components List */}
{id && unitData.components &&
<Card positons="center" className="w-full">
<CardHeader>Komponenten</CardHeader>
<CardContent className="p-2">
<List className="w-120" >
{unitData.components.map((c, index) => <ListItem hover={true} size={"sm"} key={c.id}>
<ListItemIcon>
<ComponentIcon />
</ListItemIcon>
<ListItemContent className="w-100">
<ListItemTitle>
{c.type}
</ListItemTitle>
<ListItemDescription>
{c.prefix && c.prefix}
{c.name}
{c.postfix && c.postfix}
{c.index && c.index > 0 ? c.index: ""}
</ListItemDescription>
</ListItemContent>
<ListItemAction>
<Button onClick={() => setSelectedComponent(() => c)} type="button" size={"xs"} variant={"secondary"}>Details</Button>
<Button onClick={() => removeComponent(c.id)} type="button" size={"xs"} variant={"secondary"}>Löschen</Button>
</ListItemAction>
</ListItem>)}
</List>
<div>
</div>
</CardContent>
</Card >
}
</section>
}
{/* --- Components */}
<ComponentForm
component={selectedComponent}
componentTypes={componentTypes}
componentDefaults={componentDefaults}
onClose={() => setSelectedComponent(() => undefined)}
/>
{
true &&
<Card positons={"start"}>
<CardHeader variant={"danger"} >Debug</CardHeader>
<CardContent className="ps-8">
<pre>{JSON.stringify(unitData, null, 2)}</pre>
</CardContent>
</Card>
}
</>
)
}
/*
{fields.length === 0 && (<p>Noch keine Components vorhanden.</p>)}
{selectedComponent && (
<ComponentForm
index={selectedComponent.index}
register={register}
control={control}
remove={(index) => handlerRemoveItem(index)}
setValue={setValue}
componentTypes={componentTypes}
componentDefaults={componentDefaults}
/>
)}
{false && fields.map(
(field, index) => (
<ComponentForm
key={field.id}
index={index}
register={register}
control={control}
remove={(index) => handlerRemoveItem(index)}
setValue={setValue}
componentTypes={componentTypes}
componentDefaults={componentDefaults}
/>
)
)}
*/