Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Fixes #11742

Merged
merged 5 commits into from
Jun 4, 2024
Merged

UI Fixes #11742

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions frigate/api/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import Optional

import psutil
from flask import (
Blueprint,
current_app,
Expand All @@ -14,6 +15,7 @@
from peewee import DoesNotExist
from werkzeug.utils import secure_filename

from frigate.const import EXPORT_DIR
from frigate.models import Export, Recordings
from frigate.record.export import PlaybackFactorEnum, RecordingExporter

Expand Down Expand Up @@ -140,6 +142,27 @@ def export_delete(id: str):
404,
)

files_in_use = []
for process in psutil.process_iter():
try:
if process.name() != "ffmpeg":
continue
flist = process.open_files()
if flist:
for nt in flist:
if nt.path.startswith(EXPORT_DIR):
files_in_use.append(nt.path.split("/")[-1])
except psutil.Error:
continue

if export.video_path.split("/")[-1] in files_in_use:
return make_response(
jsonify(
{"success": False, "message": "Can not delete in progress export."}
),
400,
)

Path(export.video_path).unlink(missing_ok=True)

if export.thumb_path:
Expand Down
46 changes: 25 additions & 21 deletions frigate/record/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from enum import Enum
from pathlib import Path

from peewee import DoesNotExist

from frigate.config import FrigateConfig
from frigate.const import (
CACHE_DIR,
Expand Down Expand Up @@ -72,30 +74,32 @@ def save_thumbnail(self, id: str) -> str:

if datetime.datetime.fromtimestamp(
self.start_time
) < datetime.datetime.now().replace(minute=0, second=0):
) < datetime.datetime.now().astimezone(datetime.timezone.dst).replace(
minute=0, second=0, microsecond=0
):
# has preview mp4
preview: Previews = (
Previews.select(
Previews.camera,
Previews.path,
Previews.duration,
Previews.start_time,
Previews.end_time,
)
.where(
Previews.start_time.between(self.start_time, self.end_time)
| Previews.end_time.between(self.start_time, self.end_time)
| (
(self.start_time > Previews.start_time)
& (self.end_time < Previews.end_time)
try:
preview: Previews = (
Previews.select(
Previews.camera,
Previews.path,
Previews.duration,
Previews.start_time,
Previews.end_time,
)
.where(
Previews.start_time.between(self.start_time, self.end_time)
| Previews.end_time.between(self.start_time, self.end_time)
| (
(self.start_time > Previews.start_time)
& (self.end_time < Previews.end_time)
)
)
.where(Previews.camera == self.camera)
.limit(1)
.get()
)
.where(Previews.camera == self.camera)
.limit(1)
.get()
)

if not preview:
except DoesNotExist:
return ""

diff = self.start_time - preview.start_time
Expand Down
11 changes: 8 additions & 3 deletions web/src/components/card/AnimatedEventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ import { baseUrl } from "@/api/baseUrl";

type AnimatedEventCardProps = {
event: ReviewSegment;
selectedGroup?: string;
};
export function AnimatedEventCard({ event }: AnimatedEventCardProps) {
export function AnimatedEventCard({
event,
selectedGroup,
}: AnimatedEventCardProps) {
const { data: config } = useSWR<FrigateConfig>("config");

const currentHour = useMemo(() => isCurrentHour(event.start_time), [event]);
Expand Down Expand Up @@ -53,7 +57,8 @@ export function AnimatedEventCard({ event }: AnimatedEventCardProps) {

const navigate = useNavigate();
const onOpenReview = useCallback(() => {
navigate("review", {
const url = selectedGroup ? `review?group=${selectedGroup}` : "review";
navigate(url, {
state: {
severity: event.severity,
recording: {
Expand All @@ -64,7 +69,7 @@ export function AnimatedEventCard({ event }: AnimatedEventCardProps) {
},
});
axios.post(`reviews/viewed`, { ids: [event.id] });
}, [navigate, event]);
}, [navigate, selectedGroup, event]);

// image behavior

Expand Down
77 changes: 37 additions & 40 deletions web/src/components/card/ExportCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,43 +109,38 @@ export default function ExportCard({
"relative flex aspect-video items-center justify-center rounded-lg bg-black md:rounded-2xl",
className,
)}
onMouseEnter={
isDesktop && !exportedRecording.in_progress
? () => setHovered(true)
: undefined
}
onMouseLeave={
isDesktop && !exportedRecording.in_progress
? () => setHovered(false)
: undefined
}
onClick={
isDesktop || exportedRecording.in_progress
? undefined
: () => setHovered(!hovered)
}
onMouseEnter={isDesktop ? () => setHovered(true) : undefined}
onMouseLeave={isDesktop ? () => setHovered(false) : undefined}
onClick={isDesktop ? undefined : () => setHovered(!hovered)}
>
{hovered && (
<>
<div className="absolute inset-0 z-10 rounded-lg bg-black bg-opacity-60 md:rounded-2xl" />
<div className="absolute right-1 top-1 flex items-center gap-2">
<a
className="z-20"
download
href={`${baseUrl}${exportedRecording.video_path.replace("/media/frigate/", "")}`}
>
<Chip className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500">
<FaDownload className="size-4 text-white" />
{!exportedRecording.in_progress && (
<a
className="z-20"
download
href={`${baseUrl}${exportedRecording.video_path.replace("/media/frigate/", "")}`}
>
<Chip className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500">
<FaDownload className="size-4 text-white" />
</Chip>
</a>
)}
{!exportedRecording.in_progress && (
<Chip
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
onClick={() =>
setEditName({
original: exportedRecording.name,
update: "",
})
}
>
<MdEditSquare className="size-4 text-white" />
</Chip>
</a>
<Chip
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
onClick={() =>
setEditName({ original: exportedRecording.name, update: "" })
}
>
<MdEditSquare className="size-4 text-white" />
</Chip>
)}
<Chip
className="cursor-pointer rounded-md bg-gray-500 bg-gradient-to-br from-gray-400 to-gray-500"
onClick={() =>
Expand All @@ -159,15 +154,17 @@ export default function ExportCard({
</Chip>
</div>

<Button
className="absolute left-1/2 top-1/2 z-20 h-20 w-20 -translate-x-1/2 -translate-y-1/2 cursor-pointer text-white hover:bg-transparent hover:text-white"
variant="ghost"
onClick={() => {
onSelect(exportedRecording);
}}
>
<FaPlay />
</Button>
{!exportedRecording.in_progress && (
<Button
className="absolute left-1/2 top-1/2 z-20 h-20 w-20 -translate-x-1/2 -translate-y-1/2 cursor-pointer text-white hover:bg-transparent hover:text-white"
variant="ghost"
onClick={() => {
onSelect(exportedRecording);
}}
>
<FaPlay />
</Button>
)}
</>
)}
{exportedRecording.in_progress ? (
Expand Down
13 changes: 13 additions & 0 deletions web/src/pages/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ export default function Events() {
const [reviewFilter, setReviewFilter, reviewSearchParams] =
useApiFilter<ReviewFilter>();

useSearchEffect("group", (reviewGroup) => {
if (config && reviewGroup) {
const group = config.camera_groups[reviewGroup];

if (group) {
setReviewFilter({
...reviewFilter,
cameras: group.cameras,
});
}
}
});

const onUpdateFilter = useCallback(
(newFilter: ReviewFilter) => {
setReviewFilter(newFilter);
Expand Down
47 changes: 26 additions & 21 deletions web/src/views/events/RecordingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -668,27 +668,32 @@ function Timeline({
<Skeleton className="size-full" />
)
) : (
<div
className={`grid h-full grid-cols-1 gap-4 overflow-auto bg-secondary p-4 ${isDesktop ? "" : "sm:grid-cols-2"}`}
>
{mainCameraReviewItems.map((review) => {
if (review.severity == "significant_motion") {
return;
}

return (
<ReviewCard
key={review.id}
event={review}
currentTime={currentTime}
onClick={() => {
setScrubbing(true);
setCurrentTime(review.start_time - REVIEW_PADDING);
setScrubbing(false);
}}
/>
);
})}
<div className="h-full overflow-auto bg-secondary">
<div
className={cn(
"grid h-auto grid-cols-1 gap-4 overflow-auto p-4",
isMobile && "sm:grid-cols-2",
)}
>
{mainCameraReviewItems.map((review) => {
if (review.severity == "significant_motion") {
return;
}

return (
<ReviewCard
key={review.id}
event={review}
currentTime={currentTime}
onClick={() => {
setScrubbing(true);
setCurrentTime(review.start_time - REVIEW_PADDING);
setScrubbing(false);
}}
/>
);
})}
</div>
</div>
)}
</div>
Expand Down
8 changes: 8 additions & 0 deletions web/src/views/live/DraggableGridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ export default function DraggableGridLayout({
);
}, [config]);

// editing

const [editGroup, setEditGroup] = useState(false);

useEffect(() => {
setEditGroup(false);
}, [cameraGroup]);

// camera state

const [currentCameras, setCurrentCameras] = useState<CameraConfig[]>();
const [currentIncludeBirdseye, setCurrentIncludeBirdseye] =
useState<boolean>();
Expand Down
8 changes: 7 additions & 1 deletion web/src/views/live/LiveDashboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ export default function LiveDashboardView({
<TooltipProvider>
<div className="flex items-center gap-2 px-1">
{events.map((event) => {
return <AnimatedEventCard key={event.id} event={event} />;
return (
<AnimatedEventCard
key={event.id}
event={event}
selectedGroup={cameraGroup}
/>
);
})}
</div>
</TooltipProvider>
Expand Down
Loading