Merge branch 'dev' into feature/add-basic-authentication

This commit is contained in:
Meier Lukas
2023-08-02 06:44:26 +02:00
4 changed files with 65 additions and 42 deletions

View File

@@ -22,6 +22,8 @@
"test:ui": "vitest --ui",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"docker:build": "turbo build && docker build . -t homarr:dev",
"docker:start": "docker run --env-file ./.env -p 7575:7575 homarr:dev ",
"postinstall": "prisma generate"
},
"dependencies": {

View File

@@ -3,7 +3,10 @@
"name": "Media request stats",
"description": "Statistics about your media requests",
"settings": {
"title": "Media requests stats"
"title": "Media requests stats",
"direction": {
"label": "Direction of the layout."
}
}
},
"stats": {

View File

@@ -5,8 +5,12 @@ function Post(req: NextApiRequest, res: NextApiResponse) {
const { tried, type = 'password' } = req.body;
// If the type of password is "edit", we run this branch to check the edit password
if (type === 'edit') {
if (tried === process.env.EDIT_MODE_PASSWORD) {
process.env.DISABLE_EDIT_MODE = process.env.DISABLE_EDIT_MODE === 'true' ? 'false' : 'true';
if ((tried === process.env.EDIT_MODE_PASSWORD) !== undefined) {
if (process.env.DISABLE_EDIT_MODE?.toLowerCase() === 'true') {
process.env.DISABLE_EDIT_MODE = 'false';
} else {
process.env.DISABLE_EDIT_MODE = 'true';
}
return res.status(200).json({
success: true,
});

View File

@@ -1,4 +1,4 @@
import { Card, Center, Flex, Stack, Text } from '@mantine/core';
import { Card, Flex, Stack, Text } from '@mantine/core';
import { IconChartBar } from '@tabler/icons-react';
import { useTranslation } from 'next-i18next';
@@ -11,14 +11,23 @@ import { MediaRequestStatus } from './media-request-types';
const definition = defineWidget({
id: 'media-requests-stats',
icon: IconChartBar,
options: {},
component: MediaRequestStatsTile,
options: {
direction: {
type: 'select',
defaultValue: 'row' as 'row' | 'column',
data: [
{ label: 'Horizontal', value: 'row' },
{ label: 'Vertical', value: 'column' },
],
},
},
gridstack: {
minWidth: 1,
minHeight: 2,
minHeight: 1,
maxWidth: 12,
maxHeight: 12,
},
component: MediaRequestStatsTile,
});
export type MediaRequestStatsWidget = IWidget<(typeof definition)['id'], typeof definition>;
@@ -36,41 +45,46 @@ function MediaRequestStatsTile({ widget }: MediaRequestStatsWidgetProps) {
}
return (
<Flex gap="md" wrap="wrap">
<Card w={100} h={100} withBorder>
<Center h="100%">
<Stack spacing={0} align="center">
<Text>
{data.filter((x) => x.status === MediaRequestStatus.PendingApproval).length}
</Text>
<Text color="dimmed" align="center" size="xs">
{t('stats.pending')}
</Text>
</Stack>
</Center>
</Card>
<Card w={100} h={100} withBorder>
<Center h="100%">
<Stack spacing={0} align="center">
<Text align="center">{data.filter((x) => x.type === 'tv').length}</Text>
<Text color="dimmed" align="center" size="xs">
{t('stats.tvRequests')}
</Text>
</Stack>
</Center>
</Card>
<Card w={100} h={100} withBorder>
<Center h="100%">
<Stack spacing={0} align="center">
<Text align="center">{data.filter((x) => x.type === 'movie').length}</Text>
<Text color="dimmed" align="center" size="xs">
{t('stats.movieRequests')}
</Text>
</Stack>
</Center>
</Card>
<Flex
w="100%"
h="100%"
gap="md"
direction={ widget.properties.direction?? 'row' }
>
<StatCard
number={data.filter((x) => x.status === MediaRequestStatus.PendingApproval).length}
label={t('stats.pending')}
/>
<StatCard
number={data.filter((x) => x.type === 'tv').length}
label={t('stats.tvRequests')}
/>
<StatCard
number={data.filter((x) => x.type === 'movie').length}
label={t('stats.movieRequests')}
/>
</Flex>
);
}
interface StatCardProps {
number: number;
label: string;
}
const StatCard = ({ number, label }: StatCardProps) => {
return (
<Card w="100%" h="100%" withBorder style={{flex:"1 1 auto"}}>
<Stack w="100%" h="100%" align="center" justify="center" spacing={0}>
<Text align="center">
{number}
</Text>
<Text color="dimmed" align="center" size="xs">
{label}
</Text>
</Stack>
</Card>
);
};
export default definition;