Compare commits

...

6 Commits

11 changed files with 191 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "bayiq-ui", "name": "bayiq-ui",
"private": true, "private": true,
"version": "1.0.1", "version": "1.0.3",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -48,7 +48,6 @@ const RegionSelector = ({
const getMagnificationLevel = () => { const getMagnificationLevel = () => {
const test = socket?.data; const test = socket?.data;
if (!socket?.data) return null; if (!socket?.data) return null;
console.log(test);
if (!test || !test.magnificationLevel) return "1x"; if (!test || !test.magnificationLevel) return "1x";
return test?.magnificationLevel; return test?.magnificationLevel;
}; };

View File

@@ -23,7 +23,6 @@ const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
id: `Camera${zoomConfig.cameraFeedID}-onvif-controller`, id: `Camera${zoomConfig.cameraFeedID}-onvif-controller`,
fields, fields,
}; };
console.log(zoomPayload);
const response = await fetch(`${CAMBASE}/api/update-config`, { const response = await fetch(`${CAMBASE}/api/update-config`, {
method: "POST", method: "POST",
body: JSON.stringify(zoomPayload), body: JSON.stringify(zoomPayload),

View File

@@ -1,7 +1,7 @@
import { Field, useFormikContext } from "formik"; import { Field, useFormikContext } from "formik";
import { useOSDConfig } from "../hooks/useOSDConfig"; import { useOSDConfig } from "../../hooks/useOSDConfig";
import OSDFieldToggle from "./OSDFieldToggle"; import OSDFieldToggle from "./OSDFieldToggle";
import type { OSDConfigFields } from "../../../types/types"; import type { OSDConfigFields } from "../../../../types/types";
import { toast } from "sonner"; import { toast } from "sonner";
type OSDFieldsProps = { type OSDFieldsProps = {
@@ -12,7 +12,16 @@ const OSDFields = ({ isOSDLoading }: OSDFieldsProps) => {
const { osdMutation } = useOSDConfig(); const { osdMutation } = useOSDConfig();
const { values } = useFormikContext<OSDConfigFields>(); const { values } = useFormikContext<OSDConfigFields>();
const includeKeys = Object.keys(values as OSDConfigFields).filter((value) => value.includes("include")); const validOSDKeys: Array<keyof OSDConfigFields> = [
"includeVRM",
"includeMotion",
"includeTimeStamp",
"includeCameraName",
"overlayPosition",
"OSDTimestampFormat",
];
const includeKeys = validOSDKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
const handleSubmit = async (values: OSDConfigFields) => { const handleSubmit = async (values: OSDConfigFields) => {
const result = await osdMutation.mutateAsync(values); const result = await osdMutation.mutateAsync(values);

View File

@@ -1,5 +1,6 @@
import Card from "../../../ui/Card"; import Card from "../../../../ui/Card";
import CardHeader from "../../../ui/CardHeader"; import CardHeader from "../../../../ui/CardHeader";
import PayloadOptions from "../PayloadOptions/PayloadOptions";
import OSDFields from "./OSDFields"; import OSDFields from "./OSDFields";
import { Tab, TabList, TabPanel, Tabs } from "react-tabs"; import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
import "react-tabs/style/react-tabs.css"; import "react-tabs/style/react-tabs.css";
@@ -15,13 +16,13 @@ const OSDOptionsCard = ({ isOSDLoading }: OSDOptionsCardProps) => {
<Tabs> <Tabs>
<TabList> <TabList>
<Tab>OSD Settings</Tab> <Tab>OSD Settings</Tab>
<Tab>payload Settings</Tab> <Tab>Payload Settings</Tab>
</TabList> </TabList>
<TabPanel> <TabPanel>
<OSDFields isOSDLoading={isOSDLoading} /> <OSDFields isOSDLoading={isOSDLoading} />
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
<div>payload settings</div> <PayloadOptions />
</TabPanel> </TabPanel>
</Tabs> </Tabs>
</Card> </Card>

View File

@@ -6,7 +6,7 @@ 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 { useCustomFields } from "../hooks/useCustomFields";
import OSDOptionsCard from "./OSDOptionsCard"; import OSDOptionsCard from "./OSD/OSDOptionsCard";
import { useOSDConfig } from "../hooks/useOSDConfig"; import { useOSDConfig } from "../hooks/useOSDConfig";
const OutputForms = () => { const OutputForms = () => {
@@ -89,6 +89,39 @@ const OutputForms = () => {
includeCameraName: includeCameraName ?? false, includeCameraName: includeCameraName ?? false,
overlayPosition: overlayPosition ?? "Top", overlayPosition: overlayPosition ?? "Top",
OSDTimestampFormat: OSDTimestampFormat ?? "UTC", OSDTimestampFormat: OSDTimestampFormat ?? "UTC",
// payload ooptions
includeMac: false,
includeSaFID: false,
includeCharHeight: false,
includeConfidence: false,
includeCorrectSpacing: false,
includeDecodeID: false,
includeDirection: false,
includeFrameHeight: false,
includeFrameID: false,
includeFrameTimeRef: false,
includeFrameWidth: false,
includeHorizSlew: false,
inclduePlate: false,
includeNightModeAction: false,
includeOverview: false,
includePlateSecondary: false,
includePlateTrack: false,
includePlateTrackSecondary: false,
includePreferredCountry: false,
includeRawReads: false,
includeRawREADSSecondary: false,
includeRef: false,
includeSeenCount: false,
includeRepeatedPlate: false,
includeSerialCount: false,
includeTraceCount: false,
includeTrack: false,
includeTrackSecondary: false,
includeVertSlew: false,
includeVRMSecondary: false,
includeHotListMatches: false,
}; };
const handleSubmit = async (values: FormTypes) => { const handleSubmit = async (values: FormTypes) => {

View File

@@ -0,0 +1,56 @@
import { useFormikContext } from "formik";
import type { PayloadConfigFields } from "../../../../types/types";
import PayloadOptionsToggle from "./PayloadOptionsToggle";
const PayloadOptions = () => {
const { values } = useFormikContext<PayloadConfigFields>();
const validPayloadKeys: Array<keyof PayloadConfigFields> = [
"includeMac",
"includeSaFID",
"includeCharHeight",
"includeConfidence",
"includeCorrectSpacing",
"includeDecodeID",
"includeDirection",
"includeFrameHeight",
"includeFrameID",
"includeFrameTimeRef",
"includeFrameWidth",
"includeHorizSlew",
"inclduePlate",
"includeNightModeAction",
"includeOverview",
"includePlateSecondary",
"includePlateTrack",
];
const includeKeys = validPayloadKeys.filter((key) => key.includes("include") && typeof values[key] === "boolean");
const handleSubmit = async (values: PayloadConfigFields) => {
console.log("Payload Config Submitted:", values);
};
return (
<div className="">
<div className="flex flex-col space-y-4">
<div className="p-4 border border-gray-600 rounded-lg flex flex-col space-y-4">
<div className="flex flex-col space-y-4 h-100 overflow-y-auto p-3">
{includeKeys.map((key, index) => (
<PayloadOptionsToggle key={index} label={key} value={key} />
))}
</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"
>
Save Settings
</button>
</div>
</div>
</div>
);
};
export default PayloadOptions;

View File

@@ -0,0 +1,22 @@
import { Field } from "formik";
type PayloadOptionsToggleProps = {
label: string;
value: string;
};
const PayloadOptionsToggle = ({ label, value }: PayloadOptionsToggleProps) => {
return (
<label className="flex items-center gap-3 cursor-pointer select-none w-full justify-between">
<span className="text-lg">{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 PayloadOptionsToggle;

View File

@@ -0,0 +1,16 @@
import { useQuery } from "@tanstack/react-query";
const fetchPayloadConfig = async () => {
const response = await fetch("/api/payload-config");
if (!response.ok) throw new Error("Failed to fetch payload config");
return response.json();
};
export const usePayloadCongfig = () => {
const payloadConfigQuery = useQuery({
queryKey: ["payloadConfig"],
queryFn: fetchPayloadConfig,
});
return { payloadConfigQuery };
};

View File

@@ -88,7 +88,51 @@ export type OSDConfigFields = {
OSDTimestampFormat: "UTC" | "LOCAL"; OSDTimestampFormat: "UTC" | "LOCAL";
}; };
export type FormTypes = BearerTypeFields & OptionalConstants & OptionalLaneIDs & CustomFields & OSDConfigFields; export type PayloadConfigFields = {
includeMac: boolean;
includeSaFID: boolean;
includeCameraName: boolean;
includeCharHeight: boolean;
includeConfidence: boolean;
includeCorrectSpacing: boolean;
includeDecodeID: boolean;
includeDirection: boolean;
includeFrameHeight: boolean;
includeFrameID: boolean;
includeFrameTimeRef: boolean;
includeFrameWidth: boolean;
includeHorizSlew: boolean;
includeMotion: boolean;
inclduePlate: boolean;
includeNightModeAction: boolean;
includeOverview: boolean;
includePlateSecondary: boolean;
includePlateTrack: boolean;
includePlateTrackSecondary: boolean;
includePreferredCountry: boolean;
includeRawReads: boolean;
includeRawREADSSecondary: boolean;
includeRef: boolean;
includeSeenCount: boolean;
includeRepeatedPlate: boolean;
includeSerialCount: boolean;
includeTimeStamp: boolean;
includeTraceCount: boolean;
includeTrack: boolean;
includeTrackSecondary: boolean;
includeVertSlew: boolean;
includeVRM: boolean;
includeVRMSecondary: boolean;
includeHotListMatches: boolean;
};
export type FormTypes = BearerTypeFields &
OptionalConstants &
OptionalLaneIDs &
CustomFields &
OSDConfigFields &
PayloadConfigFields;
type FieldProperty = { type FieldProperty = {
datatype: string; datatype: string;
value: string; value: string;