Including audio file count in statistics.

This commit is contained in:
Roland 2022-12-15 13:39:00 -07:00
parent e24990aae2
commit f8c0e77f87
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 62 additions and 42 deletions

View file

@ -3,7 +3,7 @@ import {Divider, SegmentGroup, StatisticLabel, StatisticValue} from "semantic-ui
import {Route, Routes} from "react-router-dom"; import {Route, Routes} from "react-router-dom";
import "../static/wrolpi.css"; import "../static/wrolpi.css";
import {decryptOTP, encryptOTP} from "../api"; import {decryptOTP, encryptOTP} from "../api";
import {PageContainer, useTitle} from "./Common"; import {mimetypeColor, PageContainer, useTitle} from "./Common";
import {ThemeContext} from "../contexts/contexts"; import {ThemeContext} from "../contexts/contexts";
import {Button, Header, Loader, Segment, Statistic, StatisticGroup, TextArea} from "./Theme"; import {Button, Header, Loader, Segment, Statistic, StatisticGroup, TextArea} from "./Theme";
import {useFileStatistics} from "../hooks/customHooks"; import {useFileStatistics} from "../hooks/customHooks";
@ -153,57 +153,74 @@ function FileStatistics() {
const {statistics} = useFileStatistics(); const {statistics} = useFileStatistics();
let body = <Loader inline active/>; let body = <Segment><Loader inline active/></Segment>;
if (statistics === undefined) { if (statistics === undefined) {
body = <p {...s}>Failed to fetch statistics</p>; body = <Segment><p {...s}>Failed to fetch statistics</p></Segment>;
} }
if (statistics !== undefined && statistics !== null) { if (statistics !== undefined && statistics !== null) {
const {total_count, video_count, pdf_count, ebook_count, archive_count, image_count, zip_count} = statistics; const {
archive_count,
audio_count,
ebook_count,
image_count,
pdf_count,
total_count,
video_count,
zip_count,
} = statistics;
body = <> body = <>
<StatisticGroup> <Segment>
<Statistic> <StatisticGroup>
<StatisticValue>{total_count}</StatisticValue> <Statistic>
<StatisticLabel>All Files</StatisticLabel> <StatisticValue>{total_count}</StatisticValue>
</Statistic> <StatisticLabel>All Files</StatisticLabel>
</StatisticGroup> </Statistic>
<StatisticGroup size='small'> </StatisticGroup>
<Statistic color='blue'> </Segment>
<StatisticValue>{video_count}</StatisticValue> <Segment>
<StatisticLabel>Videos</StatisticLabel> <StatisticGroup size='small'>
</Statistic> <Statistic color={mimetypeColor('video/')}>
<Statistic color='red'> <StatisticValue>{video_count}</StatisticValue>
<StatisticValue>{pdf_count}</StatisticValue> <StatisticLabel>Videos</StatisticLabel>
<StatisticLabel>PDFs</StatisticLabel> </Statistic>
</Statistic> <Statistic color={mimetypeColor('application/pdf')}>
<Statistic color='yellow'> <StatisticValue>{pdf_count}</StatisticValue>
<StatisticValue>{ebook_count}</StatisticValue> <StatisticLabel>PDFs</StatisticLabel>
<StatisticLabel>eBooks</StatisticLabel> </Statistic>
</Statistic> <Statistic color={mimetypeColor('application/epub')}>
<Statistic color='green'> <StatisticValue>{ebook_count}</StatisticValue>
<StatisticValue>{archive_count}</StatisticValue> <StatisticLabel>eBooks</StatisticLabel>
<StatisticLabel>Archives</StatisticLabel> </Statistic>
</Statistic> <Statistic color={mimetypeColor('text/html')}>
<Statistic color='pink'> <StatisticValue>{archive_count}</StatisticValue>
<StatisticValue>{image_count}</StatisticValue> <StatisticLabel>Archives</StatisticLabel>
<StatisticLabel>Images</StatisticLabel> </Statistic>
</Statistic> <Statistic color={mimetypeColor('image/')}>
</StatisticGroup> <StatisticValue>{image_count}</StatisticValue>
<StatisticGroup> <StatisticLabel>Images</StatisticLabel>
<Statistic color='grey'> </Statistic>
<StatisticValue>{zip_count}</StatisticValue> </StatisticGroup>
<StatisticLabel>ZIP</StatisticLabel> </Segment>
</Statistic> <Segment>
</StatisticGroup> <StatisticGroup size='tiny'>
<Statistic>
<StatisticValue>{zip_count}</StatisticValue>
<StatisticLabel>ZIP</StatisticLabel>
</Statistic>
<Statistic>
<StatisticValue>{audio_count}</StatisticValue>
<StatisticLabel>Audio</StatisticLabel>
</Statistic>
</StatisticGroup>
</Segment>
</>; </>;
} }
return <> return <>
<Header as='h1'>File Statistics</Header> <Header as='h1'>File Statistics</Header>
<Segment> {body}
{body}
</Segment>
</> </>
} }

View file

@ -631,7 +631,8 @@ async def get_file_statistics():
COUNT(path) FILTER (WHERE file.mimetype LIKE 'video/%') AS "video_count", COUNT(path) FILTER (WHERE file.mimetype LIKE 'video/%') AS "video_count",
COUNT(path) FILTER (WHERE file.mimetype = 'application/pdf') AS "pdf_count", COUNT(path) FILTER (WHERE file.mimetype = 'application/pdf') AS "pdf_count",
COUNT(path) FILTER (WHERE file.mimetype LIKE 'image/%' AND file.associated = FALSE) AS "image_count", COUNT(path) FILTER (WHERE file.mimetype LIKE 'image/%' AND file.associated = FALSE) AS "image_count",
COUNT(path) FILTER (WHERE file.mimetype = 'application/zip') AS "zip_count" COUNT(path) FILTER (WHERE file.mimetype = 'application/zip') AS "zip_count",
COUNT(path) FILTER (WHERE file.mimetype LIKE 'audio/%' AND file.associated = FALSE) AS "audio_count"
FROM FROM
file file
''') ''')

View file

@ -252,6 +252,7 @@ def test_file_statistics(test_session, test_client, example_pdf, example_mobi, e
assert response.json == { assert response.json == {
'statistics': { 'statistics': {
'archive_count': 0, 'archive_count': 0,
'audio_count': 0,
'ebook_count': 0, 'ebook_count': 0,
'image_count': 0, 'image_count': 0,
'pdf_count': 0, 'pdf_count': 0,
@ -267,6 +268,7 @@ def test_file_statistics(test_session, test_client, example_pdf, example_mobi, e
assert response.json == { assert response.json == {
'statistics': { 'statistics': {
'archive_count': 0, 'archive_count': 0,
'audio_count': 0,
'ebook_count': 2, 'ebook_count': 2,
'image_count': 0, 'image_count': 0,
'pdf_count': 1, 'pdf_count': 1,