mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-03 13:19:58 -05:00
Fixing JS warnings.
Handling all combinations of toggle in light and dark. Changing CPUUsageProgress colors to be more readable in dark mode. Moving theme handling into Theme.js. Importing element wrappers from Theme.js to handle element theming. Changing video menu to dark mode. Creating ThemeContext to share Dark Mode setting. Removing duplicate code for search functions. Displaying X when downloads are disabled. Using react context to share settings across components. Refusing to start workers when WROL Mode is enabled. Changing warning to debug. Queuing recurring downloads first. Adding Video.url index. Adding special handling for youtube shorts to videos. Reworking Downloads to have one worker per process. Testing creating downloads and getting downloaders. Testing video validation and poster generation. Testing video statistics. Increasing inventory test coverage. Adding pytest.ini to automatically detect async test. Adding more archive test coverage. Testing Archive CRUD. Catching and logging when encountering error during indexing. Using FileIcon when Archive has no screenshot. A Video will be assigned to a Channel by its info json first, then to its directory. Including suffix in File json. Adding index for File.suffix. Gathering suffix during indexing. Passing entire file down to FileIcon. Moving logging up. Returning File.associated in file json. Associated files are last in file search. Removing duplicate refreshing code by creating new _refresh_directory function. Changing File.idempotency to a datetime to avoid having to clear idempotency. Truncating indexes to avoid error with large files. Don't overwrite video data when info json is empty. Using already_downloaded for channel videos. Awaiting refresh in Channel.refresh. Testing that videos already downloaded aren't downloaded again. Adding indexes for video/archive referenced paths. Changing grid width for mobile or computer. Adding button to refresh specific directories. Restoring Channel edit link. Fixing caption path in video_modeler. Adding ZIP files to mimetype colors. Using model instead of first file's model. Fetching File models in batches to avoid issuing a SELECT for every File with a model. Flushing generated poster file. Getting Channel in VideoPage, relying on Video.channl_id, falling back to URL's channel_id. Attaching Video to it's Channel during download. Using ExternalCardLink for ArchivePage singlefile link. Validating and indexing videos after download. Handling glob when file name contains matching characters. Reworking and testing split_path_stem_and_suffix and glob_shared_stem. Adding associated video files to DB during upsert. Adding pending downloads to dashboard. Hiding status when download is open. Handling when load is empty. Adding load statistics to Dashboard. Limiting concurrent after_refresh functions. Handling when no onSelect is declared. Adding ImageRow for FileTable. Moving image date into Card.Meta. Using ExternalLink for FileCard. Using ExternalLink for ImageCard. Handling when error occurs during refresh of a directory. Committing during refresh to avoid losing all files if an error occurs. Removing api health check to avoid spamming logs. Creating ImageCard to display image posters when they aren't too large. Removing archive.domain_id not null. Reworking file refresh to process all files in a single directory. Bumping version for major file rework. No longer checking for video corruption. Adding duration by default to speed up tests. Using register_indexer for all indexers. Adding CPU usage progress bar in Welcome. Modifying TextIndexer to ignore large text files. Counting all files during refresh. Adding refresh_logger to clarify logging. Checking for wrol_mode before refresh functions. Removing unused idempotency from video/channel tables. Using magic module to speed up mimetype identification. All tests pass. Archive tests pass. Changing video get endpoint to return 'file' to avoid ambiguity. Video tests pass. Simplifying regex filtering. Using regex to ignore case when filtering. Converting all channel classes to functions. Restoring channel refresh and download buttons. Matching format of Archive and Video pages. Adding sorting to Archives search. Reworking video orders for file search. Using SearchInput for videos search. Archives can be searched on the Archives page. Domains can be filtered. Reworking Archive search to use Files. Videos, Archives and Global search use the FilesView. Videos are claimed by their Channel based on the Channel's directory. Prev and Next video cards are displayed on the VideoPage. Creating useVideo for reworked VideoWrapper and VideoPage. Adding Paginator to FilesView. Moving file refresh button out of manage tab. Removing Files page tabs. Limiting refresh to one at a time. Adding class for card icon to match poster height. Video and Archives always re-claim their files on refresh. Archive files are indexed and claimed. FileView table is compact and striped. Videos page uses FileView. Updated navlinks to router v6. Removing ! character from file names. Disabling select button when cards are visible. Adding show/hide button for FileTable selection. The Archive Page is displayed. Adding mimetype dropdown. Upgrading to React Router v6 for useSearchParams. Validating video during modeling. Removing screenshot during corruption check because it was very slow. Updating app to use video files as search results. Updating video search to return Files. Video and WROLPi tests pass. Creating function to refresh files within a channel's directory. Removing troubleshooting print. Updating result order in test. Reworking video_factory to handle a specific video file location. Returning video model on file search. Getting session using video_file. Screenshotting when checking for video corruption. Reducing ffmpeg calls by gathering duration during poster generation. Moving video file matching into model. VideoIndexer is moved into video module. Video files are validated. Moving files module into wrolpi in preparation to use it in modules. Title and contents are indexed for text file. Files are indexed on refresh by using their indexer. Zip files are indexed using their contents. Testing multiple zip files. Adding unique to file.path. Checking that the correct indexer is used. Adding index to file.modification_datetime and file.size. Handling file info gathering in File.do_index. Only reading contents of file if file.indexed is False. Video model is found during file refresh. A Video record is created that has the associated files. Videos without associated files are found. Videos are found using registered video_modeler() rather than in refresh code. Removing old video columns. Handling video info json files. Trying to import each module individually. Will continue to import modules even if one fails. Reworking refresh so it performs less DB calls. Converting file.path to primary key. file.path is always a pathlib.Path. Updating video_factory to use new file system, testing it. Bump sanic from 21.9.1 to 21.12.2 in /docker/archive Bumps [sanic](https://github.com/sanic-org/sanic) from 21.9.1 to 21.12.2. - [Release notes](https://github.com/sanic-org/sanic/releases) - [Changelog](https://github.com/sanic-org/sanic/blob/main/CHANGELOG.rst) - [Commits](https://github.com/sanic-org/sanic/compare/v21.9.1...v21.12.2) --- updated-dependencies: - dependency-name: sanic dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
parent
1ede5f3f55
commit
d4ed5fa5ce
98 changed files with 7441 additions and 5257 deletions
|
|
@ -1,619 +1,193 @@
|
|||
import React from 'react';
|
||||
import {Link, Route} from "react-router-dom";
|
||||
import OldPaginator, {
|
||||
changePageHistory,
|
||||
DEFAULT_LIMIT,
|
||||
import {Link, Route, Routes, useParams} from "react-router-dom";
|
||||
import {
|
||||
defaultSearchOrder,
|
||||
defaultVideoOrder,
|
||||
humanFileSize,
|
||||
PageContainer,
|
||||
scrollToTop,
|
||||
searchOrders,
|
||||
secondsToString,
|
||||
SearchInput,
|
||||
TabLinks,
|
||||
VideoCards,
|
||||
videoOrders,
|
||||
WROLModeMessage
|
||||
useTitle,
|
||||
videoOrders
|
||||
} from "./Common"
|
||||
import VideoPage from "./VideoPlayer";
|
||||
import {download, getChannel, getStatistics, getVideo, refresh, searchVideos} from "../api";
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
Form,
|
||||
Grid,
|
||||
Header,
|
||||
Icon,
|
||||
Input,
|
||||
Loader,
|
||||
Modal,
|
||||
Radio,
|
||||
Segment,
|
||||
Statistic
|
||||
} from "semantic-ui-react";
|
||||
import * as QueryString from 'query-string';
|
||||
import Container from "semantic-ui-react/dist/commonjs/elements/Container";
|
||||
import {Dropdown, PlaceholderHeader, PlaceholderLine, StatisticLabel, StatisticValue} from "semantic-ui-react";
|
||||
import {Channels, EditChannel, NewChannel} from "./Channels";
|
||||
import {VideoPlaceholder} from "./Placeholder";
|
||||
import {useChannel, useQuery, useSearchVideos, useVideo, useVideoStatistics} from "../hooks/customHooks";
|
||||
import {FilesView} from "./Files";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
import {Header, Loader, Placeholder, Segment, Statistic, StatisticGroup} from "./Theme";
|
||||
|
||||
class ManageVideos extends React.Component {
|
||||
export function VideoWrapper() {
|
||||
const {videoId} = useParams();
|
||||
const {videoFile, prevFile, nextFile} = useVideo(videoId);
|
||||
scrollToTop();
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
streamUrl: null,
|
||||
mostRecentDownload: '',
|
||||
}
|
||||
}
|
||||
|
||||
download = async (e) => {
|
||||
e.preventDefault();
|
||||
let response = await download();
|
||||
if (response.stream_url) {
|
||||
this.setState({streamUrl: response.stream_url});
|
||||
}
|
||||
}
|
||||
|
||||
refresh = async (e) => {
|
||||
e.preventDefault();
|
||||
let response = await refresh();
|
||||
if (response.stream_url) {
|
||||
this.setState({streamUrl: response.stream_url});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container fluid>
|
||||
<WROLModeMessage content='Cannot modify Videos'/>
|
||||
|
||||
<p>
|
||||
<Button secondary
|
||||
id='refresh_videos'
|
||||
onClick={this.refresh}
|
||||
>
|
||||
Refresh Video Files
|
||||
</Button>
|
||||
<label htmlFor='refresh_videos'>
|
||||
Find any new video files. Remove any Videos which no longer have files.
|
||||
</label>
|
||||
</p>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
return <VideoPage videoFile={videoFile} prevFile={prevFile} nextFile={nextFile} autoplay={true}/>
|
||||
}
|
||||
|
||||
export class VideoWrapper extends React.Component {
|
||||
function Videos({filter}) {
|
||||
const {channelId} = useParams();
|
||||
const {searchParams, updateQuery} = useQuery();
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
video: null,
|
||||
prev: null,
|
||||
next: null,
|
||||
channel: null,
|
||||
no_channel: null,
|
||||
}
|
||||
let searchOrder = defaultVideoOrder;
|
||||
if (searchParams.get('order')) {
|
||||
// Use whatever order the user specified.
|
||||
searchOrder = searchParams.get('order');
|
||||
} else if (searchParams.get('q')) {
|
||||
// User used a search_str
|
||||
searchOrder = defaultSearchOrder;
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchVideo();
|
||||
let filtersEnabled = searchParams.getAll('filter');
|
||||
filtersEnabled = filter ? [...filtersEnabled, filter] : filtersEnabled;
|
||||
|
||||
const {searchStr, setSearchStr, videos, activePage, setPage, limit, setLimit, totalPages, setOrderBy} =
|
||||
useSearchVideos(null, channelId, searchOrder, filtersEnabled);
|
||||
const setView = (value) => updateQuery({view: value});
|
||||
const view = searchParams.get('view');
|
||||
|
||||
const {channel} = useChannel(channelId);
|
||||
|
||||
const filterOptions = [
|
||||
{text: 'Favorites', key: 'favorite', value: 'favorite'},
|
||||
{text: 'Censored', key: 'censored', value: 'censored'},
|
||||
];
|
||||
const setFilters = (value) => updateQuery({filter: value});
|
||||
|
||||
const menuColumns = <>
|
||||
<Grid.Column mobile={8} computer={5}>
|
||||
<SearchInput clearable searchStr={searchStr} onSubmit={setSearchStr} actionIcon='search'/>
|
||||
</Grid.Column>
|
||||
<Grid.Column mobile={6} computer={5}>
|
||||
<Dropdown selection fluid
|
||||
size='large'
|
||||
placeholder='Sort by...'
|
||||
value={searchOrder}
|
||||
options={videoOrders}
|
||||
onChange={(e, {value}) => setOrderBy(value)}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</>;
|
||||
|
||||
let header;
|
||||
if (channel && channel.name) {
|
||||
const editLink = `/videos/channel/${channelId}/edit`;
|
||||
header = <>
|
||||
<Header as='h1'>
|
||||
{channel.name}
|
||||
<Link to={editLink}>
|
||||
<Icon name='edit' style={{marginLeft: '0.5em'}}/>
|
||||
</Link>
|
||||
</Header>
|
||||
</>;
|
||||
} else if (channelId) {
|
||||
header = <Placeholder style={{marginBottom: '1em'}}>
|
||||
<PlaceholderHeader>
|
||||
<PlaceholderLine/>
|
||||
</PlaceholderHeader>
|
||||
</Placeholder>;
|
||||
}
|
||||
|
||||
async fetchVideo() {
|
||||
// Get and display the Video specified in the Router match
|
||||
let [video, prev, next] = await getVideo(this.props.match.params.video_id);
|
||||
let channel_id = this.props.match.params.channel_id;
|
||||
let channel = channel_id ? await getChannel(channel_id) : null;
|
||||
let no_channel = false;
|
||||
if (!channel) {
|
||||
no_channel = true;
|
||||
}
|
||||
this.setState({video, prev, next, channel, no_channel}, scrollToTop);
|
||||
}
|
||||
|
||||
async componentDidUpdate(prevProps, prevState) {
|
||||
if (prevProps.match.params.video_id !== this.props.match.params.video_id) {
|
||||
// Clear the current video so that it will change, even if the video is playing.
|
||||
this.setState({video: null, prev: null, next: null, channel: null});
|
||||
await this.fetchVideo();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.video && (this.state.no_channel || this.state.channel)) {
|
||||
return <VideoPage {...this.state} history={this.props.history} autoplay={true}/>
|
||||
} else {
|
||||
return <VideoPlaceholder/>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function VideosPreview({videos}) {
|
||||
let body = <VideoPlaceholder/>
|
||||
if (videos && videos.length === 0) {
|
||||
body = <p>No videos available.</p>
|
||||
} else if (videos && videos.length > 0) {
|
||||
body = <VideoCards videos={videos}/>
|
||||
}
|
||||
return <>
|
||||
{body}
|
||||
{header}
|
||||
<FilesView
|
||||
files={videos}
|
||||
view={view}
|
||||
limit={limit}
|
||||
activePage={activePage}
|
||||
totalPages={totalPages}
|
||||
showView={true}
|
||||
showLimit={true}
|
||||
showSelect={true}
|
||||
setView={setView}
|
||||
setLimit={setLimit}
|
||||
setPage={setPage}
|
||||
filterOptions={filterOptions}
|
||||
activeFilters={filtersEnabled}
|
||||
setFilters={setFilters}
|
||||
multipleFilters={true}
|
||||
menuColumnsCount={3}
|
||||
menuColumns={menuColumns}
|
||||
>
|
||||
</FilesView>
|
||||
</>
|
||||
}
|
||||
|
||||
function FilterModal(props) {
|
||||
/*
|
||||
Expecting props.filters = [
|
||||
{label: 'Favorites', name: 'favorite', value: false},
|
||||
{label: 'Censored', name: 'censored', value: false},
|
||||
function Statistics() {
|
||||
const {statistics} = useVideoStatistics();
|
||||
const {videos, historical, channels} = statistics;
|
||||
|
||||
if (!videos) {
|
||||
return <Loader active inline='centered'/>
|
||||
}
|
||||
|
||||
const videoNames = [
|
||||
{key: 'videos', label: 'Downloaded Videos'},
|
||||
{key: 'favorites', label: 'Favorite Videos'},
|
||||
{key: 'sum_size', label: 'Total Size'},
|
||||
{key: 'max_size', label: 'Largest Video'},
|
||||
{key: 'week', label: 'Downloads Past Week'},
|
||||
{key: 'month', label: 'Downloads Past Month'},
|
||||
{key: 'year', label: 'Downloads Past Year'},
|
||||
{key: 'sum_duration', label: 'Total Duration'},
|
||||
];
|
||||
*/
|
||||
let inputs = props.filters.map((i) =>
|
||||
<Form.Input>
|
||||
<Radio toggle
|
||||
checked={i.value}
|
||||
label={i.label}
|
||||
onClick={!i.disabled ? () => props.toggleFilter(i.name) : null}
|
||||
disabled={i.disabled}
|
||||
/>
|
||||
</Form.Input>
|
||||
)
|
||||
const historicalNames = [
|
||||
{key: 'average_count', label: 'Average Monthly Downloads'},
|
||||
{key: 'average_size', label: 'Average Monthly Usage'},
|
||||
];
|
||||
const channelNames = [
|
||||
{key: 'channels', label: 'Channels'},
|
||||
];
|
||||
|
||||
const buildSegment = (title, names, stats) => {
|
||||
return <Segment>
|
||||
<Header textAlign='center' as='h1'>{title}</Header>
|
||||
<StatisticGroup>
|
||||
{names.map(
|
||||
({key, label}) =>
|
||||
<Statistic key={key} style={{margin: '2em'}}>
|
||||
<StatisticValue>{stats[key]}</StatisticValue>
|
||||
<StatisticLabel>{label}</StatisticLabel>
|
||||
</Statistic>
|
||||
)}
|
||||
</StatisticGroup>
|
||||
</Segment>
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal closeIcon open={props.open} onClose={props.onClose} onOpen={props.onOpen} size='mini'>
|
||||
<Modal.Header>{props.header}</Modal.Header>
|
||||
<Modal.Content>
|
||||
<Modal.Description>
|
||||
<Form>
|
||||
{inputs}
|
||||
</Form>
|
||||
</Modal.Description>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
{props.applyButton && <Button color='blue'>Apply</Button>}
|
||||
<Button color='black' onClick={props.onClose}>Close</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class Videos extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const query = QueryString.parse(this.props.location.search);
|
||||
let activePage = query.page ? parseInt(query.page) : 1; // First page is 1 by default, of course.
|
||||
let searchStr = query.q || '';
|
||||
let searchOrder = query.o || defaultVideoOrder;
|
||||
let filtersEnabled = query.f && query.f.length > 0 ? query.f.split(',') : [];
|
||||
|
||||
let filters = [
|
||||
{
|
||||
label: 'Favorites',
|
||||
name: 'favorite',
|
||||
value: filtersEnabled.indexOf('favorite') >= 0 || props.filter === 'favorite',
|
||||
disabled: props.filter === 'favorite',
|
||||
},
|
||||
{
|
||||
label: 'Censored',
|
||||
name: 'censored',
|
||||
value: filtersEnabled.indexOf('censored') >= 0
|
||||
},
|
||||
];
|
||||
|
||||
this.state = {
|
||||
activePage,
|
||||
channel: null,
|
||||
filters,
|
||||
filtersEnabled,
|
||||
filtersOpen: false,
|
||||
header: '',
|
||||
limit: DEFAULT_LIMIT,
|
||||
next: null,
|
||||
prev: null,
|
||||
queryStr: searchStr,
|
||||
searchOrder,
|
||||
searchStr: '',
|
||||
totalPages: null,
|
||||
videoOrders: searchStr === '' ? videoOrders : searchOrders,
|
||||
videos: null,
|
||||
};
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
if (this.props.match.params.channel_id) {
|
||||
await this.fetchChannel();
|
||||
} else {
|
||||
await this.fetchVideos();
|
||||
}
|
||||
this.setHeader();
|
||||
}
|
||||
|
||||
async componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
let params = this.props.match.params;
|
||||
|
||||
let channelChanged = params.channel_id !== prevProps.match.params.channel_id;
|
||||
let pageChanged = (
|
||||
prevState.activePage !== this.state.activePage ||
|
||||
prevState.searchOrder !== this.state.searchOrder ||
|
||||
prevState.queryStr !== this.state.queryStr
|
||||
);
|
||||
|
||||
if (channelChanged) {
|
||||
await this.fetchChannel();
|
||||
} else if (pageChanged) {
|
||||
this.applyStateToHistory();
|
||||
// TODO this causes a double search request. This will be fixed with a custom hook.
|
||||
await this.fetchVideos();
|
||||
}
|
||||
}
|
||||
|
||||
setHeader() {
|
||||
let header = '';
|
||||
if (this.props.header) {
|
||||
header = this.props.header;
|
||||
} else if (this.state.channel) {
|
||||
header = this.state.channel.name;
|
||||
} else {
|
||||
// Find the matching header from the search orders.
|
||||
for (let i = 0; i < this.state.videoOrders.length; i++) {
|
||||
let item = this.state.videoOrders[i];
|
||||
if (item.value === this.state.searchOrder) {
|
||||
header = item.title;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setState({header: header});
|
||||
}
|
||||
|
||||
async fetchChannel() {
|
||||
// Get and display the channel specified in the Router match
|
||||
let channel_id = this.props.match.params.channel_id;
|
||||
let channel = null;
|
||||
if (channel_id) {
|
||||
channel = await getChannel(channel_id);
|
||||
}
|
||||
this.setState({
|
||||
channel,
|
||||
title: channel ? channel.title : '',
|
||||
offset: 0,
|
||||
total: null,
|
||||
videos: null,
|
||||
video: null,
|
||||
},
|
||||
this.fetchVideos);
|
||||
}
|
||||
|
||||
enabledFilters = () => {
|
||||
let filters = this.state.filters;
|
||||
let filtersArr = [];
|
||||
for (let i = 0; i < filters.length; i++) {
|
||||
let filter = filters[i];
|
||||
if (filter['value'] === true) {
|
||||
filtersArr = filtersArr.concat([filter['name']]);
|
||||
}
|
||||
}
|
||||
return filtersArr;
|
||||
}
|
||||
|
||||
async fetchVideos() {
|
||||
this.setState({videos: null});
|
||||
let offset = this.state.limit * this.state.activePage - this.state.limit;
|
||||
let channel_id = this.state.channel ? this.state.channel.id : null;
|
||||
let {queryStr, searchOrder, limit} = this.state;
|
||||
|
||||
// Pass any enabled filters to the search.
|
||||
let filtersArr = this.enabledFilters();
|
||||
|
||||
try {
|
||||
let [videos, total] = await searchVideos(offset, limit, channel_id, queryStr, searchOrder, filtersArr);
|
||||
let totalPages = Math.round(total / this.state.limit) || 1;
|
||||
this.setState({videos, totalPages});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
changePage = async (activePage) => {
|
||||
this.setState({activePage});
|
||||
}
|
||||
|
||||
clearSearch = async () => {
|
||||
this.setState({searchStr: '', queryStr: '', searchOrder: defaultVideoOrder, activePage: 1});
|
||||
}
|
||||
|
||||
applyStateToHistory = () => {
|
||||
let {history, location} = this.props;
|
||||
let {activePage, queryStr, searchOrder} = this.state;
|
||||
let filters = this.enabledFilters();
|
||||
changePageHistory(history, location, activePage, queryStr, searchOrder, filters);
|
||||
}
|
||||
|
||||
handleSearch = async (e) => {
|
||||
e && e.preventDefault();
|
||||
this.setState({activePage: 1, searchOrder: defaultSearchOrder, queryStr: this.state.searchStr},
|
||||
this.applyStateToHistory);
|
||||
}
|
||||
|
||||
handleInputChange = (event, {name, value}) => {
|
||||
this.setState({[name]: value});
|
||||
}
|
||||
|
||||
changeSearchOrder = (event, {value}) => {
|
||||
this.setState({searchOrder: value, activePage: 1}, this.applyStateToHistory);
|
||||
}
|
||||
|
||||
toggleFilter = (name) => {
|
||||
let filters = this.state.filters;
|
||||
let filtersEnabled = [];
|
||||
for (let i = 0; i < filters.length; i++) {
|
||||
let filter = filters[i];
|
||||
if (filter.name === name) {
|
||||
filter.value = !filter.value;
|
||||
}
|
||||
if (filter.value) {
|
||||
filtersEnabled = filtersEnabled.concat([filter.name]);
|
||||
}
|
||||
}
|
||||
this.setState({filters, filtersEnabled});
|
||||
}
|
||||
|
||||
applyFilters = async () => {
|
||||
this.applyStateToHistory();
|
||||
await this.fetchVideos();
|
||||
}
|
||||
|
||||
closeFilters = () => {
|
||||
this.setState({filtersOpen: false}, this.applyFilters);
|
||||
}
|
||||
|
||||
openFilters = () => {
|
||||
this.setState({filtersOpen: true});
|
||||
}
|
||||
|
||||
render() {
|
||||
let {
|
||||
activePage,
|
||||
channel,
|
||||
queryStr,
|
||||
searchOrder,
|
||||
searchStr,
|
||||
header,
|
||||
totalPages,
|
||||
videoOrders,
|
||||
videos,
|
||||
filtersEnabled,
|
||||
} = this.state;
|
||||
|
||||
let body = <Container fluid style={{marginTop: '1em'}}><VideoPlaceholder/></Container>;
|
||||
|
||||
if (videos && videos.length === 0) {
|
||||
// API didn't send back any videos, tell the user what to do.
|
||||
if (this.props.filter === 'favorites') {
|
||||
body = <p>You haven't tagged any videos as favorite.</p>;
|
||||
} else {
|
||||
// default empty body.
|
||||
body = <p>No videos retrieved. Have you downloaded videos yet?</p>;
|
||||
}
|
||||
} else if (videos) {
|
||||
body = <VideoCards videos={videos}/>;
|
||||
}
|
||||
|
||||
let pagination = null;
|
||||
if (totalPages) {
|
||||
pagination = (
|
||||
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
||||
<OldPaginator
|
||||
activePage={activePage}
|
||||
changePage={this.changePage}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
let clearSearchButton = (
|
||||
<Button icon labelPosition='right' onClick={this.clearSearch}>
|
||||
Search: {queryStr}
|
||||
<Icon name='close'/>
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<Container fluid>
|
||||
<Grid columns={4} stackable>
|
||||
<Grid.Column textAlign='left' width={6}>
|
||||
<h1>
|
||||
{header}
|
||||
{
|
||||
channel &&
|
||||
<>
|
||||
|
||||
|
||||
<Link to={`/videos/channel/${channel.id}/edit`}>
|
||||
<Icon name="edit"/>
|
||||
</Link>
|
||||
</>
|
||||
}
|
||||
</h1>
|
||||
{queryStr && clearSearchButton}
|
||||
</Grid.Column>
|
||||
<Grid.Column width={1}>
|
||||
<Button icon onClick={this.openFilters} color={filtersEnabled.length > 0 ? 'black' : null}>
|
||||
<Icon name='filter'/>
|
||||
</Button>
|
||||
<FilterModal
|
||||
applyFilters={this.applyFilters}
|
||||
open={this.state.filtersOpen}
|
||||
onClose={this.closeFilters}
|
||||
header='Filter Videos'
|
||||
filters={this.state.filters}
|
||||
toggleFilter={this.toggleFilter}
|
||||
applyButton={null}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column textAlign='right' width={5}>
|
||||
<Form onSubmit={this.handleSearch}>
|
||||
<Input
|
||||
fluid
|
||||
icon='search'
|
||||
placeholder='Search...'
|
||||
name="searchStr"
|
||||
value={searchStr}
|
||||
onChange={this.handleInputChange}/>
|
||||
</Form>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={4}>
|
||||
<Dropdown
|
||||
size='large'
|
||||
placeholder='Sort by...'
|
||||
selection
|
||||
fluid
|
||||
name='searchOrder'
|
||||
onChange={this.changeSearchOrder}
|
||||
value={searchOrder}
|
||||
options={videoOrders}
|
||||
disabled={searchOrder === defaultSearchOrder}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
<Container fluid>
|
||||
{body}
|
||||
</Container>
|
||||
{pagination}
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function ManageTab(props) {
|
||||
return (
|
||||
<Container fluid>
|
||||
<ManageVideos/>
|
||||
<Statistics/>
|
||||
</Container>
|
||||
<>
|
||||
{buildSegment('Videos', videoNames, videos)}
|
||||
{buildSegment('Historical Video', historicalNames, historical)}
|
||||
{buildSegment('Channels', channelNames, channels)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function VideosRoute(props) {
|
||||
useTitle('Videos');
|
||||
|
||||
const links = [
|
||||
{text: 'Videos', to: '/videos', exact: true, key: 'videos'},
|
||||
{text: 'Videos', to: '/videos', key: 'videos', end: true},
|
||||
{text: 'Favorites', to: '/videos/favorites', key: 'favorites'},
|
||||
{text: 'Channels', to: '/videos/channel', key: 'channel'},
|
||||
{text: 'Manage', to: '/videos/manage', key: 'manage'},
|
||||
{text: 'Statistics', to: '/videos/statistics', key: 'statistics'},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer>
|
||||
<TabLinks links={links}/>
|
||||
|
||||
<Route path='/videos' exact
|
||||
component={(i) =>
|
||||
<Videos
|
||||
match={i.match}
|
||||
history={i.history}
|
||||
location={i.location}
|
||||
/>}
|
||||
/>
|
||||
<Route path='/videos/favorites' exact
|
||||
component={(i) =>
|
||||
<Videos
|
||||
match={i.match}
|
||||
history={i.history}
|
||||
location={i.location}
|
||||
filter='favorite'
|
||||
header='Favorite Videos'
|
||||
/>
|
||||
}/>
|
||||
<Route path='/videos/channel' exact component={Channels}/>
|
||||
<Route path='/videos/manage' exact component={ManageTab}/>
|
||||
<Route path='/videos/channel/new' exact component={NewChannel}/>
|
||||
<Route path='/videos/channel/:channel_id/edit' exact
|
||||
component={(i) =>
|
||||
<EditChannel
|
||||
match={i.match}
|
||||
history={i.history}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Route path='/videos/channel/:channel_id/video' exact component={Videos}/>
|
||||
<Routes>
|
||||
<Route path='/' exact element={<Videos/>}/>
|
||||
<Route path='favorites' exact element={<Videos filter='favorite' header='Favorite Videos'/>}/>
|
||||
<Route path='channel' exact element={<Channels/>}/>
|
||||
<Route path='statistics' exact element={<Statistics/>}/>
|
||||
<Route path='channel/new' exact element={<NewChannel/>}/>
|
||||
<Route path='channel/:channelId/edit' exact element={<EditChannel/>}/>
|
||||
<Route path='channel/:channelId/video' exact element={<Videos/>}/>
|
||||
</Routes>
|
||||
</PageContainer>
|
||||
)
|
||||
}
|
||||
|
||||
class Statistics extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
videos: null,
|
||||
historical: null,
|
||||
channels: null,
|
||||
};
|
||||
this.videoNames = [
|
||||
{key: 'videos', label: 'Downloaded Videos'},
|
||||
{key: 'favorites', label: 'Favorite Videos'},
|
||||
{key: 'sum_size', label: 'Total Size'},
|
||||
{key: 'max_size', label: 'Largest Video'},
|
||||
{key: 'week', label: 'Downloads Past Week'},
|
||||
{key: 'month', label: 'Downloads Past Month'},
|
||||
{key: 'year', label: 'Downloads Past Year'},
|
||||
{key: 'sum_duration', label: 'Total Duration'},
|
||||
];
|
||||
this.historicalNames = [
|
||||
{key: 'average_count', label: 'Average Monthly Downloads'},
|
||||
{key: 'average_size', label: 'Average Monthly Usage'},
|
||||
];
|
||||
this.channelNames = [
|
||||
{key: 'channels', label: 'Channels'},
|
||||
];
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchStatistics();
|
||||
}
|
||||
|
||||
async fetchStatistics() {
|
||||
try {
|
||||
let stats = await getStatistics();
|
||||
stats.videos.sum_duration = secondsToString(stats.videos.sum_duration);
|
||||
stats.videos.sum_size = humanFileSize(stats.videos.sum_size, true);
|
||||
stats.videos.max_size = humanFileSize(stats.videos.max_size, true);
|
||||
stats.historical.average_size = humanFileSize(stats.historical.average_size, true);
|
||||
this.setState({...stats});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
buildSegment(title, names, stats) {
|
||||
return <Segment secondary>
|
||||
<Header textAlign='center' as='h1'>{title}</Header>
|
||||
<Statistic.Group>
|
||||
{names.map(
|
||||
({key, label}) =>
|
||||
<Statistic key={key} style={{margin: '2em'}}>
|
||||
<Statistic.Value>{stats[key]}</Statistic.Value>
|
||||
<Statistic.Label>{label}</Statistic.Label>
|
||||
</Statistic>
|
||||
)}
|
||||
</Statistic.Group>
|
||||
</Segment>
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.videos) {
|
||||
return (
|
||||
<>
|
||||
{this.buildSegment('Videos', this.videoNames, this.state.videos)}
|
||||
{this.buildSegment('Historical Video', this.historicalNames, this.state.historical)}
|
||||
{this.buildSegment('Channels', this.channelNames, this.state.channels)}
|
||||
</>
|
||||
)
|
||||
} else {
|
||||
return <Loader active inline='centered'/>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue