stand2026_10_06
This commit is contained in:
1 parent
41f80ce947
commit
266f8c3b4f
199 files changed
+17061
-87
No files matched your search
@@ -0,0 +1,119 @@
|
||||
"use client"
|
||||
|
||||
import { ProConView, ProConXamlData } from "@/types/procon"
|
||||
import { useEffect, useState } from "react";
|
||||
import VisualisierungPositionen from "./visualiserungPositionen";
|
||||
import { api_ProconViews_UpdateXAML } from "@/actions/procon/api-procon-views";
|
||||
import { useVisuAgg } from "@/hooks/procon/useVisuAgg";
|
||||
import SvgView from "./svg/SvgView";
|
||||
|
||||
|
||||
interface Props {
|
||||
visuElements: ProConView[]
|
||||
}
|
||||
|
||||
|
||||
export default function Visualisierungen({ visuElements }: Props) {
|
||||
const [selectedElement, setSelectedElement] = useState<ProConView | undefined>();
|
||||
const [selectedView, setSelectedView] = useState<ProConXamlData | undefined>();
|
||||
|
||||
const { elements, viewNames, selectedViewElement, onSelectViewElement, graphics } = useVisuAgg({ data: visuElements });
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedElement(undefined);
|
||||
setSelectedView(undefined);
|
||||
}, [visuElements])
|
||||
|
||||
|
||||
const headers = ['Symbol', "PosX", "PosY", "Höhe", "Breite", "Ebene", "Auswahl"]
|
||||
|
||||
const handlerSaveXaml = () => {
|
||||
if (!selectedView) return;
|
||||
api_ProconViews_UpdateXAML(selectedView.id, selectedView.xaml)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex gap-8">
|
||||
<section>
|
||||
<div>
|
||||
XAML-Views
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 w-50 ">
|
||||
{viewNames.map((v) => (
|
||||
<div
|
||||
className="border-1 rounded p-1 bg-gray-100"
|
||||
key={v.index}
|
||||
onClick={() => onSelectViewElement(v.index)}
|
||||
>
|
||||
{v.name}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div>
|
||||
{selectedViewElement?.viewType}
|
||||
<div className="flex gap-4">
|
||||
<div>X</div>
|
||||
<div>{selectedViewElement?.posX}</div>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
{graphics.map((g) => (<div>{g.viewType}-{g.viewIndex}-{g.state}</div>))}
|
||||
</div>
|
||||
<div>
|
||||
{graphics.map((g) => <SvgView svg={g.svg} />)
|
||||
|
||||
|
||||
}
|
||||
|
||||
</div>
|
||||
<div>
|
||||
{ graphics[0] &&
|
||||
<textarea className="w-300 h-100" value={(graphics[0].xaml)} />
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<div className="grid grid-cols-[200px_50px_50px_50px_50px_50px_400px] gap-4">
|
||||
{headers.map((name) => <div key={name}>{name}</div>)}
|
||||
</div>
|
||||
|
||||
{elements.map((element) => (
|
||||
<div className="grid grid-cols-[200px_50px_50px_50px_50px_50px_400px] gap-4" key={element.id}>
|
||||
<div>{element.viewType}{element.viewType == 'pfeil' && element.viewIndex}</div>
|
||||
<VisualisierungPositionen id={element.id} koordinaten={{ ...element }}></VisualisierungPositionen>
|
||||
<div>{element.views.length > 0 && <button onClick={() => setSelectedElement(() => element)}>x</button>}</div>
|
||||
</div>
|
||||
))
|
||||
}
|
||||
|
||||
<div className="mt-8">
|
||||
{selectedElement && <div>
|
||||
<div className="font-bold p-4">View {selectedElement.viewType}{selectedElement.viewType == "pfeil" && selectedElement.viewIndex}</div>
|
||||
<div className="flex gap-4 p-4">
|
||||
{selectedElement.views.map((view) => <div onClick={() => setSelectedView(view)} key={view.id}>{view.state}</div>)}
|
||||
</div>
|
||||
</div>}
|
||||
</div>
|
||||
{selectedViewElement?.viewType}
|
||||
{selectedViewElement && selectedViewElement.views &&
|
||||
<div>
|
||||
<div>
|
||||
<textarea className="w-300 h-100" value={atob(selectedViewElement.views[0].xaml)} onChange={(e) => setSelectedView((old) => ({ ...old!, xaml: btoa(e.target.value) }))} />
|
||||
</div>
|
||||
<div>
|
||||
<button onClick={() => handlerSaveXaml()}>Save</button>
|
||||
<button onClick={() => setSelectedView((old) => undefined)}>cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Modal from "../ui/Modal";
|
||||
interface Props {
|
||||
xamlBase64Data: string
|
||||
}
|
||||
|
||||
|
||||
export default function AggregateXamlData({ xamlBase64Data }: Props) {
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [text, setText] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
setText(atob(xamlBase64Data))
|
||||
}, [xamlBase64Data])
|
||||
|
||||
return (
|
||||
<section>
|
||||
<button onClick={() => setShowDetails(!showDetails)}>
|
||||
{showDetails ? "Weniger Details" : "Mehr Details"}
|
||||
</button>
|
||||
|
||||
|
||||
|
||||
{showDetails && (
|
||||
<Modal onClose={()=>setShowDetails(false)}>
|
||||
<div className="w-400 h-200">
|
||||
<textarea className="w-full h-full" name="xaml" id="xaml" value={text} onChange={(e) => setText(e.target.value)}></textarea>
|
||||
</div>
|
||||
</Modal>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Modal from "../ui/Modal";
|
||||
import { InputNumber } from "../ui/InputNumber";
|
||||
import { api_ProconVisualisierungen_Update } from "@/actions/procon/api-procon-visualisierungen";
|
||||
import { ProConView } from "@/types/procon";
|
||||
|
||||
interface Positionen{
|
||||
|
||||
}
|
||||
|
||||
interface Props {
|
||||
data:ProConView
|
||||
}
|
||||
|
||||
|
||||
export default function EditXaml({ data }: Props) {
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [text, setText] = useState('');
|
||||
|
||||
const handleChange = (name:string,value:number)=>{
|
||||
console.log('Submit','name',name,' value',value);
|
||||
let data :Partial<ProConView> = {}
|
||||
if(name==='posX') data['posX'] = value;
|
||||
if(name==='posY') data['posY'] = value;
|
||||
if(name==='height') data['height'] = value;
|
||||
if(name==='width') data['width'] = value;
|
||||
if(name==='zIndex') data['zIndex'] = value;
|
||||
|
||||
|
||||
//api_ProconVisualisierungen_Update(id,data);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{data.views.map((view)=><div>{view.state}</div>)}
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<div>{element.posX}</div>
|
||||
<div>{element.posY}</div>
|
||||
<div>{element.height}</div>
|
||||
<div>{element.width}</div>
|
||||
<div>{element.zIndex}</div>
|
||||
*/
|
||||
@@ -0,0 +1,15 @@
|
||||
'use client';
|
||||
|
||||
interface Props {
|
||||
svg: string;
|
||||
}
|
||||
|
||||
export default function SvgView({ svg }: Props) {
|
||||
return (
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: svg,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Whitespace-only changes.
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Modal from "../ui/Modal";
|
||||
import { InputNumber } from "../ui/InputNumber";
|
||||
import { api_ProconVisualisierungen_Update } from "@/actions/procon/api-procon-visualisierungen";
|
||||
import { ProConView } from "@/types/procon";
|
||||
|
||||
interface Positionen{
|
||||
posX:number,
|
||||
posY:number,
|
||||
height:number,
|
||||
width:number,
|
||||
zIndex:number
|
||||
}
|
||||
|
||||
interface Props {
|
||||
id:number,
|
||||
koordinaten: Positionen
|
||||
}
|
||||
|
||||
|
||||
export default function VisualisierungPositionen({ id,koordinaten }: Props) {
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const [text, setText] = useState('');
|
||||
|
||||
const handleChange = (name:string,value:number)=>{
|
||||
console.log('Submit','name',name,' value',value);
|
||||
let data :Partial<ProConView> = {}
|
||||
if(name==='posX') data['posX'] = value;
|
||||
if(name==='posY') data['posY'] = value;
|
||||
if(name==='height') data['height'] = value;
|
||||
if(name==='width') data['width'] = value;
|
||||
if(name==='zIndex') data['zIndex'] = value;
|
||||
|
||||
|
||||
api_ProconVisualisierungen_Update(id,data);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<InputNumber name="posX" inValue={koordinaten.posX} onChanged={handleChange} />
|
||||
<InputNumber name="posY" inValue={koordinaten.posY} onChanged={handleChange} />
|
||||
<InputNumber name="height" inValue={koordinaten.height} onChanged={handleChange} />
|
||||
<InputNumber name="width" inValue={koordinaten.width} onChanged={handleChange} />
|
||||
<InputNumber name="zIndex" inValue={koordinaten.zIndex} onChanged={handleChange} />
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<div>{element.posX}</div>
|
||||
<div>{element.posY}</div>
|
||||
<div>{element.height}</div>
|
||||
<div>{element.width}</div>
|
||||
<div>{element.zIndex}</div>
|
||||
*/
|
||||
@@ -0,0 +1,32 @@
|
||||
"use client"
|
||||
import { api_anlage_setSelected } from "@/actions/rk/api-anlage";
|
||||
import { Anlage } from "@/types/rk";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
data: Anlage,
|
||||
isSelected: boolean
|
||||
}
|
||||
|
||||
export default function AnlageColumn({ data, isSelected }: Props) {
|
||||
|
||||
|
||||
|
||||
return <div style={{ backgroundColor: isSelected ? "#00ff00" : "#ffffff" }}
|
||||
onClick={() => api_anlage_setSelected(data.id)}>
|
||||
<div>
|
||||
{data.id}
|
||||
</div>
|
||||
<div>
|
||||
{data.anlageNr}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{data.name}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
"use client"
|
||||
|
||||
import { Anlage, Element, ExcelProCon, Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ElementEdit } from "./elementEdit";
|
||||
import ElementViewItem from "./elementsViewItem";
|
||||
import ElementViewListHeader from "./elementsViewListHeader";
|
||||
import ElementSelectExcelList from "./elementsSelectExcelList";
|
||||
import { ElementEditRow } from "./elementEditRow";
|
||||
import { useElements } from "@/hooks/useElements";
|
||||
|
||||
|
||||
interface Props {
|
||||
analge:Anlage,
|
||||
elements: Element[],
|
||||
groups: Group[]
|
||||
}
|
||||
|
||||
export default function ElementCreateView({ analge,elements:initElements, groups }: Props) {
|
||||
|
||||
const { elements, selectedElement, filterExcelListe, setFilterExcelListe, setSelectedItem } = useElements({ elements: initElements });
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[1200_300]">
|
||||
<div>
|
||||
|
||||
<ElementSelectExcelList onSelect={(liste) => setFilterExcelListe(liste)}></ElementSelectExcelList>
|
||||
|
||||
<ElementEditRow anlage={analge} groups={groups}></ElementEditRow>
|
||||
{filterExcelListe}
|
||||
|
||||
<div className="m-4 p-4">
|
||||
<ElementViewListHeader></ElementViewListHeader>
|
||||
<div className="h-180 overflow-y-scroll border">
|
||||
{elements.map((item) =>
|
||||
|
||||
<ElementViewItem key={item.id} element={item} onSelect={setSelectedItem}></ElementViewItem>
|
||||
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import { Element, ElementCreate, emptyElement, Group } from "@/types/rk";
|
||||
|
||||
import { api_elementDelete, elementCreate, elementUpdate } from "@/actions/rk/api-element";
|
||||
import { SelectR } from "@/components/ui/selectR";
|
||||
|
||||
|
||||
interface Params {
|
||||
groups: Group[]
|
||||
initData?: Element
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
export const ElementEdit = ({ initData, groups, debug }: Params) => {
|
||||
|
||||
const { control, register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<ElementCreate>({ defaultValues: emptyElement, })
|
||||
|
||||
|
||||
const [modeUpdate, setModeUpdate] = useState(false);
|
||||
const [selGroup, setSelGroup] = useState<string | undefined>();
|
||||
|
||||
const [id, setId] = useState<string | undefined>();
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (initData) {
|
||||
const { id, group, ...rest } = initData;
|
||||
setId(id);
|
||||
setModeUpdate(true);
|
||||
if (initData.group) setSelGroup(() => initData.group.id);
|
||||
reset({ ...rest, groupId: group ? group.id : undefined })
|
||||
}
|
||||
}, [initData]);
|
||||
|
||||
const onSubmit = async (data: ElementCreate) => {
|
||||
setError(undefined);
|
||||
//const { name, isConsumable, description } = data;
|
||||
if (modeUpdate) {
|
||||
if (id) {
|
||||
elementUpdate(id, data);
|
||||
} else {
|
||||
setError('Etwas ist falsch, keine ID');
|
||||
}
|
||||
|
||||
} else {
|
||||
elementCreate(data);
|
||||
}
|
||||
}
|
||||
|
||||
const handlerDelete = async () => {
|
||||
if (id) api_elementDelete(id);
|
||||
}
|
||||
|
||||
const excelListe = [{ id: "keine", value: "" },
|
||||
{ id: "Aggregate", value: "Aggregate" },
|
||||
{ id: "Sensoren", value: "Sensoren" },
|
||||
{ id: "Analogwerte", value: "Analogwerte" },
|
||||
{ id: "AnlagenVisu", value: "AnlagenVisualisierung" },
|
||||
]
|
||||
|
||||
const options = watch("options")
|
||||
|
||||
return (
|
||||
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
|
||||
<div className="border-1 p-4">
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
|
||||
<div>
|
||||
|
||||
{initData && initData.group &&
|
||||
<div>
|
||||
{initData?.group.nr}_{initData?.group.name}
|
||||
</div>}
|
||||
|
||||
<div>
|
||||
<SelectR label="Gruppe" options={groups.map((g) => ({ id: g.id, value: g.nr + '_' + g.name }))} {...register("groupId")} ></SelectR>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-[60px_1fr] gap-2">
|
||||
<InputTextR label="Nr" {...register("excelNr", { required: "Pflichtfeld" })} error={errors.excelNr?.message} />
|
||||
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
|
||||
</div>
|
||||
<InputTextR label="Prefix" {...register("prefix", { required: false })} error={errors.prefix?.message} />
|
||||
<InputTextR label="funcTxt" {...register("funcTxt", { required: false })} error={errors.funcTxt?.message} />
|
||||
<InputTextR label="Type" {...register("type", { required: "Pflichtfeld" })} error={errors.type?.message} />
|
||||
<SelectR label="Excel Liste" options={excelListe.map((e) => ({ id: e.id, value: e.value }))} {...register("excelListe")} ></SelectR>
|
||||
|
||||
<div>
|
||||
{error && <div>{error}</div>}
|
||||
{errors.name && <div>{errors.name.message}</div>}
|
||||
</div>
|
||||
|
||||
<div className="p-2 mt-4 ">
|
||||
<div className="font-semibold">Optionen</div>
|
||||
<div className="border-1 rounded border-gray-200 p-4 ">
|
||||
{options &&
|
||||
Object.entries(options).map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-[100px_200px] pt-1">
|
||||
|
||||
<label className="font-semibold">{key}:</label>
|
||||
|
||||
{typeof value === "boolean" ? (
|
||||
<div className="flex flex-start ">
|
||||
<input
|
||||
className=""
|
||||
type="checkbox"
|
||||
{...register(`options.${key}` as const)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
) : (
|
||||
<div className="">
|
||||
<InputTextR {...register(`options.${key}` as const)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
|
||||
{id && <button className="bg-red-500 text-white p-2 rounded mt-2 hover:bg-blue-600" onClick={() => handlerDelete()}>Löschen</button>}
|
||||
</div>
|
||||
</form>
|
||||
</div >
|
||||
|
||||
{debug &&
|
||||
<div>
|
||||
<div>ID: {id}</div>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>
|
||||
}
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import { Anlage, Element, ElementCreate, emptyElement, Group } from "@/types/rk";
|
||||
|
||||
import { api_elementDelete, elementCreate, elementUpdate } from "@/actions/rk/api-element";
|
||||
import { SelectR } from "@/components/ui/selectR";
|
||||
import { useElement } from "@/hooks/useElement";
|
||||
import { Sites } from "@/_config/sites";
|
||||
import Toast from "@/components/ui/Toast";
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage: Anlage,
|
||||
groups: Group[]
|
||||
elementIntial?: Element
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
export const ElementEditRow = ({ anlage, elementIntial, groups, debug }: Params) => {
|
||||
|
||||
const { control, register, handleSubmit, formState: { errors }, watch, setFocus, reset } = useForm<ElementCreate>({ defaultValues: emptyElement, })
|
||||
const { proConExcelLists } = useElement({ element: elementIntial })
|
||||
const [selGroup, setSelGroup] = useState<string | undefined>();
|
||||
const [toast, setToast] = useState<string | null>(null);
|
||||
|
||||
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (elementIntial) {
|
||||
const { id, group, ...rest } = elementIntial;
|
||||
|
||||
if (elementIntial.group) setSelGroup(() => elementIntial.group.id);
|
||||
reset({ ...rest, groupId: group ? group.id : undefined })
|
||||
} else {
|
||||
reset({ ...emptyElement, anlageId: anlage.id })
|
||||
}
|
||||
}, [elementIntial]);
|
||||
|
||||
const onSubmit = async (data: ElementCreate) => {
|
||||
setError(undefined);
|
||||
//await elementCreate(data);
|
||||
setToast("Erfolgreich gespeichert!");
|
||||
setFocus('excelNr')
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const options = watch("options")
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 pt-10 ps-10" >
|
||||
|
||||
<div className="relative inline-block">
|
||||
{toast && (
|
||||
<Toast
|
||||
message={toast}
|
||||
onClose={() => setToast(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="">
|
||||
<div className="flex gap-4 border-1 border-gray-200 rounded-sm p-4 shadow-md">
|
||||
|
||||
<div className="grid grid-cols-[60px_1fr] gap-2">
|
||||
<InputTextR label="Nr" {...register("excelNr", { required: "Pflichtfeld" })} error={errors.excelNr?.message} />
|
||||
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
|
||||
</div>
|
||||
<InputTextR label="Prefix" {...register("prefix", { required: false })} error={errors.prefix?.message} />
|
||||
<InputTextR label="funcTxt" {...register("funcTxt", { required: false })} error={errors.funcTxt?.message} />
|
||||
<InputTextR label="Type" {...register("type", { required: "Pflichtfeld" })} error={errors.type?.message} />
|
||||
<SelectR label="Excel Liste" options={proConExcelLists} {...register("excelListe")} ></SelectR>
|
||||
|
||||
<div>
|
||||
{error && <div>{error}</div>}
|
||||
{errors.name && <div>{errors.name.message}</div>}
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex gap-4">
|
||||
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div >
|
||||
</form>
|
||||
|
||||
{true &&
|
||||
<div>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>
|
||||
}
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Element, Group } from "@/types/rk";
|
||||
|
||||
|
||||
interface Props {
|
||||
elements: Element[],
|
||||
onSelect?: (element:Element)=>void
|
||||
}
|
||||
|
||||
export default function ElementSelect({ elements,onSelect }: Props) {
|
||||
|
||||
const handleSelect = (element:Element)=>{
|
||||
if(onSelect) onSelect(element);
|
||||
}
|
||||
return (
|
||||
<div className="">
|
||||
<div className="flex flex-col m-4 pt-4 overflow-y-scroll border h-150">
|
||||
{elements.map((el) => (
|
||||
|
||||
<div className="flex hover:bg-sky-100 h-8 items-center" onClick={()=>handleSelect(el)} key={el.id}>
|
||||
<div className="ps-4 ">{`${el.group ? el.group.nr:'noGroup'}${el.prefix ? el.prefix:""} ${el.name}`}</div>
|
||||
</div>))}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"use client"
|
||||
|
||||
import { ExcelProCon } from "@/types/rk";
|
||||
import MonButton from "@/components/ui/MonBotton";
|
||||
|
||||
|
||||
interface Props {
|
||||
|
||||
onSelect:(excelListitem:ExcelProCon)=> void
|
||||
}
|
||||
|
||||
export default function ElementSelectExcelList({ onSelect }: Props) {
|
||||
|
||||
|
||||
return (
|
||||
<div className="flex gap-4 p-4">
|
||||
{Object.values(ExcelProCon).map((item) => (
|
||||
<MonButton key={item} onClick={()=>onSelect(item)}>
|
||||
{item}
|
||||
</MonButton>
|
||||
))}
|
||||
</div>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client"
|
||||
|
||||
import { Element, ExcelProCon, Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ElementEdit } from "./elementEdit";
|
||||
import ElementViewItem from "./elementsViewItem";
|
||||
import ElementViewListHeader from "./elementsViewListHeader";
|
||||
import ElementSelectExcelList from "./elementsSelectExcelList";
|
||||
import { useElements } from "@/hooks/useElements";
|
||||
|
||||
|
||||
interface Props {
|
||||
elements: Element[],
|
||||
groups: Group[]
|
||||
}
|
||||
|
||||
export default function ElementView({ elements: initElements, groups }: Props) {
|
||||
|
||||
const { elements, selectedElement, filterExcelListe, setFilterExcelListe, setSelectedItem } = useElements({ elements: initElements });
|
||||
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[1200_300]">
|
||||
<div>
|
||||
<ElementSelectExcelList onSelect={(liste) => setFilterExcelListe(liste)}></ElementSelectExcelList>
|
||||
{filterExcelListe}
|
||||
|
||||
<div className="m-4 p-4">
|
||||
<ElementViewListHeader></ElementViewListHeader>
|
||||
<div className="h-180 overflow-y-scroll border">
|
||||
{elements.map((item) =>
|
||||
|
||||
<ElementViewItem key={item.id} element={item} onSelect={setSelectedItem}></ElementViewItem>
|
||||
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{selectedElement &&
|
||||
<div>
|
||||
<ElementEdit initData={selectedElement} debug={true} groups={groups}></ElementEdit>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"use client"
|
||||
|
||||
import { Element, ExcelProCon, Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ElementEdit } from "./elementEdit";
|
||||
|
||||
|
||||
interface Props {
|
||||
element: Element,
|
||||
onSelect: (element: Element) => void
|
||||
}
|
||||
|
||||
export default function ElementViewItem({ element, onSelect }: Props) {
|
||||
|
||||
|
||||
const cols = [180, 80, 200, 300, 300, 150];
|
||||
|
||||
const style = { gridTemplateColumns: cols.map(c => `${c}px`).join(" ") }
|
||||
|
||||
return (
|
||||
|
||||
<div className="grid grid-cols-[1200_300]" style={style} onClick={() => onSelect(element)}>
|
||||
|
||||
<div>{element.excelListe}</div>
|
||||
<div>{element.excelNr}</div>
|
||||
{element.group ? <div>{element.group.nr} {element.group.name}</div> : <div>-</div>}
|
||||
<div>{element.name}</div>
|
||||
|
||||
{/* Type */}
|
||||
{element.group ? <div>
|
||||
G_{element.group.nr}
|
||||
{element.prefix != undefined && element.prefix !== "" && "_" + element.prefix}
|
||||
_{element.group.name}
|
||||
|
||||
{element.funcTxt != undefined && element.funcTxt !== "" && "_" + element.funcTxt}
|
||||
</div> : <div>n.v.</div>}
|
||||
{<div>{element.type}</div>}
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
"use client"
|
||||
|
||||
import { Element, ExcelProCon, Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ElementEdit } from "./elementEdit";
|
||||
import ElementViewItem from "./elementsViewItem";
|
||||
|
||||
|
||||
interface Props {
|
||||
|
||||
}
|
||||
|
||||
export default function ElementViewListHeader({ }: Props) {
|
||||
|
||||
|
||||
const cols = [180, 80, 200, 300, 300, 150];
|
||||
const style = { gridTemplateColumns: cols.map(c => `${c}px`).join(" ") };
|
||||
|
||||
const headers = [
|
||||
{ id: 0, name: "Excel Liste" },
|
||||
{ id: 1, name: "Excel Nr" },
|
||||
{ id: 2, name: "Gruppe" },
|
||||
{ id: 3, name: "Element" },
|
||||
{ id: 4, name: "ProConName" },
|
||||
{ id: 5, name: "Typ" },
|
||||
|
||||
]
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<div className={`grid font-bold `} style={style}>
|
||||
{headers.map((col) => <div key={col.id}>{col.name}</div>)}
|
||||
</div>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Group } from "@/types/rk";
|
||||
|
||||
|
||||
interface Props {
|
||||
groups: Group[],
|
||||
onSelect?: (id:Group)=>void
|
||||
}
|
||||
|
||||
export default function GroupSelect({ groups,onSelect }: Props) {
|
||||
|
||||
const handleSelect = (id:Group)=>{
|
||||
if(onSelect) onSelect(id);
|
||||
}
|
||||
return (
|
||||
<div className="">
|
||||
<div className="flex flex-col m-4 pt-4 overflow-y-scroll border h-150">
|
||||
{groups.map((group) => (
|
||||
|
||||
<div className="flex hover:bg-sky-100 h-8 items-center" onClick={()=>handleSelect(group)} key={group.id}>
|
||||
<div className="ps-4 ">{`${group.nr} ${group.name}`}</div>
|
||||
</div>))}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"use client"
|
||||
|
||||
import { Group } from "@/types/rk";
|
||||
import GroupSelect from "./groupSelect";
|
||||
import { useEffect, useState } from "react";
|
||||
import GroupViewItem from "./group_ViewItem";
|
||||
import GroupFilter from "./group_Filter";
|
||||
import { GroupEdit } from "./group_Edit";
|
||||
|
||||
|
||||
interface Props {
|
||||
groups: Group[],
|
||||
}
|
||||
|
||||
export default function GroupView({ groups }: Props) {
|
||||
|
||||
const [selectedItem, setSelectedItem] = useState<Group | undefined>();
|
||||
const [groupFilterd, setGroupFilterd] = useState<Group[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setGroupFilterd([...groups]);
|
||||
if(selectedItem){
|
||||
const updatedGroup = groups.find((g)=>g.id==selectedItem.id);
|
||||
if(updatedGroup) setSelectedItem(()=>updatedGroup);
|
||||
|
||||
}
|
||||
}, [groups])
|
||||
|
||||
const handlerOnChangeFilter = (groups: Group[]) => {
|
||||
setGroupFilterd([...groups]);
|
||||
}
|
||||
|
||||
const handleSelect = (item: Group) => {
|
||||
console.log(item);
|
||||
setSelectedItem(item);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="m-4 p-4 border-1 border-gray-100 w-256">
|
||||
<GroupFilter groups={groups} onChange={handlerOnChangeFilter}></GroupFilter>
|
||||
|
||||
</div>
|
||||
<div className="m-4 grid grid-cols-[300_2fr]">
|
||||
{/** Spalte 1 Auswahl Gruppe */}
|
||||
<div>
|
||||
<GroupSelect onSelect={handleSelect} groups={groupFilterd}></GroupSelect>
|
||||
</div>
|
||||
|
||||
{/** Spalte 2 Anzeige Gruppe details */}
|
||||
<div className="flex flex-col w-256 h-10">
|
||||
{selectedItem && <div >
|
||||
<div>edit</div>
|
||||
<GroupViewItem group={selectedItem} ></GroupViewItem>
|
||||
{<GroupEdit debug={true} initData={selectedItem} ></GroupEdit>}
|
||||
</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import { Anlage, emptyGroup, Group, GroupCreate } from "@/types/rk";
|
||||
import { groupCreate, groupUpdate } from "@/actions/rk/api-groups";
|
||||
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage:Anlage
|
||||
initData?: Group
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
export const GroupEdit = ({anlage, initData, debug }: Params) => {
|
||||
|
||||
const { control, register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<GroupCreate>({ defaultValues: emptyGroup, })
|
||||
|
||||
|
||||
const [modeUpdate, setModeUpdate] = useState(false);
|
||||
const [id, setId] = useState<string | undefined>();
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (initData) {
|
||||
const { id, ...rest } = initData;
|
||||
setId(id);
|
||||
setModeUpdate(true);
|
||||
reset({ ...rest })
|
||||
}else{
|
||||
reset({ ...emptyGroup,anlageId:anlage.id })
|
||||
|
||||
}
|
||||
}, [initData]);
|
||||
|
||||
const onSubmit = async (data: GroupCreate) => {
|
||||
setError(undefined);
|
||||
//const { name, isConsumable, description } = data;
|
||||
if (modeUpdate) {
|
||||
if (id) {
|
||||
groupUpdate(id, data);
|
||||
} else {
|
||||
setError('Etwas ist falsch, keine ID');
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log('create',data)
|
||||
groupCreate(data);
|
||||
}
|
||||
}
|
||||
const options = watch("options")
|
||||
|
||||
return (
|
||||
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
|
||||
<div className="border-1 p-4">
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
|
||||
<div className="grid grid-cols-[60px_1fr] gap-2">
|
||||
<InputTextR label="Nr" {...register("nr", { required: "Pflichtfeld" })} error={errors.nr?.message} />
|
||||
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
|
||||
</div>
|
||||
<InputTextR label="Anzeige Name" {...register("displayName", {})} error={errors.displayName?.message} />
|
||||
<InputTextR label="Info" {...register("info", { required: "Pflichtfeld" })} error={errors.info?.message} />
|
||||
<InputTextR label="Ort" {...register("ort", { required: "Pflichtfeld" })} error={errors.ort?.message} />
|
||||
<InputTextR label="Type" {...register("type", { required: "Pflichtfeld" })} error={errors.type?.message} />
|
||||
|
||||
<div>
|
||||
{error && <div>{error}</div>}
|
||||
{errors.name && <div>{errors.name.message}</div>}
|
||||
</div>
|
||||
|
||||
<div className="p-2 mt-4 ">
|
||||
<div className="font-semibold">Optionen</div>
|
||||
<div className="border-1 rounded border-gray-200 p-4 ">
|
||||
{options &&
|
||||
Object.entries(options).map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-[100px_200px] pt-1">
|
||||
|
||||
<label className="font-semibold">{key}:</label>
|
||||
|
||||
{typeof value === "boolean" ? (
|
||||
<div className="flex flex-start ">
|
||||
<input
|
||||
className=""
|
||||
type="checkbox"
|
||||
{...register(`options.${key}` as const)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
) : (
|
||||
<div className="">
|
||||
<InputTextR {...register(`options.${key}` as const)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
|
||||
</form>
|
||||
</div >
|
||||
|
||||
{debug &&
|
||||
<div>
|
||||
<div>{watch("name")}</div>
|
||||
<pre>touched:{getFieldState("displayName").isTouched ? 'true' : 'false'}</pre>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>
|
||||
}
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
<div className="mt-4 mb-4 p-2 border-1 border-gray-200 relative ">
|
||||
<div className="absolute -top-2 left-2 bg-white ps-1 pe-1 text-xs">Optionen</div>
|
||||
<InputCheckboxR label="Konsumierbar" {...register("isConsumable")} error={errors.isConsumable?.message} />
|
||||
</div>
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,36 @@
|
||||
"use client"
|
||||
|
||||
import { Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
groups: Group[],
|
||||
onChange: (filterdGroups:Group[])=>void
|
||||
}
|
||||
|
||||
export default function GroupFilter({ groups,onChange }: Props) {
|
||||
|
||||
const [txt,setText] = useState('');
|
||||
|
||||
useEffect(()=>{
|
||||
const filterd = groups.filter((group)=>{
|
||||
let found = false;
|
||||
if(group.name.includes(txt)) found = true;
|
||||
if(group.nr.includes(txt)) found = true;
|
||||
return found
|
||||
})
|
||||
onChange(filterd);
|
||||
},[txt,groups])
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
<div className="text-sm font-semibold">Suche</div>
|
||||
<input onChange={(e)=>setText(e.target.value)} value={txt} className="w-96 border rounded p-2 border-gray-300" />
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client"
|
||||
|
||||
import { Group } from "@/types/rk";
|
||||
import GroupListItem from "./group_List_Item";
|
||||
|
||||
|
||||
interface Props {
|
||||
groups: Group[]
|
||||
}
|
||||
|
||||
export default function GroupList({ groups }: Props) {
|
||||
|
||||
return (
|
||||
<div className="m-16 ms-32 w-256 bg-gray-0 border-t-1 border-gray-100 shadow-xl">
|
||||
<div className="flex flex-col m-4 gap-2">
|
||||
<div className="grid grid-cols-[200px_200px_250px_1fr] border-b-1 border-gray-800 ps-4 pb-1 pt-1 text-lg font-bold" >
|
||||
<div>ID</div>
|
||||
<div>Name</div>
|
||||
<div>Optionen</div>
|
||||
<div>Aggregate</div>
|
||||
</div>
|
||||
{groups.map((group) => (
|
||||
|
||||
|
||||
<div className="grid grid-cols-[200px_200px_250px_1fr] border-b-1 min-h-16 border-gray-200 ps-4 pb-4 pt-2" key={group.id}>
|
||||
<GroupListItem item={group}></GroupListItem>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"use client"
|
||||
|
||||
import { Group } from "@/types/rk";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
item: Group
|
||||
}
|
||||
|
||||
export default function GroupListItem({ item }: Props) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{item.nr}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{item.name}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{item.options &&
|
||||
Object.entries(item.options).map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-2 gap-8">
|
||||
<div >{key}</div>
|
||||
<div>
|
||||
{typeof value === "boolean" ? (value ? "Ja" : "Nein") : value}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="">
|
||||
{item.elements && <div>
|
||||
{item.elements.map((element) => (
|
||||
<div key={element.id} className="grid grid-cols-2 gap-8">
|
||||
{false && element.prefix && <div>
|
||||
{element.prefix}
|
||||
</div>}
|
||||
{element.name}
|
||||
<div>
|
||||
{element.excelNr}
|
||||
</div>
|
||||
|
||||
</div>))}
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
"use client"
|
||||
|
||||
import { Group, Peripherie, PeripherieFilterOptionen } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import PeripherieListView from "../peripherie/peripherieListView";
|
||||
import { PeripherieFindApi } from "@/actions/rk/api-peripherie";
|
||||
import { api_GroupAll, api_groupDelete } from "@/actions/rk/api-groups";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
group: Group
|
||||
}
|
||||
|
||||
export default function GroupViewItem({ group }: Props) {
|
||||
|
||||
const [showEA_Group, setShowEA_Group] = useState(false);
|
||||
const [showEA_Element, setShowEA_Element] = useState(false);
|
||||
const [showEA_Diff, setShowEA_Diff] = useState(false);
|
||||
const [peripheries, setPeripheries] = useState<Peripherie[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setPeripheries([]);
|
||||
setShowEA_Group(false);
|
||||
setShowEA_Element(false);
|
||||
setShowEA_Diff(false);
|
||||
|
||||
}, [group])
|
||||
|
||||
const handlerShow_Group = () => {
|
||||
const newMode = !showEA_Group;
|
||||
setShowEA_Group(newMode)
|
||||
if (newMode) {
|
||||
let filter: PeripherieFilterOptionen = {
|
||||
groupId: group.id
|
||||
}
|
||||
PeripherieFindApi(filter).then(setPeripheries);
|
||||
|
||||
} else {
|
||||
setPeripheries([])
|
||||
};
|
||||
|
||||
};
|
||||
const handlerShow_Element = () => {
|
||||
setShowEA_Element((pre) => !pre)
|
||||
//if (filterElementId) filter['elementId'] = filterElementId;
|
||||
if (showEA_Group) {
|
||||
let filter: PeripherieFilterOptionen = {
|
||||
// elementId: group..id
|
||||
};
|
||||
|
||||
// PeripherieFindApi(filter).then(setPeripheries);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
const handlerShow_Diff = () => {
|
||||
setShowEA_Diff((pre) => !pre)
|
||||
|
||||
};
|
||||
|
||||
const handlerDelete = () => {
|
||||
if(group.id) api_groupDelete(group.id);
|
||||
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className="ms-2">
|
||||
<div className="flex gap-2 text-lg font-semibold bg-gray-200 ps-2">
|
||||
<div>Gruppe :</div>
|
||||
<div>{group.nr}</div>
|
||||
<div>{group.name}</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<div>Anzeige Name :{group.displayName}</div>
|
||||
<div>Info: {group.info}</div>
|
||||
<div>Ort: {group.ort}</div>
|
||||
<div>Type {group.type}</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-2 ps-2">
|
||||
<div className="text-lg font-semibold">Eigenschaften</div>
|
||||
{group.options &&
|
||||
Object.entries(group.options).map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-2 gap-8">
|
||||
<div >{key}</div>
|
||||
<div>
|
||||
{typeof value === "boolean" ? (value ? "Ja" : "Nein") : value}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-2 ps-2">
|
||||
<div className="text-lg font-semibold">Elemente</div>
|
||||
|
||||
{group.elements && <div>
|
||||
{group.elements.map((element) => (
|
||||
<div key={element.id} className="grid grid-cols-2 gap-8">
|
||||
{false && element.prefix &&
|
||||
<div> {element.prefix}</div>
|
||||
}
|
||||
<div>{element.name}</div>
|
||||
<div>{element.excelNr}</div>
|
||||
|
||||
</div>))}
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<button className="bg-gray-300 rounded-xl p-2 hover:bg-gray-500 me-2" onClick={() => handlerShow_Group()}>Show EA Group</button>
|
||||
<button className="bg-gray-300 rounded-xl p-2 hover:bg-gray-500 me-2" onClick={() => handlerShow_Element()}>Show EA Elements</button>
|
||||
<button className="bg-red-300 rounded-xl p-2 hover:bg-gray-500 me-2" onClick={() => handlerDelete()}>Löschen</button>
|
||||
|
||||
<button className="bg-gray-300 rounded-xl p-2 hover:bg-gray-500 me-2">Show EA Diffrences to Excel</button>
|
||||
</div>
|
||||
{showEA_Group && <div>
|
||||
Ein-Ausgänge
|
||||
</div>}
|
||||
{showEA_Group && <div className="border-1">
|
||||
|
||||
</div>}
|
||||
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
import { useFieldArray, useForm } from "react-hook-form"
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import { InputCheckboxR } from "@/components/ui/inputCheckboxR";
|
||||
import { Anlage, emptyGroup, Group, GroupCreate } from "@/types/rk";
|
||||
import { groupCreate, groupUpdate } from "@/actions/rk/api-groups";
|
||||
import { api_anlage_getSelected } from "@/actions/rk/api-anlage";
|
||||
import { useFocusManager } from "@/components/ui/editable/useFocusManager";
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage:Anlage
|
||||
defaultGroup?: Group
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
export const GroupBulkEdit = ({anlage, defaultGroup, debug }: Params) => {
|
||||
|
||||
const { control, register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<GroupCreate>({ defaultValues: emptyGroup, })
|
||||
|
||||
|
||||
|
||||
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if(defaultGroup){
|
||||
const {id,elements,options,...defaults} = defaultGroup;
|
||||
reset({ ...emptyGroup,...defaults })
|
||||
}
|
||||
|
||||
|
||||
}, []);
|
||||
|
||||
const onSubmit = async (data: GroupCreate) => {
|
||||
setError(undefined);
|
||||
groupCreate(data);
|
||||
|
||||
}
|
||||
const options = watch("options")
|
||||
|
||||
const focus = useFocusManager();
|
||||
|
||||
return (
|
||||
<div className="w-120 flex flex-col p-4 pt-10 ps-10" >
|
||||
|
||||
<div className="border-1 p-4">
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
|
||||
<div className="grid grid-cols-[60px_1fr] gap-2">
|
||||
<InputTextR label="Nr" {...register("nr", { required: "Pflichtfeld" })} error={errors.nr?.message} />
|
||||
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
|
||||
</div>
|
||||
<InputTextR label="Anzeige Name" {...register("displayName", {})} error={errors.displayName?.message} />
|
||||
<InputTextR label="Info" {...register("info", { required: "Pflichtfeld" })} error={errors.info?.message} />
|
||||
<InputTextR label="Ort" {...register("ort", { required: "Pflichtfeld" })} error={errors.ort?.message} />
|
||||
<InputTextR label="Type" {...register("type", { required: "Pflichtfeld" })} error={errors.type?.message} />
|
||||
|
||||
<div>
|
||||
{error && <div>{error}</div>}
|
||||
{errors.name && <div>{errors.name.message}</div>}
|
||||
</div>
|
||||
|
||||
<div className="p-2 mt-4 ">
|
||||
<div className="font-semibold">Optionen</div>
|
||||
<div className="border-1 rounded border-gray-200 p-4 ">
|
||||
{options &&
|
||||
Object.entries(options).map(([key, value]) => (
|
||||
<div key={key} className="grid grid-cols-[100px_200px] pt-1">
|
||||
|
||||
<label className="font-semibold">{key}:</label>
|
||||
|
||||
{typeof value === "boolean" ? (
|
||||
<div className="flex flex-start ">
|
||||
<input
|
||||
className=""
|
||||
type="checkbox"
|
||||
{...register(`options.${key}` as const)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
) : (
|
||||
<div className="">
|
||||
<InputTextR {...register(`options.${key}` as const)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
|
||||
|
||||
</form>
|
||||
</div >
|
||||
|
||||
{debug &&
|
||||
<div>
|
||||
<div>{watch("name")}</div>
|
||||
<pre>touched:{getFieldState("displayName").isTouched ? 'true' : 'false'}</pre>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>
|
||||
}
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
<div className="mt-4 mb-4 p-2 border-1 border-gray-200 relative ">
|
||||
<div className="absolute -top-2 left-2 bg-white ps-1 pe-1 text-xs">Optionen</div>
|
||||
<InputCheckboxR label="Konsumierbar" {...register("isConsumable")} error={errors.isConsumable?.message} />
|
||||
</div>
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,50 @@
|
||||
"use client"
|
||||
|
||||
import { useEditableList } from "@/components/ui/editable-list/useEditableList";
|
||||
import { Group } from "@/types/rk";
|
||||
import { useRef } from "react";
|
||||
import { GroupEditRow } from "./group_edit_row";
|
||||
|
||||
|
||||
interface Props {
|
||||
data: Group[],
|
||||
}
|
||||
|
||||
|
||||
export const GroupEditList = ({ data }: Props) => {
|
||||
|
||||
|
||||
const listRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const list = useEditableList({
|
||||
ref: listRef, data: data, onSave: async (group) => {
|
||||
|
||||
//await anlageApiUpdate(anlage.id, { anlageNr: anlage.anlageNr, name: anlage.name });
|
||||
console.log(group)
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col w-400 p-4 border-1 border-gray-200 focus:outline-none focus:ring-1 focus:ring-sky-100 rounded focus:border-1 "
|
||||
ref={listRef}
|
||||
tabIndex={0}
|
||||
onKeyDown={list.onKeyDown}
|
||||
>
|
||||
|
||||
|
||||
{data.map((a, index) => (
|
||||
|
||||
<GroupEditRow
|
||||
key={a.id}
|
||||
data={a}
|
||||
options={{ col1_w: 250, col2_w: 350,col3_w: 350, col: true }}
|
||||
selected={list.isItemSelected(index)}
|
||||
editing={list.isItemEditing(index)}
|
||||
onClick={() => list.select(index)}
|
||||
onSave={list.save}
|
||||
onCancel={list.cancelEdit}
|
||||
/>
|
||||
|
||||
))}
|
||||
</div>)
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import { EditableRow } from "@/components/ui/editable/EditableRow";
|
||||
import { NumberCell } from "@/components/ui/editable/NumberCell";
|
||||
import { TextCell } from "@/components/ui/editable/TextCell";
|
||||
import { useFocusManager } from "@/components/ui/editable/useFocusManager";
|
||||
import { emptyGroup, Group } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
data: Group,
|
||||
|
||||
editing: boolean,
|
||||
selected: boolean,
|
||||
onSave: (value: Group) => void;
|
||||
onCancel: () => void;
|
||||
onClick: () => void;
|
||||
options?: {
|
||||
col1_w?: number
|
||||
col2_w?: number,
|
||||
col3_w?: number,
|
||||
col4_w?: number,
|
||||
col5_w?: number,
|
||||
col6_w?: number,
|
||||
col7_w?: number,
|
||||
full?: boolean,
|
||||
col?: boolean,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const GroupEditRow = ({ data, selected, editing, options, onSave, onCancel }: Props) => {
|
||||
const [id, setId] = useState('');
|
||||
const [editData, setEditData] = useState(emptyGroup);
|
||||
|
||||
const focus = useFocusManager();
|
||||
|
||||
const col1w = options?.col1_w ? options?.col1_w : 100
|
||||
const col2w = options?.col2_w ? options?.col2_w : 100
|
||||
const col3w = options?.col3_w ? options?.col3_w : 100
|
||||
const col4w = options?.col4_w ? options?.col4_w : 100
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const { id, ...anlageData } = data;
|
||||
setEditData(() => ({ ...anlageData }));
|
||||
setId(() => id);
|
||||
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editing) {
|
||||
focus.focusFirst();
|
||||
}
|
||||
}, [editing]);
|
||||
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
|
||||
switch (e.key) {
|
||||
|
||||
case "Enter":
|
||||
e.preventDefault();
|
||||
onSave({ ...data, ...editData })
|
||||
break;
|
||||
|
||||
case "Escape":
|
||||
e.preventDefault();
|
||||
onCancel();
|
||||
break;
|
||||
|
||||
case "Tab":
|
||||
e.preventDefault();
|
||||
|
||||
if (e.shiftKey) focus.focusPrevious(e.currentTarget);
|
||||
else focus.focusNext(e.currentTarget);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<EditableRow selected={selected} columns={`${col1w}px ${col2w}px ${col3w}px ${col4w}px`}>
|
||||
|
||||
<NumberCell
|
||||
ref={focus.register(0)}
|
||||
editing={editing}
|
||||
value={editData.nr.toString()}
|
||||
onChange={(value) => setEditData((o) => ({ ...o, nr: value }))}
|
||||
onKey={handleKeyDown}
|
||||
/>
|
||||
|
||||
<TextCell
|
||||
ref={focus.register(1)}
|
||||
editing={editing}
|
||||
value={editData.name}
|
||||
onChange={(value) => setEditData((o) => ({ ...o, name: value }))}
|
||||
onKey={handleKeyDown}
|
||||
/>
|
||||
|
||||
<TextCell
|
||||
ref={focus.register(2)}
|
||||
editing={editing}
|
||||
value={editData.funcTxt ? editData.funcTxt : '' }
|
||||
onChange={(value) => setEditData((o) => ({ ...o, funcTxt: value }))}
|
||||
onKey={handleKeyDown}
|
||||
/>
|
||||
|
||||
<TextCell
|
||||
ref={focus.register(3)}
|
||||
editing={editing}
|
||||
value={editData.info ? editData.info : '' }
|
||||
onChange={(value) => setEditData((o) => ({ ...o, info: value }))}
|
||||
onKey={handleKeyDown}
|
||||
/>
|
||||
|
||||
</EditableRow>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
"use client"
|
||||
|
||||
|
||||
|
||||
import { LogNote } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import LogNoteListItem from "./logNoteListItem";
|
||||
|
||||
|
||||
interface Props {
|
||||
notes: LogNote[],
|
||||
}
|
||||
|
||||
export default function LogNoteList({ notes }: Props) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
{notes.map((item)=><LogNoteListItem note={item} key={item.id}></LogNoteListItem>)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
|
||||
|
||||
import { LogNote } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
note: LogNote,
|
||||
}
|
||||
|
||||
export default function LogNoteListItem({ note }: Props) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="m-4 grid grid-cols-[300_2fr]">
|
||||
{/** Spalte 1 Topic */}
|
||||
<div>
|
||||
{note.topic}
|
||||
</div>
|
||||
<div>
|
||||
{note.status}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
|
||||
|
||||
|
||||
import { LogNote } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import LogNoteList from "./logNoteList";
|
||||
|
||||
|
||||
interface Props {
|
||||
notes: LogNote[],
|
||||
}
|
||||
|
||||
export default function LogNoteView({ notes }: Props) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="m-4 p-4 border-1 border-gray-100 w-256">
|
||||
<LogNoteList notes={notes}></LogNoteList>
|
||||
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
"use client"
|
||||
|
||||
import { Group, GroupSubElement, Peripherie, PeripherieFilterOptionen, PeripherieUpdate } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { api_peripherieUpdate, PeripherieFindApi } from "@/actions/rk/api-peripherie";
|
||||
import { useStringInput } from "@/hooks/useStringInput";
|
||||
|
||||
|
||||
interface Props {
|
||||
peripheries: Peripherie
|
||||
groups: Group[]
|
||||
|
||||
}
|
||||
|
||||
export default function PeripherieListInput({ peripheries, groups }: Props) {
|
||||
|
||||
|
||||
|
||||
const [filteredGroups, setFilteredGroups] = useState<Group[]>([]);
|
||||
|
||||
const nameInput = useStringInput({ value: peripheries.name, fallback: "", onCommit: (value) => api_peripherieUpdate(peripheries.id, { name: value }) });
|
||||
const functionTxtInput = useStringInput({ value: peripheries.functionTxt, fallback: "", onCommit: (value) => api_peripherieUpdate(peripheries.id, { functionTxt: value }) });
|
||||
const textInput = useStringInput({ value: peripheries.text, fallback: "", onCommit: (value) => api_peripherieUpdate(peripheries.id, { text: value }) });
|
||||
|
||||
useEffect(() => {
|
||||
setFilteredGroups(groups);
|
||||
}, [groups])
|
||||
|
||||
const handleChangeGroup = (id: string, value: string) => {
|
||||
api_peripherieUpdate(id, { groupId: value })
|
||||
console.log(id, { groupId: value });
|
||||
}
|
||||
//if(peripheries.excelData?.functionText === peripheries.text) return < ></>
|
||||
return (
|
||||
|
||||
|
||||
<div className="grid grid-cols-[300px_250px_250px_350px_200px_600px_10px_600px]">
|
||||
<div>
|
||||
|
||||
<select onChange={(e) => handleChangeGroup(peripheries.id, e.target.value)} value={peripheries.group?.id}>
|
||||
{
|
||||
filteredGroups.map((group) => <option key={group.id} value={group.id} >{group.nr}_{group.name}</option>)
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
{peripheries.element?.name}
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" {...nameInput} name="name" />
|
||||
</div>
|
||||
<div className="border-1 flex w-full">
|
||||
<input type="text" {...functionTxtInput} name="functionTxt" />
|
||||
|
||||
</div>
|
||||
<div>
|
||||
{peripheries.adrType}{peripheries.adrByte}.{peripheries.adrBit}
|
||||
</div>
|
||||
|
||||
<div className="border-1 flex">
|
||||
<input type="text" {...textInput} name="text" className="w-full" />
|
||||
</div>
|
||||
|
||||
<div className="bg-gray-100"></div>
|
||||
|
||||
<div>
|
||||
{peripheries.excelData?.functionText}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"use client"
|
||||
|
||||
import { Element, Group, GroupSubElement, Peripherie, PeripherieFilterOptionen } from "@/types/rk";
|
||||
import { useEffect, useState } from "react";
|
||||
import { api_peripherieUpdate, PeripherieFindApi } from "@/actions/rk/api-peripherie";
|
||||
import PeripherieListInput from "./peripherieListInput";
|
||||
|
||||
|
||||
interface Props {
|
||||
peripheries:Peripherie[]
|
||||
groups:Group[]
|
||||
elemente:Element[]
|
||||
}
|
||||
|
||||
export default function PeripherieListView({peripheries, groups }: Props) {
|
||||
|
||||
|
||||
|
||||
const [filteredGroups,setFilteredGroups] = useState<Group[]>([]);
|
||||
|
||||
useEffect(()=>{
|
||||
setFilteredGroups(groups);
|
||||
},[groups])
|
||||
|
||||
const handleChangeGroup = (id:string,value:string)=>{
|
||||
api_peripherieUpdate(id,{groupId:value})
|
||||
console.log(id,{groupId:value});
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
|
||||
{peripheries.map((p) => (<div key={p.id} className="grid grid-cols-[100px_150px_100px_150px_100px_200px_200px_250px_250px_200px_400px]">
|
||||
<PeripherieListInput peripheries={p} groups={groups} key={p.id} />
|
||||
|
||||
|
||||
</div>))}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
"use client";
|
||||
|
||||
import { Anlage } from "@/types/rk";
|
||||
import Modal from "@/components/ui/Modal";
|
||||
import { GroupResponse } from "@/types/anlagen/groups";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useGroups } from "@/hooks/rk2/useGroups";
|
||||
import { UnitResponse } from "@/types/anlagen/units";
|
||||
import { useUnit } from "@/hooks/rk2/useUnit";
|
||||
import { ComponentResponse } from "@/types/anlagen/components";
|
||||
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage?: Anlage,
|
||||
groups: GroupResponse[],
|
||||
units: UnitResponse[]
|
||||
}
|
||||
|
||||
export const AusgabeUnitInfo = ({ anlage, groups, units }: Params) => {
|
||||
|
||||
const {getPathToRoot} = useGroups({groups})
|
||||
|
||||
const getUnitInfo = (unit:UnitResponse) =>{
|
||||
let groupId = unit.groupId;
|
||||
|
||||
let uGroupPath = getPathToRoot(groupId);
|
||||
|
||||
let unitName = [unit.prefix,unit.bmk,unit.name]
|
||||
if(unit.postfix) unitName.push(unit.postfix)
|
||||
|
||||
let typ = unit.type;
|
||||
|
||||
//--- Components
|
||||
let txt = "";
|
||||
txt = uGroupPath.map((g)=>g.name).join('\t')+'\t';
|
||||
txt += "\t" + unitName.join('_')+'\t';
|
||||
//txt += "\tTyp:" + typ+'\n';
|
||||
|
||||
//txt += "\t\tKomponenten:"+'\n'
|
||||
unit.components.forEach((comp)=>{
|
||||
let cName:string[] = []
|
||||
comp.prefix && cName.push(comp.prefix);
|
||||
comp.name && cName.push(comp.name + (comp.index ? comp.index.toString():""));
|
||||
//comp.index && cName.push();
|
||||
comp.postfix && cName.push(comp.postfix);
|
||||
//,comp.name,comp.index,comp.postfix
|
||||
|
||||
txt += '\t' + cName.join('_')+''
|
||||
})
|
||||
|
||||
return txt;
|
||||
|
||||
}
|
||||
|
||||
const getComponentData = (comp:ComponentResponse) =>{
|
||||
const name = [comp.prefix, comp.name,comp.index, comp.postfix]
|
||||
}
|
||||
|
||||
const getText = ()=>{
|
||||
let txt = ""
|
||||
|
||||
units.forEach((u)=> txt += getUnitInfo(u)+`\n`)
|
||||
return txt;
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<textarea className="w-full h-100" value={getText()} />
|
||||
|
||||
|
||||
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { Anlage } from "@/types/rk";
|
||||
import { GroupSelect } from "./groupSelect";
|
||||
import { GroupForm } from "./groupForm";
|
||||
import Modal from "@/components/ui/Modal";
|
||||
import { GroupResponse } from "@/types/anlagen/groups";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useGroups } from "@/hooks/rk2/useGroups";
|
||||
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage: Anlage,
|
||||
groups: GroupResponse[],
|
||||
selectedGroup?: GroupResponse
|
||||
}
|
||||
|
||||
export const GroupEdit = ({ anlage, groups, selectedGroup }: Params) => {
|
||||
|
||||
|
||||
const { getGroupById } = useGroups({ groups });
|
||||
const [showSelectParentGroup, setShowSelectParentGroup] = useState(false);
|
||||
const [selectedParentGroup, setSelectedParentGroup] = useState<GroupResponse>();
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedGroup && selectedGroup.parentId) {
|
||||
const pGroup = getGroupById(selectedGroup.parentId)
|
||||
setSelectedParentGroup(() => pGroup)
|
||||
}
|
||||
}, [selectedGroup])
|
||||
|
||||
|
||||
const handlerParentSelect = (group: GroupResponse) => {
|
||||
if (selectedGroup && selectedGroup.id == group.id) {
|
||||
setShowSelectParentGroup(false);
|
||||
return;
|
||||
}
|
||||
setSelectedParentGroup(() => group);
|
||||
setShowSelectParentGroup(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="" >
|
||||
|
||||
<GroupForm
|
||||
anlage={anlage}
|
||||
groupIntial={selectedGroup}
|
||||
parentGroup={selectedParentGroup}
|
||||
onDisplaySelectParent={() => setShowSelectParentGroup(true)}
|
||||
onResetParent={() => setSelectedParentGroup(() => undefined)}
|
||||
/>
|
||||
{showSelectParentGroup &&
|
||||
<Modal onClose={() => setShowSelectParentGroup(false)} >
|
||||
<GroupSelect groups={groups} onSelect={handlerParentSelect} />
|
||||
</Modal>
|
||||
}
|
||||
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import Toast from "@/components/ui/Toast";
|
||||
import { GroupCreate, GroupResponse } from "@/types/anlagen/groups";
|
||||
import { useGroup } from "@/hooks/rk2/useGroup";
|
||||
import { Anlage } from "@/types/rk";
|
||||
import { api_groups_create, api_groups_update } from "@/actions/rk2/api-groups";
|
||||
import MonButton from "@/components/ui/MonBotton";
|
||||
import { GroupSelect } from "./groupSelect";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
|
||||
|
||||
interface Params {
|
||||
anlage: Anlage,
|
||||
groupIntial?: GroupResponse,
|
||||
parentGroup?: GroupResponse,
|
||||
onDisplaySelectParent?: () => void,
|
||||
onResetParent: () => void
|
||||
|
||||
}
|
||||
|
||||
export const GroupForm = ({ anlage, groupIntial, onDisplaySelectParent, parentGroup, onResetParent }: Params) => {
|
||||
const router = useRouter();
|
||||
const { emptyGroup } = useGroup({ group: groupIntial });
|
||||
|
||||
const [id, setId] = useState<string>();
|
||||
const { register, handleSubmit, formState: { errors }, watch, reset, setValue } = useForm<GroupCreate>({ defaultValues: emptyGroup, })
|
||||
const [toast, setToast] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
|
||||
//--- GroupInit changed
|
||||
useEffect(() => {
|
||||
|
||||
if (groupIntial) {
|
||||
const { id, ...rest } = groupIntial;
|
||||
setId(id);
|
||||
reset({ ...emptyGroup, ...rest })
|
||||
} else {
|
||||
reset({ ...emptyGroup })
|
||||
}
|
||||
}, [groupIntial]);
|
||||
|
||||
//--- Parent Group hat sich geändert
|
||||
useEffect(() => {
|
||||
parentGroup ? setValue("parentId", parentGroup.id) : setValue("parentId", undefined);
|
||||
}, [parentGroup])
|
||||
|
||||
const onSubmit = async (data: GroupCreate) => {
|
||||
|
||||
setError(undefined);
|
||||
|
||||
const { id: id1, ...sendData } = data; // Id entfernen!
|
||||
|
||||
let response = id ? await api_groups_update(id, sendData) : await api_groups_create(data);
|
||||
if (response.success) {
|
||||
reset({ ...emptyGroup, ...response.data })
|
||||
setId(response.data.id);
|
||||
setToast("Erfolgreich gespeichert!");
|
||||
router.back();
|
||||
} else {
|
||||
setToast("Fehler beim Speichern!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 " >
|
||||
<div className="relative inline-block">
|
||||
{toast && (
|
||||
<Toast
|
||||
message={toast}
|
||||
onClose={() => setToast(null)}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="">
|
||||
<div className="flex gap-8 border-1 border-gray-200 rounded-sm p-4 pt-8 shadow-md">
|
||||
|
||||
<section className="relative flex flex-col gap-1 border-1 border-gray-200 rounded-sm p-2 ">
|
||||
<div className="absolute -top-4 bg-gray-100 rounded-sm border-1 border-gray-200 w-20 ps-2 font-bold ">Gruppe</div>
|
||||
<InputTextR label="Name" {...register("name", { required: "Pflichtfeld" })} error={errors.name?.message} />
|
||||
<InputTextR label="Nr" {...register("nr")} error={errors.nr?.message} />
|
||||
<input type="hidden" {...register("parentId")} />
|
||||
</section>
|
||||
|
||||
<section className="flex flex-col gap-4 border-1 border-gray-200 rounded-sm p-2 ">
|
||||
{/* Eltern zuordnung */}
|
||||
<div className="">
|
||||
<div>Zuordnung </div>
|
||||
{parentGroup &&
|
||||
<div className="flex flex-row gap-2 pb-2 ">
|
||||
<div>Ändern</div>
|
||||
<div>{parentGroup.name}</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
{/* Eltern zuordnung ändern */}
|
||||
<div>
|
||||
<div className="flex flex-col gap-2 ps-8">
|
||||
<MonButton onClick={() => onResetParent()}>root</MonButton>
|
||||
<MonButton onClick={() => onDisplaySelectParent && onDisplaySelectParent()}>Auswahl</MonButton>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<div>
|
||||
{error && <div>{error}</div>}
|
||||
{errors.name && <div>{errors.name.message}</div>}
|
||||
</div>
|
||||
|
||||
|
||||
<div className="flex gap-4">
|
||||
<button type="submit" className="bg-blue-500 text-white p-2 rounded mt-2 hover:bg-blue-600">Speichern</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form >
|
||||
|
||||
{
|
||||
true &&
|
||||
<div>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>
|
||||
}
|
||||
</div >
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { useGroups } from "@/hooks/rk2/useGroups";
|
||||
import { GroupResponse } from "@/types/anlagen/groups";
|
||||
|
||||
interface Props {
|
||||
groups: GroupResponse[],
|
||||
groupId?: string,
|
||||
}
|
||||
|
||||
|
||||
export const GroupPath = ({ groups, groupId }: Props) => {
|
||||
const { getPathToRoot } = useGroups({ groups: groups })
|
||||
|
||||
return (
|
||||
<>
|
||||
{groupId ?
|
||||
<div>{getPathToRoot(groupId).map((g)=>g.name).join(".")}</div>:<div></div>
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client"
|
||||
import { useGroups } from "@/hooks/rk2/useGroups"
|
||||
import { useGroupTree } from "@/hooks/rk2/useGroupTree"
|
||||
import { GroupResponse } from "@/types/anlagen/groups"
|
||||
import { GroupTreeView } from "./groupTreeView"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
groups: GroupResponse[]
|
||||
onSelect: (group: GroupResponse) => void
|
||||
}
|
||||
|
||||
export function GroupSelect({ groups, onSelect }: Props) {
|
||||
|
||||
const { getGroupById, groupsExtended } = useGroups({ groups })
|
||||
const { tree, close, closeAll, isOpen, open, openAll, openGroups, toggle, isSelected, select, selectedGroupId } = useGroupTree(groups);
|
||||
const [modalClose,setModalClose] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedGroupId) {
|
||||
const group = getGroupById(selectedGroupId);
|
||||
if (group){
|
||||
onSelect(group)
|
||||
setModalClose(true)
|
||||
}
|
||||
}
|
||||
}, [selectedGroupId]);
|
||||
|
||||
const handelModalClose = ()=>{
|
||||
setModalClose(false);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
<div className="flex flex-col gap-8">
|
||||
<GroupTreeView isSelected={isSelected} select={select} nodes={tree} isOpen={isOpen} toggle={toggle} />
|
||||
</div>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
"use client"
|
||||
import { GroupTree } from "@/types/anlagen/groups"
|
||||
|
||||
interface GroupTreeViewProps {
|
||||
nodes: GroupTree[]
|
||||
isOpen: (id: string) => boolean
|
||||
toggle: (id: string) => void
|
||||
isSelected: (id: string) => boolean
|
||||
select: (id: string|undefined) => void
|
||||
}
|
||||
|
||||
export function GroupTreeView({ nodes, isOpen, toggle, select, isSelected }: GroupTreeViewProps) {
|
||||
return (
|
||||
<ul className="ps-6">
|
||||
{nodes.map((node) => {
|
||||
const id = node.group.id
|
||||
const hasChildren = node.childs.length > 0
|
||||
const open = isOpen(id)
|
||||
const selected = isSelected(id)
|
||||
|
||||
return (
|
||||
<li key={id}>
|
||||
<div
|
||||
onClick={() => select(id)}
|
||||
className={selected ? "bg-sky-100" : ""}
|
||||
>
|
||||
{hasChildren && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation()
|
||||
toggle(id)
|
||||
}}
|
||||
>
|
||||
{open ? "▼" : "▶"}
|
||||
</button>
|
||||
)}
|
||||
|
||||
<span>{node.group.name}</span>
|
||||
</div>
|
||||
|
||||
{open && hasChildren && (
|
||||
<GroupTreeView
|
||||
nodes={node.childs}
|
||||
isOpen={isOpen}
|
||||
toggle={toggle}
|
||||
isSelected={isSelected}
|
||||
select={select}
|
||||
/>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
"use client"
|
||||
|
||||
import { Sites } from "@/_config/sites"
|
||||
import { api_groups_delete } from "@/actions/rk2/api-groups"
|
||||
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { ListItem, ListItemAction } from "@/components/ui/list"
|
||||
import { GroupResponse } from "@/types/anlagen/groups"
|
||||
import { useRouter } from "next/navigation"
|
||||
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
group: GroupResponse,
|
||||
parent?: GroupResponse
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function GroupViewItem({ group, parent }: Props) {
|
||||
|
||||
let router = useRouter()
|
||||
|
||||
return (
|
||||
<ListItem key={group.id} size={"md"} >
|
||||
{parent ? <div className="w-20">
|
||||
{parent.name}
|
||||
</div> : <div className="w-20">root</div>}
|
||||
|
||||
<div className="w-30">
|
||||
{group.name}
|
||||
</div>
|
||||
<div className="w-30">
|
||||
{group.nr}
|
||||
</div>
|
||||
<ListItemAction>
|
||||
<Button variant={"secondary"} size={"xs"} onClick={()=>router.push(`${Sites.rk2.groups.edit.url}/${group.id}`)}>Ändern</Button>
|
||||
</ListItemAction>
|
||||
<ListItemAction>
|
||||
<Button variant={"danger"} onClick={()=>api_groups_delete(group.id)} size={"xs"}>Löschen</Button>
|
||||
</ListItemAction>
|
||||
</ListItem>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
"use client"
|
||||
import { useGroups } from "@/hooks/rk2/useGroups"
|
||||
import { useGroupTree } from "@/hooks/rk2/useGroupTree"
|
||||
import { GroupResponse } from "@/types/anlagen/groups"
|
||||
import { GroupTreeView } from "./groupTreeView"
|
||||
import { GroupViewItem } from "./groupViewItem"
|
||||
import { GroupForm } from "./groupForm"
|
||||
import { Anlage } from "@/types/rk"
|
||||
import Modal from "@/components/ui/Modal"
|
||||
import { GroupSelect } from "./groupSelect"
|
||||
import { GroupEdit } from "./groupEdit"
|
||||
import MonButton from "@/components/ui/MonBotton"
|
||||
import Link from "next/link"
|
||||
import { Sites } from "@/_config/sites"
|
||||
import { List, ListItem } from "@/components/ui/list"
|
||||
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
anlage: Anlage,
|
||||
groups: GroupResponse[]
|
||||
}
|
||||
|
||||
export function GroupViewList({ anlage, groups }: Props) {
|
||||
|
||||
const { getGroupById, groupsExtended } = useGroups({ groups })
|
||||
const { tree, close, closeAll, isOpen, open, openAll, openGroups, toggle, isSelected, select, selectedGroupId } = useGroupTree(groups);
|
||||
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-8">
|
||||
|
||||
{/* Gruppe neu anlegen */}
|
||||
<div>
|
||||
<Link href={Sites.rk2.groups.new.url}>{Sites.rk2.groups.new.name}</Link>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Grupplist flat */}
|
||||
<List size={"md"} className="w-130">
|
||||
|
||||
{groupsExtended.map((item) =>
|
||||
|
||||
<GroupViewItem key={item.group.id} group={item.group} parent={item.parent} />
|
||||
|
||||
|
||||
)}
|
||||
|
||||
</List>
|
||||
|
||||
|
||||
{/* Grupplist as Tree */}
|
||||
<div className="flex gap-8">
|
||||
<div className="ps-4">
|
||||
<div onClick={() => select(undefined)}>root</div>
|
||||
<GroupTreeView isSelected={isSelected} select={select} nodes={tree} isOpen={isOpen} toggle={toggle} />
|
||||
</div>
|
||||
<div className="">
|
||||
{selectedGroupId && <div>
|
||||
<GroupEdit anlage={anlage} groups={groups} selectedGroup={getGroupById(selectedGroupId)} />
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client"
|
||||
|
||||
import { api_signals, api_signals_create } from "@/actions/rk2/api-signals";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select } from "@/components/ui/select";
|
||||
import { useSignal } from "@/hooks/rk2/useSignal";
|
||||
import { ComponentResponse } from "@/types/anlagen/components"
|
||||
import { SignalCreate, SignalResponse, SignalType } from "@/types/anlagen/signals"
|
||||
import { useEffect } from "react";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
componente: ComponentResponse,
|
||||
initSignal?: SignalResponse,
|
||||
}
|
||||
|
||||
export function SignalForm({ componente, initSignal }: Props) {
|
||||
|
||||
const { setSignal, setValue, signalData, string_to_signalType } = useSignal({});
|
||||
|
||||
/*
|
||||
useEffect(() => {
|
||||
if (initSignal) setSignal({...initSignal,componentId:componente.id});
|
||||
}, [initSignal]);
|
||||
*/
|
||||
useEffect(() => {
|
||||
setValue("componentId",componente.id);
|
||||
//if (initSignal) setSignal({...initSignal,componentId:componente.id});
|
||||
// setSignal({componentId:componente.id});
|
||||
}, [componente]);
|
||||
|
||||
const handlerSave = ()=>{
|
||||
console.log("save")
|
||||
const saveData:SignalCreate ={
|
||||
componentId:signalData.componentId!,
|
||||
name:signalData.name!,
|
||||
description:signalData.description!,
|
||||
type:signalData.type!,
|
||||
}
|
||||
api_signals_create(saveData);
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ border: "1px solid #ccc", padding: 16, marginBottom: 16, borderRadius: 8, }} >
|
||||
|
||||
{/*---Form Data */}
|
||||
<div className="flex gap-4">
|
||||
<div className="w-30 flex flex-row">
|
||||
<Label size={"xs"} >Name</Label>
|
||||
<Input sizeVariant={"xs"} type="text" value={signalData.name} onChange={(e) => setValue('name', e.target.value)} />
|
||||
</div>
|
||||
<div className="w-50 flex flex-row">
|
||||
<Label className="w-30" size={"xs"} >Signal Typ</Label>
|
||||
<Select sizeVariant={"xs"} value={signalData.type} onChange={(e) => setValue('type', string_to_signalType(e.target.value))} >
|
||||
<option value={SignalType.ANALOG_INPUT}>{SignalType.ANALOG_INPUT}</option>
|
||||
<option value={SignalType.ANALOG_OUTPUT}>{SignalType.ANALOG_OUTPUT}</option>
|
||||
<option value={SignalType.DIGITAL_INPUT}>{SignalType.DIGITAL_INPUT}</option>
|
||||
<option value={SignalType.DIGITAL_OUTPUT}>{SignalType.DIGITAL_OUTPUT}</option>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="w-40 flex flex-row">
|
||||
<Label size={"xs"} >Beschreibung</Label>
|
||||
<Input sizeVariant={"xs"} type="text" value={signalData.description} onChange={(e) => setValue('description', e.target.value)} />
|
||||
</div>
|
||||
<Button onClick={()=>handlerSave()} >Save </Button>
|
||||
</div>
|
||||
|
||||
|
||||
{true &&
|
||||
<div>
|
||||
<pre>{JSON.stringify(signalData, null, 2)}</pre>
|
||||
|
||||
</div>
|
||||
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { DndContext, closestCenter } from "@dnd-kit/core";
|
||||
import {
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
useSortable,
|
||||
verticalListSortingStrategy,
|
||||
} from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import { useState } from "react";
|
||||
|
||||
interface Props{
|
||||
item:{id:string,name:string},
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export function SortableItem({ item,children }:Props) {
|
||||
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id:item.id });
|
||||
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
padding: "12px",
|
||||
border: "1px solid #ccc",
|
||||
marginBottom: "8px",
|
||||
background: "white",
|
||||
cursor: "grab",
|
||||
};
|
||||
|
||||
return (
|
||||
<div ref={setNodeRef} style={style} {...attributes} {...listeners}>
|
||||
{item.id} {item.name}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
"use client";
|
||||
|
||||
import { error } from "console";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
inValue: number,
|
||||
name: string,
|
||||
onChanged: (name: string, newValue: number) => void
|
||||
}
|
||||
|
||||
export function InputNumber({ inValue, name, onChanged }: Props) {
|
||||
|
||||
const [value, setValue] = useState('');
|
||||
const [lastValue, setLastValue] = useState(0);
|
||||
const [errorNumber, setErrorNumber] = useState(false);
|
||||
const inputRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
setValue("" + inValue);
|
||||
setLastValue(inValue);
|
||||
}, [inValue])
|
||||
|
||||
const handleValueChange = (newValue: string) => {
|
||||
const isNumber = /^-?\d+$/.test(newValue);
|
||||
if (isNumber) {
|
||||
setValue(newValue);
|
||||
|
||||
setErrorNumber(false);
|
||||
} else {
|
||||
setErrorNumber(true);
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = () => {
|
||||
|
||||
if (!errorNumber && value !== lastValue.toString()) {
|
||||
onChanged(name, Number(value));
|
||||
}
|
||||
else setValue("" + lastValue);
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||
console.log(e.key);
|
||||
if (e.key == 'ArrowUp' && !e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
setValue((old) => "" + (Number(old) + 1))
|
||||
}
|
||||
|
||||
if (e.key == 'ArrowUp' && e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
setValue((old) => "" + (Number(old) + 10))
|
||||
}
|
||||
|
||||
if (e.key == 'ArrowDown' && !e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
setValue((old) => "" + (Number(old) - 1))
|
||||
}
|
||||
|
||||
if (e.key == 'ArrowDown' && e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
setValue((old) => "" + (Number(old) - 10))
|
||||
}
|
||||
|
||||
if (e.key == 'Escape') {
|
||||
e.preventDefault();
|
||||
setValue((old) => "" + lastValue)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<input ref={inputRef} onKeyDown={(e) => handleKeyDown(e)} value={value} onBlur={() => handleSubmit()} onChange={(e) => handleValueChange(e.target.value)} />
|
||||
{errorNumber && <div>Error not a number</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
type ModalProps = {
|
||||
children: React.ReactNode;
|
||||
goBack?:boolean,
|
||||
doClose?:boolean,
|
||||
onClose?:()=>void
|
||||
};
|
||||
|
||||
export default function Modal({ children,goBack,onClose,doClose}: ModalProps) {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(()=>{
|
||||
if(doClose){
|
||||
handlerClose();
|
||||
}
|
||||
},[doClose])
|
||||
|
||||
useEffect(() => {
|
||||
function handleKeyDown(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") {
|
||||
handlerClose()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
};
|
||||
}, [router]);
|
||||
|
||||
const handlerClose = ()=>{
|
||||
if(goBack) router.back();
|
||||
if(onClose) onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/50"
|
||||
onMouseDown={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
handlerClose()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="relative rounded-lg bg-white p-6">
|
||||
<button
|
||||
onClick={() => handlerClose()}
|
||||
className="absolute right-4 top-4"
|
||||
aria-label="Schließen"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
|
||||
"use Client"
|
||||
import { ReactEventHandler, ReactNode } from "react";
|
||||
|
||||
|
||||
interface Props {
|
||||
onClick: () => void,
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export default function MonButton({ onClick, children }: Props) {
|
||||
|
||||
const handlerKey = (e:React.KeyboardEvent)=>{
|
||||
const code = e.key;
|
||||
if(code ==='Enter') onClick();
|
||||
}
|
||||
return (
|
||||
<div className="
|
||||
flex bg-gray-200
|
||||
rounded-lg w-40
|
||||
items-center
|
||||
justify-center
|
||||
shadow-sm
|
||||
cursor-pointer
|
||||
hover:bg-gray-600"
|
||||
|
||||
onKeyDown={(e)=>handlerKey(e)}
|
||||
onClick={ (e)=>onClick()}
|
||||
tabIndex={0}
|
||||
>
|
||||
|
||||
|
||||
{children}
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
type ToastProps = {
|
||||
message: string;
|
||||
duration?: number;
|
||||
position?: "top" | "bottom";
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
export default function Toast({
|
||||
message,
|
||||
duration = 3000,
|
||||
position = "bottom",
|
||||
onClose,
|
||||
}: ToastProps) {
|
||||
const [visible, setVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const showTimer = setTimeout(() => {
|
||||
setVisible(true);
|
||||
}, 10);
|
||||
|
||||
const hideTimer = setTimeout(() => {
|
||||
setVisible(false);
|
||||
}, duration);
|
||||
|
||||
const removeTimer = setTimeout(() => {
|
||||
onClose();
|
||||
}, duration + 300);
|
||||
|
||||
return () => {
|
||||
clearTimeout(showTimer);
|
||||
clearTimeout(hideTimer);
|
||||
clearTimeout(removeTimer);
|
||||
};
|
||||
}, [duration, onClose]);
|
||||
|
||||
const positionClasses =
|
||||
position === "top"
|
||||
? "bottom-full mb-2"
|
||||
: "top-full mt-2";
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`
|
||||
absolute left-1/2 z-50
|
||||
-translate-x-1/2
|
||||
${positionClasses}
|
||||
whitespace-nowrap
|
||||
rounded-lg bg-gray-900 px-4 py-2
|
||||
text-sm text-white shadow-lg
|
||||
transition-all duration-300 ease-out
|
||||
${
|
||||
visible
|
||||
? "translate-y-0 opacity-100"
|
||||
: position === "top"
|
||||
? "translate-y-2 opacity-0"
|
||||
: "-translate-y-2 opacity-0"
|
||||
}
|
||||
`}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const buttonVariants = cva(
|
||||
"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
primary: "bg-blue-600 text-white hover:bg-blue-700",
|
||||
secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300",
|
||||
danger: "bg-red-600 text-white hover:bg-red-700",
|
||||
select: "bg-gray-800 text-gray-300 hover:bg-gray-700",
|
||||
ghost: "hover:bg-gray-100",
|
||||
},
|
||||
|
||||
size: {
|
||||
xs: "h-6 px-3 text-xs",
|
||||
sm: "h-8 px-3 text-sm",
|
||||
md: "h-10 px-4 text-sm",
|
||||
lg: "h-12 px-6 text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "primary",
|
||||
size: "md",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
type ButtonProps =
|
||||
React.ComponentProps<"button"> &
|
||||
VariantProps<typeof buttonVariants> & {
|
||||
asChild?: boolean;
|
||||
};
|
||||
|
||||
function Button({
|
||||
className,
|
||||
variant,
|
||||
size,
|
||||
asChild = false,
|
||||
children,
|
||||
...props
|
||||
}: ButtonProps) {
|
||||
const Comp = asChild ? Slot : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(
|
||||
buttonVariants({
|
||||
variant,
|
||||
size,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Button,
|
||||
buttonVariants,
|
||||
};
|
||||
@@ -0,0 +1,158 @@
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const cardVariants = cva(
|
||||
"mb-2",//"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
primary: "border-1 flex flex-col rounded shadow border-gray-200",
|
||||
secondary: "bg-gray-200 text-gray-900 hover:bg-gray-300",
|
||||
danger: "bg-red-600 text-white hover:bg-red-700",
|
||||
select: "bg-gray-800 text-gray-300 hover:bg-gray-700",
|
||||
ghost: "hover:bg-gray-100",
|
||||
},
|
||||
|
||||
positons: {
|
||||
start:"items-start",
|
||||
center:"",
|
||||
end:"items-end"
|
||||
},
|
||||
|
||||
size: {
|
||||
xs: "h-6 px-3 text-xs",
|
||||
sm: "h-8 px-3 text-sm",
|
||||
md: "h-10 px-4 text-sm",
|
||||
lg: "h-12 px-6 text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "primary",
|
||||
positons:"center"
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const cardHeaderVariants = cva(
|
||||
"flex items-center justify-center w-full text-gray-800",//"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "border-b-1 bg-gray-200 border-gray-400 font-bold mb-2",
|
||||
danger: "border-b-1 bg-red-600 border-gray-400 font-bold text-white mb-2",
|
||||
ghost: "border-b-1 w-full border-gray-400 font-bold text-gray-400 mb-2",
|
||||
},
|
||||
|
||||
size: {
|
||||
xs: "h-6 px-3 text-xs",
|
||||
sm: "h-8 px-3 text-sm",
|
||||
md: "h-10 px-4 text-sm",
|
||||
lg: "h-12 px-6 text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
type CardProps =
|
||||
React.ComponentProps<"div"> &
|
||||
VariantProps<typeof cardVariants> & {
|
||||
asChild?: boolean;
|
||||
};
|
||||
|
||||
|
||||
function Card({ className, variant, size,positons, asChild = false, children, ...props }: CardProps) {
|
||||
const Comp = asChild ? Slot : "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(
|
||||
cardVariants({
|
||||
variant,
|
||||
size,
|
||||
positons
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
CardHeader
|
||||
*/
|
||||
|
||||
type CardHeaderProps =
|
||||
React.ComponentProps<"div"> &
|
||||
VariantProps<typeof cardHeaderVariants>
|
||||
|
||||
function CardHeader({ className, variant, size, ...props }: CardHeaderProps) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
cardHeaderVariants({
|
||||
variant,
|
||||
size,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
CardTitle
|
||||
*/
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"h3">) {
|
||||
return (
|
||||
<h3
|
||||
className={cn(
|
||||
"text-lg font-semibold",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
CardContent
|
||||
*/
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(className,"mt-2")}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardFooder({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(className,"pt-4")}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
export {
|
||||
Card,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
CardFooder,
|
||||
cardVariants,
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { useDroppable } from "@dnd-kit/core";
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function DroppableContainer({ id, children }: Props) {
|
||||
const { setNodeRef } = useDroppable({
|
||||
id,
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={setNodeRef}
|
||||
style={{
|
||||
border: "2px dashed gray",
|
||||
padding: 16,
|
||||
minHeight: 200
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { RefObject, useEffect, useState } from "react";
|
||||
|
||||
interface Props<T> {
|
||||
ref: RefObject<HTMLDivElement | null>;
|
||||
data: T[];
|
||||
|
||||
onSave: (item: T) => Promise<void> | void;
|
||||
|
||||
};
|
||||
|
||||
export function useEditableList<T>({ ref, data, onSave }: Props<T>) {
|
||||
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
const [editingIndex, setEditingIndex] = useState<number | null>(null);
|
||||
|
||||
const save = async (item: T) => {
|
||||
|
||||
await onSave(item);
|
||||
setEditingIndex(null);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (editingIndex == null) {
|
||||
console.log('set focus to div')
|
||||
|
||||
ref.current?.focus();
|
||||
}
|
||||
}, [editingIndex])
|
||||
|
||||
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
|
||||
if (editingIndex !== null) return;
|
||||
|
||||
console.log(e.key)
|
||||
switch (e.key) {
|
||||
|
||||
case "ArrowDown":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(
|
||||
Math.min(selectedIndex + 1, data.length - 1)
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
case "ArrowUp":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(
|
||||
Math.max(selectedIndex - 1, 0)
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
case "Home":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(0);
|
||||
break;
|
||||
|
||||
|
||||
case "End":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(data.length - 1);
|
||||
break;
|
||||
|
||||
case "+":
|
||||
console.log('Plus')
|
||||
break;
|
||||
case "Enter":
|
||||
e.preventDefault();
|
||||
|
||||
setEditingIndex(selectedIndex);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function select(index: number) {
|
||||
setSelectedIndex(index);
|
||||
}
|
||||
|
||||
function startEdit(index = selectedIndex) {
|
||||
setEditingIndex(index);
|
||||
}
|
||||
|
||||
function stopEdit() {
|
||||
setEditingIndex(null);
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
|
||||
setEditingIndex(null);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return {
|
||||
isEditing: editingIndex != null,
|
||||
selectedIndex,
|
||||
editingIndex,
|
||||
|
||||
selectedItem: data[selectedIndex],
|
||||
|
||||
editingItem: editingIndex === null ? undefined : data[editingIndex],
|
||||
|
||||
isItemSelected(index: number) {
|
||||
return index === selectedIndex;
|
||||
},
|
||||
isItemEditing(index: number) {
|
||||
return index === editingIndex;
|
||||
},
|
||||
|
||||
onKeyDown,
|
||||
select,
|
||||
startEdit,
|
||||
stopEdit,
|
||||
cancelEdit,
|
||||
save,
|
||||
setSelectedIndex,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
type KeyboardNavigationOptions = {
|
||||
enabled?: boolean;
|
||||
count: number;
|
||||
selectedIndex: number;
|
||||
setSelectedIndex: (index: number) => void;
|
||||
|
||||
onEnter?: () => void;
|
||||
onEscape?: () => void;
|
||||
};
|
||||
|
||||
export function useKeyboardNavigation({
|
||||
enabled = true,
|
||||
count,
|
||||
selectedIndex,
|
||||
setSelectedIndex,
|
||||
onEnter,
|
||||
onEscape,
|
||||
}: KeyboardNavigationOptions) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
switch (e.key) {
|
||||
|
||||
case "ArrowDown":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(
|
||||
Math.min(selectedIndex + 1, count - 1)
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
case "ArrowUp":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(
|
||||
Math.max(selectedIndex - 1, 0)
|
||||
);
|
||||
break;
|
||||
|
||||
|
||||
case "Home":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(0);
|
||||
break;
|
||||
|
||||
|
||||
case "End":
|
||||
e.preventDefault();
|
||||
|
||||
setSelectedIndex(count - 1);
|
||||
break;
|
||||
|
||||
|
||||
case "Enter":
|
||||
e.preventDefault();
|
||||
|
||||
onEnter?.();
|
||||
break;
|
||||
|
||||
|
||||
case "Escape":
|
||||
e.preventDefault();
|
||||
|
||||
onEscape?.();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.addEventListener(
|
||||
"keydown",
|
||||
handleKeyDown
|
||||
);
|
||||
|
||||
|
||||
return () => {
|
||||
window.removeEventListener(
|
||||
"keydown",
|
||||
handleKeyDown
|
||||
);
|
||||
};
|
||||
|
||||
}, [
|
||||
enabled,
|
||||
count,
|
||||
selectedIndex,
|
||||
setSelectedIndex,
|
||||
onEnter,
|
||||
onEscape,
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
type Props = {
|
||||
editing: boolean;
|
||||
display: ReactNode;
|
||||
editor: ReactNode;
|
||||
};
|
||||
|
||||
export function EditableCell({ editing, display, editor }: Props) {
|
||||
|
||||
return editing
|
||||
? editor
|
||||
: <div className="truncate">{display}</div>;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import clsx from "clsx";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
type Props = {
|
||||
children: ReactNode;
|
||||
selected?: boolean;
|
||||
columns?: string;
|
||||
|
||||
};
|
||||
|
||||
export function EditableRow({ children, selected = false, columns }: Props) {
|
||||
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
className={clsx(
|
||||
"grid",
|
||||
"gap-4",
|
||||
"border",
|
||||
selected ? "border-sky-500" : "border-gray-300",
|
||||
false && "rounded-sm",
|
||||
"mt-1",
|
||||
"py-2",
|
||||
"px-2"
|
||||
)}
|
||||
style={{
|
||||
gridTemplateColumns: columns,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { forwardRef } from "react";
|
||||
import { EditableCell } from "./EditableCell";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
editing: boolean;
|
||||
|
||||
onChange(value: string): void;
|
||||
onKey?: React.KeyboardEventHandler<HTMLInputElement>;
|
||||
};
|
||||
|
||||
export const NumberCell = forwardRef<HTMLInputElement, Props>(({ value, editing, onChange,onKey }, ref) => {
|
||||
return (
|
||||
<EditableCell
|
||||
|
||||
editing={editing}
|
||||
|
||||
display={value}
|
||||
|
||||
editor={
|
||||
<input ref={ref} className="w-full border-b-4 border-transparent focus:border-green-300 rounded px-1 focus:outline-none "
|
||||
value={value}
|
||||
onKeyDown={onKey}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
}
|
||||
|
||||
/>
|
||||
);
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { forwardRef } from "react";
|
||||
import { EditableCell } from "./EditableCell";
|
||||
|
||||
type Props = {
|
||||
value: string;
|
||||
editing: boolean;
|
||||
|
||||
onChange(value: string): void;
|
||||
onKey?:React.KeyboardEventHandler<HTMLInputElement>;
|
||||
};
|
||||
|
||||
export const TextCell = forwardRef<HTMLInputElement, Props>(({ value, editing, onChange, onKey }, ref) => {
|
||||
|
||||
return (
|
||||
<EditableCell
|
||||
editing={editing}
|
||||
display={<input className="w-full border-b-4 border-transparent rounded px-1 focus:outline-none" disabled
|
||||
value={value}
|
||||
/>}
|
||||
editor={
|
||||
<input className="w-full border-b-4 border-transparent focus:border-green-300 rounded px-1 focus:outline-none "
|
||||
ref={ref}
|
||||
value={value}
|
||||
onKeyDown={onKey}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
}
|
||||
|
||||
/>
|
||||
);
|
||||
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,47 @@
|
||||
import { useRef } from "react";
|
||||
|
||||
export function useFocusManager() {
|
||||
|
||||
const elements = useRef<(HTMLElement | null)[]>([]);
|
||||
|
||||
const register = (index: number) => (element: HTMLElement | null) => {
|
||||
|
||||
elements.current[index] = element;
|
||||
};
|
||||
|
||||
|
||||
const focusFirst = () => {
|
||||
elements.current[0]?.focus();
|
||||
};
|
||||
|
||||
const focusNext = (current: HTMLElement) => {
|
||||
|
||||
const index = elements.current.indexOf(current);
|
||||
|
||||
if (index === -1) return;
|
||||
|
||||
const next = (index + 1) % elements.current.length;
|
||||
|
||||
elements.current[next]?.focus();
|
||||
};
|
||||
|
||||
const focusPrevious = (current: HTMLElement) => {
|
||||
|
||||
const index = elements.current.indexOf(current);
|
||||
|
||||
if (index === -1) return;
|
||||
|
||||
const previous = (index - 1 + elements.current.length) % elements.current.length;
|
||||
|
||||
elements.current[previous]?.focus();
|
||||
};
|
||||
|
||||
|
||||
|
||||
return {
|
||||
register,
|
||||
focusFirst,
|
||||
focusNext,
|
||||
focusPrevious,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
cva,
|
||||
type VariantProps,
|
||||
} from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const inputVariants = cva(
|
||||
[
|
||||
"w-full",
|
||||
"rounded-md",
|
||||
"border",
|
||||
"outline-none",
|
||||
"transition-colors",
|
||||
"placeholder:text-gray-400",
|
||||
"focus:ring-2",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-gray-300 focus:border-blue-500 focus:ring-blue-500/20",
|
||||
|
||||
error:
|
||||
"border-red-500 focus:border-red-500 focus:ring-red-500/20",
|
||||
|
||||
success:
|
||||
"border-green-500 focus:border-green-500 focus:ring-green-500/20",
|
||||
},
|
||||
|
||||
sizeVariant: {
|
||||
xs: "h-5 px-3 text-xs",
|
||||
sm: "h-8 px-3 text-sm",
|
||||
md: "h-10 px-3 text-sm",
|
||||
lg: "h-12 px-4 text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
sizeVariant: "xs",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
type InputVariants = VariantProps<typeof inputVariants>;
|
||||
|
||||
type InputProps =
|
||||
React.ComponentProps<"input"> &
|
||||
InputVariants;
|
||||
|
||||
function Input({ className, variant, sizeVariant, ...props }: InputProps) {
|
||||
|
||||
return (
|
||||
<input
|
||||
className={cn(
|
||||
inputVariants({
|
||||
variant,
|
||||
sizeVariant,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Input,
|
||||
inputVariants,
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useEffect, useState } from "react"
|
||||
import { forwardRef } from "react"
|
||||
interface ChangeValue {
|
||||
[key: string]: boolean
|
||||
}
|
||||
|
||||
interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
label?: string
|
||||
error?: string | undefined
|
||||
|
||||
}
|
||||
|
||||
export const InputCheckboxR = forwardRef<HTMLInputElement, Props>(
|
||||
({ label, error, ...props }, ref) => {
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="p-2 mb-1 mt-1 bg-green-0 flex items-center">
|
||||
|
||||
<input ref={ref} type="checkbox" className=" me-2 w-6 h-6 " {...props} />
|
||||
{label && <div className="text-md font-normal text-gray-00 font-mono ps-1">{label}</div>}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,30 @@
|
||||
import { forwardRef } from "react"
|
||||
|
||||
interface InputTextProps
|
||||
extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
label?: string
|
||||
error?: string | undefined
|
||||
}
|
||||
|
||||
export const InputTextR = forwardRef<HTMLInputElement, InputTextProps>(
|
||||
({ label, error, ...props }, ref) => {
|
||||
return (
|
||||
<div className="flex flex-col bg-green-00">
|
||||
{label && (
|
||||
<label className="ps-1 font-normal text-xs text-gray-600 ">
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
|
||||
<input ref={ref}
|
||||
className={`ps-2 w-full font-normal shadow text-xs h-5 border rounded ${error ? "border-red-500" : "border-gray-300"} focus:outline-none focus:ring-1 focus:ring-blue-800`}
|
||||
{...props}
|
||||
/>
|
||||
|
||||
{false && error && <p className="text-red-500 text-sm mt-1">{error}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
InputTextR.displayName = "InputR"
|
||||
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
cva,
|
||||
type VariantProps,
|
||||
} from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const labelVariants = cva(
|
||||
[
|
||||
"w-full",
|
||||
"outline-none",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"flex items-center justify-start font-normal text-gray-600 ",
|
||||
|
||||
|
||||
},
|
||||
|
||||
size: {
|
||||
xs: "text-xs",
|
||||
sm: "text-sm",
|
||||
md: "text-sm",
|
||||
lg: "text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "xs",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
type LabelVariants = VariantProps<typeof labelVariants>;
|
||||
|
||||
type LabelProps = React.ComponentProps<"label"> & LabelVariants;
|
||||
|
||||
function Label({ className, variant, size, ...props }: LabelProps) {
|
||||
|
||||
return (
|
||||
<label
|
||||
className={cn(
|
||||
labelVariants({
|
||||
variant,
|
||||
size,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Label,
|
||||
labelVariants,
|
||||
};
|
||||
@@ -0,0 +1,247 @@
|
||||
import { Slot } from "@radix-ui/react-slot";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const listVariants = cva(
|
||||
"w-full overflow-hidden transition-colors",//"inline-flex items-center justify-center rounded-md font-medium transition-colors",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
transparent: "",
|
||||
default: "border-gray-200",
|
||||
muted: "border-gray-200 bg-gray-50",
|
||||
dark: "border-gray-700 bg-gray-900 text-white",
|
||||
},
|
||||
|
||||
border: {
|
||||
none: "",
|
||||
primary: "border-1 border-gray-800",
|
||||
secondary: "border-1 border-gray-200",
|
||||
danger: "border-1 border-red-600",
|
||||
},
|
||||
|
||||
size: {
|
||||
xs: "px-3 text-xs",
|
||||
sm: "px-3 text-sm",
|
||||
md: "px-3 text-sm",
|
||||
lg: "px-3 text-base",
|
||||
},
|
||||
|
||||
divide: {
|
||||
true: "divide-y divide-gray-300",
|
||||
false: "",
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "transparent",
|
||||
size: "xs",
|
||||
divide: true,
|
||||
border: "none"
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const listItemVariants = cva(
|
||||
"flex items-center gap-4 transition-colors",//"flex items-center justify-between transition-colors",
|
||||
{
|
||||
variants: {
|
||||
|
||||
|
||||
|
||||
selected: {
|
||||
true: "bg-blue-50 text-blue-700",
|
||||
false: "hover:bg-gray-50",
|
||||
},
|
||||
|
||||
size: {
|
||||
sm: "px-3 py-1",
|
||||
md: "px-3 py-1",
|
||||
lg: "px-3 py-1",
|
||||
},
|
||||
|
||||
hover: {
|
||||
true: "hover:bg-gray-100",
|
||||
false: "",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
size: "md",
|
||||
hover: false,
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
List
|
||||
----------------------------------------------------------------------------*/
|
||||
type ListProps =
|
||||
React.ComponentProps<"ul"> &
|
||||
VariantProps<typeof listVariants>;
|
||||
|
||||
|
||||
function List({ className, variant, size, border, divide, children, ...props }: ListProps) {
|
||||
const Comp = "ul";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(listVariants({ variant, size, divide, border }), className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
ListHeader
|
||||
----------------------------------------------------------------------------*/
|
||||
type ListHeaderProps =
|
||||
React.ComponentProps<"div"> ;
|
||||
|
||||
function ListHeader({ className,children, ...props }: ListHeaderProps) {
|
||||
const Comp = "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn("flex border-b-2 mb-1 border-black", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
ListHeaderItem
|
||||
----------------------------------------------------------------------------*/
|
||||
type ListHeaderItemProps =
|
||||
React.ComponentProps<"div"> ;
|
||||
|
||||
function ListHeaderItem({ className,children, ...props }: ListHeaderItemProps) {
|
||||
const Comp = "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn("px-3 truncate font-bold text-sm text-gray-500", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
ListItem
|
||||
----------------------------------------------------------------------------*/
|
||||
type ListItemProps =
|
||||
React.ComponentProps<"li"> &
|
||||
VariantProps<typeof listItemVariants>;
|
||||
|
||||
function ListItem({ className, hover, size, children, ...props }: ListItemProps) {
|
||||
const Comp = "li";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
className={cn(listItemVariants({ size, hover }), className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Comp>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
ListIcon
|
||||
----------------------------------------------------------------------------*/
|
||||
function ListItemIcon({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex size-4 shrink-0 items-center justify-center rounded-full bg-gray-100 me-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ListItemContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"min-w-0 flex-1",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ListItemTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"truncate font-medium",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ListItemDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"truncate text-sm text-gray-500",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function ListItemAction({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"ml-4 flex shrink-0 items-center gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
export {
|
||||
List,
|
||||
ListHeader,
|
||||
ListHeaderItem,
|
||||
ListItem,
|
||||
listVariants,
|
||||
ListItemIcon,
|
||||
ListItemTitle,
|
||||
ListItemAction,
|
||||
ListItemContent,
|
||||
ListItemDescription
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export type BreadcrumbItem = {
|
||||
label: string;
|
||||
href?: string;
|
||||
};
|
||||
|
||||
type BreadcrumbsProps = {
|
||||
items: BreadcrumbItem[];
|
||||
};
|
||||
|
||||
export default function Breadcrumbs({ items}: BreadcrumbsProps) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<nav className="flex items-center gap-2 border-b px-6 py-3 text-sm">
|
||||
{items.map((item, index) => {
|
||||
const isLast = index === items.length - 1;
|
||||
|
||||
return (
|
||||
<div key={`${item.label} -${index} `}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
{index > 0 && (
|
||||
<ChevronRight
|
||||
size={16}
|
||||
className="text-gray-400"
|
||||
/>
|
||||
)}
|
||||
|
||||
{item.href && !isLast ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => router.push(item.href!)}
|
||||
className="text-gray-500 hover:text-gray-900 hover:underline"
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
) : (
|
||||
<span
|
||||
className={
|
||||
isLast
|
||||
? "font-medium text-gray-900"
|
||||
: "text-gray-500"
|
||||
}
|
||||
>
|
||||
{item.label}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
cva,
|
||||
type VariantProps,
|
||||
} from "class-variance-authority";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const selectVariants = cva(
|
||||
[
|
||||
"w-full",
|
||||
"rounded-md",
|
||||
"border",
|
||||
"outline-none",
|
||||
"transition-colors",
|
||||
"placeholder:text-gray-400",
|
||||
"focus:ring-2",
|
||||
],
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default:
|
||||
"border-gray-300 focus:border-blue-500 focus:ring-blue-500/20",
|
||||
|
||||
error:
|
||||
"border-red-500 focus:border-red-500 focus:ring-red-500/20",
|
||||
|
||||
success:
|
||||
"border-green-500 focus:border-green-500 focus:ring-green-500/20",
|
||||
},
|
||||
|
||||
sizeVariant: {
|
||||
xs: "h-5 px-3 text-xs",
|
||||
sm: "h-8 px-3 text-sm",
|
||||
md: "h-10 px-3 text-sm",
|
||||
lg: "h-12 px-4 text-base",
|
||||
},
|
||||
},
|
||||
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
sizeVariant: "xs",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
type SelectVariants = VariantProps<typeof selectVariants>;
|
||||
|
||||
type SelectProps =
|
||||
React.ComponentProps<"select"> &
|
||||
SelectVariants;
|
||||
|
||||
function Select({ className, variant, sizeVariant, ...props }: SelectProps) {
|
||||
|
||||
return (
|
||||
<select
|
||||
className={cn(
|
||||
selectVariants({
|
||||
variant,
|
||||
sizeVariant,
|
||||
}),
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
selectVariants,
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import { forwardRef } from "react"
|
||||
|
||||
interface SelectOptions{
|
||||
id:string,
|
||||
value:string
|
||||
}
|
||||
|
||||
interface SelectProps
|
||||
extends React.InputHTMLAttributes<HTMLSelectElement> {
|
||||
options:SelectOptions[]
|
||||
label?: string
|
||||
error?: string | undefined
|
||||
}
|
||||
|
||||
export const SelectR = forwardRef<HTMLSelectElement, SelectProps>(
|
||||
({ label, error,options, ...props }, ref) => {
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
{label && (
|
||||
<label className="ps-1 text-xs font-normal text-gray-600 ">
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
|
||||
<select ref={ref}
|
||||
className={`w-full ps-2 text-xs font-normal h-5 border rounded ${error ? "border-red-500" : "border-gray-300"} focus:outline-none focus:ring-1 focus:ring-blue-800`}
|
||||
{...props}
|
||||
>
|
||||
{options.map((o)=><option key={o.id} value={o.id}>{o.value}</option>)}
|
||||
</select>
|
||||
|
||||
{false && error && <p className="text-red-500 text-sm mt-1">{error}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
SelectR.displayName = "SelectR"
|
||||
@@ -0,0 +1,25 @@
|
||||
import {JSX} from "react";
|
||||
|
||||
interface ColDef{
|
||||
width:number
|
||||
widthTyp:"fr" | "px"
|
||||
}
|
||||
|
||||
interface Props{
|
||||
cols:ColDef[],
|
||||
children: string | JSX.Element | JSX.Element[]
|
||||
}
|
||||
|
||||
export default async function TableView({children,cols}:Props) {
|
||||
|
||||
const c0 = cols.reduce((prev,cur)=>`${prev}_${cur.width.toString()}${cur.widthTyp}`,'[__').replace('___','');
|
||||
console.log(c0)
|
||||
const c = `grid grid-cols-${c0+']'} border-b-1 min-h-16 border-gray-200 ps-4 pb-4 pt-2`
|
||||
return (
|
||||
|
||||
<div className={c}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import VisuPoint from "./visuPoints";
|
||||
import VisuDrawPath from "./visuDrawPath";
|
||||
|
||||
|
||||
interface Props {
|
||||
}
|
||||
|
||||
type Pos = { x: number; y: number };
|
||||
type Point = { id: number, x: number; y: number };
|
||||
|
||||
export default function VisuCreatePlatform({ }: Props) {
|
||||
const x = 0;
|
||||
const y = 0;
|
||||
|
||||
const [scale, setScale] = useState(1.0);
|
||||
const [points, setPoints] = useState<Point[]>([{ id: 1, x: 50, y: 50 }, { id: 2, x: 100, y: 100 }])
|
||||
const [pos, setPos] = useState<Pos>({ x: 0, y: 0 });
|
||||
const frame = useRef<number | null>(null);
|
||||
const latest = useRef<Pos>({ x: 0, y: 0 });
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
|
||||
latest.current = {
|
||||
x: e.clientX - rect.left,
|
||||
y: e.clientY - rect.top,
|
||||
};
|
||||
|
||||
if (frame.current === null) {
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
setPos(latest.current);
|
||||
frame.current = null;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleSelect = (id: number) => {
|
||||
console.log(id)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="" >
|
||||
<div style={{ padding: "20px" }}>
|
||||
<h2>Mausposition</h2>
|
||||
<p>X: {pos.x}</p>
|
||||
<p>Y: {pos.y}</p>
|
||||
</div>
|
||||
<div className="m-4 " tabIndex={1} onMouseMove={(e) => handleMouseMove(e)} >
|
||||
|
||||
<svg
|
||||
|
||||
viewBox="0 0 800 800" width="800" height="800" xmlns="http://www.w3.org/2000/svg"
|
||||
className=" border border-gray-300"
|
||||
style={{ transform: `scale(${2.0})`, transformOrigin: "top left" }}
|
||||
shapeRendering="crispEdges"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
>
|
||||
|
||||
<g transform={`translate(${x + 100.0}, ${y + 100.0})`}>
|
||||
<VisuDrawPath />
|
||||
</g>
|
||||
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<line x1="0" y1="0" x2="600" y2="600" stroke="black" />
|
||||
<rect x="10.5" y="10.5" width="200.5" height="200.5" stroke="black" fill="none" />
|
||||
<rect x="100" y="100" width="200" height="200" stroke="black" fill="none" />
|
||||
{points.map((point)=>(
|
||||
<VisuPoint key={point.id} id={point.id} pos={{x:point.x,y:point.y}} onSelect={(id)=>handleSelect(id)} />
|
||||
|
||||
))}
|
||||
|
||||
<rect width={item.length} height={item.height} fill="#f0f0f0"/>
|
||||
*/
|
||||
@@ -0,0 +1,150 @@
|
||||
"use client"
|
||||
|
||||
import { PathCommand } from "@/types/draw/draw.path.types";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
type Pos = { x: number; y: number };
|
||||
|
||||
interface Props {
|
||||
id?: number
|
||||
pos?: Pos,
|
||||
onSelect?: (id: number) => void
|
||||
}
|
||||
|
||||
type Position = { x: number, y: number, data: PathCommand };
|
||||
|
||||
export default function VisuDrawPath({ id, pos, onSelect }: Props) {
|
||||
|
||||
const [hasFocus, setHasFocus] = useState(false);
|
||||
const [path, setPath] = useState<PathCommand[]>([])
|
||||
const [positions, setPositions] = useState<Position[]>([])
|
||||
const handleMouseLeafe = () => {
|
||||
console.log('Leaf')
|
||||
setHasFocus(() => false);
|
||||
}
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
console.log('Enter')
|
||||
setHasFocus(() => true);
|
||||
}
|
||||
const raster = 4.0;
|
||||
const scale = 2.0;
|
||||
const l = 9;
|
||||
const h = 7;
|
||||
const y1 = 2 * raster * scale;
|
||||
const x1 = 5 * raster * scale;
|
||||
const x2 = l * raster * scale;
|
||||
const y2 = 4 * raster * scale;
|
||||
|
||||
let l1 = l * raster * scale;
|
||||
let h1 = (h * raster * scale);
|
||||
|
||||
let r = 6 * raster
|
||||
|
||||
useEffect(() => {
|
||||
setPath(() => [
|
||||
{ type: "M", x: 0, y: y1 },
|
||||
{ type: "L", x: x1, y: 0 },
|
||||
{ type: "L", x: x2, y: y2 },
|
||||
{ type: "V", y: h1 },
|
||||
{ type: "H", x: 0 },
|
||||
{ type: "Z" }])
|
||||
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
console.log(getKoordnates())
|
||||
setPositions(() => getKoordnates())
|
||||
}, [path])
|
||||
|
||||
const getKoordnates = (): Position[] => {
|
||||
let lastPoint = { x: 0, y: 0 };
|
||||
let points: Position[] = [];
|
||||
for (const p of path) {
|
||||
|
||||
let retValue: Position = { x: 0, y: 0, data: p }
|
||||
switch (p.type) {
|
||||
case "M":
|
||||
lastPoint = { x: p.x, y: p.y };
|
||||
points.push({ x: p.x, y: p.y, data: p });
|
||||
break;
|
||||
case "L":
|
||||
lastPoint = { x: p.x, y: p.y };
|
||||
points.push({ x: p.x, y: p.y, data: p });
|
||||
break;
|
||||
case "H":
|
||||
retValue = { x: p.x, y: lastPoint.y, data: p }
|
||||
lastPoint = { ...lastPoint, x: p.x };
|
||||
points.push(retValue);
|
||||
break;
|
||||
case "V":
|
||||
retValue = { x: lastPoint.x, y: p.y, data: p }
|
||||
lastPoint = { ...lastPoint, y: p.y };
|
||||
points.push(retValue);
|
||||
break;
|
||||
// case "Z":
|
||||
// retValue = { x: -1, y: -1, data: p }
|
||||
// lastPoint = { x: -1, y: -1 };
|
||||
// points.push(retValue);
|
||||
// break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return points;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const drawPath = () => {
|
||||
|
||||
if (path.length == 0) return;
|
||||
|
||||
let pathValues = path.reduce((curent, cmdEle) => {
|
||||
let value = ''
|
||||
if (cmdEle.type === 'L') {
|
||||
value = ` ${cmdEle.x} ${cmdEle.y}`
|
||||
}
|
||||
if (cmdEle.type === 'H') {
|
||||
value = ` ${cmdEle.x}`
|
||||
}
|
||||
if (cmdEle.type === 'V') {
|
||||
value = ` ${cmdEle.y}`
|
||||
}
|
||||
if (cmdEle.type === 'M') {
|
||||
value = ` ${cmdEle.x} ${cmdEle.y}`
|
||||
}
|
||||
|
||||
curent += ' ' + cmdEle.type + value;
|
||||
return curent;
|
||||
}, '')
|
||||
|
||||
return <path d={`${pathValues}`} strokeWidth="1" stroke="#000000" fill="#808080" shapeRendering="auto" strokeLinecap="round" strokeLinejoin="round" strokeOpacity={0.8}
|
||||
style={{ filter: "drop-shadow(3px 3px 4px rgba(0,0,0,0.4))" }}></path>
|
||||
//return <g> {`<path d="${pathValues}" stroke-width="1" stroke="#000000" ></path>`} </g>
|
||||
}
|
||||
if (path.length == 0) <div>No Path</div>
|
||||
return (
|
||||
|
||||
|
||||
<g transform={`translate(${0}, ${0}) scale(1.0)`}>
|
||||
|
||||
{drawPath()}
|
||||
<g transform={`translate(${40}, ${18})`}>
|
||||
{<circle cx={0} cy={0} r={22} stroke="#000000" fill="#808080" style={{ filter: "drop-shadow(3px 3px 4px rgba(0,0,0,0.4))" }}/>}
|
||||
</g>
|
||||
<g>
|
||||
<line x1={4} y1={h1-4} x2={4} y2={(16)} stroke="#000000" strokeWidth="2" strokeOpacity={0.4}/>
|
||||
<line x1={8} y1={h1-4} x2={28} y2={(16)} stroke="#000000" strokeWidth="2" strokeOpacity={0.4}/>
|
||||
</g>
|
||||
{false && positions.map((p, index) => <rect key={index} x={p.x - 5} y={p.y - 5} width="10" height="10" stroke="black" fill={hasFocus ? "orange" : "none"} />)}
|
||||
</g>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<rect width={item.length} height={item.height} fill="#f0f0f0"/>
|
||||
*/
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
type Pos = { x: number; y: number };
|
||||
|
||||
interface Props {
|
||||
id:number
|
||||
pos:Pos,
|
||||
onSelect:(id:number)=>void
|
||||
}
|
||||
|
||||
|
||||
export default function VisuPoint({id,pos,onSelect }: Props) {
|
||||
|
||||
const [hasFocus,setHasFocus] = useState(false);
|
||||
|
||||
const handleMouseLeafe = ()=>{
|
||||
console.log('Leaf')
|
||||
setHasFocus(()=>false);
|
||||
}
|
||||
|
||||
const handleMouseEnter = ()=>{
|
||||
console.log('Enter')
|
||||
setHasFocus(()=>true);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
|
||||
<g transform={`translate(${pos.x}, ${pos.y})`}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeafe}
|
||||
onClick={()=>onSelect(id)}
|
||||
>
|
||||
<rect x={pos.x-5} y={pos.y-5} width="10" height="10" stroke="black" fill={hasFocus ? "orange" : "none"}/>
|
||||
</g>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<rect width={item.length} height={item.height} fill="#f0f0f0"/>
|
||||
*/
|
||||
@@ -0,0 +1,28 @@
|
||||
"use client"
|
||||
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import { JSX, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
svg: string;
|
||||
}
|
||||
|
||||
//<path d="M 0 0 H 100 V100" stroke-width="1" />
|
||||
export function SvgShow({ svg }: Props) {
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
<g>
|
||||
|
||||
|
||||
<g
|
||||
|
||||
dangerouslySetInnerHTML={{ __html: svg }}
|
||||
style={{ pointerEvents: "none" }}
|
||||
/>
|
||||
|
||||
</g>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
"use client"
|
||||
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import { RefObject, useEffect, useRef } from "react";
|
||||
|
||||
interface Props {
|
||||
element: VisuElement,
|
||||
selected: boolean,
|
||||
onSelect: () => void,
|
||||
//isPanningRef: RefObject<boolean>
|
||||
onDrag: (element: VisuElement, dx: number, dy: number) => void;
|
||||
gridSize: number;
|
||||
}
|
||||
|
||||
|
||||
export function SvgVisuElement({ element, onSelect, onDrag, selected, gridSize }: Props) {
|
||||
const draggingRef = useRef(false);
|
||||
const isMouseDownRef = useRef(false);
|
||||
const lastPos = useRef({ x: 0, y: 0 });
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const handleGlobalMouseUp = () => {
|
||||
draggingRef.current = false;
|
||||
isMouseDownRef.current = false;
|
||||
};
|
||||
|
||||
window.addEventListener("mouseup", handleGlobalMouseUp);
|
||||
return () => window.removeEventListener("mouseup", handleGlobalMouseUp);
|
||||
}, []);
|
||||
|
||||
const handleMouseDown = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
draggingRef.current = false;
|
||||
isMouseDownRef.current = true;
|
||||
lastPos.current = { x: e.clientX, y: e.clientY };
|
||||
};
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!isMouseDownRef.current) return; //
|
||||
const dx = e.clientX - lastPos.current.x;
|
||||
const dy = e.clientY - lastPos.current.y;
|
||||
|
||||
if (!draggingRef.current && (Math.abs(dx) > 2 || Math.abs(dy) > 2)) {
|
||||
draggingRef.current = true;
|
||||
}
|
||||
|
||||
if (draggingRef.current) {
|
||||
onDrag(element, dx, dy);
|
||||
lastPos.current = { x: e.clientX, y: e.clientY };
|
||||
}
|
||||
};
|
||||
|
||||
const handleMouseUp = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
//if (!draggingRef.current) {
|
||||
// onSelect(element);
|
||||
//}
|
||||
draggingRef.current = false;
|
||||
isMouseDownRef.current = false;
|
||||
};
|
||||
|
||||
return (
|
||||
<g
|
||||
transform={`translate(${element.posX}, ${element.posY})`}
|
||||
onMouseDown={handleMouseDown}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseUp={handleMouseUp}
|
||||
onMouseLeave={handleMouseUp}
|
||||
>
|
||||
|
||||
|
||||
{selected && <rect x="-2" y="-2" width={element.width + 4} height={element.height + 4} fill="#f0f0f0" />}
|
||||
<g dangerouslySetInnerHTML={{ __html: element.svg }} />
|
||||
{draggingRef.current ? <text x="20" y="20">DD</text> : <text x="20" y="20">Normal</text>}
|
||||
{element.group?.nr ? <text x="10" y="10">{element.group.nr}</text> : <text x="10" y="10">{element.id}</text>}
|
||||
|
||||
|
||||
<rect
|
||||
x={0}
|
||||
y={0}
|
||||
width={element.width}
|
||||
height={element.height}
|
||||
fill="transparent"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
"use client"
|
||||
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import { JSX, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
element: VisuElement;
|
||||
selected: boolean;
|
||||
onElementMouseDown: (element: VisuElement, mouseEvent: React.MouseEvent) => void;
|
||||
}
|
||||
|
||||
interface LineX {
|
||||
pos: { x: number, y: number }[]
|
||||
}
|
||||
|
||||
export function SvgVisuElement({ element, selected, onElementMouseDown }: Props) {
|
||||
|
||||
const [lines, setLinies] = useState<LineX>({ pos: [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 50 }] })
|
||||
|
||||
const handleMouseDown = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
onElementMouseDown(element, e);
|
||||
};
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<g
|
||||
transform={`translate(${element.posX}, ${element.posY})`}
|
||||
onMouseDown={(e) => handleMouseDown(e)}
|
||||
style={{ cursor: selected ? "move" : "pointer" }}
|
||||
>
|
||||
{/* 🔥 HITBOX (oben!) */}
|
||||
<rect
|
||||
x={0}
|
||||
y={0}
|
||||
width={element.px_width}
|
||||
height={element.px_height}
|
||||
fill="transparent"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
|
||||
{/* SVG DARF KEINE EVENTS BLOCKEN */}
|
||||
<g
|
||||
dangerouslySetInnerHTML={{ __html: element.svg }}
|
||||
style={{ pointerEvents: "none" }}
|
||||
/>
|
||||
|
||||
{element.lines && <g >
|
||||
|
||||
{element.lines.map((line, index) => {
|
||||
const result: JSX.Element[] = [];
|
||||
for (let i = 0; i < line.points.length - 1; i++) {
|
||||
const p1 = line.points[i];
|
||||
const p2 = line.points[i + 1];
|
||||
|
||||
result.push(
|
||||
<line
|
||||
key={`${element.id}-${index}-${i}`}
|
||||
x1={p1.x}
|
||||
y1={p1.y}
|
||||
x2={p2.x}
|
||||
y2={p2.y}
|
||||
stroke="#505050"
|
||||
strokeWidth={1.5}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <g key={index} transform={`translate(${line.offsetX}, ${line.offsetY})`}>{result}</g>;
|
||||
})}
|
||||
|
||||
|
||||
|
||||
</g>}
|
||||
|
||||
|
||||
|
||||
{/* Label */}
|
||||
{element.group && !element.posAggElemente && (
|
||||
<text x={0} y={0}>
|
||||
{element.group.nr}
|
||||
</text>
|
||||
)}
|
||||
|
||||
|
||||
|
||||
{/* Auswahl */}
|
||||
{selected && (
|
||||
<rect
|
||||
x={-2}
|
||||
y={-2}
|
||||
width={element.px_width + 4}
|
||||
height={element.px_height + 4}
|
||||
stroke="blue"
|
||||
fill="transparent"
|
||||
pointerEvents="none"
|
||||
/>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
{element.group && element.posAggElemente && (
|
||||
<g>
|
||||
<rect
|
||||
x={element.posAggElemente.posText.x}
|
||||
y={element.posAggElemente.posText.y}
|
||||
width={element.posAggElemente.posText.width}
|
||||
height={element.posAggElemente.posText.height}
|
||||
stroke="yellow"
|
||||
fill="yellow"
|
||||
pointerEvents="all"
|
||||
>
|
||||
</rect>
|
||||
<text x={element.posAggElemente.posText.x}
|
||||
y={element.posAggElemente.posText.y} stroke="black" >tt</text>
|
||||
</g>
|
||||
)}
|
||||
|
||||
{element.posAggElemente && element.posAggElemente.posAnfahrwarnung &&
|
||||
<rect
|
||||
x={element.posAggElemente.posAnfahrwarnung.x}
|
||||
y={element.posAggElemente.posAnfahrwarnung.y}
|
||||
width={element.posAggElemente.posAnfahrwarnung.width}
|
||||
height={element.posAggElemente.posAnfahrwarnung.height}
|
||||
stroke="yellow"
|
||||
fill="yellow"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
}
|
||||
|
||||
{element.posAggElemente && element.posAggElemente.posBetriebsart &&
|
||||
<rect
|
||||
x={element.posAggElemente.posBetriebsart.x}
|
||||
y={element.posAggElemente.posBetriebsart.y}
|
||||
width={element.posAggElemente.posBetriebsart.width}
|
||||
height={element.posAggElemente.posBetriebsart.height}
|
||||
stroke="green"
|
||||
fill="green"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
}
|
||||
|
||||
{element.posAggElemente && element.posAggElemente.posMotor &&
|
||||
<rect
|
||||
x={element.posAggElemente.posMotor.x}
|
||||
y={element.posAggElemente.posMotor.y}
|
||||
width={element.posAggElemente.posMotor.width}
|
||||
height={element.posAggElemente.posMotor.height}
|
||||
stroke="green"
|
||||
fill="green"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
}
|
||||
|
||||
{element.posAggElemente && element.posAggElemente.posFuIst &&
|
||||
<rect
|
||||
x={element.posAggElemente.posFuIst.x}
|
||||
y={element.posAggElemente.posFuIst.y}
|
||||
width={element.posAggElemente.posFuIst.width}
|
||||
height={element.posAggElemente.posFuIst.height}
|
||||
stroke="green"
|
||||
fill="green"
|
||||
pointerEvents="all"
|
||||
/>
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
export const snapToGrid = (value: number, gridSize: number) => {
|
||||
return Math.round(value / gridSize) * gridSize;
|
||||
};
|
||||
|
||||
export const snapPointToGrid = (x: number, y: number, gridSize: number) => {
|
||||
return {
|
||||
x: snapToGrid(x, gridSize),
|
||||
y: snapToGrid(y, gridSize),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,154 @@
|
||||
"use client"
|
||||
|
||||
|
||||
import { api_VisuElementCreate } from "@/actions/rk/api-visuElements";
|
||||
import GroupSelect from "@/components/rk/groups/groupSelect";
|
||||
|
||||
import VisuElementList from "@/components/visu/visuElementList";
|
||||
import { Element, Group } from "@/types/rk";
|
||||
import { VisuElement, VisuElementCreate } from "@/types/visu/visuElements.types";
|
||||
import { useEffect, useState } from "react";
|
||||
import ElementSelect from "../rk/elements/elementSelect";
|
||||
|
||||
interface Props {
|
||||
groups: Group[],
|
||||
elements: Element[]
|
||||
visuElements: VisuElement[]
|
||||
}
|
||||
|
||||
|
||||
export default function VisuAddGroups({ groups, visuElements, elements }: Props) {
|
||||
|
||||
const [selectedGroup, setSelectedGroup] = useState<Group>()
|
||||
const [selectedElement, setSelectedElement] = useState<Element>()
|
||||
const [filteredGroups, setFilterdGroups] = useState<Group[]>([])
|
||||
const [filteredElements, setFilterdElements] = useState<Element[]>([])
|
||||
const [svgTypeName, setSvgTypeName] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
filterGroups();
|
||||
filterElements()
|
||||
}, [visuElements, groups,elements])
|
||||
|
||||
const handleSelectGroup = (group: Group) => {
|
||||
setSelectedGroup(() => group);
|
||||
}
|
||||
|
||||
const handleSelectElement = (element: Element) => {
|
||||
setSelectedElement(() => element);
|
||||
}
|
||||
|
||||
const filterGroups = () => {
|
||||
const filterd = groups.filter((g) => {
|
||||
const findGroupInElements = visuElements.find((ve) => ve.groupId == g.id);
|
||||
if (!findGroupInElements) return g;
|
||||
})
|
||||
|
||||
setFilterdGroups(() => filterd);
|
||||
}
|
||||
|
||||
const filterElements = () => {
|
||||
const filterd = elements.filter((el) => {
|
||||
const findElementInVisuElements = visuElements.find((ve) => ve.elementId == el.id);
|
||||
if (!findElementInVisuElements) return el;
|
||||
})
|
||||
|
||||
setFilterdElements(() => filterd);
|
||||
}
|
||||
|
||||
const onSaveGroup_old = () => {
|
||||
if (!selectedGroup) return;
|
||||
if (!svgTypeName) return;
|
||||
|
||||
let name = svgTypeName;
|
||||
let variant = ""
|
||||
if (svgTypeName === 'pumpensumpf') {
|
||||
name = 'behaelter';
|
||||
variant = 'pumpensumpf'
|
||||
}
|
||||
|
||||
const data: VisuElementCreate = {
|
||||
anlageId: selectedGroup.anlageId,
|
||||
groupId: selectedGroup.id,
|
||||
name: 'G_' + selectedGroup.nr + '_' + selectedGroup.name,
|
||||
svgTypeName: name,
|
||||
svgTypeVariant: variant,
|
||||
posX: 100,
|
||||
posY: 100
|
||||
|
||||
}
|
||||
api_VisuElementCreate(data)
|
||||
}
|
||||
|
||||
const onSave = () => {
|
||||
if (!selectedElement) return;
|
||||
if (!svgTypeName) return;
|
||||
|
||||
let name = svgTypeName;
|
||||
let variant = ""
|
||||
if (svgTypeName === 'pumpensumpf') {
|
||||
name = 'behaelter';
|
||||
variant = 'pumpensumpf'
|
||||
}
|
||||
const prefix = selectedElement.prefix ? "_"+ selectedElement.prefix : ""
|
||||
const funcTxt = selectedElement.funcTxt ? "_"+ selectedElement.funcTxt : ""
|
||||
const data: VisuElementCreate = {
|
||||
anlageId: selectedElement.anlageId,
|
||||
groupId: selectedElement.group.id,
|
||||
elementId: selectedElement.id,
|
||||
name: 'G_' + selectedElement.group.nr + prefix + '_' + selectedElement.group.name + funcTxt,
|
||||
svgTypeName: name,
|
||||
svgTypeVariant: variant,
|
||||
posX: 100,
|
||||
posY: 100
|
||||
|
||||
}
|
||||
api_VisuElementCreate(data)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
|
||||
<div className="grid grid-cols-[400_200_400] gap-4">
|
||||
<div>
|
||||
{/* <GroupSelect onSelect={handleSelectGroup} groups={filteredGroups}></GroupSelect> */}
|
||||
<ElementSelect elements={filteredElements} onSelect={handleSelectElement}></ElementSelect>
|
||||
<ElementSelect elements={filteredElements} onSelect={handleSelectElement}></ElementSelect>
|
||||
</div>
|
||||
{selectedElement ?
|
||||
<div>
|
||||
<div>{selectedElement.group.nr}{selectedElement.prefix ? '_'+ selectedElement.prefix:"" }_{selectedElement.group.name}</div>
|
||||
<ul className="flex flex-col gap-1">
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('band')}>Band</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('gurtfoerderer')}>Gurtfoerderer</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('sieb')}>Sieb</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('band')}>Band</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('setzmaschine')}>Setzmaschine</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('brecher')}>Brecher</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('behaelter')}>Behaelter</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('siebentwaesserung')}>Siebentwaesserung</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('weiche')}>Weiche</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('zyklon')}>Zyklon</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('turbowascher')}>Turbowascher</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('haspel')}>Haspel</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('silo')}>Silo</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('pumpensumpf')}>Pumpensumpf</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('pumpe')}>Pumpe</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('ventil')}>Ventil</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('wasserZufuhr')}>WasserZufuhr</li>
|
||||
<li className="hover:bg-yellow-100 bg-gray-200" onClick={() => setSvgTypeName('motor')}>Motor</li>
|
||||
|
||||
</ul>
|
||||
{svgTypeName ? <button className="rounded hover:bg-sky-200 bg-sky-300 p-4 m-2" onClick={onSave}>Add Element as {svgTypeName}</button> : <div>Bitt SVG Typ Auswählen</div>}
|
||||
</div>
|
||||
:
|
||||
<div>Select Group</div>
|
||||
}
|
||||
<div>
|
||||
<VisuElementList elements={visuElements}></VisuElementList>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
"use client"
|
||||
|
||||
import { useRef, useState, useEffect } from "react";
|
||||
import { SvgVisuElement } from "./svgElement";
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import { api_VisuElementUpdate } from "@/actions/rk/api-visuElements";
|
||||
import { useSvgDrag } from "@/hooks/useSvgDrag";
|
||||
|
||||
interface Props {
|
||||
elements: VisuElement[];
|
||||
}
|
||||
|
||||
export default function VisuContent({ elements }: Props) {
|
||||
const [viewBox, setViewBox] = useState({ x: 0, y: 0, w: 1000, h: 1000 });
|
||||
const [selectedElement, setSelectedElement] = useState<VisuElement | null>(null);
|
||||
const [elementStates, setElementStates] = useState<VisuElement[]>(elements);
|
||||
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
const gridSize = 20;
|
||||
|
||||
const frame = useRef<number | null>(null);
|
||||
|
||||
const { startCanvasDrag, startElementDrag, dragState } = useSvgDrag({svgRef, gridSize, setElementStates, setViewBox,});
|
||||
|
||||
|
||||
|
||||
// 🔥 Screen → SVG
|
||||
const screenToSvg = (clientX: number, clientY: number) => {
|
||||
const svg = svgRef.current!;
|
||||
const pt = svg.createSVGPoint();
|
||||
pt.x = clientX;
|
||||
pt.y = clientY;
|
||||
const transformed = pt.matrixTransform(dragState.current.ctm!);
|
||||
return { x: transformed.x, y: transformed.y };
|
||||
};
|
||||
|
||||
// -----------------------
|
||||
// 🖱 Canvas Pan
|
||||
// -----------------------
|
||||
const handleMouseDownCanvas = (e: React.MouseEvent) => {
|
||||
const svg = svgRef.current!;
|
||||
const ctm = svg.getScreenCTM()!.inverse();
|
||||
|
||||
const pt = svg.createSVGPoint();
|
||||
pt.x = e.clientX;
|
||||
pt.y = e.clientY;
|
||||
const pos = pt.matrixTransform(ctm);
|
||||
|
||||
dragState.current = {
|
||||
type: "canvas",
|
||||
lastX: pos.x,
|
||||
lastY: pos.y,
|
||||
startX: 0,
|
||||
startY: 0,
|
||||
ctm,
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------
|
||||
// 🖱 Element Drag Start
|
||||
// -----------------------
|
||||
const handleStartElementDrag = (element: VisuElement, e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
|
||||
const svg = svgRef.current!;
|
||||
const ctm = svg.getScreenCTM()!.inverse();
|
||||
|
||||
const pt = svg.createSVGPoint();
|
||||
pt.x = e.clientX;
|
||||
pt.y = e.clientY;
|
||||
const pos = pt.matrixTransform(ctm);
|
||||
|
||||
dragState.current = {
|
||||
type: "element",
|
||||
element,
|
||||
lastX: pos.x,
|
||||
lastY: pos.y,
|
||||
startX: element.posX,
|
||||
startY: element.posY,
|
||||
ctm,
|
||||
};
|
||||
};
|
||||
|
||||
// -----------------------
|
||||
// 🖱 GLOBAL MOVE + UP
|
||||
// -----------------------
|
||||
useEffect(() => {
|
||||
const handleMouseMove = (e: MouseEvent) => {
|
||||
if (frame.current) return;
|
||||
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
frame.current = null;
|
||||
|
||||
const state = dragState.current;
|
||||
if (!state.type) return;
|
||||
|
||||
const pos = screenToSvg(e.clientX, e.clientY);
|
||||
const dx = pos.x - state.lastX;
|
||||
const dy = pos.y - state.lastY;
|
||||
|
||||
// 🔥 Element bewegen (stabil!)
|
||||
if (state.type === "element" && state.element) {
|
||||
state.startX += dx;
|
||||
state.startY += dy;
|
||||
|
||||
const newX = Math.round(state.startX);
|
||||
const newY = Math.round(state.startY);
|
||||
|
||||
setElementStates((prev) =>
|
||||
prev.map((el) =>
|
||||
el.id === state.element!.id
|
||||
? { ...el, posX: newX, posY: newY }
|
||||
: el
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// 🔥 Canvas bewegen
|
||||
if (state.type === "canvas") {
|
||||
setViewBox((prev) => ({
|
||||
...prev,
|
||||
x: prev.x - dx,
|
||||
y: prev.y - dy,
|
||||
}));
|
||||
}
|
||||
|
||||
state.lastX = pos.x;
|
||||
state.lastY = pos.y;
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
|
||||
|
||||
|
||||
if (event.code === "Escape") {
|
||||
setSelectedElement(null);
|
||||
dragState.current.type = null;
|
||||
//api_VisuElementUpdate(selectedElement.id, { posX: newPosX, posY: newPosY })
|
||||
return;
|
||||
}
|
||||
const state = dragState.current;
|
||||
if (state.type !== 'selected' || state.type == null) return;
|
||||
let dx = 0;
|
||||
let dy = 0;
|
||||
|
||||
if (!event.shiftKey && event.key === "ArrowRight") dx += 1;
|
||||
if (event.shiftKey && event.key === "ArrowRight") dx += 10;
|
||||
if (!event.shiftKey && event.key === "ArrowLeft") dx -= 1;
|
||||
if (event.shiftKey && event.key === "ArrowLeft") dx -= 10;
|
||||
|
||||
if (!event.shiftKey && event.key === "ArrowDown") dy += 1;
|
||||
if (event.shiftKey && event.key === "ArrowDown") dy += 10;
|
||||
if (!event.shiftKey && event.key === "ArrowUp") dy -= 1;
|
||||
if (event.shiftKey && event.key === "ArrowUp") dy -= 10;
|
||||
if (dx == 0 && dy == 0 || !state.element) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (state) {
|
||||
setElementStates((prev) =>
|
||||
prev.map((el) => {
|
||||
if (el.id !== state.element!.id) return el; // 2
|
||||
|
||||
let newX = el.posX + dx;
|
||||
let newY = el.posY + dy;
|
||||
|
||||
dragState.current.lastX = newX;
|
||||
dragState.current.lastY = newY;
|
||||
let element = { ...el, posX: newX, posY: newY };
|
||||
console.log("se")
|
||||
setSelectedElement(() => element)
|
||||
return element;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const handleMouseUp = () => {
|
||||
const state = dragState.current;
|
||||
|
||||
if (state.type === "element" && state.element) {
|
||||
setElementStates((prev) =>
|
||||
prev.map((el) => {
|
||||
if (el.id !== state.element!.id) return el;
|
||||
|
||||
return {
|
||||
...el,
|
||||
posX: Math.round(el.posX / gridSize) * gridSize,
|
||||
posY: Math.round(el.posY / gridSize) * gridSize,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
dragState.current.type = "selected";
|
||||
} else {
|
||||
dragState.current.type = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
window.addEventListener("mousemove", handleMouseMove);
|
||||
window.addEventListener("mouseup", handleMouseUp);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("mousemove", handleMouseMove);
|
||||
window.removeEventListener("mouseup", handleMouseUp);
|
||||
};
|
||||
}, []);
|
||||
|
||||
// -----------------------
|
||||
// 🎯 Grid
|
||||
// -----------------------
|
||||
const renderGrid = () => {
|
||||
const lines = [];
|
||||
|
||||
for (let x = 0; x < 2560; x += gridSize) {
|
||||
lines.push(
|
||||
<line key={`v-${x}`} x1={x} y1={0} x2={x} y2={1440} stroke="#eee" strokeWidth={0.5} />
|
||||
);
|
||||
}
|
||||
|
||||
for (let y = 0; y < 1440; y += gridSize) {
|
||||
lines.push(
|
||||
<line key={`h-${y}`} x1={0} y1={y} x2={2560} y2={y} stroke="#eee" strokeWidth={0.5} />
|
||||
);
|
||||
}
|
||||
|
||||
return <g>{lines}</g>;
|
||||
};
|
||||
|
||||
// -----------------------
|
||||
// 🎨 Render
|
||||
// -----------------------
|
||||
return (
|
||||
<div>
|
||||
<div className="m-4">{JSON.stringify(selectedElement)}</div>
|
||||
<div className="m-4"> {JSON.stringify(dragState.current)}</div>
|
||||
<div
|
||||
style={{
|
||||
width: 1000,
|
||||
height: 1000,
|
||||
border: "1px solid black",
|
||||
cursor: dragState.current.type === "canvas" ? "grabbing" : "grab",
|
||||
}}
|
||||
onMouseDown={handleMouseDownCanvas}
|
||||
>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
width="100%"
|
||||
height="100%"
|
||||
viewBox={`${viewBox.x} ${viewBox.y} ${viewBox.w} ${viewBox.h}`}
|
||||
>
|
||||
{renderGrid()}
|
||||
|
||||
{elementStates.map((el) => (
|
||||
<SvgVisuElement
|
||||
key={el.id}
|
||||
element={el}
|
||||
selected={selectedElement?.id === el.id}
|
||||
onSelect={() => setSelectedElement(el)}
|
||||
onMouseDown={handleStartElementDrag}
|
||||
/>
|
||||
))}
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
|
||||
"use client"
|
||||
|
||||
import { SvgVisuElement } from "./svgElement";
|
||||
import { useRef, useState } from "react";
|
||||
import { api_VisuElementUpdate } from "@/actions/rk/api-visuElements";
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
|
||||
interface Props {
|
||||
elements: VisuElement[]
|
||||
}
|
||||
/**
|
||||
*
|
||||
🔲 Element Drag (nicht nur Canvas)
|
||||
📦 Resize Handles
|
||||
🧲 Snap to Grid
|
||||
🔍 Zoom Limits + Centering
|
||||
*/
|
||||
export default function VisuContent({ elements }: Props) {
|
||||
const [selectedElement, setSelectedElement] = useState<VisuElement | undefined>();
|
||||
const [elementStates, setElementStates] = useState<VisuElement[]>(elements);
|
||||
const [viewBox, setViewBox] = useState({ x: 0, y: 0, w: 1000, h: 1000 });
|
||||
|
||||
const isPanningRef = useRef(false);
|
||||
const isMouseDown = useRef(false);
|
||||
const lastPos = useRef({ x: 0, y: 0 });
|
||||
const gridSize = 20;
|
||||
|
||||
|
||||
const clamp = (val: number, min: number, max: number) => Math.max(min, Math.min(max, val));
|
||||
|
||||
|
||||
|
||||
const dragThreshold = 5;
|
||||
|
||||
const handleMouseDown = (e: React.MouseEvent) => {
|
||||
//if (!isSpacePressed) return; // 🔥 KEY FIX
|
||||
|
||||
lastPos.current = { x: e.clientX, y: e.clientY };
|
||||
isPanningRef.current = false;
|
||||
isMouseDown.current = true;
|
||||
|
||||
|
||||
};
|
||||
|
||||
const handleMouseUp = () => {
|
||||
isPanningRef.current = false;
|
||||
isMouseDown.current = false;
|
||||
|
||||
};
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent) => {
|
||||
if (!isMouseDown.current) return;
|
||||
|
||||
const dx = e.clientX - lastPos.current.x;
|
||||
const dy = e.clientY - lastPos.current.y;
|
||||
console.log(isPanningRef.current);
|
||||
if (!isPanningRef.current && (Math.abs(dx) > 2 || Math.abs(dy) > 2)) {
|
||||
isPanningRef.current = true;
|
||||
}
|
||||
if (isPanningRef.current) {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
const scaleX = viewBox.w / rect.width;
|
||||
const scaleY = viewBox.h / rect.height;
|
||||
setViewBox((prev) => ({
|
||||
...prev,
|
||||
x: prev.x - dx * scaleX,
|
||||
y: prev.y - dy * scaleY,
|
||||
}));
|
||||
lastPos.current = { x: e.clientX, y: e.clientY };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleWheel = (e: React.WheelEvent) => {
|
||||
e.preventDefault();
|
||||
const zoomFactor = e.deltaY > 0 ? 1.1 : 1 / 1.1;
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
const mouseX = e.clientX - rect.left;
|
||||
const mouseY = e.clientY - rect.top;
|
||||
const scaleX = viewBox.w / rect.width;
|
||||
const scaleY = viewBox.h / rect.height;
|
||||
const svgX = viewBox.x + mouseX * scaleX;
|
||||
const svgY = viewBox.y + mouseY * scaleY;
|
||||
const newW = clamp(viewBox.w * zoomFactor, 200, 2560);
|
||||
const newH = clamp(viewBox.h * zoomFactor, 200, 1440);
|
||||
setViewBox({
|
||||
x: svgX - (mouseX / rect.width) * newW,
|
||||
y: svgY - (mouseY / rect.height) * newH,
|
||||
w: newW,
|
||||
h: newH,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
const handleSelectElement = (element: VisuElement) => {
|
||||
setSelectedElement(element);
|
||||
}
|
||||
|
||||
const handleChangeParameter = (changeData: { posX?: number, posY?: number }) => {
|
||||
console.log(changeData)
|
||||
if (!selectedElement) return;
|
||||
setSelectedElement((c) => c ? { ...c, ...changeData } : undefined)
|
||||
api_VisuElementUpdate(selectedElement.id, { ...changeData })
|
||||
}
|
||||
|
||||
const handleKeyUp = (event: React.KeyboardEvent) => {
|
||||
//if (event.code === "Space") setIsSpacePressed(false);
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: React.KeyboardEvent) => {
|
||||
//if (event.code === "Space") setIsSpacePressed(true);
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if (event.code === "Escape") setSelectedElement(undefined);
|
||||
if (!selectedElement) return;
|
||||
|
||||
let oldPosX = selectedElement.posX;
|
||||
let newPosX = oldPosX;
|
||||
|
||||
let oldPosY = selectedElement.posY;
|
||||
let newPosY = oldPosY;
|
||||
|
||||
if (!event.shiftKey && event.key === "ArrowRight") newPosX += 1;
|
||||
if (event.shiftKey && event.key === "ArrowRight") newPosX += 10;
|
||||
if (!event.shiftKey && event.key === "ArrowLeft") newPosX -= 1;
|
||||
if (event.shiftKey && event.key === "ArrowLeft") newPosX -= 10;
|
||||
|
||||
if (!event.shiftKey && event.key === "ArrowDown") newPosY += 1;
|
||||
if (event.shiftKey && event.key === "ArrowDown") newPosY += 10;
|
||||
if (!event.shiftKey && event.key === "ArrowUp") newPosY -= 1;
|
||||
if (event.shiftKey && event.key === "ArrowUp") newPosY -= 10;
|
||||
|
||||
if (oldPosX != newPosX || oldPosY != newPosY) {
|
||||
if (selectedElement) setSelectedElement((c) => c ? { ...c, posX: newPosX, posY: newPosY } : undefined)
|
||||
api_VisuElementUpdate(selectedElement.id, { posX: newPosX, posY: newPosY })
|
||||
}
|
||||
}
|
||||
|
||||
// Element Drag mit Snap
|
||||
const handleDragElement = (element: VisuElement, dx: number, dy: number) => {
|
||||
setElementStates((prev) =>
|
||||
prev.map((el) => {
|
||||
if (el.id === element.id) {
|
||||
const scaleX = viewBox.w / 1000;
|
||||
const scaleY = viewBox.h / 1000;
|
||||
let newX = el.posX + dx * scaleX;
|
||||
let newY = el.posY + dy * scaleY;
|
||||
|
||||
// Snap-to-Grid
|
||||
newX = Math.round(newX / gridSize) * gridSize;
|
||||
newY = Math.round(newY / gridSize) * gridSize;
|
||||
|
||||
return { ...el, posX: newX, posY: newY };
|
||||
}
|
||||
return el;
|
||||
})
|
||||
);
|
||||
};
|
||||
// Grid Linien rendern
|
||||
const renderGrid = () => {
|
||||
const lines = [];
|
||||
for (let x = 0; x < 2560; x += gridSize) {
|
||||
lines.push(<line key={`v-${x}`} x1={x} y1={0} x2={x} y2={1440} stroke="#eee" strokeWidth={0.5} />);
|
||||
}
|
||||
for (let y = 0; y < 1440; y += gridSize) {
|
||||
lines.push(<line key={`h-${y}`} x1={0} y1={y} x2={2560} y2={y} stroke="#eee" strokeWidth={0.5} />);
|
||||
}
|
||||
return <g>{lines}</g>;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="">
|
||||
|
||||
<div>
|
||||
|
||||
</div>
|
||||
|
||||
<div style={{
|
||||
width: "1000px",
|
||||
height: "1000px",
|
||||
border: "1px solid black",
|
||||
overflow: "hidden",
|
||||
cursor: isPanningRef.current ? "grabbing" : "grab"
|
||||
}}
|
||||
onMouseDown={handleMouseDown}
|
||||
onMouseMove={handleMouseMove}
|
||||
onMouseUp={handleMouseUp}
|
||||
onMouseLeave={handleMouseUp}
|
||||
onWheel={handleWheel}
|
||||
>
|
||||
<svg
|
||||
width="100%"
|
||||
height="100%"
|
||||
viewBox={`${viewBox.x} ${viewBox.y} ${viewBox.w} ${viewBox.h}`}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
|
||||
{renderGrid()}
|
||||
{elementStates.map((ele) => (
|
||||
<SvgVisuElement
|
||||
key={ele.id}
|
||||
element={ele}
|
||||
selected={ele.id === selectedElement?.id}
|
||||
onSelect={() => setSelectedElement(el)}
|
||||
onDrag={handleDragElement}
|
||||
gridSize={gridSize}
|
||||
/>
|
||||
))}
|
||||
|
||||
|
||||
|
||||
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
|
||||
{selectedElement && <div>
|
||||
<input type="number" value={selectedElement.posX} onChange={(v) => handleChangeParameter({ posX: Number.parseFloat(v.target.value) })} />
|
||||
<input type="number" value={selectedElement.posY} onChange={(v) => handleChangeParameter({ posY: Number.parseFloat(v.target.value) })} />
|
||||
<div className="grid grid-cols-[100_50]">
|
||||
<div>Höhe</div>
|
||||
<div>{selectedElement.height}</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<rect width={item.length} height={item.height} fill="#f0f0f0"/>
|
||||
style={{ transform: `scale(${1.0})`, transformOrigin: "top left" }}
|
||||
*/
|
||||
@@ -0,0 +1,72 @@
|
||||
"use client"
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import { SvgVisuElement } from "./svgElement";
|
||||
import { useSvgDrag } from "@/hooks/useSvgDrag";
|
||||
import { useSvgKey } from "@/hooks/useSvgKey";
|
||||
import { useVisuElementContext } from "@/_context/visu/useVisuElementsContext";
|
||||
import VisuElementProps from "./visuElementProps";
|
||||
import VisuContentGrid from "./visuContentGrid";
|
||||
|
||||
interface Props {
|
||||
//elements: VisuElement[];
|
||||
}
|
||||
|
||||
export default function VisuContent({ }: Props) {
|
||||
const height = 1120;
|
||||
const width = 1810;
|
||||
const raster = 20;
|
||||
|
||||
const { state, dispatch } = useVisuElementContext();
|
||||
const [viewBox, setViewBox] = useState({ x: 0, y: 0, w: 1820, h: 1120 });
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
|
||||
|
||||
|
||||
const { startCanvasDrag, startElementDrag, handleWheel } = useSvgDrag({ svgRef, gridSize: raster, setViewBox, });
|
||||
const {onKeyDown } = useSvgKey({enabled:true} )
|
||||
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[1fr_200px] w-[2000]" tabIndex={0}>
|
||||
<div
|
||||
style={{
|
||||
width: width,
|
||||
height: height,
|
||||
border: "1px solid black",
|
||||
cursor: state.drag.mode === "canvas" ? "grabbing" : "grab",
|
||||
}}
|
||||
onMouseDown={startCanvasDrag}
|
||||
onWheel={handleWheel}
|
||||
>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
width="100%"
|
||||
height="100%"
|
||||
viewBox={`${viewBox.x} ${viewBox.y} ${viewBox.w} ${viewBox.h}`}
|
||||
onKeyDown={(e)=>onKeyDown(e)}
|
||||
>
|
||||
<VisuContentGrid height={height} width={width} raster={raster} />
|
||||
|
||||
{state.elements.map((el) => (
|
||||
<SvgVisuElement
|
||||
key={el.id}
|
||||
element={el}
|
||||
selected={state.selectedElement?.id === el.id}
|
||||
onElementMouseDown={(element,e) => startElementDrag(element, e)}
|
||||
/>
|
||||
))}
|
||||
</svg>
|
||||
</div>
|
||||
{state.selectedElement && <VisuElementProps onChange={(element) => console.log('on change n.v.') }/>}
|
||||
|
||||
{true &&
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="m-4">{JSON.stringify(state.selectedElement)}</div>
|
||||
<div className="m-4"> {JSON.stringify(state.drag)}</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
interface Props {
|
||||
height:number;
|
||||
width:number;
|
||||
raster:number;
|
||||
}
|
||||
|
||||
export default function VisuContentGrid({ height,width,raster }: Props) {
|
||||
const renderGrid = () => {
|
||||
const Lines = [];
|
||||
|
||||
for (let x = 0; x < width; x += raster) {
|
||||
Lines.push(<line key={`v-${x}`} x1={x} y1={0} x2={x} y2={height} stroke="#eee" strokeWidth={0.5} />);
|
||||
}
|
||||
|
||||
for (let y = 0; y < height; y += raster) {
|
||||
Lines.push(<line key={`h-${y}`} x1={0} y1={y} x2={width} y2={y} stroke="#eee" strokeWidth={0.5} />);
|
||||
}
|
||||
Lines.push(<rect key={`r-${height}`} x={0} y={0} height={height} width={width} stroke="#000" strokeWidth={1.5} fill="none" />)
|
||||
|
||||
return Lines;
|
||||
};
|
||||
|
||||
|
||||
|
||||
return <g>
|
||||
|
||||
{renderGrid()}
|
||||
</g>
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
elements: VisuElement[],
|
||||
onSelect?: (item: VisuElement) => void
|
||||
}
|
||||
|
||||
export default function VisuElementListOld({ elements, onSelect }: Props) {
|
||||
|
||||
const handleSelect = (item: VisuElement) => {
|
||||
if (onSelect) onSelect(item);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-1">
|
||||
<div className="flex flex-col m-4">
|
||||
{elements.map((item) => (
|
||||
<div className="flex hover:bg-sky-100 h-8 items-center" onClick={() => handleSelect(item)} key={item.id}>
|
||||
{item.group ?
|
||||
<div className="ps-4 ">{`${item.group.nr} ${item.group.name}`}</div>
|
||||
:
|
||||
<div className="ps-4 ">{`${item.id} no Group`}</div>
|
||||
}
|
||||
{item.elementId ?
|
||||
<div className="ps-4 ">{item.elementId} </div>
|
||||
:
|
||||
<div className="ps-4 ">{`${item.id} no Element`}</div>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import { api_VisuElementUpdate } from "@/actions/rk/api-visuElements";
|
||||
import VisuLineProps from "./visuLineProps";
|
||||
import { VisuLine, VisuLinePoint } from "@/types/visu/visuLine.types";
|
||||
import { useVisuElementContext } from "@/_context/visu/useVisuElementsContext";
|
||||
import { useNumberInput } from "@/hooks/useNumberInput";
|
||||
|
||||
interface Props {
|
||||
|
||||
onChange: (updatedElement: VisuElement) => void;
|
||||
}
|
||||
|
||||
export default function VisuElementProps({ onChange }: Props) {
|
||||
const { state, dispatch } = useVisuElementContext();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------
|
||||
// 🔄 UPDATE STATE ONLY
|
||||
// -----------------------
|
||||
const updateField = <K extends keyof VisuElement>(field: K) => {
|
||||
let element = state.selectedElement;
|
||||
|
||||
return (value: VisuElement[K]) => {
|
||||
if(!element) return;
|
||||
dispatch({
|
||||
type: "UPDATE_ELEMENT",
|
||||
payload: {
|
||||
...element,
|
||||
[field]: value,
|
||||
},
|
||||
});
|
||||
|
||||
api_VisuElementUpdate(element.id, {
|
||||
[field]: value,
|
||||
});
|
||||
};
|
||||
};
|
||||
if(!state.selectedElement) return <div>No Selection</div>
|
||||
const scaleInput = useNumberInput({ value: state.selectedElement.scale, fallback: 1, min: 0.1, onCommit: updateField("scale"), });
|
||||
const widthInput = useNumberInput({ value: state.selectedElement.width, fallback: 5, min: 1, onCommit: updateField("width"), });
|
||||
const heightInput = useNumberInput({ value: state.selectedElement.height, fallback: 5, min: 1, onCommit: updateField("height"), });
|
||||
const rasterInput = useNumberInput({ value: state.selectedElement.raster, fallback: 5, min: 1, onCommit: updateField("raster"), });
|
||||
const posXInput = useNumberInput({ value: state.selectedElement.posX, fallback: 5, min: 1, onCommit: updateField("posX"), });
|
||||
const posYInput = useNumberInput({ value: state.selectedElement.posY, fallback: 5, min: 1, onCommit: updateField("posY"), });
|
||||
const angleInput = useNumberInput({ value: state.selectedElement.angle, fallback: 0, onCommit: updateField("angle"), });
|
||||
|
||||
|
||||
|
||||
const handleChangeLine = (line: VisuLine, index: number) => {
|
||||
if (!state.selectedElement?.lines) return;
|
||||
|
||||
const lines = state.selectedElement.lines;
|
||||
if (lines && index < lines.length) {
|
||||
lines[index] = line;
|
||||
api_VisuElementUpdate(state.selectedElement.id, { lines: lines })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const addLine = ()=>{
|
||||
let element = state.selectedElement;
|
||||
if(!element) return;
|
||||
if(!element.lines) element['lines'] = [];
|
||||
|
||||
element?.lines?.push({bezeichnung:"ausgang",color:"#202020",offsetX:0,offsetY:0,points:[{x:0,y:0},{x:0,y:50},{x:50,y:50}]});
|
||||
console.log(element)
|
||||
dispatch({type:"UPDATE_ELEMENT",payload:element})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
|
||||
<div className="h-200 w-200 bg-gray-100 p-2">
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>X</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="posX"
|
||||
type="number"
|
||||
{...posXInput}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Y</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="posY"
|
||||
type="number"
|
||||
{...posYInput}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Scalierung</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="scale"
|
||||
type="number"
|
||||
{...scaleInput}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Raster</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="raster"
|
||||
type="number"
|
||||
{...rasterInput}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Länge</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="width"
|
||||
type="number"
|
||||
{...widthInput}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Höhe</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="height"
|
||||
type="number"
|
||||
{...heightInput}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Winkel</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="angle"
|
||||
type="number"
|
||||
{...angleInput}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Länge Pixel</label>
|
||||
<div>{state.selectedElement.px_width}</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>Höhe Pixel</label>
|
||||
<div>{state.selectedElement.px_height}</div>
|
||||
|
||||
</div>
|
||||
{ <div><button onClick={addLine}>Add Line</button></div> }
|
||||
{state.selectedElement.lines?.map((line, index) => <VisuLineProps key={index} line={line} onChangePoints={(line) => handleChangeLine(line, index)}></VisuLineProps>)}
|
||||
|
||||
</div>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
"use client"
|
||||
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { emptyVisuElement, VisuElement, VisuElementCreate, VisuElementUpdate } from "@/types/visu/visuElements.types";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { InputTextR } from "@/components/ui/inputTextR";
|
||||
import { api_VisuElementUpdate } from "@/actions/rk/api-visuElements";
|
||||
import { Element } from "@/types/rk";
|
||||
import { SelectR } from "@/components/ui/selectR";
|
||||
|
||||
|
||||
interface Props {
|
||||
visuElement: VisuElement,
|
||||
elements: Element[]
|
||||
}
|
||||
|
||||
export default function VisuElementItem({ visuElement, elements }: Props) {
|
||||
|
||||
const { control, register, handleSubmit, formState: { errors }, watch, getFieldState, reset } = useForm<VisuElementUpdate>({ defaultValues: emptyVisuElement, })
|
||||
const [id, setId] = useState("");
|
||||
|
||||
const cols = [300, 200, 300];
|
||||
|
||||
useEffect(() => {
|
||||
if (visuElement) {
|
||||
const { id,elementId, ...rest } = visuElement;
|
||||
setId(id);
|
||||
reset({ ...rest,elementId })
|
||||
}
|
||||
}, [visuElement]);
|
||||
|
||||
const onSubmit = async (data: VisuElementUpdate) => {
|
||||
console.log('submitt')
|
||||
await api_VisuElementUpdate(id,data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="max-w-md mx-auto">
|
||||
<div className="grid grid-cols-[250_200_200] gap-4 mb-1">
|
||||
<InputTextR {...register("name", {})} error={errors.name?.message} />
|
||||
<SelectR options={elements.map((el) => ({ id: el.id, value: el.group.nr +" "+ el.name }))} {...register("elementId", {})} error={errors.elementId?.message} />
|
||||
<button type="submit" className="bg-blue-500 text-white rounded hover:bg-blue-600">Speichern</button>
|
||||
{false && <div>
|
||||
<pre>{JSON.stringify(getFieldState("elementId"), null, 2)}</pre>
|
||||
<pre>{JSON.stringify(watch(), null, 2)}</pre>
|
||||
</div>}
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"use client"
|
||||
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { VisuElement } from "@/types/visu/visuElements.types";
|
||||
import VisuElementItem from "./visuElementItem";
|
||||
import { Element } from "@/types/rk";
|
||||
|
||||
|
||||
interface Props {
|
||||
visuElements: VisuElement[],
|
||||
elements:Element[]
|
||||
|
||||
}
|
||||
|
||||
export default function VisuElementsList({ visuElements,elements }: Props) {
|
||||
|
||||
const cols = [300, 200, 300];
|
||||
|
||||
const head = () => {
|
||||
return <div className={`grid font-bold border-b mb-1 pt-2 pb-2`}
|
||||
style={{
|
||||
gridTemplateColumns: cols.map(c => `${c}px`).join(" ")
|
||||
}}>
|
||||
<div>Group</div>
|
||||
<div>Name</div>
|
||||
<div>SVG Name</div>
|
||||
</div>
|
||||
|
||||
}
|
||||
|
||||
const show = () => {
|
||||
return visuElements.map((item) =>
|
||||
<div key={item.id}
|
||||
className="grid"
|
||||
style={{
|
||||
gridTemplateColumns: cols.map(c => `${c}px`).join(" ")
|
||||
}}
|
||||
>
|
||||
<div>{item.group.nr}_{item.group.name}</div>
|
||||
<div><VisuElementItem visuElement={item} elements={elements}></VisuElementItem> </div>
|
||||
|
||||
|
||||
</div>)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[1200]">
|
||||
{head()}
|
||||
{show()}
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"use client"
|
||||
|
||||
import { VisuLinePoint } from "@/types/visu/visuLine.types";
|
||||
import { useNumberInput } from "@/hooks/useNumberInput";
|
||||
|
||||
interface Props {
|
||||
index: number;
|
||||
point: VisuLinePoint;
|
||||
|
||||
onChangePoints: (index: number, point: Partial<VisuLinePoint>) => void;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default function VisuLinePointInput({ index, point, onChangePoints }: Props) {
|
||||
|
||||
|
||||
const update = (field: 'x' | 'y', value: number) => {
|
||||
|
||||
let point: Partial<VisuLinePoint> = {}
|
||||
if (field === 'x') point['x'] = value;
|
||||
if (field === 'y') point['y'] = value;
|
||||
|
||||
|
||||
onChangePoints(index, point);
|
||||
}
|
||||
|
||||
const posX = useNumberInput({ value: point.x, onCommit: (value) => update('x', value), });
|
||||
const posY = useNumberInput({ value: point.y, onCommit: (value) => update('y', value), });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
|
||||
<div className="grid grid-cols-[50_200_200] gap-1" >
|
||||
<div>{index}</div>
|
||||
<div className="grid grid-cols-[50_100]">
|
||||
<label>X</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
type="number"
|
||||
{...posX}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[50_100]">
|
||||
<label>Y</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
type="number"
|
||||
{...posY}
|
||||
/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
"use client"
|
||||
|
||||
import { VisuLine, VisuLinePoint } from "@/types/visu/visuLine.types";
|
||||
import VisuLinePointInput from "./visuLinePointInput";
|
||||
import { useNumberInput } from "@/hooks/useNumberInput";
|
||||
|
||||
|
||||
interface Props {
|
||||
line: VisuLine;
|
||||
onChangePoints: (points: VisuLine) => void;
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default function VisuLineProps({ line, onChangePoints }: Props) {
|
||||
|
||||
const offsetX = useNumberInput({ value: line.offsetX, onCommit: (value) => update('offsetX', value), });
|
||||
const offsetY = useNumberInput({ value: line.offsetY, onCommit: (value) => update('offsetY', value), });
|
||||
|
||||
|
||||
const changeLinePoint = (index: number, point: Partial<VisuLinePoint>) => {
|
||||
let newLine = { ...line }
|
||||
let points = [...newLine.points];
|
||||
|
||||
if (point.x != undefined) points[index].x = point.x;
|
||||
if (point.y != undefined) points[index].y = point.y;
|
||||
//if(!newLine.points) newLine['points'] = []
|
||||
newLine['points'] = points;
|
||||
onChangePoints(newLine);
|
||||
|
||||
}
|
||||
|
||||
const update = (field: 'offsetX' | 'offsetY', value: number) => {
|
||||
let newLine = { ...line }
|
||||
|
||||
let point: Partial<VisuLinePoint> = {}
|
||||
if (field === 'offsetX') newLine['offsetX'] = value;
|
||||
if (field === 'offsetY') newLine['offsetY'] = value;
|
||||
|
||||
|
||||
|
||||
onChangePoints(newLine);
|
||||
}
|
||||
|
||||
const addPoint = (index: number) => {
|
||||
let newLine = { ...line }
|
||||
let points = newLine.points;
|
||||
newLine.points.splice(index + 1, 0, { x: 0, y: 0 });
|
||||
let point: Partial<VisuLinePoint> = {}
|
||||
onChangePoints(newLine);
|
||||
|
||||
}
|
||||
|
||||
const removePoint = (index: number) => {
|
||||
let newLine = { ...line }
|
||||
|
||||
newLine.points.splice(index, 1);
|
||||
|
||||
onChangePoints(newLine);
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
|
||||
<div className="p-2">
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>OffsetX</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="offsetX"
|
||||
type="number"
|
||||
{...offsetX}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[100_100_10]">
|
||||
<label>OffsetY</label>
|
||||
<input className="bg-white p-1 me-1"
|
||||
name="offsetY"
|
||||
type="number"
|
||||
{...offsetY}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-[50_100_100] bg-gray-300 mb-1 p-1">
|
||||
<div>Nr</div>
|
||||
<div>x</div>
|
||||
<div>y</div>
|
||||
</div>
|
||||
|
||||
{line.points.map((point, index) =>
|
||||
<div key={index} className="flex">
|
||||
<VisuLinePointInput
|
||||
index={index}
|
||||
point={point}
|
||||
onChangePoints={changeLinePoint} />
|
||||
<button onClick={() => addPoint(index)}>Add</button>
|
||||
<button onClick={() => removePoint(index)}>Remove</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
"use client"
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
|
||||
|
||||
interface Props {
|
||||
}
|
||||
|
||||
type Pos = { x: number; y: number };
|
||||
type Point = { id: number, x: number; y: number };
|
||||
|
||||
export default function VisuCreatePlatform({ }: Props) {
|
||||
const x = 0;
|
||||
const y = 0;
|
||||
|
||||
const [pos, setPos] = useState<Pos>({ x: 0, y: 0 });
|
||||
const frame = useRef<number | null>(null);
|
||||
const latest = useRef<Pos>({ x: 0, y: 0 });
|
||||
|
||||
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
|
||||
latest.current = {
|
||||
x: e.clientX - rect.left,
|
||||
y: e.clientY - rect.top,
|
||||
};
|
||||
|
||||
if (frame.current === null) {
|
||||
frame.current = requestAnimationFrame(() => {
|
||||
setPos(latest.current);
|
||||
frame.current = null;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div style={{ padding: "20px" }}>
|
||||
<h2>Mausposition</h2>
|
||||
<p>X: {pos.x}</p>
|
||||
<p>Y: {pos.y}</p>
|
||||
</div>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user