2023-04-09 14:13:36 -06:00
|
|
|
import React, {useContext, useState} from "react";
|
2022-11-30 20:13:54 -07:00
|
|
|
import {
|
|
|
|
|
CardContent,
|
2022-11-30 20:21:00 -07:00
|
|
|
CardDescription,
|
2022-11-30 20:13:54 -07:00
|
|
|
CardHeader,
|
2022-11-30 20:21:00 -07:00
|
|
|
CardMeta,
|
2023-04-09 14:13:36 -06:00
|
|
|
Checkbox,
|
2022-12-09 11:22:20 -07:00
|
|
|
Container,
|
2022-11-30 20:13:54 -07:00
|
|
|
Dropdown,
|
2023-04-09 14:13:36 -06:00
|
|
|
Form,
|
2022-11-30 20:13:54 -07:00
|
|
|
Image,
|
|
|
|
|
PlaceholderLine,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHeaderCell,
|
|
|
|
|
} from "semantic-ui-react";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {
|
|
|
|
|
CardGroupCentered,
|
2023-03-29 13:46:39 -06:00
|
|
|
CardPoster,
|
|
|
|
|
encodeMediaPath,
|
2023-09-07 20:13:36 -06:00
|
|
|
ErrorMessage,
|
2022-08-06 05:22:07 +00:00
|
|
|
ExternalCardLink,
|
|
|
|
|
FileIcon,
|
2023-03-29 13:46:39 -06:00
|
|
|
findPosterPath,
|
2022-08-06 05:22:07 +00:00
|
|
|
humanFileSize,
|
2023-01-04 09:14:33 -07:00
|
|
|
isoDatetimeToString,
|
2022-08-06 05:22:07 +00:00
|
|
|
mimetypeColor,
|
|
|
|
|
PageContainer,
|
|
|
|
|
Paginator,
|
2023-02-15 20:58:07 -07:00
|
|
|
PreviewLink,
|
2023-05-29 18:04:03 -06:00
|
|
|
TagIcon,
|
2022-08-06 05:22:07 +00:00
|
|
|
textEllipsis,
|
2023-01-04 09:14:33 -07:00
|
|
|
useTitle
|
2022-08-06 05:22:07 +00:00
|
|
|
} from "./Common";
|
2023-04-09 14:13:36 -06:00
|
|
|
import {
|
|
|
|
|
useFilesProgressInterval,
|
|
|
|
|
usePages,
|
|
|
|
|
useQuery,
|
|
|
|
|
useSearchFiles,
|
|
|
|
|
useSearchFilter,
|
2023-09-07 20:13:36 -06:00
|
|
|
useSearchView,
|
|
|
|
|
useStatusFlag,
|
2023-07-21 15:14:09 -06:00
|
|
|
useWROLMode
|
2023-04-09 14:13:36 -06:00
|
|
|
} from "../hooks/customHooks";
|
2022-08-06 05:22:07 +00:00
|
|
|
import {Route, Routes} from "react-router-dom";
|
2023-05-29 18:04:03 -06:00
|
|
|
import {CardPlaceholder} from "./Placeholder";
|
2022-11-04 09:58:38 -06:00
|
|
|
import {ArchiveCard, ArchiveRowCells} from "./Archive";
|
2022-08-06 05:22:07 +00:00
|
|
|
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
2023-09-07 20:13:36 -06:00
|
|
|
import {Media, ThemeContext} from "../contexts/contexts";
|
2023-04-18 22:03:45 -06:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Card,
|
|
|
|
|
CardIcon,
|
|
|
|
|
Icon,
|
|
|
|
|
Modal,
|
|
|
|
|
ModalActions,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalHeader,
|
|
|
|
|
Placeholder,
|
|
|
|
|
Progress,
|
|
|
|
|
Segment
|
|
|
|
|
} from "./Theme";
|
2022-10-24 09:07:08 -06:00
|
|
|
import {SelectableTable} from "./Tables";
|
2022-11-04 09:58:38 -06:00
|
|
|
import {VideoCard, VideoRowCells} from "./Videos";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {FileBrowser} from "./FileBrowser";
|
2023-07-27 15:53:47 -06:00
|
|
|
import {refreshFiles} from "../api";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {useSubscribeEventName} from "../Events";
|
2023-04-09 14:13:36 -06:00
|
|
|
import {TagsSelector} from "../Tags";
|
2023-04-12 18:09:10 -06:00
|
|
|
import {Headlines} from "./Headline";
|
2022-01-29 16:50:22 -07:00
|
|
|
|
2022-12-09 11:22:20 -07:00
|
|
|
function EbookCard({file}) {
|
|
|
|
|
const {s} = useContext(ThemeContext);
|
2022-12-17 14:42:46 -07:00
|
|
|
|
2023-03-29 13:46:39 -06:00
|
|
|
const downloadUrl = `/download/${encodeMediaPath(file.primary_path)}`;
|
2022-12-17 14:42:46 -07:00
|
|
|
const isEpub = file['mimetype'].startsWith('application/epub');
|
2023-05-29 18:04:03 -06:00
|
|
|
const viewerUrl = isEpub ? `/epub/epub.html?url=${downloadUrl}` : null;
|
2022-12-09 11:22:20 -07:00
|
|
|
|
|
|
|
|
const color = mimetypeColor(file.mimetype);
|
|
|
|
|
return <Card color={color}>
|
2023-03-29 13:46:39 -06:00
|
|
|
<CardPoster file={file} preview={true}/>
|
2022-12-09 11:22:20 -07:00
|
|
|
<CardContent {...s}>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<Container textAlign='left'>
|
2023-11-02 10:07:49 -06:00
|
|
|
<ExternalCardLink to={viewerUrl || downloadUrl} className='card-title-ellipsis'>
|
|
|
|
|
{file.title || file.stem || file.name}
|
2022-12-19 10:40:01 -07:00
|
|
|
</ExternalCardLink>
|
2022-12-09 11:22:20 -07:00
|
|
|
</Container>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardMeta>
|
2023-10-24 10:20:06 -06:00
|
|
|
{file.author ? <b {...s}>{file.author}</b> : null}
|
2023-03-24 08:58:18 -06:00
|
|
|
{file.size && <p {...s}>{humanFileSize(file.size)}</p>}
|
2022-12-09 11:22:20 -07:00
|
|
|
</CardMeta>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function ImageCard({file}) {
|
|
|
|
|
const {s} = useContext(ThemeContext);
|
2023-03-29 13:46:39 -06:00
|
|
|
const url = `/media/${encodeMediaPath(file.primary_path)}`;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
return <Card color={mimetypeColor(file.mimetype)}>
|
2023-02-15 20:58:07 -07:00
|
|
|
<PreviewLink file={file}>
|
2023-03-29 13:46:39 -06:00
|
|
|
<CardPoster file={file}/>
|
2023-02-15 20:58:07 -07:00
|
|
|
</PreviewLink>
|
2022-11-30 20:21:00 -07:00
|
|
|
<CardContent {...s}>
|
|
|
|
|
<CardHeader>
|
2022-08-06 05:22:07 +00:00
|
|
|
<ExternalCardLink to={url} className='no-link-underscore card-link'>
|
2023-03-24 08:58:18 -06:00
|
|
|
<p>{textEllipsis(file.title || file.stem || file.primary_path)}</p>
|
2022-08-06 05:22:07 +00:00
|
|
|
</ExternalCardLink>
|
2022-11-30 20:21:00 -07:00
|
|
|
</CardHeader>
|
|
|
|
|
<CardMeta {...s}>
|
2022-12-23 16:04:09 -07:00
|
|
|
<p>{isoDatetimeToString(file.modified / 1000)}</p>
|
2022-11-30 20:21:00 -07:00
|
|
|
</CardMeta>
|
|
|
|
|
<CardDescription {...s}>
|
2022-08-06 05:22:07 +00:00
|
|
|
<p>{humanFileSize(file.size)}</p>
|
2022-11-30 20:21:00 -07:00
|
|
|
</CardDescription>
|
|
|
|
|
</CardContent>
|
2022-08-06 05:22:07 +00:00
|
|
|
</Card>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FileCard({file}) {
|
|
|
|
|
const {s} = useContext(ThemeContext);
|
|
|
|
|
|
2022-12-15 14:25:47 -07:00
|
|
|
const isEbookType = file.mimetype && (
|
|
|
|
|
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
|
|
|
|
);
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
if (file.model === 'video' && 'video' in file) {
|
2023-03-24 08:58:18 -06:00
|
|
|
return <VideoCard key={file['primary_path']} file={file}/>;
|
|
|
|
|
} else if (file.model === 'archive') {
|
|
|
|
|
return <ArchiveCard key={file['primary_path']} file={file}/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
2023-03-24 08:58:18 -06:00
|
|
|
return <ImageCard key={file['primary_path']} file={file}/>;
|
2022-12-15 14:25:47 -07:00
|
|
|
} else if (isEbookType) {
|
2023-03-24 08:58:18 -06:00
|
|
|
return <EbookCard key={file['primary_path']} file={file}/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-20 18:53:26 -06:00
|
|
|
const author = file.author;
|
2023-03-29 13:46:39 -06:00
|
|
|
const downloadUrl = `/download/${encodeMediaPath(file.primary_path)}`;
|
2022-08-06 05:22:07 +00:00
|
|
|
const color = mimetypeColor(file.mimetype);
|
2022-10-24 17:15:15 -06:00
|
|
|
const size = file.size !== null && file.size !== undefined ? humanFileSize(file.size) : null;
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
return <Card color={color}>
|
2023-03-29 13:46:39 -06:00
|
|
|
<CardPoster to={downloadUrl} file={file}/>
|
2022-11-30 20:13:54 -07:00
|
|
|
<CardContent {...s}>
|
|
|
|
|
<CardHeader>
|
2023-11-02 10:07:49 -06:00
|
|
|
<ExternalCardLink to={downloadUrl} className='card-title-ellipsis'>
|
|
|
|
|
{file.title || file.name || file.primary_path}
|
2022-08-06 05:22:07 +00:00
|
|
|
</ExternalCardLink>
|
2022-11-30 20:13:54 -07:00
|
|
|
</CardHeader>
|
2023-03-24 08:58:18 -06:00
|
|
|
{author && <b {...s}>{author}</b>}
|
|
|
|
|
<p>{isoDatetimeToString(file.modified)}</p>
|
2022-10-24 17:15:15 -06:00
|
|
|
<p>{size}</p>
|
2022-11-30 20:13:54 -07:00
|
|
|
</CardContent>
|
2022-08-06 05:22:07 +00:00
|
|
|
</Card>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FileCards({files}) {
|
2023-09-07 20:13:36 -06:00
|
|
|
if (files && files.length >= 1) {
|
2022-08-06 05:22:07 +00:00
|
|
|
return <CardGroupCentered>
|
2023-03-24 08:58:18 -06:00
|
|
|
{files.map(i => <FileCard key={i['primary_path']} file={i}/>)}
|
2022-08-06 05:22:07 +00:00
|
|
|
</CardGroupCentered>
|
2022-11-05 15:24:06 -06:00
|
|
|
} else if (files && files.length === 0) {
|
2023-01-04 09:14:33 -07:00
|
|
|
return <Segment>No results!</Segment>
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (files === undefined) {
|
|
|
|
|
return <ErrorMessage>Could not search!</ErrorMessage>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
2023-09-07 20:13:36 -06:00
|
|
|
// Response is pending.
|
|
|
|
|
return <CardGroupCentered><CardPlaceholder/></CardGroupCentered>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-24 09:07:08 -06:00
|
|
|
function ImageRowCells({file}) {
|
2023-03-29 13:46:39 -06:00
|
|
|
const url = `/media/${encodeMediaPath(file.primary_path)}`;
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
let poster = <FileIcon file={file} size='large'/>;
|
|
|
|
|
if (file.size && file.size < 50000000) {
|
|
|
|
|
// Image is less than 5mb, use it.
|
|
|
|
|
poster = <Image wrapped src={url} width='50px'/>;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-24 09:07:08 -06:00
|
|
|
// Fragment for SelectableRow
|
2023-02-15 21:30:12 -07:00
|
|
|
return <React.Fragment>
|
2022-10-24 09:07:08 -06:00
|
|
|
<TableCell>
|
|
|
|
|
<center>
|
|
|
|
|
{poster}
|
|
|
|
|
</center>
|
2022-09-23 16:22:57 -06:00
|
|
|
</TableCell>
|
2022-10-24 09:07:08 -06:00
|
|
|
<TableCell>
|
2023-02-15 21:30:12 -07:00
|
|
|
<PreviewLink file={file}>
|
2023-03-24 08:58:18 -06:00
|
|
|
<p>{textEllipsis(file.title || file.stem || file.primary_path)}</p>
|
2023-02-15 21:30:12 -07:00
|
|
|
</PreviewLink>
|
2022-10-24 09:07:08 -06:00
|
|
|
</TableCell>
|
2023-02-15 21:30:12 -07:00
|
|
|
</React.Fragment>
|
2022-10-24 09:07:08 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2022-12-28 19:49:18 -07:00
|
|
|
export function EbookRowCells({file}) {
|
|
|
|
|
let cover = <CardIcon><FileIcon file={file}/></CardIcon>;
|
2023-03-29 13:46:39 -06:00
|
|
|
const posterPath = findPosterPath(file);
|
|
|
|
|
if (posterPath) {
|
|
|
|
|
const coverSrc = `/media/${encodeMediaPath(posterPath)}`;
|
2022-12-28 19:49:18 -07:00
|
|
|
cover = <Image wrapped src={coverSrc} width='50px'/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fragment for SelectableRow
|
2023-02-15 21:30:12 -07:00
|
|
|
return <React.Fragment>
|
2022-12-28 19:49:18 -07:00
|
|
|
<TableCell>
|
|
|
|
|
<center>{cover}</center>
|
|
|
|
|
</TableCell>
|
|
|
|
|
<TableCell>
|
2023-02-15 21:30:12 -07:00
|
|
|
<PreviewLink file={file}>
|
2023-03-29 13:46:39 -06:00
|
|
|
<FileRowTagIcon file={file}/>
|
2023-03-24 08:58:18 -06:00
|
|
|
{textEllipsis(file.title || file.stem)}
|
2023-02-15 21:30:12 -07:00
|
|
|
</PreviewLink>
|
2022-12-28 19:49:18 -07:00
|
|
|
</TableCell>
|
2023-02-15 21:30:12 -07:00
|
|
|
</React.Fragment>
|
2022-12-28 19:49:18 -07:00
|
|
|
}
|
|
|
|
|
|
2022-10-24 09:07:08 -06:00
|
|
|
function FileRow({file}) {
|
2022-12-28 19:49:18 -07:00
|
|
|
const isEbookType = file.mimetype && (
|
|
|
|
|
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
|
|
|
|
);
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
if (file.model === 'video' && 'video' in file) {
|
2022-10-24 09:07:08 -06:00
|
|
|
return <VideoRowCells file={file}/>;
|
2023-03-24 08:58:18 -06:00
|
|
|
} else if (file.model === 'archive') {
|
2022-10-24 09:07:08 -06:00
|
|
|
return <ArchiveRowCells file={file}/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
2022-10-24 09:07:08 -06:00
|
|
|
return <ImageRowCells file={file}/>;
|
2022-12-28 19:49:18 -07:00
|
|
|
} else if (isEbookType) {
|
2023-03-24 08:58:18 -06:00
|
|
|
return <EbookRowCells key={file['primary_path']} file={file}/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-24 09:07:08 -06:00
|
|
|
// Fragment for SelectableRow
|
|
|
|
|
return <React.Fragment>
|
2022-08-06 05:22:07 +00:00
|
|
|
<TableCell>
|
|
|
|
|
<center><FileIcon file={file} size='large'/></center>
|
|
|
|
|
</TableCell>
|
2023-02-15 21:30:12 -07:00
|
|
|
<TableCell>
|
2023-03-29 13:46:39 -06:00
|
|
|
<FileRowTagIcon file={file}/>
|
|
|
|
|
<PreviewLink file={file}>{textEllipsis(file.title || file.name || file.stem)}</PreviewLink>
|
2022-08-06 05:22:07 +00:00
|
|
|
</TableCell>
|
2022-10-24 09:07:08 -06:00
|
|
|
</React.Fragment>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-24 17:15:15 -06:00
|
|
|
export function FileTable({files, selectOn, onSelect, footer, selectedKeys}) {
|
2023-09-07 20:13:36 -06:00
|
|
|
if (files && files.length > 0) {
|
2022-10-24 09:07:08 -06:00
|
|
|
const headerContents = ['Poster', 'Title'];
|
|
|
|
|
const rows = files.map(i => <FileRow key={i['key']} file={i}/>);
|
|
|
|
|
return <SelectableTable
|
|
|
|
|
headerContents={headerContents}
|
|
|
|
|
selectOn={selectOn}
|
|
|
|
|
onSelect={onSelect}
|
2022-10-24 17:15:15 -06:00
|
|
|
selectedKeys={selectedKeys}
|
2022-10-24 09:07:08 -06:00
|
|
|
footer={footer}
|
|
|
|
|
rows={rows}
|
|
|
|
|
/>;
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (files) {
|
2023-01-04 19:45:42 -07:00
|
|
|
return <Segment>No results!</Segment>
|
2023-09-07 20:13:36 -06:00
|
|
|
} else if (files === undefined) {
|
|
|
|
|
return <ErrorMessage>Could not search!</ErrorMessage>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
2023-09-07 20:13:36 -06:00
|
|
|
|
|
|
|
|
return <Placeholder>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</Placeholder>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-24 08:58:18 -06:00
|
|
|
export function FileRowTagIcon({file}) {
|
|
|
|
|
if (file.tags && file.tags.length) {
|
2023-05-29 18:04:03 -06:00
|
|
|
return <TagIcon/>;
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 18:09:10 -06:00
|
|
|
export function SearchViewButton({headlines}) {
|
2023-04-09 14:13:36 -06:00
|
|
|
const {view, setView} = useSearchView();
|
|
|
|
|
|
2023-04-12 18:09:10 -06:00
|
|
|
if (headlines) {
|
|
|
|
|
// Cycle: cards -> headline -> list
|
|
|
|
|
if (view === 'headline') {
|
|
|
|
|
return <Button icon='list' onClick={() => setView('list')}/>;
|
|
|
|
|
} else if (view === 'list') {
|
|
|
|
|
return <Button icon='th' onClick={() => setView('cards')}/>;
|
|
|
|
|
}
|
|
|
|
|
return <Button icon='searchengin' onClick={() => setView('headline')}/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cycle: cards -> list
|
2023-04-09 14:13:36 -06:00
|
|
|
if (view === 'list') {
|
|
|
|
|
return <Button icon='th' onClick={() => setView('cards')}/>;
|
|
|
|
|
}
|
|
|
|
|
return <Button icon='browser' onClick={() => setView('list')}/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SearchLimitDropdown({limits = []}) {
|
|
|
|
|
const {limit, setLimit} = usePages();
|
|
|
|
|
const limitOptions = limits.map(i => {
|
|
|
|
|
return {key: i, value: i, text: i.toString()}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return <Dropdown fluid selection
|
|
|
|
|
placeholder='Limit'
|
|
|
|
|
options={limitOptions}
|
2023-04-09 14:34:33 -06:00
|
|
|
value={limit || limitOptions[0]['value']}
|
2023-04-09 14:13:36 -06:00
|
|
|
onChange={(e, {value}) => setLimit(value)}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FilesView(
|
|
|
|
|
files,
|
|
|
|
|
activePage,
|
|
|
|
|
totalPages,
|
|
|
|
|
selectElem,
|
|
|
|
|
selectedKeys,
|
|
|
|
|
onSelect,
|
|
|
|
|
setPage,
|
2023-04-12 18:09:10 -06:00
|
|
|
headlines = false,
|
2023-04-09 14:13:36 -06:00
|
|
|
limitOptions = [12, 24, 48, 96],
|
|
|
|
|
) {
|
|
|
|
|
const {view} = useSearchView();
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
let selectButton;
|
|
|
|
|
const [selectOn, setSelectOn] = React.useState(false);
|
|
|
|
|
const toggleSelectOn = () => setSelectOn(!selectOn);
|
|
|
|
|
const selectButtonDisabled = view !== 'list';
|
2023-04-09 14:13:36 -06:00
|
|
|
if (selectOn) {
|
2022-08-06 05:22:07 +00:00
|
|
|
selectButton = <Button active disabled={selectButtonDisabled} icon='checkmark box'
|
|
|
|
|
onClick={toggleSelectOn}/>;
|
2023-04-09 14:13:36 -06:00
|
|
|
} else {
|
2022-08-06 05:22:07 +00:00
|
|
|
selectButton = <Button icon='checkmark box' disabled={selectButtonDisabled}
|
|
|
|
|
onClick={toggleSelectOn}/>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const paginator = <center style={{marginTop: '2em'}}>
|
|
|
|
|
<Paginator activePage={activePage} totalPages={totalPages} onPageChange={setPage}/>
|
|
|
|
|
</center>;
|
|
|
|
|
|
|
|
|
|
let body;
|
|
|
|
|
if (view === 'list') {
|
2022-10-24 09:07:08 -06:00
|
|
|
const footer = selectOn && selectElem ?
|
|
|
|
|
<>
|
2023-01-04 09:14:33 -07:00
|
|
|
<TableHeaderCell colSpan='3'>{selectElem}</TableHeaderCell>
|
2022-10-24 09:07:08 -06:00
|
|
|
</> : null;
|
2023-04-09 14:13:36 -06:00
|
|
|
body = <FileTable
|
|
|
|
|
files={files}
|
|
|
|
|
selectOn={selectOn}
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
footer={footer}
|
|
|
|
|
selectedKeys={selectedKeys || []}
|
|
|
|
|
/>;
|
2023-04-12 18:09:10 -06:00
|
|
|
} else if (view === 'headline') {
|
|
|
|
|
body = <Headlines results={files}/>;
|
2022-08-06 05:22:07 +00:00
|
|
|
} else {
|
|
|
|
|
body = <FileCards files={files}/>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 18:09:10 -06:00
|
|
|
const viewButton = <SearchViewButton headlines={headlines}/>
|
2023-04-09 14:13:36 -06:00
|
|
|
const limitDropdown = <SearchLimitDropdown limits={limitOptions}/>;
|
|
|
|
|
const tagQuerySelector = <TagsQuerySelector/>;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
body,
|
|
|
|
|
paginator,
|
|
|
|
|
selectButton,
|
|
|
|
|
viewButton,
|
|
|
|
|
limitDropdown,
|
|
|
|
|
tagQuerySelector,
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
2023-11-02 15:24:07 -06:00
|
|
|
export function SearchFilter({filters = [], modalHeader, size = 'medium'}) {
|
2023-04-09 14:13:36 -06:00
|
|
|
const {filter, setFilter} = useSearchFilter();
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
const handleOpen = (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setOpen(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleClear = (e) => {
|
|
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
setFilter(null);
|
|
|
|
|
setOpen(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filterFields = filters.map(
|
|
|
|
|
i => <Form.Field key={i['text']}>
|
|
|
|
|
<Checkbox radio
|
|
|
|
|
label={i['text']}
|
|
|
|
|
name='searchFilterRadioGroup'
|
|
|
|
|
checked={filter === i['value']}
|
|
|
|
|
value={i['value']}
|
|
|
|
|
onChange={() => setFilter(i['value'])}
|
|
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (filters && filters.length > 0) {
|
|
|
|
|
return <>
|
|
|
|
|
<Modal open={open} onOpen={() => handleOpen()} onClose={() => setOpen(false)} closeIcon>
|
2023-04-18 22:03:45 -06:00
|
|
|
{modalHeader || <ModalHeader>Filter</ModalHeader>}
|
|
|
|
|
<ModalContent>
|
2023-04-09 14:13:36 -06:00
|
|
|
<Form>
|
|
|
|
|
{filterFields}
|
|
|
|
|
</Form>
|
2023-04-18 22:03:45 -06:00
|
|
|
</ModalContent>
|
|
|
|
|
<ModalActions>
|
|
|
|
|
<Button onClick={handleClear} secondary>Clear</Button>
|
|
|
|
|
<Button onClick={() => setOpen(false)}>Close</Button>
|
|
|
|
|
</ModalActions>
|
2023-04-09 14:13:36 -06:00
|
|
|
</Modal>
|
|
|
|
|
<Button
|
|
|
|
|
icon='filter'
|
|
|
|
|
onClick={handleOpen}
|
|
|
|
|
primary={!!filter}
|
2023-11-02 15:24:07 -06:00
|
|
|
size={size}
|
2023-04-09 14:13:36 -06:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
}
|
2023-11-02 15:24:07 -06:00
|
|
|
|
2023-04-09 14:13:36 -06:00
|
|
|
return <></>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-09 14:13:36 -06:00
|
|
|
export function TagsQuerySelector({onChange}) {
|
2023-03-29 13:46:39 -06:00
|
|
|
// Creates dropdown that the User can use to manipulate the tag query.
|
2023-03-24 08:58:18 -06:00
|
|
|
const {searchParams, updateQuery} = useQuery();
|
2023-04-05 14:37:14 -06:00
|
|
|
const activeTags = searchParams.getAll('tag');
|
2023-03-24 08:58:18 -06:00
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
const localOnChange = (tagNames) => {
|
|
|
|
|
updateQuery({'tag': tagNames});
|
2023-03-24 08:58:18 -06:00
|
|
|
if (onChange) {
|
2023-05-29 18:04:03 -06:00
|
|
|
onChange(tagNames);
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-09 14:13:36 -06:00
|
|
|
return <TagsSelector hideGroup={true}
|
|
|
|
|
hideEdit={true}
|
|
|
|
|
active={activeTags && activeTags.length > 0}
|
|
|
|
|
selectedTagNames={activeTags}
|
|
|
|
|
onToggle={localOnChange}
|
|
|
|
|
style={{marginLeft: '0.3em', marginTop: '0.3em'}}
|
2023-04-05 14:37:14 -06:00
|
|
|
/>
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
|
2023-11-02 15:24:07 -06:00
|
|
|
export function FileSearchFilterButton({size = 'medium'}) {
|
2023-11-02 15:31:13 -06:00
|
|
|
// see `filterToMimetypes`
|
2023-04-09 14:13:36 -06:00
|
|
|
const filterOptions = [
|
2022-12-09 11:22:20 -07:00
|
|
|
{key: 'video', text: 'Video', value: 'video'},
|
|
|
|
|
{key: 'archive', text: 'Archive', value: 'archive'},
|
|
|
|
|
{key: 'pdf', text: 'PDF', value: 'pdf'},
|
|
|
|
|
{key: 'ebook', text: 'eBook', value: 'ebook'},
|
2023-02-22 12:41:41 -07:00
|
|
|
{key: 'audio', text: 'Audio', value: 'audio'},
|
2022-12-09 11:22:20 -07:00
|
|
|
{key: 'image', text: 'Image', value: 'image'},
|
|
|
|
|
{key: 'zip', text: 'ZIP', value: 'zip'},
|
2023-04-09 14:13:36 -06:00
|
|
|
{key: 'model', text: '3D Model', value: 'model'},
|
2023-10-29 21:26:35 -06:00
|
|
|
{key: 'software', text: 'Software', value: 'software'},
|
2022-12-09 11:22:20 -07:00
|
|
|
];
|
|
|
|
|
|
2023-11-02 15:24:07 -06:00
|
|
|
return <SearchFilter filters={filterOptions} size={size}/>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FilesSearchView({
|
|
|
|
|
showView = true,
|
|
|
|
|
showSelect = false,
|
|
|
|
|
emptySearch = false,
|
|
|
|
|
model,
|
|
|
|
|
}) {
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
const {searchFiles, pages} = useSearchFiles(24, emptySearch, model);
|
2023-04-09 14:13:36 -06:00
|
|
|
|
|
|
|
|
const {body, paginator, selectButton, viewButton, limitDropdown, tagQuerySelector} = FilesView(
|
|
|
|
|
searchFiles,
|
2023-05-29 18:04:03 -06:00
|
|
|
pages.activePage,
|
|
|
|
|
pages.totalPages,
|
2023-04-12 18:09:10 -06:00
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
2023-05-29 18:04:03 -06:00
|
|
|
pages.setPage,
|
2023-04-12 18:09:10 -06:00
|
|
|
true,
|
2023-04-09 14:13:36 -06:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
<Media at='mobile'>
|
|
|
|
|
<Grid>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
{showSelect &&
|
|
|
|
|
<Grid.Column width={2}>{selectButton}</Grid.Column>}
|
|
|
|
|
{showView &&
|
|
|
|
|
<Grid.Column width={2}>{viewButton}</Grid.Column>}
|
|
|
|
|
<Grid.Column width={4}>{limitDropdown}</Grid.Column>
|
|
|
|
|
<Grid.Column width={2}>{tagQuerySelector}</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Media>
|
|
|
|
|
<Media greaterThanOrEqual='tablet'>
|
|
|
|
|
<Grid>
|
|
|
|
|
<Grid.Row>
|
|
|
|
|
{showSelect &&
|
|
|
|
|
<Grid.Column width={1}>{selectButton}</Grid.Column>}
|
|
|
|
|
{showView &&
|
|
|
|
|
<Grid.Column width={1}>{viewButton}</Grid.Column>}
|
2023-04-09 14:34:33 -06:00
|
|
|
<Grid.Column width={2}>{limitDropdown}</Grid.Column>
|
2023-04-09 14:13:36 -06:00
|
|
|
<Grid.Column width={1}>{tagQuerySelector}</Grid.Column>
|
|
|
|
|
</Grid.Row>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Media>
|
|
|
|
|
{body}
|
|
|
|
|
{paginator}
|
|
|
|
|
</>
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 10:18:52 -06:00
|
|
|
export function FilesRefreshProgress() {
|
2023-03-27 20:46:31 -06:00
|
|
|
const {progress} = useFilesProgressInterval();
|
|
|
|
|
|
|
|
|
|
if (!progress) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-10 16:28:10 -06:00
|
|
|
const {
|
|
|
|
|
discovery,
|
|
|
|
|
refreshing,
|
|
|
|
|
modeling,
|
|
|
|
|
indexing,
|
|
|
|
|
cleanup,
|
|
|
|
|
indexed,
|
|
|
|
|
unindexed,
|
|
|
|
|
counted_files,
|
|
|
|
|
total_file_groups,
|
|
|
|
|
modeled
|
|
|
|
|
} = progress;
|
2023-03-27 20:46:31 -06:00
|
|
|
|
|
|
|
|
if (refreshing) {
|
2023-04-10 16:28:10 -06:00
|
|
|
// Default is Counting / Step 1. Move progress bar toward the middle to avoid clipping out of the screen.
|
2023-04-12 16:09:09 -06:00
|
|
|
let params = {value: Math.floor(counted_files / 2), total: counted_files, progress: 'ratio'};
|
2023-04-10 16:28:10 -06:00
|
|
|
let label = 'Refresh: Counting';
|
|
|
|
|
|
|
|
|
|
if (discovery) {
|
|
|
|
|
params['value'] = total_file_groups;
|
|
|
|
|
params['total'] = counted_files;
|
|
|
|
|
label = 'Refresh: Discovery'
|
|
|
|
|
} else if (modeling) {
|
2023-03-27 20:46:31 -06:00
|
|
|
params['value'] = modeled;
|
2023-04-10 15:56:25 -06:00
|
|
|
params['total'] = total_file_groups;
|
2023-03-27 20:46:31 -06:00
|
|
|
label = 'Refresh: Modeling';
|
|
|
|
|
} else if (indexing) {
|
|
|
|
|
params['value'] = unindexed;
|
|
|
|
|
params['total'] = unindexed + indexed;
|
|
|
|
|
label = 'Refresh: Indexing';
|
|
|
|
|
} else if (cleanup) {
|
|
|
|
|
params['value'] = 3;
|
|
|
|
|
params['total'] = 4;
|
|
|
|
|
label = 'Refresh: Cleanup';
|
|
|
|
|
}
|
2023-04-05 10:18:52 -06:00
|
|
|
return <Progress active color='violet' {...params}>{label}</Progress>
|
2023-03-27 20:46:31 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FilesPage() {
|
|
|
|
|
useTitle('Files');
|
|
|
|
|
|
|
|
|
|
return <>
|
2023-04-05 10:18:52 -06:00
|
|
|
<FilesRefreshProgress/>
|
2023-03-27 20:46:31 -06:00
|
|
|
<FileBrowser/>
|
|
|
|
|
</>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
export function FilesRoute() {
|
|
|
|
|
return <PageContainer>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path='/' exact element={<FilesPage/>}/>
|
|
|
|
|
</Routes>
|
|
|
|
|
</PageContainer>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 15:53:47 -06:00
|
|
|
const useRefresh = () => {
|
|
|
|
|
const refreshing = useStatusFlag('refreshing');
|
|
|
|
|
const refreshingDirectory = useStatusFlag('refreshing_directory');
|
2023-07-21 15:14:09 -06:00
|
|
|
const wrolModeEnabled = useWROLMode();
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
const [loading, setLoading] = React.useState(false);
|
|
|
|
|
|
2023-07-27 15:53:47 -06:00
|
|
|
const localRefreshFiles = async (paths) => {
|
2022-08-06 05:22:07 +00:00
|
|
|
setLoading(true);
|
2023-07-27 15:53:47 -06:00
|
|
|
await refreshFiles(paths);
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-01-04 11:16:40 -07:00
|
|
|
// Clear loading when global refresh event completes.
|
2023-07-27 15:53:47 -06:00
|
|
|
useSubscribeEventName('refresh_completed', () => setLoading(false));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
refreshing,
|
|
|
|
|
refreshingDirectory,
|
|
|
|
|
wrolModeEnabled,
|
|
|
|
|
loading,
|
|
|
|
|
refreshFiles: localRefreshFiles,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FilesRefreshButton() {
|
|
|
|
|
const {refreshing, refreshingDirectory, wrolModeEnabled, loading, refreshFiles} = useRefresh();
|
2023-01-04 11:16:40 -07:00
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
return <Button icon
|
|
|
|
|
labelPosition='left'
|
|
|
|
|
loading={loading || refreshing || refreshingDirectory}
|
2023-07-27 15:53:47 -06:00
|
|
|
onClick={() => refreshFiles()}
|
2023-07-21 15:14:09 -06:00
|
|
|
disabled={wrolModeEnabled || loading || refreshing}>
|
2023-01-31 18:08:07 -07:00
|
|
|
<Icon name='refresh'/>
|
|
|
|
|
Refresh All
|
|
|
|
|
</Button>;
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export function DirectoryRefreshButton({paths}) {
|
2023-07-27 15:53:47 -06:00
|
|
|
const {refreshing, refreshingDirectory, wrolModeEnabled, loading, refreshFiles} = useRefresh();
|
2023-01-04 11:16:40 -07:00
|
|
|
|
2023-01-31 18:08:07 -07:00
|
|
|
return <Button icon
|
|
|
|
|
labelPosition='left'
|
|
|
|
|
loading={loading || refreshing || refreshingDirectory}
|
2023-07-27 15:53:47 -06:00
|
|
|
onClick={() => refreshFiles(paths)}
|
2023-07-21 15:14:09 -06:00
|
|
|
disabled={wrolModeEnabled || loading || refreshing || refreshingDirectory}
|
2023-01-31 18:08:07 -07:00
|
|
|
>
|
|
|
|
|
<Icon name='refresh'/>
|
2023-05-29 18:04:03 -06:00
|
|
|
Refresh
|
2023-01-31 18:08:07 -07:00
|
|
|
</Button>
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|