2024-03-06 13:24:21 +01:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
2024-03-08 01:32:26 +01:00
|
|
|
import FilterCheckBox from "@/components/filter/FilterCheckBox";
|
2024-03-07 15:34:11 +01:00
|
|
|
import { Button } from "@/components/ui/button";
|
2024-03-06 13:24:21 +01:00
|
|
|
import {
|
2024-03-07 15:34:11 +01:00
|
|
|
Dialog,
|
|
|
|
DialogContent,
|
|
|
|
DialogDescription,
|
|
|
|
DialogFooter,
|
|
|
|
DialogHeader,
|
|
|
|
DialogTitle,
|
|
|
|
} from "@/components/ui/dialog";
|
2024-03-08 18:14:58 +01:00
|
|
|
import { Drawer, DrawerContent, DrawerTrigger } from "@/components/ui/drawer";
|
2024-03-08 01:32:26 +01:00
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuLabel,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2024-03-06 13:24:21 +01:00
|
|
|
import { Event } from "@/types/event";
|
2024-03-08 01:32:26 +01:00
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-03-06 13:24:21 +01:00
|
|
|
import axios from "axios";
|
2024-04-12 14:31:30 +02:00
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
2024-03-08 18:14:58 +01:00
|
|
|
import { isMobile } from "react-device-detect";
|
2024-03-08 01:32:26 +01:00
|
|
|
import { FaList, FaVideo } from "react-icons/fa";
|
2024-03-06 13:24:21 +01:00
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
export default function SubmitPlus() {
|
2024-03-16 00:28:57 +01:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
2024-04-12 14:31:30 +02:00
|
|
|
useEffect(() => {
|
|
|
|
document.title = "Plus - Frigate";
|
|
|
|
}, []);
|
|
|
|
|
2024-03-08 01:32:26 +01:00
|
|
|
// filters
|
|
|
|
|
|
|
|
const [selectedCameras, setSelectedCameras] = useState<string[]>();
|
|
|
|
const [selectedLabels, setSelectedLabels] = useState<string[]>();
|
|
|
|
|
|
|
|
// data
|
|
|
|
|
2024-03-06 13:24:21 +01:00
|
|
|
const { data: events, mutate: refresh } = useSWR<Event[]>([
|
|
|
|
"events",
|
2024-03-08 01:32:26 +01:00
|
|
|
{
|
|
|
|
limit: 100,
|
|
|
|
in_progress: 0,
|
|
|
|
is_submitted: 0,
|
|
|
|
cameras: selectedCameras ? selectedCameras.join(",") : null,
|
|
|
|
labels: selectedLabels ? selectedLabels.join(",") : null,
|
|
|
|
},
|
2024-03-06 13:24:21 +01:00
|
|
|
]);
|
|
|
|
const [upload, setUpload] = useState<Event>();
|
|
|
|
|
2024-03-16 00:28:57 +01:00
|
|
|
const grow = useMemo(() => {
|
|
|
|
if (!config || !upload) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const camera = config.cameras[upload.camera];
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (camera.detect.width / camera.detect.height < 16 / 9) {
|
|
|
|
return "aspect-video object-contain";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}, [config, upload]);
|
|
|
|
|
2024-03-06 13:24:21 +01:00
|
|
|
const onSubmitToPlus = useCallback(
|
|
|
|
async (falsePositive: boolean) => {
|
|
|
|
if (!upload) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-07 15:34:11 +01:00
|
|
|
falsePositive
|
|
|
|
? axios.put(`events/${upload.id}/false_positive`)
|
|
|
|
: axios.post(`events/${upload.id}/plus`, {
|
2024-03-06 13:24:21 +01:00
|
|
|
include_annotation: 1,
|
|
|
|
});
|
|
|
|
|
2024-03-07 15:34:11 +01:00
|
|
|
refresh(
|
|
|
|
(data: Event[] | undefined) => {
|
|
|
|
if (!data) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
const index = data.findIndex((e) => e.id == upload.id);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [...data.slice(0, index), ...data.slice(index + 1)];
|
|
|
|
},
|
|
|
|
{ revalidate: false, populateCache: true },
|
|
|
|
);
|
|
|
|
setUpload(undefined);
|
2024-03-06 13:24:21 +01:00
|
|
|
},
|
|
|
|
[refresh, upload],
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2024-03-08 01:32:26 +01:00
|
|
|
<div className="size-full flex flex-col">
|
|
|
|
<PlusFilterGroup
|
|
|
|
selectedCameras={selectedCameras}
|
|
|
|
setSelectedCameras={setSelectedCameras}
|
|
|
|
selectedLabels={selectedLabels}
|
|
|
|
setSelectedLabels={setSelectedLabels}
|
|
|
|
/>
|
|
|
|
<div className="size-full flex flex-1 flex-wrap content-start gap-2 md:gap-4 overflow-y-auto no-scrollbar">
|
|
|
|
<div className="w-full p-2 grid sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-2">
|
|
|
|
<Dialog
|
|
|
|
open={upload != undefined}
|
|
|
|
onOpenChange={(open) => (!open ? setUpload(undefined) : null)}
|
|
|
|
>
|
|
|
|
<DialogContent className="md:max-w-4xl">
|
|
|
|
<DialogHeader>
|
|
|
|
<DialogTitle>Submit To Frigate+</DialogTitle>
|
|
|
|
<DialogDescription>
|
|
|
|
Objects in locations you want to avoid are not false
|
|
|
|
positives. Submitting them as false positives will confuse the
|
|
|
|
model.
|
|
|
|
</DialogDescription>
|
|
|
|
</DialogHeader>
|
|
|
|
<img
|
2024-03-16 00:28:57 +01:00
|
|
|
className={`w-full ${grow} bg-black`}
|
2024-03-08 01:32:26 +01:00
|
|
|
src={`${baseUrl}api/events/${upload?.id}/snapshot.jpg`}
|
|
|
|
alt={`${upload?.label}`}
|
|
|
|
/>
|
|
|
|
<DialogFooter>
|
2024-03-09 15:08:06 +01:00
|
|
|
<Button onClick={() => setUpload(undefined)}>Cancel</Button>
|
2024-03-08 01:32:26 +01:00
|
|
|
<Button
|
|
|
|
className="bg-success"
|
|
|
|
onClick={() => onSubmitToPlus(false)}
|
|
|
|
>
|
|
|
|
This is a {upload?.label}
|
|
|
|
</Button>
|
|
|
|
<Button
|
2024-04-07 22:36:08 +02:00
|
|
|
className="text-white"
|
2024-03-08 01:32:26 +01:00
|
|
|
variant="destructive"
|
|
|
|
onClick={() => onSubmitToPlus(true)}
|
|
|
|
>
|
|
|
|
This is not a {upload?.label}
|
|
|
|
</Button>
|
|
|
|
</DialogFooter>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
{events?.map((event) => {
|
2024-03-15 12:59:03 +01:00
|
|
|
if (event.data.type != "object") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-08 01:32:26 +01:00
|
|
|
return (
|
|
|
|
<div
|
2024-03-27 01:54:00 +01:00
|
|
|
key={event.id}
|
2024-03-08 01:32:26 +01:00
|
|
|
className="w-full rounded-2xl aspect-video flex justify-center items-center bg-black cursor-pointer"
|
|
|
|
onClick={() => setUpload(event)}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="aspect-video h-full object-contain rounded-2xl"
|
|
|
|
src={`${baseUrl}api/events/${event.id}/snapshot.jpg`}
|
|
|
|
loading="lazy"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ATTRIBUTES = ["amazon", "face", "fedex", "license_plate", "ups"];
|
|
|
|
|
|
|
|
type PlusFilterGroupProps = {
|
|
|
|
selectedCameras: string[] | undefined;
|
|
|
|
setSelectedCameras: (cameras: string[] | undefined) => void;
|
|
|
|
selectedLabels: string[] | undefined;
|
|
|
|
setSelectedLabels: (cameras: string[] | undefined) => void;
|
|
|
|
};
|
|
|
|
function PlusFilterGroup({
|
|
|
|
selectedCameras,
|
|
|
|
setSelectedCameras,
|
|
|
|
selectedLabels,
|
|
|
|
setSelectedLabels,
|
|
|
|
}: PlusFilterGroupProps) {
|
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
|
|
const allCameras = useMemo(() => {
|
|
|
|
if (!config) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(config.cameras);
|
|
|
|
}, [config]);
|
|
|
|
const allLabels = useMemo<string[]>(() => {
|
|
|
|
if (!config) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
const labels = new Set<string>();
|
|
|
|
const cameras = selectedCameras || Object.keys(config.cameras);
|
|
|
|
|
|
|
|
cameras.forEach((camera) => {
|
|
|
|
const cameraConfig = config.cameras[camera];
|
|
|
|
cameraConfig.objects.track.forEach((label) => {
|
|
|
|
if (!ATTRIBUTES.includes(label)) {
|
|
|
|
labels.add(label);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return [...labels].sort();
|
|
|
|
}, [config, selectedCameras]);
|
|
|
|
|
|
|
|
const [open, setOpen] = useState<"none" | "camera" | "label">("none");
|
|
|
|
const [currentCameras, setCurrentCameras] = useState<string[] | undefined>(
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
const [currentLabels, setCurrentLabels] = useState<string[] | undefined>(
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
|
2024-03-08 18:14:58 +01:00
|
|
|
const Menu = isMobile ? Drawer : DropdownMenu;
|
|
|
|
const Trigger = isMobile ? DrawerTrigger : DropdownMenuTrigger;
|
|
|
|
const Content = isMobile ? DrawerContent : DropdownMenuContent;
|
|
|
|
|
2024-03-08 01:32:26 +01:00
|
|
|
return (
|
|
|
|
<div className="w-full h-16 flex justify-start gap-2 items-center">
|
2024-03-08 18:14:58 +01:00
|
|
|
<Menu
|
2024-03-08 01:32:26 +01:00
|
|
|
open={open == "camera"}
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
if (!open) {
|
|
|
|
setCurrentCameras(selectedCameras);
|
|
|
|
}
|
|
|
|
setOpen(open ? "camera" : "none");
|
|
|
|
}}
|
2024-03-06 13:24:21 +01:00
|
|
|
>
|
2024-03-08 18:14:58 +01:00
|
|
|
<Trigger asChild>
|
2024-04-10 00:49:14 +02:00
|
|
|
<Button size="sm" className="mx-1 capitalize">
|
2024-04-04 22:55:04 +02:00
|
|
|
<FaVideo className="md:mr-[10px] text-secondary-foreground" />
|
2024-04-10 00:49:14 +02:00
|
|
|
<div className="hidden md:block text-primary">
|
2024-03-08 01:32:26 +01:00
|
|
|
{selectedCameras == undefined
|
|
|
|
? "All Cameras"
|
|
|
|
: `${selectedCameras.length} Cameras`}
|
|
|
|
</div>
|
|
|
|
</Button>
|
2024-03-08 18:14:58 +01:00
|
|
|
</Trigger>
|
|
|
|
<Content className={isMobile ? "max-h-[75dvh]" : ""}>
|
2024-03-08 01:32:26 +01:00
|
|
|
<DropdownMenuLabel className="flex justify-center">
|
|
|
|
Filter Cameras
|
|
|
|
</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<FilterCheckBox
|
|
|
|
isChecked={currentCameras == undefined}
|
|
|
|
label="All Cameras"
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
if (isChecked) {
|
|
|
|
setCurrentCameras(undefined);
|
|
|
|
}
|
|
|
|
}}
|
2024-03-06 13:24:21 +01:00
|
|
|
/>
|
2024-03-08 01:32:26 +01:00
|
|
|
<DropdownMenuSeparator />
|
2024-03-08 18:14:58 +01:00
|
|
|
<div className={isMobile ? "h-auto overflow-y-auto" : ""}>
|
|
|
|
{allCameras.map((item) => (
|
|
|
|
<FilterCheckBox
|
|
|
|
key={item}
|
|
|
|
isChecked={currentCameras?.includes(item) ?? false}
|
|
|
|
label={item.replaceAll("_", " ")}
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
if (isChecked) {
|
|
|
|
const updatedCameras = currentCameras
|
|
|
|
? [...currentCameras]
|
|
|
|
: [];
|
2024-03-08 01:32:26 +01:00
|
|
|
|
2024-03-08 18:14:58 +01:00
|
|
|
updatedCameras.push(item);
|
2024-03-08 01:32:26 +01:00
|
|
|
setCurrentCameras(updatedCameras);
|
2024-03-08 18:14:58 +01:00
|
|
|
} else {
|
|
|
|
const updatedCameras = currentCameras
|
|
|
|
? [...currentCameras]
|
|
|
|
: [];
|
|
|
|
|
|
|
|
// can not deselect the last item
|
|
|
|
if (updatedCameras.length > 1) {
|
|
|
|
updatedCameras.splice(updatedCameras.indexOf(item), 1);
|
|
|
|
setCurrentCameras(updatedCameras);
|
|
|
|
}
|
2024-03-08 01:32:26 +01:00
|
|
|
}
|
2024-03-08 18:14:58 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2024-03-08 01:32:26 +01:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<div className="flex justify-center items-center">
|
2024-03-07 15:34:11 +01:00
|
|
|
<Button
|
2024-03-08 01:32:26 +01:00
|
|
|
variant="select"
|
|
|
|
onClick={() => {
|
|
|
|
setSelectedCameras(currentCameras);
|
|
|
|
setOpen("none");
|
|
|
|
}}
|
2024-03-06 13:24:21 +01:00
|
|
|
>
|
2024-03-08 01:32:26 +01:00
|
|
|
Apply
|
2024-03-07 15:34:11 +01:00
|
|
|
</Button>
|
2024-03-08 01:32:26 +01:00
|
|
|
</div>
|
2024-03-08 18:14:58 +01:00
|
|
|
</Content>
|
|
|
|
</Menu>
|
|
|
|
<Menu
|
2024-03-08 01:32:26 +01:00
|
|
|
open={open == "label"}
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
if (!open) {
|
|
|
|
setCurrentLabels(selectedLabels);
|
|
|
|
}
|
|
|
|
setOpen(open ? "label" : "none");
|
|
|
|
}}
|
|
|
|
>
|
2024-03-08 18:14:58 +01:00
|
|
|
<Trigger asChild>
|
2024-04-10 00:49:14 +02:00
|
|
|
<Button size="sm" className="mx-1 capitalize">
|
2024-04-04 22:55:04 +02:00
|
|
|
<FaList className="md:mr-[10px] text-secondary-foreground" />
|
2024-04-10 00:49:14 +02:00
|
|
|
<div className="hidden md:block text-primary">
|
2024-03-08 01:32:26 +01:00
|
|
|
{selectedLabels == undefined
|
|
|
|
? "All Labels"
|
|
|
|
: `${selectedLabels.length} Labels`}
|
|
|
|
</div>
|
|
|
|
</Button>
|
2024-03-08 18:14:58 +01:00
|
|
|
</Trigger>
|
|
|
|
<Content className={isMobile ? "max-h-[75dvh]" : ""}>
|
2024-03-08 01:32:26 +01:00
|
|
|
<DropdownMenuLabel className="flex justify-center">
|
|
|
|
Filter Labels
|
|
|
|
</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<FilterCheckBox
|
|
|
|
isChecked={currentLabels == undefined}
|
|
|
|
label="All Labels"
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
if (isChecked) {
|
|
|
|
setCurrentLabels(undefined);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<DropdownMenuSeparator />
|
2024-03-08 18:14:58 +01:00
|
|
|
<div className={isMobile ? "h-auto overflow-y-auto" : ""}>
|
|
|
|
{allLabels.map((item) => (
|
|
|
|
<FilterCheckBox
|
|
|
|
key={item}
|
|
|
|
isChecked={currentLabels?.includes(item) ?? false}
|
|
|
|
label={item.replaceAll("_", " ")}
|
|
|
|
onCheckedChange={(isChecked) => {
|
|
|
|
if (isChecked) {
|
|
|
|
const updatedLabels = currentLabels
|
|
|
|
? [...currentLabels]
|
|
|
|
: [];
|
2024-03-08 01:32:26 +01:00
|
|
|
|
2024-03-08 18:14:58 +01:00
|
|
|
updatedLabels.push(item);
|
2024-03-08 01:32:26 +01:00
|
|
|
setCurrentLabels(updatedLabels);
|
2024-03-08 18:14:58 +01:00
|
|
|
} else {
|
|
|
|
const updatedLabels = currentLabels
|
|
|
|
? [...currentLabels]
|
|
|
|
: [];
|
|
|
|
|
|
|
|
// can not deselect the last item
|
|
|
|
if (updatedLabels.length > 1) {
|
|
|
|
updatedLabels.splice(updatedLabels.indexOf(item), 1);
|
|
|
|
setCurrentLabels(updatedLabels);
|
|
|
|
}
|
2024-03-08 01:32:26 +01:00
|
|
|
}
|
2024-03-08 18:14:58 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</div>
|
2024-03-08 01:32:26 +01:00
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<div className="flex justify-center items-center">
|
|
|
|
<Button
|
|
|
|
variant="select"
|
|
|
|
onClick={() => {
|
|
|
|
setSelectedLabels(currentLabels);
|
|
|
|
setOpen("none");
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Apply
|
|
|
|
</Button>
|
2024-03-06 13:24:21 +01:00
|
|
|
</div>
|
2024-03-08 18:14:58 +01:00
|
|
|
</Content>
|
|
|
|
</Menu>
|
2024-03-06 13:24:21 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|