Compare commits

...

11 Commits

Author SHA1 Message Date
8a5a4f5c67 - added OSD configuration components and hooks for managing overlay settings 2025-12-06 21:16:11 +00:00
f0587a2b43 - improved layouts across app
- adjusted card spacing
2025-12-05 17:01:57 +00:00
9e89193747 - finally fixed custom imput to match what is on backend on sighting amend endpoint 2025-12-05 12:53:42 +00:00
9208470e53 - addressing feedback 2025-12-04 19:14:14 +00:00
3af4e585e7 Merge pull request '- added formik custom fields to settings and output' (#14) from enhancement/customFields into develop
Reviewed-on: #14
2025-12-04 09:55:18 +00:00
7f9923167e - added formik custom fields to settings and output 2025-12-03 19:51:02 +00:00
018203b203 Merge pull request '- improved statuses acress dashboard and child cards' (#13) from enhancement/statusIndicators into develop
Reviewed-on: #13
2025-12-03 16:06:14 +00:00
173b1d0e51 - improved statuses acress dashboard and child cards 2025-12-03 16:05:06 +00:00
9b35deaf12 Merge pull request '- Enhance layout and responsiveness of camera components' (#12) from enhancement/videoFeed into develop
Reviewed-on: #12
2025-12-03 13:42:43 +00:00
59bcb3c45b - Enhance layout and responsiveness of camera components
- update system health hook for periodic refetching
2025-12-03 13:39:18 +00:00
10590e5658 Merge pull request 'enhancement/dashboardFeedback' (#11) from enhancement/dashboardFeedback into develop
Reviewed-on: #11
2025-12-03 10:58:07 +00:00
27 changed files with 789 additions and 237 deletions

View File

@@ -9,25 +9,25 @@ export const initialState: CameraFeedState = {
}, },
regionsByCamera: { regionsByCamera: {
A: [ A: [
{ name: "Region 1", brushColour: "#ff0000" }, { name: "Bay 1", brushColour: "#ff0000" },
{ name: "Region 2", brushColour: "#00ff00" }, { name: "Bay 2", brushColour: "#00ff00" },
{ name: "Region 3", brushColour: "#0400ff" }, { name: "Bay 3", brushColour: "#0400ff" },
{ name: "Region 4", brushColour: "#ffff00" }, { name: "Bay 4", brushColour: "#ffff00" },
{ name: "Region 5", brushColour: "#fc35db" }, { name: "Bay 5", brushColour: "#fc35db" },
], ],
B: [ B: [
{ name: "Region 1", brushColour: "#ff0000" }, { name: "Bay 1", brushColour: "#ff0000" },
{ name: "Region 2", brushColour: "#00ff00" }, { name: "Bay 2", brushColour: "#00ff00" },
{ name: "Region 3", brushColour: "#0400ff" }, { name: "Bay 3", brushColour: "#0400ff" },
{ name: "Region 4", brushColour: "#ffff00" }, { name: "Bay 4", brushColour: "#ffff00" },
{ name: "Region 5", brushColour: "#fc35db" }, { name: "Bay 5", brushColour: "#fc35db" },
], ],
C: [ C: [
{ name: "Region 1", brushColour: "#ff0000" }, { name: "Bay 1", brushColour: "#ff0000" },
{ name: "Region 2", brushColour: "#00ff00" }, { name: "Bay 2", brushColour: "#00ff00" },
{ name: "Region 3", brushColour: "#0400ff" }, { name: "Bay 3", brushColour: "#0400ff" },
{ name: "Region 4", brushColour: "#ffff00" }, { name: "Bay 4", brushColour: "#ffff00" },
{ name: "Region 5", brushColour: "#fc35db" }, { name: "Bay 5", brushColour: "#fc35db" },
], ],
}, },

View File

@@ -9,10 +9,16 @@ const CameraGrid = () => {
const [tabIndex, setTabIndex] = useState(0); const [tabIndex, setTabIndex] = useState(0);
return ( return (
<div className="grid grid-cols-1 md:grid-cols-5 md:grid-rows-5 max-h-screen"> <div className="grid grid-cols-1 md:grid-cols-3 gap-4 p-4 h-screen max-h-screen overflow-hidden">
<VideoFeedGridPainter /> <div className="col-span-2 flex flex-col gap-4">
<div className="shrink-0">
<VideoFeedGridPainter />
</div>
<div className="flex-1 overflow-hidden">
<PlatePatch />
</div>
</div>
<CameraSettings tabIndex={tabIndex} setTabIndex={setTabIndex} /> <CameraSettings tabIndex={tabIndex} setTabIndex={setTabIndex} />
<PlatePatch />
</div> </div>
); );
}; };

View File

@@ -10,7 +10,7 @@ type CameraSettingsProps = {
const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => { const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => {
return ( return (
<Card className="p-4 col-span-2 row-span-5 col-start-3 md:col-span-3 md:row-span-5 overflow-auto"> <Card className="p-4 w-full h-full max-h-screen ">
<Tabs <Tabs
selectedTabClassName="bg-gray-300 text-gray-900 font-semibold border-none rounded-sm mb-1" selectedTabClassName="bg-gray-300 text-gray-900 font-semibold border-none rounded-sm mb-1"
className="react-tabs" className="react-tabs"

View File

@@ -19,14 +19,6 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: e.target.value } }); dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: e.target.value } });
}; };
const handleAddRegionClick = () => {
const regionName = `Region ${regions.length + 1}`;
dispatch({
type: "ADD_NEW_REGION",
payload: { cameraFeedID: cameraFeedID, regionName: regionName, brushColour: "#ffffff" },
});
};
const handleResetRegion = () => { const handleResetRegion = () => {
dispatch({ dispatch({
type: "RESET_PAINTED_CELLS", type: "RESET_PAINTED_CELLS",
@@ -34,13 +26,6 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}); });
}; };
const handleRemoveClick = () => {
dispatch({
type: "REMOVE_REGION",
payload: { cameraFeedID: cameraFeedID, regionName: regions[selectedRegionIndex].name },
});
};
const handleModeChange = (newMode: string) => { const handleModeChange = (newMode: string) => {
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: newMode } }); dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: newMode } });
}; };
@@ -58,14 +43,29 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}); });
}; };
const handleAddRegionClick = () => {
const regionName = `Bay ${regions.length + 1}`;
dispatch({
type: "ADD_NEW_REGION",
payload: { cameraFeedID: cameraFeedID, regionName: regionName, brushColour: "#ffffff" },
});
};
const handleRemoveClick = () => {
dispatch({
type: "REMOVE_REGION",
payload: { cameraFeedID: cameraFeedID, regionName: regions[selectedRegionIndex].name },
});
};
const handleSaveclick = () => { const handleSaveclick = () => {
const regions: ColourData[] = []; const regions: ColourData[] = [];
const test = Array.from(paintedCells.entries()); const test = Array.from(paintedCells.entries());
const region1 = test.filter(([, cell]) => cell.region.name === "Region 1"); const region1 = test.filter(([, cell]) => cell.region.name === "Bay 1");
const region2 = test.filter(([, cell]) => cell.region.name === "Region 2"); const region2 = test.filter(([, cell]) => cell.region.name === "Bay 2");
const region3 = test.filter(([, cell]) => cell.region.name === "Region 3"); const region3 = test.filter(([, cell]) => cell.region.name === "Bay 3");
const region4 = test.filter(([, cell]) => cell.region.name === "Region 4"); const region4 = test.filter(([, cell]) => cell.region.name === "Bay 4");
const region5 = test.filter(([, cell]) => cell.region.name === "Region 5"); const region5 = test.filter(([, cell]) => cell.region.name === "Bay 5");
const region1Data = { const region1Data = {
id: 1, id: 1,
cells: region1.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]), cells: region1.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
@@ -106,99 +106,105 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
}; };
return ( return (
<div className="grid grid-cols-1 md:grid-cols-2 md:grid-rows-2 gap-4"> <div className="flex flex-col gap-4 max-h-[50%]">
<div className="p-2 border border-gray-600 rounded-lg flex flex-col"> <div className="flex flex-row gap-3">
<h2 className="text-2xl mb-2">Tools</h2> <div className="p-2 border border-gray-600 rounded-lg flex flex-col h-50 w-full">
<div className="flex flex-col"> <h2 className="text-2xl mb-2">Tools</h2>
<label <div className="flex flex-col">
htmlFor="paintMode" <label
className={`p-4 border rounded-lg mb-2 htmlFor="paintMode"
className={`p-4 border rounded-lg mb-2
${mode === "painter" ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"} ${mode === "painter" ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"}
hover:bg-[#202b36] hover:cursor-pointer`} hover:bg-[#202b36] hover:cursor-pointer`}
> >
<input <input
id="paintMode" id="paintMode"
type="radio" type="radio"
onChange={handleChange} onChange={handleChange}
checked={mode === "painter"} checked={mode === "painter"}
value="painter" value="painter"
className="sr-only" className="sr-only"
/> />
<span className="text-xl">Paint mode</span> <span className="text-xl">Paint mode</span>
</label> </label>
<label <label
htmlFor="eraseMode" htmlFor="eraseMode"
className={`p-4 border rounded-lg mb-2 className={`p-4 border rounded-lg mb-2
${mode === "eraser" ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"} ${mode === "eraser" ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"}
hover:bg-[#202b36] hover:cursor-pointer`} hover:bg-[#202b36] hover:cursor-pointer`}
> >
<input <input
id="eraseMode" id="eraseMode"
type="radio" type="radio"
onChange={handleChange} onChange={handleChange}
checked={mode === "eraser"} checked={mode === "eraser"}
value={"eraser"} value={"eraser"}
className="sr-only" className="sr-only"
/> />
<span className="text-xl">Erase mode</span> <span className="text-xl">Erase mode</span>
</label> </label>
</div>
</div> </div>
</div>
<div className="p-2 border border-gray-600 rounded-lg flex flex-col"> <div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full">
<h2 className="text-2xl mb-2">Region Select</h2> <h2 className="text-2xl mb-2">Bay Select</h2>
<> <>
{regions?.map((region, idx) => { {regions?.map((region, idx) => {
const isSelected = selectedRegionIndex === idx; const isSelected = selectedRegionIndex === idx;
const inputId = `region-${idx}`; const inputId = `region-${idx}`;
return ( return (
<label <label
htmlFor={inputId} htmlFor={inputId}
key={region.name} key={region.name}
className={`items-center p-4 m-1 rounded-xl border flex flex-row justify-between className={`items-center p-4 m-1 rounded-xl border flex flex-row justify-between
${isSelected ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"} hover:bg-[#202b36] hover:cursor-pointer`} ${isSelected ? "border-gray-400 bg-[#202b36]" : "bg-[#253445] border-gray-700"} hover:bg-[#202b36] hover:cursor-pointer`}
> >
<div className="flex flex-row gap-4 items-center"> <div className="flex flex-row gap-4 items-center">
<input <input
type="radio" type="radio"
checked={isSelected} checked={isSelected}
id={inputId} id={inputId}
name="region" name="region"
className="sr-only" className="sr-only"
onChange={() => { onChange={() => {
handleModeChange("painter"); handleModeChange("painter");
handleRegionSelect(idx); handleRegionSelect(idx);
}} }}
/>
<span className="text-xl">{region.name}</span>
</div>
<ColourPicker
colour={region.brushColour}
setColour={(c: string) => handleRegionColourChange(idx, c)}
/> />
<span className="text-xl">{region.name}</span> <div></div>
</div> </label>
<ColourPicker colour={region.brushColour} setColour={(c: string) => handleRegionColourChange(idx, c)} /> );
<div></div> })}
</label> </>
); <div className="flex flex-col gap-4 mt-4">
})} <button className="border border-blue-900 bg-blue-700 px-4 py-1 rounded-md" onClick={handleAddRegionClick}>
</> Add Bay
<div className=" mx-auto flex flex-row gap-4 mt-4"> </button>
<button className="border border-blue-900 bg-blue-700 px-4 py-1 rounded-md" onClick={handleAddRegionClick}> <button className="border border-red-900 bg-red-700 px-4 py-1 rounded-md" onClick={handleRemoveClick}>
Add Region Remove Bay
</button> </button>
<button className="border border-red-900 bg-red-700 px-4 py-1 rounded-md" onClick={handleRemoveClick}> </div>
Remove Region
</button>
</div> </div>
</div> </div>
<div className="p-2 border border-gray-600 rounded-lg flex flex-col md:col-span-2 h-50"> <div className="p-2 border border-gray-600 rounded-lg flex flex-col w-full">
<div className="flex flex-col"> <h2 className="text-2xl mb-2">Actions</h2>
<h2 className="text-2xl mb-2">Actions</h2> <div className="flex flex-col md:flex-row mx-auto gap-4 justify-center">
<button <button
onClick={handleSaveclick} onClick={handleSaveclick}
className="mt-2 px-4 py-2 border border-blue-600 rounded-md text-white bg-blue-600 w-full md:w-[40%] hover:bg-blue-700 hover:cursor-pointer" className="mt-2 px-4 py-2 border border-blue-600 rounded-md text-white bg-blue-600 w-full md:w-full hover:bg-blue-700 hover:cursor-pointer"
> >
Save Region Save Region
</button> </button>
<button <button
onClick={handleResetRegion} onClick={handleResetRegion}
className="mt-2 px-4 py-2 border border-red-600 rounded-md text-white bg-red-600 w-full md:w-[40%] hover:bg-red-700 hover:cursor-pointer" className="mt-2 px-4 py-2 border border-red-600 rounded-md text-white bg-red-600 w-full md:w-full hover:bg-red-700 hover:cursor-pointer"
> >
Reset Region Reset Region
</button> </button>

View File

@@ -18,7 +18,7 @@ const SightingEntryTable = () => {
<thead className="bg-gray-700/50 text-gray-200 sticky top-0"> <thead className="bg-gray-700/50 text-gray-200 sticky top-0">
<tr> <tr>
<th className="px-4 py-3 font-semibold">VRM</th> <th className="px-4 py-3 font-semibold">VRM</th>
<th className="px-4 py-3 font-semibold">Lane ID</th> <th className="px-4 py-3 font-semibold">Bay ID</th>
<th className="px-4 py-3 font-semibold text-center">Seen Count</th> <th className="px-4 py-3 font-semibold text-center">Seen Count</th>
<th className="px-4 py-3 font-semibold">First Seen</th> <th className="px-4 py-3 font-semibold">First Seen</th>
<th className="px-4 py-3 font-semibold">Last Seen</th> <th className="px-4 py-3 font-semibold">Last Seen</th>

View File

@@ -18,7 +18,7 @@ const SightingExitTable = () => {
<thead className="bg-gray-700/50 text-gray-200 sticky top-0"> <thead className="bg-gray-700/50 text-gray-200 sticky top-0">
<tr> <tr>
<th className="px-4 py-3 font-semibold">VRM</th> <th className="px-4 py-3 font-semibold">VRM</th>
<th className="px-4 py-3 font-semibold">Lane ID</th> <th className="px-4 py-3 font-semibold">Bay ID</th>
<th className="px-4 py-3 font-semibold text-center">Seen Count</th> <th className="px-4 py-3 font-semibold text-center">Seen Count</th>
<th className="px-4 py-3 font-semibold">First Seen</th> <th className="px-4 py-3 font-semibold">First Seen</th>
<th className="px-4 py-3 font-semibold">Last Seen</th> <th className="px-4 py-3 font-semibold">Last Seen</th>

View File

@@ -6,9 +6,9 @@ import SightingExitTable from "./SightingExitTable";
const PlatePatch = () => { const PlatePatch = () => {
return ( return (
<Card className="md:row-start-4 md:col-span-2 p-4 h-[190%]"> <Card className="p-4 w-full max-h-[600px] overflow-hidden flex flex-col">
<CardHeader title="Entry / Exit" /> <CardHeader title="Entry / Exit" />
<Tabs> <Tabs defaultIndex={1} className="flex-1 overflow-hidden flex flex-col">
<TabList> <TabList>
<Tab>Entry Sightings</Tab> <Tab>Entry Sightings</Tab>
<Tab>Exit Sightings</Tab> <Tab>Exit Sightings</Tab>

View File

@@ -93,7 +93,7 @@ const VideoFeedGridPainter = () => {
const width = window.innerWidth; const width = window.innerWidth;
const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT; const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT;
const newWidth = width * 0.39; const newWidth = width * 0.6;
const newHeight = newWidth / aspectRatio; const newHeight = newWidth / aspectRatio;
setStageSize({ width: newWidth, height: newHeight }); setStageSize({ width: newWidth, height: newHeight });
}; };
@@ -107,7 +107,7 @@ const VideoFeedGridPainter = () => {
if (image === null || isloading) return <span className="text-slate-500">Loading Video feed</span>; if (image === null || isloading) return <span className="text-slate-500">Loading Video feed</span>;
return ( return (
<div <div
className={`mt-4.5 row-span-1 col-span-2 ${mode === "painter" ? "hover:cursor-crosshair" : ""} ${ className={`w-full md:row-span-3 md:col-span-3 ${mode === "painter" ? "hover:cursor-crosshair" : ""} ${
mode === "eraser" ? "hover:cursor-pointer" : "" mode === "eraser" ? "hover:cursor-pointer" : ""
}`} }`}
> >
@@ -118,6 +118,7 @@ const VideoFeedGridPainter = () => {
onMouseMove={handleStageMouseMove} onMouseMove={handleStageMouseMove}
onMouseUp={handleStageMouseUp} onMouseUp={handleStageMouseUp}
onMouseLeave={handleStageMouseUp} onMouseLeave={handleStageMouseUp}
className="max-w-[55%]"
> >
<Layer> <Layer>
<Image image={image} width={stageSize.width} height={stageSize.height} classname={"rounded-lg"} /> <Image image={image} width={stageSize.width} height={stageSize.height} classname={"rounded-lg"} />

View File

@@ -35,7 +35,7 @@ const DashboardGrid = () => {
const categoryC = statusCategories?.channelC ?? []; const categoryC = statusCategories?.channelC ?? [];
return ( return (
<div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2"> <div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2 gap-4">
<SystemStatusCard /> <SystemStatusCard />
<SystemHealthCard <SystemHealthCard
startTime={startTime} startTime={startTime}
@@ -46,10 +46,10 @@ const DashboardGrid = () => {
dateUpdatedAt={dateUpdatedAt} dateUpdatedAt={dateUpdatedAt}
refetch={refetch} refetch={refetch}
/> />
<div className="grid grid-cols-1 md:col-span-2 md:grid-cols-3"> <div className="grid grid-cols-1 md:col-span-2 md:grid-cols-3 gap-x-4">
<CameraStatus title="Camera A" category={categoryA} /> <CameraStatus title="Camera A" category={categoryA} isError={isError} />
<CameraStatus title="Camera B" category={categoryB} /> <CameraStatus title="Camera B" category={categoryB} isError={isError} />
<CameraStatus title="Camera C" category={categoryC} /> <CameraStatus title="Camera C" category={categoryC} isError={isError} />
</div> </div>
</div> </div>
); );

View File

@@ -7,10 +7,11 @@ import CameraStatusGridItem from "./CameraStatusGridItem";
type CameraStatusProps = { type CameraStatusProps = {
title: string; title: string;
category: SystemHealthStatus[]; category: SystemHealthStatus[];
isError?: boolean;
}; };
const CameraStatus = ({ title, category }: CameraStatusProps) => { const CameraStatus = ({ title, category, isError }: CameraStatusProps) => {
const isAllGood = category?.every((status) => status.tags.includes("RUNNING")); const isAllGood = category && category.length > 0 && category.every((status) => status.tags.includes("RUNNING"));
// check if some are down // check if some are down
// check if all are down // check if all are down
//check if offline //check if offline
@@ -18,10 +19,22 @@ const CameraStatus = ({ title, category }: CameraStatusProps) => {
<Card className="p-4"> <Card className="p-4">
<div className="border-b border-gray-600"> <div className="border-b border-gray-600">
<h3 className="text-lg flex flex-row items-center"> <h3 className="text-lg flex flex-row items-center">
{isAllGood ? <StatusIndicators status={"bg-green-500"} /> : <StatusIndicators status={"bg-amber-500"} />} {isError ? (
<StatusIndicators status={"bg-red-500"} />
) : isAllGood ? (
<StatusIndicators status={"bg-green-500"} />
) : (
<StatusIndicators status={"bg-amber-500"} />
)}
{capitalize(title)} {capitalize(title)}
</h3> </h3>
<p className="text-sm text-slate-300">{isAllGood ? "All systems running" : "Some systems down"}</p> {isError ? (
<p className="text-sm text-red-500">Error loading camera health.</p>
) : isAllGood ? (
<p className="text-sm text-green-500">All systems running</p>
) : (
<p className="text-sm text-amber-500">Some systems down</p>
)}
</div> </div>
{category && category?.length <= 0 ? ( {category && category?.length <= 0 ? (
<p className=" text-gray-500">Loading Camera health...</p> <p className=" text-gray-500">Loading Camera health...</p>

View File

@@ -11,7 +11,8 @@ type StatusGridItemProps = {
const StatusGridItem = ({ title, statusCategory }: StatusGridItemProps) => { const StatusGridItem = ({ title, statusCategory }: StatusGridItemProps) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const isAllGood = statusCategory.every((status) => status.tags.includes("RUNNING")); const isAllGood =
statusCategory && statusCategory.length > 0 && statusCategory.every((status) => status.tags.includes("RUNNING"));
const handleClick = () => { const handleClick = () => {
setIsOpen(false); setIsOpen(false);

View File

@@ -38,7 +38,7 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd
return <span className="text-slate-500">Loading system health</span>; return <span className="text-slate-500">Loading system health</span>;
} }
return ( return (
<div className="h-100 md:h-75 overflow-y-auto flex flex-col gap-4"> <div className="relative h-100 md:h-75 overflow-y-auto flex flex-col gap-4">
<div className="p-2 border-b border-gray-600 grid grid-cols-2 justify-between"> <div className="p-2 border-b border-gray-600 grid grid-cols-2 justify-between">
<div className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241]"> <div className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241]">
<h3 className="text-lg">Start Time</h3> <span className="text-slate-300">{startTime}</span> <h3 className="text-lg">Start Time</h3> <span className="text-slate-300">{startTime}</span>
@@ -50,8 +50,8 @@ const SystemHealth = ({ startTime, uptime, statuses, isLoading, isError, dateUpd
<div className="overflow-auto gap-4"> <div className="overflow-auto gap-4">
<StatusGridItem title={"Modules"} statusCategory={categoryDefault} /> <StatusGridItem title={"Modules"} statusCategory={categoryDefault} />
</div> </div>
<div className="border-t border-gray-500"> <div className="absolute bottom-0 left-0 border-t border-gray-500 w-full">
<small className="italic text-gray-400">{`Last refeshed ${updatedDate}`}</small> <small className="italic text-gray-400 ">{`Last refeshed ${updatedDate}`}</small>
</div> </div>
</div> </div>
); );

View File

@@ -13,12 +13,21 @@ const SystemStatusCard = () => {
const { storeQuery } = useGetStore(); const { storeQuery } = useGetStore();
const reads = storeQuery?.data; const reads = storeQuery?.data;
const isReadsLoading = storeQuery.isFetching; const isReadsLoading = storeQuery?.isFetching;
const isError = storeQuery?.isError || !storeQuery?.data;
useEffect(() => { useEffect(() => {
storeQuery.refetch(); storeQuery.refetch();
}, [reads]); }, [reads]);
if (isError) {
return (
<Card className="p-4">
<CardHeader title="System Status" />
<span className="text-red-500">Error loading system status.</span>
</Card>
);
}
return ( return (
<Card className="p-4"> <Card className="p-4">
<CardHeader title="System Status" /> <CardHeader title="System Status" />

View File

@@ -11,6 +11,7 @@ export const useGetSystemHealth = () => {
const query = useQuery({ const query = useQuery({
queryKey: ["fetchSystemData"], queryKey: ["fetchSystemData"],
queryFn: fetchData, queryFn: fetchData,
refetchInterval: 300000,
}); });
return { query }; return { query };
}; };

View File

@@ -21,7 +21,7 @@ const ChannelCard = () => {
/> />
<button <button
type="submit" type="submit"
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5" className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
> >
{"Save Changes"} {"Save Changes"}
</button> </button>

View File

@@ -1,4 +1,4 @@
import { Field } from "formik"; import { Field, FieldArray } from "formik";
import type { FormTypes, InitialValuesFormErrors, OutputDataResponse } from "../../../types/types"; import type { FormTypes, InitialValuesFormErrors, OutputDataResponse } from "../../../types/types";
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import { useOptionalConstants } from "../hooks/useOptionalConstants"; import { useOptionalConstants } from "../hooks/useOptionalConstants";
@@ -17,6 +17,7 @@ type ChannelFieldsProps = {
const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: ChannelFieldsProps) => { const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }: ChannelFieldsProps) => {
const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || ""); const { optionalConstantsQuery } = useOptionalConstants(outputData?.id?.split("-")[1] || "");
const optionalConstants = optionalConstantsQuery?.data; const optionalConstants = optionalConstantsQuery?.data;
const channelFieldsObject = useMemo(() => { const channelFieldsObject = useMemo(() => {
return { return {
connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5", connectTimeoutSeconds: outputData?.propConnectTimeoutSeconds?.value || "5",
@@ -158,7 +159,7 @@ const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }:
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60" className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
> >
<option value={"UTC"}>UTC</option> <option value={"UTC"}>UTC</option>
<option value={"local"}>Local</option> <option value={"LOCAL"}>Local</option>
</Field> </Field>
</div> </div>
<div className="flex flex-row justify-between"> <div className="flex flex-row justify-between">
@@ -261,6 +262,52 @@ const ChannelFields = ({ errors, touched, values, outputData, onSetFieldValue }:
</div> </div>
</> </>
)} )}
<div className="border-b border-gray-500 my-3">
<h2 className="font-bold">Custom Fields</h2>
</div>
<div className="items-center mb-4">
<FieldArray name="customFields">
{(arrayHelpers) => (
<>
{values?.customFields?.map((_, index) => {
// if (!field.value) return null;
return (
<div key={index} className="flex flex-row justify-between items-center mb-4 gap-2">
<Field
name={`customFields.${index}.label`}
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder={`Custom Field ${index + 1} Label`}
/>
<Field
name={`customFields.${index}.value`}
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder={`Custom Field ${index + 1} Value`}
autoComplete="off"
/>
</div>
);
})}
<button
type="button"
onClick={() => arrayHelpers.push({ label: "", value: "" })}
className={`mr-2 border p-2 rounded-lg hover:bg-gray-700 hover:cursor-pointer ${values?.customFields && values?.customFields?.length >= 6 ? "opacity-50 cursor-not-allowed" : ""}`}
disabled={values?.customFields && values?.customFields?.length >= 6}
>
Add Custom Field
</button>
{values?.customFields && values?.customFields?.length > 0 && (
<button
type="button"
onClick={() => arrayHelpers.pop()}
className="border p-2 rounded-lg hover:bg-gray-700 hover:cursor-pointer"
>
Remove Custom Field
</button>
)}
</>
)}
</FieldArray>
</div>
</> </>
) : ( ) : (
<></> <></>

View File

@@ -0,0 +1,27 @@
import { Field } from "formik";
type OSDFieldToggleProps = {
value: string;
label: string;
};
const OSDFieldToggle = ({ value, label }: OSDFieldToggleProps) => {
const spacesWords = (label: string) => {
if (label.includes("VRM")) return label.replace("VRM", " VRM");
return label.replace(/([A-Z])/g, " $1").trim();
};
return (
<label className="flex items-center gap-3 cursor-pointer select-none w-full justify-between">
<span className="text-lg">{spacesWords(label)}</span>
<Field id={value} type="checkbox" name={value} className="sr-only peer" />
<div
className="relative w-10 h-5 rounded-full bg-gray-300 transition peer-checked:bg-blue-500 after:content-['']
after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:shadow after:transition
after:duration-300 peer-checked:after:translate-x-5"
/>
</label>
);
};
export default OSDFieldToggle;

View File

@@ -0,0 +1,70 @@
import { Field, useFormikContext } from "formik";
import { useOSDConfig } from "../hooks/useOSDConfig";
import OSDFieldToggle from "./OSDFieldToggle";
import type { OSDConfigFields } from "../../../types/types";
type OSDFieldsProps = {
isOSDLoading: boolean;
};
const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
const { osdMutation } = useOSDConfig();
const { values } = useFormikContext<OSDConfigFields>();
const includeKeys = Object.keys(values as OSDConfigFields).filter((value) => value.includes("include"));
const handleSubmit = async (values: OSDConfigFields) => {
const result = await osdMutation.mutateAsync(values);
console.log(result);
};
if (isOSDLoading) {
return <div>Loading OSD Options...</div>;
}
return (
<div>
<div className="flex flex-col space-y-4">
<div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4">
<h2 className="text-2xl mb-4">OSD Options</h2>
<div className="flex flex-col space-y-4">
{includeKeys.map((key) => (
<OSDFieldToggle key={key} value={key} label={key.replace("include", "Include ")} />
))}
</div>
<div className="flex flex-row justify-between">
<label htmlFor="overlayPosition">Overlay Position</label>
<Field
as="select"
name="overlayPosition"
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
>
<option value="Top">Top</option>
<option value="Bottom">Bottom</option>
</Field>
</div>
<div className="flex flex-row justify-between">
<label htmlFor="OSDTimestampFormat">OSD Timestamp Format</label>
<Field
as="select"
name="OSDTimestampFormat"
className="p-2 border border-gray-400 rounded-lg text-white bg-[#253445] w-full md:w-60"
>
<option value="UTC">UTC</option>
<option value="LOCAL">Local</option>
</Field>
</div>
<button
type="button"
onClick={() => handleSubmit(values)}
className="w-full md:w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5 hover:cursor-pointer"
>
Submit
</button>
</div>
</div>
</div>
);
};
export default OSDFields;

View File

@@ -0,0 +1,18 @@
import Card from "../../../ui/Card";
import CardHeader from "../../../ui/CardHeader";
import OSDFields from "./OSDFields";
type OSDOptionsCardProps = {
isOSDLoading: boolean;
};
const OSDOptionsCard = ({ isOSDLoading }: OSDOptionsCardProps) => {
return (
<Card className="p-4 flex-1">
<CardHeader title="OSD Payload Options" />
<OSDFields isOSDLoading={isOSDLoading} />
</Card>
);
};
export default OSDOptionsCard;

View File

@@ -5,12 +5,26 @@ import type { BearerTypeFields, FormTypes, OptionalBOF2Constants, OptionalUTMCCo
import { usePostBearerConfig } from "../hooks/useBearer"; import { usePostBearerConfig } from "../hooks/useBearer";
import { useDispatcherConfig } from "../hooks/useDispatcherConfig"; import { useDispatcherConfig } from "../hooks/useDispatcherConfig";
import { useOptionalConstants } from "../hooks/useOptionalConstants"; import { useOptionalConstants } from "../hooks/useOptionalConstants";
import { useCustomFields } from "../hooks/useCustomFields";
import OSDOptionsCard from "./OSDOptionsCard";
import { useOSDConfig } from "../hooks/useOSDConfig";
const OutputForms = () => { const OutputForms = () => {
const { bearerMutation } = usePostBearerConfig(); const { bearerMutation } = usePostBearerConfig();
const { dispatcherQuery, dispatcherMutation } = useDispatcherConfig(); const { dispatcherQuery, dispatcherMutation } = useDispatcherConfig();
const { customFieldsQuery, customFieldsMutation } = useCustomFields();
const { osdQuery } = useOSDConfig();
const isLoading = dispatcherQuery?.isLoading; const isLoading = dispatcherQuery?.isLoading;
const isOSDLoading = osdQuery?.isLoading;
const includeVRM = osdQuery?.data?.propIncludeVRM?.value.toLowerCase() === "true";
const includeMotion = osdQuery?.data?.propIncludeMotion?.value.toLowerCase() === "true";
const includeTimeStamp = osdQuery?.data?.propIncludeTimestamp?.value.toLowerCase() === "true";
const includeCameraName = osdQuery?.data?.propIncludeCameraName?.value.toLowerCase() === "true";
const overlayPosition = osdQuery?.data?.propOverlayPosition?.value;
const OSDTimestampFormat = osdQuery?.data?.propTimestampFormat?.value;
console.log(includeVRM);
const format = dispatcherQuery?.data?.propFormat?.value; const format = dispatcherQuery?.data?.propFormat?.value;
const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase()); const { optionalConstantsQuery, optionalConstantsMutation } = useOptionalConstants(format?.toLowerCase());
const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value; const FFID = optionalConstantsQuery?.data?.propFeedIdentifier?.value;
@@ -18,6 +32,29 @@ const OutputForms = () => {
const timestampSource = optionalConstantsQuery?.data?.propTimeZoneType?.value; const timestampSource = optionalConstantsQuery?.data?.propTimeZoneType?.value;
const gpsFormat = optionalConstantsQuery?.data?.propGpsFormat?.value; const gpsFormat = optionalConstantsQuery?.data?.propGpsFormat?.value;
const customFieldLabel1 = customFieldsQuery?.data?.propCustomFieldName1?.value;
const customFieldLabel2 = customFieldsQuery?.data?.propCustomFieldName2?.value;
const customFieldLabel3 = customFieldsQuery?.data?.propCustomFieldName3?.value;
const customFieldLabel4 = customFieldsQuery?.data?.propStringName4?.value;
const customFieldLabel5 = customFieldsQuery?.data?.propStringName5?.value;
const customFieldLabel6 = customFieldsQuery?.data?.propStringName6?.value;
const customFieldValues1 = customFieldsQuery?.data?.propCustomFieldValue1?.value;
const customFieldValues2 = customFieldsQuery?.data?.propCustomFieldValue2?.value;
const customFieldValues3 = customFieldsQuery?.data?.propCustomFieldValue3?.value;
const customFieldValues4 = customFieldsQuery?.data?.propStringValue4?.value;
const customFieldValues5 = customFieldsQuery?.data?.propStringValue5?.value;
const customFieldValues6 = customFieldsQuery?.data?.propStringValue6?.value;
const initialCustomFields = [
{ label: customFieldLabel1 || "", value: customFieldValues1 || "" },
{ label: customFieldLabel2 || "", value: customFieldValues2 || "" },
{ label: customFieldLabel3 || "", value: customFieldValues3 || "" },
{ label: customFieldLabel4 || "", value: customFieldValues4 || "" },
{ label: customFieldLabel5 || "", value: customFieldValues5 || "" },
{ label: customFieldLabel6 || "", value: customFieldValues6 || "" },
].filter((field) => field.label && field.value);
const inititalValues: FormTypes = { const inititalValues: FormTypes = {
format: format ?? "JSON", format: format ?? "JSON",
enabled: true, enabled: true,
@@ -41,6 +78,17 @@ const OutputForms = () => {
LID2: "", LID2: "",
// ftp - fields // ftp - fields
//custom fields
customFields: initialCustomFields,
// OSD Options
includeVRM: includeVRM ?? false,
includeMotion: includeMotion ?? false,
includeTimeStamp: includeTimeStamp ?? false,
includeCameraName: includeCameraName ?? false,
overlayPosition: overlayPosition ?? "Top",
OSDTimestampFormat: OSDTimestampFormat ?? "UTC",
}; };
const handleSubmit = async (values: FormTypes) => { const handleSubmit = async (values: FormTypes) => {
@@ -86,6 +134,11 @@ const OutputForms = () => {
await optionalConstantsMutation.mutateAsync(optionalUTMCFields); await optionalConstantsMutation.mutateAsync(optionalUTMCFields);
} }
} }
if (values.customFields && values.customFields.length > 0) {
const customFields = [...values.customFields];
await customFieldsMutation.mutateAsync(customFields);
}
}; };
if (isLoading) { if (isLoading) {
@@ -94,8 +147,11 @@ const OutputForms = () => {
return ( return (
<Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize> <Formik initialValues={inititalValues} onSubmit={handleSubmit} enableReinitialize>
<Form className="grid grid-cols-1 md:grid-cols-2"> <Form className="grid grid-cols-1 md:grid-cols-2 gap-4 h-[50%]">
<BearerTypeCard /> <div>
<BearerTypeCard />
<OSDOptionsCard isOSDLoading={isOSDLoading} />
</div>
<ChannelCard /> <ChannelCard />
</Form> </Form>
</Formik> </Formik>

View File

@@ -0,0 +1,65 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
import type { CustomFieldConfig } from "../../../types/types";
const fetchCustomFields = async () => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=SightingAmmend0-custom-fields`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postCustomFields = async (customFieldConfig: CustomFieldConfig[]) => {
const fields = [];
for (const customField of customFieldConfig) {
if (customField.value)
if (customFieldConfig.indexOf(customField) > 2) {
fields.push({
property: `propStringName${customFieldConfig.indexOf(customField) + 1}`,
value: customField.label,
});
fields.push({
property: `propStringValue${customFieldConfig.indexOf(customField) + 1}`,
value: customField.value,
});
} else {
fields.push(
{
property: `propCustomFieldName${customFieldConfig.indexOf(customField) + 1}`,
value: customField.label,
},
{
property: `propCustomFieldValue${customFieldConfig.indexOf(customField) + 1}`,
value: customField.value,
},
);
}
}
const customFieldConfigPayload = {
id: "SightingAmmend0-custom-fields",
fields,
};
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(customFieldConfigPayload),
});
if (!response.ok) throw new Error("Network response was not ok");
return response.json();
};
export const useCustomFields = () => {
const customFieldsQuery = useQuery({
queryKey: ["customFields"],
queryFn: fetchCustomFields,
});
const customFieldsMutation = useMutation({
mutationKey: ["customFieldsMutation"],
mutationFn: postCustomFields,
});
return { customFieldsQuery, customFieldsMutation };
};

View File

@@ -0,0 +1,53 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
import type { OSDConfigFields } from "../../../types/types";
const fetchOSDConfig = async () => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=SightingAmmend0-overlay`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.json();
};
const postOSDConfig = async (data: OSDConfigFields) => {
const fields = [
{ property: "propIncludeVRM", value: data.includeVRM },
{ property: "propIncludeMotion", value: data.includeMotion },
{ property: "propIncludeTimestamp", value: data.includeTimeStamp },
{ property: "propIncludeCameraName", value: data.includeCameraName },
{ property: "propOverlayPosition", value: data.overlayPosition },
{ property: "propTimestampFormat", value: data.OSDTimestampFormat },
];
const osdConfigPayload = {
id: "SightingAmmend0-overlay",
fields: fields,
};
console.log(osdConfigPayload);
const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST",
body: JSON.stringify(osdConfigPayload),
});
if (!response.ok) {
throw new Error("Failed to post OSD Config");
}
return response.json();
};
export const useOSDConfig = () => {
const osdQuery = useQuery({
queryKey: ["osdConfig"],
queryFn: fetchOSDConfig,
});
const osdMutation = useMutation({
mutationFn: postOSDConfig,
mutationKey: ["postOSDConfig"],
});
return { osdQuery, osdMutation };
};

View File

@@ -1,11 +1,15 @@
import { Formik, Form, Field } from "formik"; import { Formik, Form, Field, FieldArray } from "formik";
import { useSystemSettings } from "../hooks/useSystemSettings"; import { useSystemSettings } from "../hooks/useSystemSettings";
import type { SystemSettings } from "../../../types/types"; import type { NetworkConfig, SystemSettings } from "../../../types/types";
import { toast } from "sonner"; import { toast } from "sonner";
import { useGetNetworkConfig } from "../hooks/useGetNetworkConfig";
const SystemConfig = () => { const SystemConfig = () => {
const { systemSettingsQuery, systemSettingsMutation } = useSystemSettings(); const { systemSettingsQuery, systemSettingsMutation } = useSystemSettings();
const { networkConfigQuery, networkConfigMutation } = useGetNetworkConfig();
const isLoading = networkConfigMutation?.isPending || networkConfigMutation?.isPending;
const isGettingLoading = systemSettingsQuery?.isLoading || networkConfigQuery?.isLoading;
const timeZoneOptions = systemSettingsQuery?.data?.propLocalTimeZone?.accepted; const timeZoneOptions = systemSettingsQuery?.data?.propLocalTimeZone?.accepted;
const timeZoneOpts = timeZoneOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, "")); const timeZoneOpts = timeZoneOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, ""));
const timeSourceOptions = systemSettingsQuery?.data?.propTimeSource?.accepted; const timeSourceOptions = systemSettingsQuery?.data?.propTimeSource?.accepted;
@@ -15,8 +19,11 @@ const SystemConfig = () => {
const SNTPServer = systemSettingsQuery?.data?.propSNTPServer?.value; const SNTPServer = systemSettingsQuery?.data?.propSNTPServer?.value;
const SNTPInterval = systemSettingsQuery?.data?.propSNTPIntervalMinutes?.value; const SNTPInterval = systemSettingsQuery?.data?.propSNTPIntervalMinutes?.value;
const timeSource = systemSettingsQuery?.data?.propTimeSource?.value; const timeSource = systemSettingsQuery?.data?.propTimeSource?.value;
// const primaryServer = systemSettingsQuery?.data?.propPrimaryDNSServer?.value; const primaryServer = networkConfigQuery?.data?.propNameServerPrimary?.value;
// const secondaryServer = systemSettingsQuery?.data?.propSecondaryDNSServer?.value; const secondaryServer = networkConfigQuery?.data?.propNameServerSecondary?.value;
const ipAddress = networkConfigQuery?.data?.propHost?.value;
const subnetMask = networkConfigQuery?.data?.propNetmask?.value;
const gateway = networkConfigQuery?.data?.propGateway?.value;
const initialValues = { const initialValues = {
deviceName: deviceName ?? "", deviceName: deviceName ?? "",
@@ -25,107 +32,201 @@ const SystemConfig = () => {
SNTPServer: SNTPServer ?? "", SNTPServer: SNTPServer ?? "",
SNTPInterval: SNTPInterval ?? 60, SNTPInterval: SNTPInterval ?? 60,
SNTPIntervalMinutes: SNTPInterval ?? 60, SNTPIntervalMinutes: SNTPInterval ?? 60,
primaryServer: "", primaryServer: primaryServer ?? "",
secondaryServer: "", secondaryServer: secondaryServer ?? "",
timeSource: timeSource ?? "", timeSource: timeSource ?? "",
ipAddress: ipAddress ?? "",
subnetMask: subnetMask ?? "",
gateway: gateway ?? "",
customFields: [],
}; };
const handleSubmit = async (values: SystemSettings) => { const handleSubmit = async (values: SystemSettings & NetworkConfig) => {
const result = await systemSettingsMutation.mutateAsync(values); const result = await systemSettingsMutation.mutateAsync(values);
console.log(result); const networkResult = await networkConfigMutation.mutateAsync({
if (result.id) { ipAddress: values.ipAddress,
subnetMask: values.subnetMask,
gateway: values.gateway,
primaryServer: values.primaryServer,
secondaryServer: values.secondaryServer,
});
if (result.id && networkResult.id) {
toast.success("System settings updated successfully"); toast.success("System settings updated successfully");
} else {
toast.error("Failed to update system settings");
} }
}; };
if (isGettingLoading) {
return <div>Loading...</div>;
}
return ( return (
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize> <Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
<Form> {({ values }) => (
<div className="flex flex-row justify-between items-center mb-4"> <Form>
<label htmlFor="deviceName">Device Name</label> <div className="flex flex-row justify-between items-center mb-4">
<Field <label htmlFor="deviceName">Device Name</label>
name="deviceName" <Field
type="text" name="deviceName"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" type="text"
placeholder="Enter device name" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
autoComplete="off" placeholder="Enter device name"
/> autoComplete="off"
</div> />
<div className="flex flex-row justify-between items-center mb-4"> </div>
<label htmlFor="timeZone">Timezone</label> <div className="flex flex-row justify-between items-center mb-4">
<Field <label htmlFor="timeZone">Timezone</label>
name="timeZone" <Field
as="select" name="timeZone"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] " as="select"
autoComplete="off" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] "
> autoComplete="off"
{timeZoneOpts?.map((option: string) => ( >
<option key={option} value={option}> {timeZoneOpts?.map((option: string) => (
{option} <option key={option} value={option}>
</option> {option}
))} </option>
</Field> ))}
</div> </Field>
<div className="flex flex-row justify-between items-center mb-4"> </div>
<label htmlFor="timeSource">Time Source</label> <div className="flex flex-row justify-between items-center mb-4">
<Field <label htmlFor="timeSource">Time Source</label>
name="timeSource" <Field
as="select" name="timeSource"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] " as="select"
autoComplete="off" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs bg-[#253445] "
> autoComplete="off"
{timeSourceOpts?.map((option: string) => ( >
<option key={option} value={option}> {timeSourceOpts?.map((option: string) => (
{option} <option key={option} value={option}>
</option> {option}
))} </option>
</Field> ))}
</div> </Field>
</div>
<div className="flex flex-row justify-between items-center mb-4"> <div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="SNTPServer">SNTP Server</label> <label htmlFor="SNTPServer">SNTP Server</label>
<Field <Field
name="SNTPServer" name="SNTPServer"
type="text" type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter SNTP server" placeholder="Enter SNTP server"
autoComplete="off" autoComplete="off"
/> />
</div> </div>
<div className="flex flex-row justify-between items-center mb-4"> <div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="SNTPInterval">SNTP Interval</label> <label htmlFor="SNTPInterval">SNTP Interval</label>
<Field <Field
name="SNTPInterval" name="SNTPInterval"
type="number" type="number"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter SNTP interval" placeholder="Enter SNTP interval"
autoComplete="off" autoComplete="off"
/> />
</div> </div>
<div className="flex flex-row justify-between items-center mb-4"> <div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="primaryServer">Primary DNS Server</label> <label htmlFor="subnetMask">Subnet Mask</label>
<Field <Field
name="primaryServer" name="subnetMask"
type="text" type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter primary DNS server" placeholder="Enter subnet mask"
autoComplete="off" autoComplete="off"
/> />
</div> </div>
<div className="flex flex-row justify-between items-center mb-4"> <div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="secondaryServer">Secondary DNS Server</label> <label htmlFor="ipAddress">IP Address</label>
<Field <Field
name="secondaryServer" name="ipAddress"
type="text" type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs" className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter secondary DNS server" placeholder="Enter IP address"
autoComplete="off" autoComplete="off"
/> />
</div> </div>
<button type="submit" className="px-4 py-2 bg-green-700 text-white rounded-lg"> <div className="flex flex-row justify-between items-center mb-4">
Save Settings <label htmlFor="gateway">Gateway</label>
</button> <Field
</Form> name="gateway"
type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter gateway"
autoComplete="off"
/>
</div>
<div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="primaryServer">Primary DNS Server</label>
<Field
name="primaryServer"
type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter primary DNS server"
autoComplete="off"
/>
</div>
<div className="flex flex-row justify-between items-center mb-4">
<label htmlFor="secondaryServer">Secondary DNS Server</label>
<Field
name="secondaryServer"
type="text"
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder="Enter secondary DNS server"
autoComplete="off"
/>
</div>
<div className="border-b border-gray-500 my-3">
<h2 className="font-bold">Custom Fields</h2>
</div>
<div className="items-center mb-4">
<FieldArray name="customFields">
{(arrayHelpers) => (
<>
{values.customFields.map((_, index) => (
<div key={index} className="flex flex-row justify-between items-center mb-4">
<label htmlFor={`customFields.${index}`} className="mr-2">
Custom Field {index + 1}
</label>
<Field
name={`customFields.${index}`}
key={index}
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
placeholder={`Enter Custom Field ${index + 1}`}
autoComplete="off"
/>
</div>
))}
<button
type="button"
onClick={() => arrayHelpers.push("")}
className="mr-2 border p-2 rounded-lg hover:bg-gray-700 hover:cursor-pointer"
>
Add Custom Field
</button>
{values.customFields.length > 0 && (
<button
type="button"
onClick={() => arrayHelpers.pop()}
className="border p-2 rounded-lg hover:bg-gray-700 hover:cursor-pointer"
>
Remove Custom Field
</button>
)}
</>
)}
</FieldArray>
</div>
<button
type="submit"
className="px-4 py-2 bg-green-700 text-white rounded-lg hover:bg-green-800 hover:cursor-pointer"
disabled={isLoading}
>
{isLoading ? "Saving..." : "Save Settings"}
</button>
</Form>
)}
</Formik> </Formik>
); );
}; };

View File

@@ -0,0 +1,49 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
import type { NetworkConfig } from "../../../types/types";
const fetchNetworkConfig = async () => {
const response = await fetch(`${CAMBASE}/api/fetch-config?id=GLOBAL--NetworkConfig`);
if (!response.ok) throw new Error("Network response was not ok");
return response.json();
};
const postNetworkConfig = async (networkConfig: NetworkConfig) => {
const fields = [
{ property: "propNetmask", value: networkConfig.subnetMask },
{ property: "propHost", value: networkConfig.ipAddress },
{ property: "propGateway", value: networkConfig.gateway },
];
if (networkConfig.primaryServer !== undefined) {
fields.push({ property: "propNameServerPrimary", value: networkConfig.primaryServer });
}
if (networkConfig.secondaryServer !== undefined) {
fields.push({ property: "propNameServerSecondary", value: networkConfig.secondaryServer });
}
const networkConfigPayload = {
id: "GLOBAL--NetworkConfig",
fields,
};
const respones = await fetch(`${CAMBASE}/api/update-config?id=GLOBAL--NetworkConfig`, {
method: "POST",
body: JSON.stringify(networkConfigPayload),
});
if (!respones.ok) throw new Error("Network response was not ok");
return respones.json();
};
export const useGetNetworkConfig = () => {
const networkConfigQuery = useQuery({
queryKey: ["networkConfig"],
queryFn: fetchNetworkConfig,
});
const networkConfigMutation = useMutation({
mutationKey: ["networkConfigMutation"],
mutationFn: postNetworkConfig,
});
return { networkConfigQuery, networkConfigMutation };
};

View File

@@ -56,6 +56,15 @@ export type OptionalLaneIDs = {
LID3?: string; LID3?: string;
}; };
export type CustomField = {
label: string;
value: string;
};
export type CustomFields = {
customFields?: CustomField[];
};
export type InitialValuesFormErrors = { export type InitialValuesFormErrors = {
backOfficeURL?: string; backOfficeURL?: string;
username?: string; username?: string;
@@ -64,7 +73,16 @@ export type InitialValuesFormErrors = {
readTimeoutSeconds?: string; readTimeoutSeconds?: string;
}; };
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs; export type OSDConfigFields = {
includeVRM: boolean;
includeMotion: boolean;
includeTimeStamp: boolean;
includeCameraName: boolean;
overlayPosition: "Top" | "Bottom" | "Left" | "Right";
OSDTimestampFormat: "UTC" | "LOCAL";
};
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs & CustomFields & OSDConfigFields;
type FieldProperty = { type FieldProperty = {
datatype: string; datatype: string;
value: string; value: string;
@@ -182,6 +200,17 @@ export type SystemSettings = {
timeSource: string; timeSource: string;
SNTPServer: string; SNTPServer: string;
SNTPIntervalMinutes: number; SNTPIntervalMinutes: number;
};
export type NetworkConfig = {
ipAddress: string;
subnetMask: string;
gateway: string;
primaryServer?: string; primaryServer?: string;
secondaryServer?: string; secondaryServer?: string;
}; };
export type CustomFieldConfig = {
label: string;
value: string;
};

View File

@@ -10,7 +10,7 @@ const Card = ({ children, className }: CardProps) => {
return ( return (
<div <div
className={clsx( className={clsx(
"bg-[#253445] rounded-lg mt-4 mx-2 shadow-2xl overflow-x-hidden md:row-span-1 px-2 border border-gray-600 ", "bg-[#253445] rounded-lg mt-4 shadow-2xl overflow-x-hidden md:row-span-1 px-2 border border-gray-600 ",
className, className,
)} )}
> >

View File

@@ -11,7 +11,7 @@ const ModalComponent = ({ isModalOpen, children, close }: ModalComponentProps) =
<Modal <Modal
isOpen={isModalOpen} isOpen={isModalOpen}
onRequestClose={close} onRequestClose={close}
className="bg-[#1e2a38] p-6 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[40%] z-100 overflow-y-auto border border-gray-600" className="bg-[#1e2a38] p-6 rounded-lg shadow-lg w-[95%] mt-[2%] md:w-[40%] z-100 overflow-y-auto border border-gray-600 max-h-[90%]"
overlayClassName="fixed inset-0 bg-[#1e2a38]/70 flex justify-center items-start z-100" overlayClassName="fixed inset-0 bg-[#1e2a38]/70 flex justify-center items-start z-100"
> >
{children} {children}