mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-07-01 09:31:14 +03:00
add ptz presets and default role widgets
This commit is contained in:
parent
ae60197cb0
commit
d32f219c9b
@ -1674,6 +1674,17 @@
|
|||||||
"refresh": "Refresh models",
|
"refresh": "Refresh models",
|
||||||
"probeFailed": "Failed to probe models",
|
"probeFailed": "Failed to probe models",
|
||||||
"fetchedModels": "Successfully fetched model list"
|
"fetchedModels": "Successfully fetched model list"
|
||||||
|
},
|
||||||
|
"ptzPresets": {
|
||||||
|
"placeholder": "Select or enter a preset...",
|
||||||
|
"search": "Search or enter a preset...",
|
||||||
|
"noPresets": "No presets available",
|
||||||
|
"available": "Camera presets",
|
||||||
|
"useCustom": "Use \"{{value}}\""
|
||||||
|
},
|
||||||
|
"defaultRole": {
|
||||||
|
"admin": "Admin",
|
||||||
|
"viewer": "Viewer"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"globalConfig": {
|
"globalConfig": {
|
||||||
@ -1763,7 +1774,7 @@
|
|||||||
"addStream": "Add stream",
|
"addStream": "Add stream",
|
||||||
"addStreamDesc": "Enter a name for the new stream. This name will be used to reference the stream in your camera configuration.",
|
"addStreamDesc": "Enter a name for the new stream. This name will be used to reference the stream in your camera configuration.",
|
||||||
"addUrl": "Add URL",
|
"addUrl": "Add URL",
|
||||||
"streamNumber": "Stream {{index}}",
|
"sourceNumber": "Source {{index}}",
|
||||||
"streamName": "Stream name",
|
"streamName": "Stream name",
|
||||||
"streamNamePlaceholder": "e.g., front_door",
|
"streamNamePlaceholder": "e.g., front_door",
|
||||||
"streamUrlPlaceholder": "e.g., rtsp://user:pass@192.168.1.100/stream",
|
"streamUrlPlaceholder": "e.g., rtsp://user:pass@192.168.1.100/stream",
|
||||||
@ -1928,6 +1939,9 @@
|
|||||||
},
|
},
|
||||||
"semanticSearch": {
|
"semanticSearch": {
|
||||||
"jinav2SmallModelSize": "The 'small' size with the Jina V2 model has high RAM and inference cost. The 'large' model with a discrete GPU is recommended."
|
"jinav2SmallModelSize": "The 'small' size with the Jina V2 model has high RAM and inference cost. The 'large' model with a discrete GPU is recommended."
|
||||||
|
},
|
||||||
|
"onvif": {
|
||||||
|
"autotrackingNoZones": "Autotracking requires at least one zone. Define a zone for this camera in Masks / Zones, then set it as a required zone below."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,24 @@ const onvif: SectionConfigOverrides = {
|
|||||||
advancedFields: ["tls_insecure", "ignore_time_mismatch"],
|
advancedFields: ["tls_insecure", "ignore_time_mismatch"],
|
||||||
overrideFields: [],
|
overrideFields: [],
|
||||||
restartRequired: ["autotracking.calibrate_on_startup"],
|
restartRequired: ["autotracking.calibrate_on_startup"],
|
||||||
|
fieldMessages: [
|
||||||
|
{
|
||||||
|
key: "autotracking-no-zones",
|
||||||
|
field: "autotracking.required_zones",
|
||||||
|
messageKey: "configMessages.onvif.autotrackingNoZones",
|
||||||
|
severity: "error",
|
||||||
|
position: "before",
|
||||||
|
condition: (ctx) => {
|
||||||
|
if (ctx.level !== "camera") return false;
|
||||||
|
const zones = ctx.fullCameraConfig?.zones;
|
||||||
|
return (
|
||||||
|
!zones ||
|
||||||
|
typeof zones !== "object" ||
|
||||||
|
Object.keys(zones).length === 0
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
uiSchema: {
|
uiSchema: {
|
||||||
host: {
|
host: {
|
||||||
"ui:options": { size: "sm" },
|
"ui:options": { size: "sm" },
|
||||||
@ -39,11 +57,16 @@ const onvif: SectionConfigOverrides = {
|
|||||||
required_zones: {
|
required_zones: {
|
||||||
"ui:widget": "zoneNames",
|
"ui:widget": "zoneNames",
|
||||||
},
|
},
|
||||||
|
return_preset: {
|
||||||
|
"ui:options": { size: "sm" },
|
||||||
|
"ui:widget": "ptzPresets",
|
||||||
|
},
|
||||||
track: {
|
track: {
|
||||||
"ui:widget": "objectLabels",
|
"ui:widget": "objectLabels",
|
||||||
},
|
},
|
||||||
zooming: {
|
zooming: {
|
||||||
"ui:options": {
|
"ui:options": {
|
||||||
|
size: "xs",
|
||||||
enumI18nPrefix: "onvif.autotracking.zooming",
|
enumI18nPrefix: "onvif.autotracking.zooming",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -21,6 +21,10 @@ const proxy: SectionConfigOverrides = {
|
|||||||
"ui:widget": "password",
|
"ui:widget": "password",
|
||||||
"ui:options": { size: "md" },
|
"ui:options": { size: "md" },
|
||||||
},
|
},
|
||||||
|
default_role: {
|
||||||
|
"ui:widget": "defaultRole",
|
||||||
|
"ui:options": { size: "sm" },
|
||||||
|
},
|
||||||
header_map: {
|
header_map: {
|
||||||
"ui:after": { render: "ProxyRoleMap" },
|
"ui:after": { render: "ProxyRoleMap" },
|
||||||
},
|
},
|
||||||
|
|||||||
@ -33,6 +33,8 @@ import { OptionalFieldWidget } from "./widgets/OptionalFieldWidget";
|
|||||||
import { SemanticSearchModelWidget } from "./widgets/SemanticSearchModelWidget";
|
import { SemanticSearchModelWidget } from "./widgets/SemanticSearchModelWidget";
|
||||||
import { SemanticSearchModelSizeWidget } from "./widgets/SemanticSearchModelSizeWidget";
|
import { SemanticSearchModelSizeWidget } from "./widgets/SemanticSearchModelSizeWidget";
|
||||||
import { OnvifProfileWidget } from "./widgets/OnvifProfileWidget";
|
import { OnvifProfileWidget } from "./widgets/OnvifProfileWidget";
|
||||||
|
import { PTZPresetsWidget } from "./widgets/PTZPresetsWidget";
|
||||||
|
import { DefaultRoleWidget } from "./widgets/DefaultRoleWidget";
|
||||||
|
|
||||||
import { FieldTemplate } from "./templates/FieldTemplate";
|
import { FieldTemplate } from "./templates/FieldTemplate";
|
||||||
import { ObjectFieldTemplate } from "./templates/ObjectFieldTemplate";
|
import { ObjectFieldTemplate } from "./templates/ObjectFieldTemplate";
|
||||||
@ -90,6 +92,8 @@ export const frigateTheme: FrigateTheme = {
|
|||||||
semanticSearchModel: SemanticSearchModelWidget,
|
semanticSearchModel: SemanticSearchModelWidget,
|
||||||
semanticSearchModelSize: SemanticSearchModelSizeWidget,
|
semanticSearchModelSize: SemanticSearchModelSizeWidget,
|
||||||
onvifProfile: OnvifProfileWidget,
|
onvifProfile: OnvifProfileWidget,
|
||||||
|
ptzPresets: PTZPresetsWidget,
|
||||||
|
defaultRole: DefaultRoleWidget,
|
||||||
},
|
},
|
||||||
templates: {
|
templates: {
|
||||||
FieldTemplate: FieldTemplate as React.ComponentType<FieldTemplateProps>,
|
FieldTemplate: FieldTemplate as React.ComponentType<FieldTemplateProps>,
|
||||||
|
|||||||
@ -0,0 +1,56 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import type { WidgetProps } from "@rjsf/utils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import type { ConfigFormContext } from "@/types/configForm";
|
||||||
|
import { getSizedFieldClassName } from "../utils";
|
||||||
|
|
||||||
|
const BUILT_IN_ROLES = ["admin", "viewer"];
|
||||||
|
|
||||||
|
export function DefaultRoleWidget(props: WidgetProps) {
|
||||||
|
const { id, value, disabled, readonly, onChange, schema, options, registry } =
|
||||||
|
props;
|
||||||
|
const { t } = useTranslation(["views/settings"]);
|
||||||
|
|
||||||
|
const fieldClassName = getSizedFieldClassName(options, "sm");
|
||||||
|
|
||||||
|
const formContext = registry?.formContext as ConfigFormContext | undefined;
|
||||||
|
const roles = useMemo<string[]>(() => {
|
||||||
|
const configured = Object.keys(formContext?.fullConfig?.auth?.roles ?? {});
|
||||||
|
// Keep admin/viewer first, then any custom roles in config order.
|
||||||
|
const custom = configured.filter((r) => !BUILT_IN_ROLES.includes(r));
|
||||||
|
return [...BUILT_IN_ROLES, ...custom];
|
||||||
|
}, [formContext]);
|
||||||
|
|
||||||
|
const selectedValue = typeof value === "string" && value ? value : "viewer";
|
||||||
|
|
||||||
|
const getLabel = (role: string) =>
|
||||||
|
BUILT_IN_ROLES.includes(role) ? t(`configForm.defaultRole.${role}`) : role;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
value={selectedValue}
|
||||||
|
onValueChange={onChange}
|
||||||
|
disabled={disabled || readonly}
|
||||||
|
>
|
||||||
|
<SelectTrigger id={id} className={fieldClassName}>
|
||||||
|
<SelectValue placeholder={schema.title} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{roles.map((role) => (
|
||||||
|
<SelectItem key={role} value={role}>
|
||||||
|
{getLabel(role)}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DefaultRoleWidget;
|
||||||
@ -0,0 +1,151 @@
|
|||||||
|
// Combobox widget for ONVIF PTZ preset fields (e.g. autotracking.return_preset).
|
||||||
|
// Fetches the camera's PTZ presets and shows them in a dropdown, while still
|
||||||
|
// allowing a typed custom value so existing presets that the camera does not
|
||||||
|
// report (such as "home") are preserved.
|
||||||
|
import { useState, useMemo } from "react";
|
||||||
|
import type { WidgetProps } from "@rjsf/utils";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { Check, ChevronsUpDown, Plus } from "lucide-react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandGroup,
|
||||||
|
CommandInput,
|
||||||
|
CommandItem,
|
||||||
|
CommandList,
|
||||||
|
} from "@/components/ui/command";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger,
|
||||||
|
} from "@/components/ui/popover";
|
||||||
|
import type { ConfigFormContext } from "@/types/configForm";
|
||||||
|
import type { CameraPtzInfo } from "@/types/ptz";
|
||||||
|
import { getSizedFieldClassName } from "../utils";
|
||||||
|
|
||||||
|
export function PTZPresetsWidget(props: WidgetProps) {
|
||||||
|
const { id, value, disabled, readonly, onChange, options, registry } = props;
|
||||||
|
const { t } = useTranslation(["views/settings"]);
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [searchValue, setSearchValue] = useState("");
|
||||||
|
|
||||||
|
const fieldClassName = getSizedFieldClassName(options, "md");
|
||||||
|
|
||||||
|
const formContext = registry?.formContext as ConfigFormContext | undefined;
|
||||||
|
const cameraName = formContext?.cameraName;
|
||||||
|
const isCameraLevel = formContext?.level === "camera";
|
||||||
|
const hasOnvifHost = !!formContext?.fullCameraConfig?.onvif?.host;
|
||||||
|
|
||||||
|
const { data: ptzInfo } = useSWR<CameraPtzInfo>(
|
||||||
|
isCameraLevel && cameraName && hasOnvifHost
|
||||||
|
? `${cameraName}/ptz/info`
|
||||||
|
: null,
|
||||||
|
{
|
||||||
|
// ONVIF may not be initialized yet when the settings page loads,
|
||||||
|
// so retry until presets become available
|
||||||
|
refreshInterval: (data) =>
|
||||||
|
data?.presets && data.presets.length > 0 ? 0 : 5000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const presets = useMemo<string[]>(() => ptzInfo?.presets ?? [], [ptzInfo]);
|
||||||
|
|
||||||
|
const trimmedSearch = searchValue.trim();
|
||||||
|
const matchesPreset = useMemo(
|
||||||
|
() => presets.some((p) => p.toLowerCase() === trimmedSearch.toLowerCase()),
|
||||||
|
[presets, trimmedSearch],
|
||||||
|
);
|
||||||
|
const showCustomOption = trimmedSearch.length > 0 && !matchesPreset;
|
||||||
|
|
||||||
|
const commit = (next: string) => {
|
||||||
|
onChange(next);
|
||||||
|
setSearchValue("");
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const currentLabel = typeof value === "string" && value ? value : undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(next) => {
|
||||||
|
setOpen(next);
|
||||||
|
if (!next) setSearchValue("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
id={id}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
role="combobox"
|
||||||
|
aria-expanded={open}
|
||||||
|
disabled={disabled || readonly}
|
||||||
|
className={cn(
|
||||||
|
"justify-between font-normal",
|
||||||
|
!currentLabel && "text-muted-foreground",
|
||||||
|
fieldClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{currentLabel ?? t("configForm.ptzPresets.placeholder")}
|
||||||
|
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent className="w-[--radix-popover-trigger-width] p-0">
|
||||||
|
<Command>
|
||||||
|
<CommandInput
|
||||||
|
placeholder={t("configForm.ptzPresets.search")}
|
||||||
|
value={searchValue}
|
||||||
|
onValueChange={setSearchValue}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter" && showCustomOption) {
|
||||||
|
e.preventDefault();
|
||||||
|
commit(trimmedSearch);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<CommandList>
|
||||||
|
{showCustomOption && (
|
||||||
|
<CommandGroup>
|
||||||
|
<CommandItem
|
||||||
|
value={trimmedSearch}
|
||||||
|
onSelect={() => commit(trimmedSearch)}
|
||||||
|
>
|
||||||
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
|
{t("configForm.ptzPresets.useCustom", {
|
||||||
|
value: trimmedSearch,
|
||||||
|
})}
|
||||||
|
</CommandItem>
|
||||||
|
</CommandGroup>
|
||||||
|
)}
|
||||||
|
{presets.length > 0 ? (
|
||||||
|
<CommandGroup heading={t("configForm.ptzPresets.available")}>
|
||||||
|
{presets.map((preset) => (
|
||||||
|
<CommandItem
|
||||||
|
key={preset}
|
||||||
|
value={preset}
|
||||||
|
onSelect={() => commit(preset)}
|
||||||
|
>
|
||||||
|
<Check
|
||||||
|
className={cn(
|
||||||
|
"mr-2 h-4 w-4",
|
||||||
|
value === preset ? "opacity-100" : "opacity-0",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
{preset}
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
) : !showCustomOption ? (
|
||||||
|
<div className="p-4 text-center text-sm text-muted-foreground">
|
||||||
|
{t("configForm.ptzPresets.noPresets")}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user