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

FEAT: Ability to reorder & ability to hide Cameras in UI #2981

Merged
Merged
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
8 changes: 8 additions & 0 deletions docs/docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,12 @@ cameras:
quality: 70
# Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones)
required_zones: []

# Optional: Configuration for how camera is handled in the GUI.
ui:
# Optional: Adjust sort order of cameras in the UI. Larger numbers come later (default: shown below)
# By default the cameras are sorted alphabetically.
order: 0
# Optional: Whether or not to show the camera in the Frigate UI (default: shown below)
dashboard: True
```
8 changes: 8 additions & 0 deletions frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ class CameraLiveConfig(FrigateBaseModel):
quality: int = Field(default=8, ge=1, le=31, title="Live camera view quality")


class CameraUiConfig(FrigateBaseModel):
order: int = Field(default=0, title="Order of camera in UI.")
dashboard: bool = Field(default=True, title="Show this camera in Frigate dashboard UI.")


class CameraConfig(FrigateBaseModel):
name: Optional[str] = Field(title="Camera name.", regex="^[a-zA-Z0-9_-]+$")
ffmpeg: CameraFfmpegConfig = Field(title="FFmpeg configuration for the camera.")
Expand Down Expand Up @@ -546,6 +551,9 @@ class CameraConfig(FrigateBaseModel):
detect: DetectConfig = Field(
default_factory=DetectConfig, title="Object detection configuration."
)
ui: CameraUiConfig = Field(
default_factory=CameraUiConfig, title="Camera UI Modifications."
)
birdseye: BirdseyeCameraConfig = Field(
default_factory=BirdseyeCameraConfig, title="Birdseye camera configuration."
)
Expand Down
2 changes: 2 additions & 0 deletions web/config/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const handlers = [
detect: { width: 1280, height: 720 },
snapshots: {},
live: { height: 720 },
ui: { dashboard: true, order: 0 },
},
side: {
name: 'side',
Expand All @@ -28,6 +29,7 @@ export const handlers = [
detect: { width: 1280, height: 720 },
snapshots: {},
live: { height: 720 },
ui: { dashboard: true, order: 1 },
},
},
})
Expand Down
70 changes: 49 additions & 21 deletions web/src/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,42 @@ import LinkedLogo from './components/LinkedLogo';
import { Match } from 'preact-router/match';
import { memo } from 'preact/compat';
import { ENV } from './env';
import { useMemo } from 'preact/hooks'
import useSWR from 'swr';
import NavigationDrawer, { Destination, Separator } from './components/NavigationDrawer';

export default function Sidebar() {
const { data: config } = useSWR('config');

const sortedCameras = useMemo(() => {
if (!config) {
return [];
}

return Object.entries(config.cameras)
.filter(([_, conf]) => conf.ui.dashboard)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order - bConf.ui.order);
}, [config]);

if (!config) {
return null;
}
const { cameras, birdseye } = config;
const { birdseye } = config;

return (
<NavigationDrawer header={<Header />}>
<Destination href="/" text="Cameras" />
<Match path="/cameras/:camera/:other?">
{({ matches }) =>
matches ? (
<Fragment>
<Separator />
{Object.keys(cameras).map((camera) => (
<Destination key={camera} href={`/cameras/${camera}`} text={camera} />
))}
<Separator />
</Fragment>
<CameraSection sortedCameras={sortedCameras} />
) : null
}
</Match>
<Match path="/recording/:camera/:date?/:hour?/:seconds?">
{({ matches }) =>
matches ? (
<Fragment>
<Separator />
{Object.keys(cameras).map((camera) => (
<Destination
key={camera}
path={`/recording/${camera}/:date?/:hour?/:seconds?`}
href={`/recording/${camera}`}
text={camera}
/>
))}
<Separator />
</Fragment>
<RecordingSection sortedCameras={sortedCameras} />
) : null
}
</Match>
Expand All @@ -64,10 +59,43 @@ export default function Sidebar() {
);
}

function CameraSection({ sortedCameras }) {

return (
<Fragment>
<Separator />
{sortedCameras.map(([camera]) => (
<Destination key={camera} href={`/cameras/${camera}`} text={camera} />
))}
<Separator />
</Fragment>
);
}

function RecordingSection({ sortedCameras }) {

return (
<Fragment>
<Separator />
{sortedCameras.map(([camera, _]) => {
return (
<Destination
key={camera}
path={`/recording/${camera}/:date?/:hour?/:seconds?`}
href={`/recording/${camera}`}
text={camera}
/>
);
})}
<Separator />
</Fragment>
);
}

const Header = memo(() => {
return (
<div className="text-gray-500">
<LinkedLogo />
</div>
);
});
});
21 changes: 18 additions & 3 deletions web/src/routes/Cameras.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h } from 'preact';
import { h, Fragment } from 'preact';
import ActivityIndicator from '../components/ActivityIndicator';
import Card from '../components/Card';
import CameraImage from '../components/CameraImage';
Expand All @@ -16,10 +16,25 @@ export default function Cameras() {
<ActivityIndicator />
) : (
<div className="grid grid-cols-1 3xl:grid-cols-3 md:grid-cols-2 gap-4 p-2 px-4">
{Object.entries(config.cameras).map(([camera, conf]) => (
<SortedCameras unsortedCameras={config.cameras} />
</div>
);
}

function SortedCameras({ unsortedCameras }) {

const sortedCameras = useMemo(() =>
Object.entries(unsortedCameras)
.filter(([_, conf]) => conf.ui.dashboard)
.sort(([_, aConf], [__, bConf]) => aConf.ui.order - bConf.ui.order),
[unsortedCameras]);

return (
<Fragment>
{sortedCameras.map(([camera, conf]) => (
<Camera key={camera} name={camera} conf={conf} />
))}
</div>
</Fragment>
);
}

Expand Down