Compare commits
4 Commits
enhancemen
...
feature/se
| Author | SHA1 | Date | |
|---|---|---|---|
| d9594546a0 | |||
| dbadc7388c | |||
| ce79591de0 | |||
| 748be931ed |
@@ -12,12 +12,23 @@ export const initialState: CameraFeedState = {
|
|||||||
{ name: "Region 1", brushColour: "#ff0000" },
|
{ name: "Region 1", brushColour: "#ff0000" },
|
||||||
{ name: "Region 2", brushColour: "#00ff00" },
|
{ name: "Region 2", brushColour: "#00ff00" },
|
||||||
{ name: "Region 3", brushColour: "#0400ff" },
|
{ name: "Region 3", brushColour: "#0400ff" },
|
||||||
|
{ name: "Region 4", brushColour: "#ffff00" },
|
||||||
|
{ name: "Region 5", brushColour: "#fc35db" },
|
||||||
],
|
],
|
||||||
B: [
|
B: [
|
||||||
{ name: "Region 1", brushColour: "#ff0000" },
|
{ name: "Region 1", brushColour: "#ff0000" },
|
||||||
{ name: "Region 2", brushColour: "#00ff00" },
|
{ name: "Region 2", brushColour: "#00ff00" },
|
||||||
|
{ name: "Region 3", brushColour: "#0400ff" },
|
||||||
|
{ name: "Region 4", brushColour: "#ffff00" },
|
||||||
|
{ name: "Region 5", brushColour: "#fc35db" },
|
||||||
|
],
|
||||||
|
C: [
|
||||||
|
{ name: "Region 1", brushColour: "#ff0000" },
|
||||||
|
{ name: "Region 2", brushColour: "#00ff00" },
|
||||||
|
{ name: "Region 3", brushColour: "#0400ff" },
|
||||||
|
{ name: "Region 4", brushColour: "#ffff00" },
|
||||||
|
{ name: "Region 5", brushColour: "#fc35db" },
|
||||||
],
|
],
|
||||||
C: [{ name: "Region 1", brushColour: "#ff0000" }],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
selectedRegionIndex: 0,
|
selectedRegionIndex: 0,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ type CameraSettingsProps = {
|
|||||||
|
|
||||||
const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => {
|
const CameraSettings = ({ tabIndex, setTabIndex }: CameraSettingsProps) => {
|
||||||
return (
|
return (
|
||||||
<Card className="p-4 col-span-3 row-span-5 col-start-3 md:col-span-3 md:row-span-5 max-h-screen overflow-auto">
|
<Card className="p-4 col-span-2 row-span-5 col-start-3 md:col-span-3 md:row-span-5 overflow-auto">
|
||||||
<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"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const ColourPicker = ({ colour, setColour }: ColourPickerProps) => {
|
|||||||
name=""
|
name=""
|
||||||
id=""
|
id=""
|
||||||
value={colour}
|
value={colour}
|
||||||
|
disabled
|
||||||
onChange={(e) => setColour(e.target.value)}
|
onChange={(e) => setColour(e.target.value)}
|
||||||
className="h-8 w-8 p-0 rounded-md border border-slate-500 cursor-pointer"
|
className="h-8 w-8 p-0 rounded-md border border-slate-500 cursor-pointer"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { PaintedCell, Region } from "../../../../types/types";
|
import type { ColourData, PaintedCell, Region } from "../../../../types/types";
|
||||||
import ColourPicker from "./ColourPicker";
|
import ColourPicker from "./ColourPicker";
|
||||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||||
|
import { useColourDectection } from "../../hooks/useColourDetection";
|
||||||
|
|
||||||
type RegionSelectorProps = {
|
type RegionSelectorProps = {
|
||||||
regions: Region[];
|
regions: Region[];
|
||||||
@@ -10,7 +11,10 @@ type RegionSelectorProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: RegionSelectorProps) => {
|
const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: RegionSelectorProps) => {
|
||||||
const { dispatch } = useCameraFeedContext();
|
const { colourMutation } = useColourDectection();
|
||||||
|
const { state, dispatch } = useCameraFeedContext();
|
||||||
|
const paintedCells = state.paintedCells[cameraFeedID];
|
||||||
|
|
||||||
const handleChange = (e: { target: { value: string } }) => {
|
const handleChange = (e: { target: { value: string } }) => {
|
||||||
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: e.target.value } });
|
dispatch({ type: "CHANGE_MODE", payload: { cameraFeedID: cameraFeedID, mode: e.target.value } });
|
||||||
};
|
};
|
||||||
@@ -54,6 +58,53 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleSaveclick = () => {
|
||||||
|
const regions: ColourData[] = [];
|
||||||
|
const test = Array.from(paintedCells.entries());
|
||||||
|
const region1 = test.filter(([, cell]) => cell.region.name === "Region 1");
|
||||||
|
const region2 = test.filter(([, cell]) => cell.region.name === "Region 2");
|
||||||
|
const region3 = test.filter(([, cell]) => cell.region.name === "Region 3");
|
||||||
|
const region4 = test.filter(([, cell]) => cell.region.name === "Region 4");
|
||||||
|
const region5 = test.filter(([, cell]) => cell.region.name === "Region 5");
|
||||||
|
const region1Data = {
|
||||||
|
id: 1,
|
||||||
|
cells: region1.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
|
||||||
|
};
|
||||||
|
const region2Data = {
|
||||||
|
id: 2,
|
||||||
|
cells: region2.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
|
||||||
|
};
|
||||||
|
const region3Data = {
|
||||||
|
id: 3,
|
||||||
|
cells: region3.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
|
||||||
|
};
|
||||||
|
const region4Data = {
|
||||||
|
id: 4,
|
||||||
|
cells: region4.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
|
||||||
|
};
|
||||||
|
const region5Data = {
|
||||||
|
id: 5,
|
||||||
|
cells: region5.map(([key]) => [parseInt(key.split("-")[1]), parseInt(key.split("-")[0])]),
|
||||||
|
};
|
||||||
|
if (region1Data.cells.length > 0) {
|
||||||
|
regions.push(region1Data);
|
||||||
|
}
|
||||||
|
if (region2Data.cells.length > 0) {
|
||||||
|
regions.push(region2Data);
|
||||||
|
}
|
||||||
|
if (region3Data.cells.length > 0) {
|
||||||
|
regions.push(region3Data);
|
||||||
|
}
|
||||||
|
if (region4Data.cells.length > 0) {
|
||||||
|
regions.push(region4Data);
|
||||||
|
}
|
||||||
|
if (region5Data.cells.length > 0) {
|
||||||
|
regions.push(region5Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
colourMutation.mutate({ cameraFeedID, regions: regions });
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 md:grid-rows-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 md:grid-rows-2 gap-4">
|
||||||
<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">
|
||||||
@@ -103,7 +154,7 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
|
|||||||
<label
|
<label
|
||||||
htmlFor={inputId}
|
htmlFor={inputId}
|
||||||
key={region.name}
|
key={region.name}
|
||||||
className={`items-center p-4 m-4 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">
|
||||||
@@ -121,16 +172,16 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
|
|||||||
<span className="text-xl">{region.name}</span>
|
<span className="text-xl">{region.name}</span>
|
||||||
</div>
|
</div>
|
||||||
<ColourPicker colour={region.brushColour} setColour={(c: string) => handleRegionColourChange(idx, c)} />
|
<ColourPicker colour={region.brushColour} setColour={(c: string) => handleRegionColourChange(idx, c)} />
|
||||||
<p className="text-slate-400">{region.brushColour}</p>
|
<div></div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
<div className=" mx-auto flex flex-row gap-4 mt-4">
|
<div className=" mx-auto flex flex-row gap-4 mt-4">
|
||||||
<button className="border border-blue-900 bg-blue-700 px-4 rounded-md" onClick={handleAddRegionClick}>
|
<button className="border border-blue-900 bg-blue-700 px-4 py-1 rounded-md" onClick={handleAddRegionClick}>
|
||||||
Add Region
|
Add Region
|
||||||
</button>
|
</button>
|
||||||
<button className="border border-red-900 px-4 rounded-md" onClick={handleRemoveClick}>
|
<button className="border border-red-900 bg-red-700 px-4 py-1 rounded-md" onClick={handleRemoveClick}>
|
||||||
Remove Region
|
Remove Region
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -139,6 +190,12 @@ const RegionSelector = ({ regions, selectedRegionIndex, mode, cameraFeedID }: Re
|
|||||||
<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 md:col-span-2 h-50">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<h2 className="text-2xl mb-2">Actions</h2>
|
<h2 className="text-2xl mb-2">Actions</h2>
|
||||||
|
<button
|
||||||
|
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"
|
||||||
|
>
|
||||||
|
Save Region
|
||||||
|
</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-[40%] hover:bg-red-700 hover:cursor-pointer"
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ import { Stage, Layer, Image, Shape } from "react-konva";
|
|||||||
import type { KonvaEventObject } from "konva/lib/Node";
|
import type { KonvaEventObject } from "konva/lib/Node";
|
||||||
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
|
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
|
||||||
|
|
||||||
import Card from "../../../../ui/Card";
|
|
||||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||||
|
|
||||||
const rows = 40;
|
const BACKEND_WIDTH = 640;
|
||||||
|
const BACKEND_HEIGHT = 360;
|
||||||
|
const BACKEND_CELL_SIZE = 16;
|
||||||
|
|
||||||
|
const rows = 22.5;
|
||||||
const cols = 40;
|
const cols = 40;
|
||||||
const size = 20;
|
|
||||||
const gap = 0;
|
const gap = 0;
|
||||||
|
|
||||||
const VideoFeedGridPainter = () => {
|
const VideoFeedGridPainter = () => {
|
||||||
@@ -19,9 +21,12 @@ const VideoFeedGridPainter = () => {
|
|||||||
const selectedRegionIndex = state.selectedRegionIndex;
|
const selectedRegionIndex = state.selectedRegionIndex;
|
||||||
const mode = state.modeByCamera[cameraFeedID];
|
const mode = state.modeByCamera[cameraFeedID];
|
||||||
const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
|
const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
|
||||||
const [stageSize, setStageSize] = useState({ width: 740, height: 460 });
|
const [stageSize, setStageSize] = useState({ width: BACKEND_WIDTH, height: BACKEND_HEIGHT });
|
||||||
const isDrawingRef = useRef(false);
|
const isDrawingRef = useRef(false);
|
||||||
|
|
||||||
|
const currentScale = stageSize.width / BACKEND_WIDTH;
|
||||||
|
const size = BACKEND_CELL_SIZE * currentScale;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const paintLayerRef = useRef<any>(null);
|
const paintLayerRef = useRef<any>(null);
|
||||||
|
|
||||||
@@ -60,7 +65,7 @@ const VideoFeedGridPainter = () => {
|
|||||||
|
|
||||||
if (existing && existing.colour === currentColour) return;
|
if (existing && existing.colour === currentColour) return;
|
||||||
|
|
||||||
map.set(key, { colour: currentColour });
|
map.set(key, { colour: currentColour, region: activeRegion });
|
||||||
|
|
||||||
paintLayerRef.current?.batchDraw();
|
paintLayerRef.current?.batchDraw();
|
||||||
};
|
};
|
||||||
@@ -87,25 +92,25 @@ const VideoFeedGridPainter = () => {
|
|||||||
const handleResize = () => {
|
const handleResize = () => {
|
||||||
const width = window.innerWidth;
|
const width = window.innerWidth;
|
||||||
|
|
||||||
const aspectRatio = 740 / 460;
|
const aspectRatio = BACKEND_WIDTH / BACKEND_HEIGHT;
|
||||||
const newWidth = width * 0.39;
|
const newWidth = width * 0.39;
|
||||||
const newHeight = newWidth / aspectRatio;
|
const newHeight = newWidth / aspectRatio;
|
||||||
setStageSize({ width: newWidth, height: newHeight });
|
setStageSize({ width: newWidth, height: newHeight });
|
||||||
};
|
};
|
||||||
|
|
||||||
handleResize();
|
handleResize();
|
||||||
window.addEventListener("resize", handleResize);
|
window.addEventListener("resize", handleResize);
|
||||||
|
|
||||||
return () => window.removeEventListener("resize", handleResize);
|
return () => window.removeEventListener("resize", handleResize);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (image === null || isloading)
|
if (image === null || isloading) return <span className="text-slate-500">Loading Video feed…</span>;
|
||||||
return (
|
|
||||||
<Card className="row-span-3 col-span-2 rounded-lg p-4 w-full">
|
|
||||||
<span className="text-slate-500">Loading Video feed…</span>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<div className="mt-4.5 row-span-1 col-span-2">
|
<div
|
||||||
|
className={`mt-4.5 row-span-1 col-span-2 ${mode === "painter" ? "hover:cursor-crosshair" : ""} ${
|
||||||
|
mode === "eraser" ? "hover:cursor-pointer" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
<Stage
|
<Stage
|
||||||
width={stageSize.width}
|
width={stageSize.width}
|
||||||
height={stageSize.height}
|
height={stageSize.height}
|
||||||
|
|||||||
24
src/features/cameras/hooks/useColourDetection.ts
Normal file
24
src/features/cameras/hooks/useColourDetection.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
import type { ColourDetectionPayload } from "../../../types/types";
|
||||||
|
|
||||||
|
const sendColourDetectionData = async (colourData: ColourDetectionPayload) => {
|
||||||
|
const regions = {
|
||||||
|
regions: colourData.regions,
|
||||||
|
};
|
||||||
|
const response = await fetch(`${CAMBASE}/TargetDetectionColour${colourData.cameraFeedID}-region-update`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(regions),
|
||||||
|
});
|
||||||
|
if (!response.ok) throw new Error("Cannot send data to colour detection endpoint");
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useColourDectection = () => {
|
||||||
|
const colourMutation = useMutation({
|
||||||
|
mutationKey: ["colour detection"],
|
||||||
|
mutationFn: (colourData: ColourDetectionPayload) => sendColourDetectionData(colourData),
|
||||||
|
});
|
||||||
|
|
||||||
|
return { colourMutation };
|
||||||
|
};
|
||||||
25
src/features/settings/components/Settings.tsx
Normal file
25
src/features/settings/components/Settings.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { Tabs, Tab, TabList, TabPanel } from "react-tabs";
|
||||||
|
import "react-tabs/style/react-tabs.css";
|
||||||
|
import Card from "../../../ui/Card";
|
||||||
|
import SystemConfig from "./SystemConfig";
|
||||||
|
import CardHeader from "../../../ui/CardHeader";
|
||||||
|
|
||||||
|
const Settings = () => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Tabs>
|
||||||
|
<TabList>
|
||||||
|
<Tab>Systems</Tab>
|
||||||
|
</TabList>
|
||||||
|
<TabPanel>
|
||||||
|
<Card className="p-4">
|
||||||
|
<CardHeader title="System Configuration" />
|
||||||
|
<SystemConfig />
|
||||||
|
</Card>
|
||||||
|
</TabPanel>
|
||||||
|
</Tabs>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Settings;
|
||||||
133
src/features/settings/components/SystemConfig.tsx
Normal file
133
src/features/settings/components/SystemConfig.tsx
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { Formik, Form, Field } from "formik";
|
||||||
|
import { useSystemSettings } from "../hooks/useSystemSettings";
|
||||||
|
import type { SystemSettings } from "../../../types/types";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
|
const SystemConfig = () => {
|
||||||
|
const { systemSettingsQuery, systemSettingsMutation } = useSystemSettings();
|
||||||
|
|
||||||
|
const timeZoneOptions = systemSettingsQuery?.data?.propLocalTimeZone?.accepted;
|
||||||
|
const timeZoneOpts = timeZoneOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, ""));
|
||||||
|
const timeSourceOptions = systemSettingsQuery?.data?.propTimeSource?.accepted;
|
||||||
|
const timeSourceOpts = timeSourceOptions?.split(",").map((option: string) => option.trim().replace(/\[|\]/g, ""));
|
||||||
|
const deviceName = systemSettingsQuery?.data?.propDeviceName?.value;
|
||||||
|
const timeZone = systemSettingsQuery?.data?.propLocalTimeZone?.value;
|
||||||
|
const SNTPServer = systemSettingsQuery?.data?.propSNTPServer?.value;
|
||||||
|
const SNTPInterval = systemSettingsQuery?.data?.propSNTPIntervalMinutes?.value;
|
||||||
|
const timeSource = systemSettingsQuery?.data?.propTimeSource?.value;
|
||||||
|
// const primaryServer = systemSettingsQuery?.data?.propPrimaryDNSServer?.value;
|
||||||
|
// const secondaryServer = systemSettingsQuery?.data?.propSecondaryDNSServer?.value;
|
||||||
|
|
||||||
|
const initialValues = {
|
||||||
|
deviceName: deviceName ?? "",
|
||||||
|
timeZone: timeZone ?? "",
|
||||||
|
localTimeZone: timeZone ?? "",
|
||||||
|
SNTPServer: SNTPServer ?? "",
|
||||||
|
SNTPInterval: SNTPInterval ?? 60,
|
||||||
|
SNTPIntervalMinutes: SNTPInterval ?? 60,
|
||||||
|
primaryServer: "",
|
||||||
|
secondaryServer: "",
|
||||||
|
timeSource: timeSource ?? "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (values: SystemSettings) => {
|
||||||
|
const result = await systemSettingsMutation.mutateAsync(values);
|
||||||
|
console.log(result);
|
||||||
|
if (result.id) {
|
||||||
|
toast.success("System settings updated successfully");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Formik initialValues={initialValues} onSubmit={handleSubmit} enableReinitialize>
|
||||||
|
<Form>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="deviceName">Device Name</label>
|
||||||
|
<Field
|
||||||
|
name="deviceName"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter device name"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="timeZone">Timezone</label>
|
||||||
|
<Field
|
||||||
|
name="timeZone"
|
||||||
|
as="select"
|
||||||
|
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}>
|
||||||
|
{option}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="timeSource">Time Source</label>
|
||||||
|
<Field
|
||||||
|
name="timeSource"
|
||||||
|
as="select"
|
||||||
|
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}>
|
||||||
|
{option}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="SNTPServer">SNTP Server</label>
|
||||||
|
<Field
|
||||||
|
name="SNTPServer"
|
||||||
|
type="text"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter SNTP server"
|
||||||
|
autoComplete="off"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-row justify-between items-center mb-4">
|
||||||
|
<label htmlFor="SNTPInterval">SNTP Interval</label>
|
||||||
|
<Field
|
||||||
|
name="SNTPInterval"
|
||||||
|
type="number"
|
||||||
|
className="p-2 border border-gray-400 rounded-lg w-full max-w-xs"
|
||||||
|
placeholder="Enter SNTP interval"
|
||||||
|
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>
|
||||||
|
<button type="submit" className="px-4 py-2 bg-green-700 text-white rounded-lg">
|
||||||
|
Save Settings
|
||||||
|
</button>
|
||||||
|
</Form>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SystemConfig;
|
||||||
54
src/features/settings/hooks/useSystemSettings.ts
Normal file
54
src/features/settings/hooks/useSystemSettings.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||||
|
import { CAMBASE } from "../../../utils/config";
|
||||||
|
import type { SystemSettings } from "../../../types/types";
|
||||||
|
const camBase = import.meta.env.MODE !== "development" ? CAMBASE : "";
|
||||||
|
|
||||||
|
const fetchSystemSettings = async () => {
|
||||||
|
const response = await fetch(`${camBase}/api/fetch-config?id=GLOBAL--Device`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch system settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
const postSystemSettings = async (settings: SystemSettings) => {
|
||||||
|
const systemSettingConfig = {
|
||||||
|
id: "GLOBAL--Device",
|
||||||
|
fields: [
|
||||||
|
{ property: "propDeviceName", value: settings.deviceName },
|
||||||
|
{ property: "propSNTPServer", value: settings.SNTPServer },
|
||||||
|
{
|
||||||
|
property: "propSNTPIntervalMinutes",
|
||||||
|
value: Number(settings.SNTPIntervalMinutes),
|
||||||
|
},
|
||||||
|
{ property: "propLocalTimeZone", value: settings.localTimeZone },
|
||||||
|
{ property: "propTimeSource", value: settings.timeSource },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(`${camBase}/api/update-config`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(systemSettingConfig),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to update system settings");
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useSystemSettings = () => {
|
||||||
|
const systemSettingsQuery = useQuery({
|
||||||
|
queryKey: ["systemSettings"],
|
||||||
|
queryFn: fetchSystemSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
const systemSettingsMutation = useMutation({
|
||||||
|
mutationKey: ["updateSystemSettings"],
|
||||||
|
mutationFn: postSystemSettings,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { systemSettingsQuery, systemSettingsMutation };
|
||||||
|
};
|
||||||
@@ -2,12 +2,14 @@ import { createRootRoute, Outlet } from "@tanstack/react-router";
|
|||||||
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
|
||||||
import Header from "../ui/Header";
|
import Header from "../ui/Header";
|
||||||
import Footer from "../ui/Footer";
|
import Footer from "../ui/Footer";
|
||||||
|
import { Toaster } from "sonner";
|
||||||
|
|
||||||
const RootLayout = () => (
|
const RootLayout = () => (
|
||||||
<>
|
<>
|
||||||
<Header />
|
<Header />
|
||||||
<main className="p-4 min-h-screen">
|
<main className="p-4 min-h-screen">
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
<Toaster />
|
||||||
</main>
|
</main>
|
||||||
<Footer />
|
<Footer />
|
||||||
<TanStackRouterDevtools position="bottom-right" />
|
<TanStackRouterDevtools position="bottom-right" />
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import CameraGrid from "../features/cameras/components/CameraGrid";
|
import CameraGrid from "../features/cameras/components/CameraGrid";
|
||||||
import { Toaster } from "sonner";
|
|
||||||
|
|
||||||
export const Route = createFileRoute("/baywatch")({
|
export const Route = createFileRoute("/baywatch")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
@@ -10,7 +9,6 @@ function RouteComponent() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CameraGrid />
|
<CameraGrid />
|
||||||
<Toaster />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { createFileRoute } from '@tanstack/react-router'
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
import Settings from "../features/settings/components/Settings";
|
||||||
|
|
||||||
export const Route = createFileRoute('/settings')({
|
export const Route = createFileRoute("/settings")({
|
||||||
component: RouteComponent,
|
component: RouteComponent,
|
||||||
})
|
});
|
||||||
|
|
||||||
function RouteComponent() {
|
function RouteComponent() {
|
||||||
return <div>Hello "/settings"!</div>
|
return (
|
||||||
|
<div>
|
||||||
|
<Settings />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ export type OutputDataResponse = {
|
|||||||
|
|
||||||
export type PaintedCell = {
|
export type PaintedCell = {
|
||||||
colour: string;
|
colour: string;
|
||||||
|
region: Region;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DispatcherConfig = {
|
export type DispatcherConfig = {
|
||||||
@@ -164,3 +165,23 @@ export type DecodeReading = {
|
|||||||
firstSeenTimeHumane: string;
|
firstSeenTimeHumane: string;
|
||||||
lastSeenTimeHumane: string;
|
lastSeenTimeHumane: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ColourData = {
|
||||||
|
id: string | number;
|
||||||
|
cells: number[][];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ColourDetectionPayload = {
|
||||||
|
cameraFeedID: "A" | "B" | "C";
|
||||||
|
regions: ColourData[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type SystemSettings = {
|
||||||
|
deviceName: string;
|
||||||
|
localTimeZone: string;
|
||||||
|
timeSource: string;
|
||||||
|
SNTPServer: string;
|
||||||
|
SNTPIntervalMinutes: number;
|
||||||
|
primaryServer?: string;
|
||||||
|
secondaryServer?: string;
|
||||||
|
};
|
||||||
|
|||||||
@@ -9,3 +9,12 @@ export const convertObjtoArray = (obj: Record<string, SystemHealthStatus[]>) =>
|
|||||||
const statusCategoryArray = Object.entries(obj);
|
const statusCategoryArray = Object.entries(obj);
|
||||||
return statusCategoryArray;
|
return statusCategoryArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const data = {
|
||||||
|
// camera: cameraFeedID,
|
||||||
|
// cells: Array.from(paintedCells.entries()).map(([key, cell]) => ({
|
||||||
|
// position: key,
|
||||||
|
// ...cell,
|
||||||
|
// region: regions[selectedRegionIndex]?.name || "Unnamed",
|
||||||
|
// })),
|
||||||
|
// };
|
||||||
|
|||||||
@@ -13,4 +13,12 @@ export default defineConfig({
|
|||||||
react(),
|
react(),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
],
|
],
|
||||||
|
server: {
|
||||||
|
proxy: {
|
||||||
|
"/api": {
|
||||||
|
target: "http://100.115.125.56",
|
||||||
|
changeOrigin: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user