mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 09:56:17 -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,24 +1,23 @@
|
|||
import React from 'react';
|
||||
import React, {useContext} from 'react';
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Confirm,
|
||||
Container,
|
||||
Dimmer,
|
||||
Divider,
|
||||
Form,
|
||||
Header,
|
||||
Icon,
|
||||
Loader,
|
||||
Modal,
|
||||
Placeholder, Progress, Statistic,
|
||||
Table
|
||||
PlaceholderLine,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHeader,
|
||||
TableHeaderCell,
|
||||
TableRow
|
||||
} from "semantic-ui-react";
|
||||
import {
|
||||
clearCompletedDownloads,
|
||||
clearFailedDownloads,
|
||||
getDownloads,
|
||||
getSettings, getStatus,
|
||||
getSettings,
|
||||
getStatus,
|
||||
killDownload,
|
||||
postDownload,
|
||||
saveSettings
|
||||
|
|
@ -26,18 +25,38 @@ import {
|
|||
import TimezoneSelect from 'react-timezone-select';
|
||||
import {
|
||||
DisableDownloadsToggle,
|
||||
ExternalCardLink,
|
||||
HelpPopup,
|
||||
HotspotToggle, humanFileSize,
|
||||
HotspotToggle,
|
||||
humanFileSize,
|
||||
LoadStatistic,
|
||||
PageContainer,
|
||||
secondsToDate,
|
||||
secondsToFrequency,
|
||||
TabLinks,
|
||||
textEllipsis,
|
||||
ThrottleToggle,
|
||||
Toggle,
|
||||
WROLModeMessage
|
||||
} from "./Common";
|
||||
import {Route} from "react-router-dom";
|
||||
import {Route, Routes} from "react-router-dom";
|
||||
import QRCode from "react-qr-code";
|
||||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {useDownloads} from "../hooks/customHooks";
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
FormField,
|
||||
FormGroup,
|
||||
FormInput,
|
||||
Header,
|
||||
Loader,
|
||||
Placeholder,
|
||||
Progress,
|
||||
Statistic,
|
||||
StatisticGroup,
|
||||
Table
|
||||
} from "./Theme";
|
||||
|
||||
class Settings extends React.Component {
|
||||
|
||||
|
|
@ -150,54 +169,53 @@ class Settings extends React.Component {
|
|||
|
||||
const qrButton = <Button icon style={{marginBottom: '1em'}}><Icon name='qrcode' size='big'/></Button>;
|
||||
|
||||
return (
|
||||
<Container fluid>
|
||||
return <ThemeContext.Consumer>
|
||||
{({i, t}) => <Container fluid>
|
||||
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
||||
|
||||
<HotspotToggle/>
|
||||
<br/>
|
||||
<ThrottleToggle style={{marginTop: '0.5em'}}/>
|
||||
<ThrottleToggle/>
|
||||
<Divider/>
|
||||
|
||||
<Header as='h3'>
|
||||
The settings for your WROLPi.
|
||||
</Header>
|
||||
<p className="text-muted">
|
||||
<p {...t}>
|
||||
Any changes will be written to <i>config/wrolpi.yaml</i>.
|
||||
</p>
|
||||
|
||||
<Form id="settings" onSubmit={this.handleSubmit}>
|
||||
<Checkbox toggle
|
||||
style={{marginTop: '0.5em', marginBottom: '0.5em'}}
|
||||
label='Download on Startup'
|
||||
disabled={disabled || download_on_startup === null}
|
||||
checked={download_on_startup === true}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'download_on_startup', d.checked)}
|
||||
/>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='Download on Startup'
|
||||
disabled={disabled || download_on_startup === null}
|
||||
checked={download_on_startup === true}
|
||||
onChange={(checked) => this.handleInputChange(null, 'download_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<Checkbox toggle
|
||||
style={{marginTop: '0.5em', marginBottom: '0.5em'}}
|
||||
label='WiFi Hotspot on Startup'
|
||||
disabled={disabled || hotspot_on_startup === null}
|
||||
checked={hotspot_on_startup === true}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'hotspot_on_startup', d.checked)}
|
||||
/>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='WiFi Hotspot on Startup'
|
||||
disabled={disabled || hotspot_on_startup === null}
|
||||
checked={hotspot_on_startup === true}
|
||||
onChange={(checked) => this.handleInputChange(null, 'hotspot_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<div style={{margin: '0.5em'}}>
|
||||
<Toggle
|
||||
label='CPU Power-save on Startup'
|
||||
disabled={disabled || throttle_on_startup === null}
|
||||
checked={throttle_on_startup === true}
|
||||
onChange={(checked) => this.handleInputChange(null, 'throttle_on_startup', checked)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Checkbox toggle
|
||||
style={{marginTop: '0.5em', marginBottom: '0.5em'}}
|
||||
label='CPU Power-save on Startup'
|
||||
disabled={disabled || throttle_on_startup === null}
|
||||
checked={throttle_on_startup === true}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'throttle_on_startup', d.checked)}
|
||||
/>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label={<>
|
||||
<b>Download Timeout</b>
|
||||
<b {...t}>Download Timeout</b>
|
||||
<HelpPopup content='Downloads will be stopped after this many seconds have elapsed.
|
||||
Downloads will never timeout if this is empty.'/>
|
||||
</>}
|
||||
|
|
@ -205,30 +223,30 @@ class Settings extends React.Component {
|
|||
disabled={disabled || download_timeout === null}
|
||||
onChange={(e, d) => this.handleTimeoutChange(e, 'download_timeout', d.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
</FormGroup>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
<FormGroup inline>
|
||||
<FormInput
|
||||
label='Hotspot SSID'
|
||||
value={hotspot_ssid}
|
||||
disabled={disabled || hotspot_ssid === null}
|
||||
onChange={(e, d) =>
|
||||
this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<Form.Input
|
||||
<FormInput
|
||||
label='Hotspot Password'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_password}
|
||||
onChange={(e, d) =>
|
||||
this.setState({hotspot_password: d.value}, this.handleHotspotChange)}
|
||||
/>
|
||||
<Form.Input
|
||||
<FormInput
|
||||
label='Hotspot Device'
|
||||
disabled={disabled || hotspot_password === null}
|
||||
value={hotspot_device}
|
||||
onChange={(e, d) => this.handleInputChange(e, 'hotspot_device', d.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
</FormGroup>
|
||||
|
||||
<Modal closeIcon
|
||||
onClose={() => this.setState({qrOpen: false})}
|
||||
|
|
@ -244,25 +262,26 @@ class Settings extends React.Component {
|
|||
</Modal.Content>
|
||||
</Modal>
|
||||
|
||||
<Form.Field>
|
||||
<FormField>
|
||||
<label>Timezone</label>
|
||||
<TimezoneSelect
|
||||
value={timezone}
|
||||
onChange={(v) => this.handleInputChange(null, 'timezone', v)}
|
||||
onChange={i => this.handleInputChange(null, 'timezone', i)}
|
||||
/>
|
||||
</Form.Field>
|
||||
</FormField>
|
||||
|
||||
<Button color="blue" type="submit" disabled={disabled}>
|
||||
Save
|
||||
</Button>
|
||||
|
||||
<Dimmer active={pending} inverted>
|
||||
<Dimmer active={pending}>
|
||||
<Loader active={pending} size='large'/>
|
||||
</Dimmer>
|
||||
|
||||
</Form>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -284,13 +303,13 @@ class WROLMode extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
toggleWROLMode = async () => {
|
||||
toggleWROLMode = async (checked) => {
|
||||
// Handle WROL Mode toggling by itself so that other settings are not modified.
|
||||
let config = {
|
||||
wrol_mode: !this.state.WROLMode,
|
||||
wrol_mode: checked,
|
||||
}
|
||||
await saveSettings(config);
|
||||
this.setState({disabled: !this.state.WROLMode, WROLMode: !this.state.WROLMode});
|
||||
this.setState({disabled: !this.state.WROLMode, WROLMode: checked});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
@ -298,39 +317,28 @@ class WROLMode extends React.Component {
|
|||
return <Loader active inline='centered'/>
|
||||
}
|
||||
|
||||
return (
|
||||
<Container fluid>
|
||||
return <ThemeContext.Consumer>
|
||||
{({i, t}) => <Container fluid>
|
||||
|
||||
<Header as="h1">WROL Mode</Header>
|
||||
<h4>
|
||||
<Header as='h4'>
|
||||
Enable read-only mode. No content can be deleted or modified. Enable this when the SHTF and you
|
||||
want to prevent any potential loss of data.
|
||||
</h4>
|
||||
<p>
|
||||
</Header>
|
||||
<p {...t}>
|
||||
Note: User settings and favorites can still be modified.
|
||||
</p>
|
||||
<Checkbox toggle
|
||||
checked={this.state.WROLMode}
|
||||
onChange={this.toggleWROLMode}
|
||||
label={this.state.WROLMode ? 'WROL Mode Enabled' : 'WROL Mode Disabled'}
|
||||
<Toggle
|
||||
checked={this.state.WROLMode}
|
||||
onChange={this.toggleWROLMode}
|
||||
label={this.state.WROLMode ? 'WROL Mode Enabled' : 'WROL Mode Disabled'}
|
||||
/>
|
||||
|
||||
</Container>
|
||||
)
|
||||
</Container>}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
}
|
||||
|
||||
function LoadStatistic({label, value, cores}) {
|
||||
let color;
|
||||
const quarter = cores / 4;
|
||||
if (cores && value >= (quarter * 3)) {
|
||||
color = 'red';
|
||||
} else if (cores && value >= (quarter * 2)) {
|
||||
color = 'yellow';
|
||||
}
|
||||
return <Statistic label={label} value={parseFloat(value).toFixed(1)} color={color}/>;
|
||||
}
|
||||
|
||||
function DriveInfo({used, size, percent, mount}) {
|
||||
let color;
|
||||
if (percent >= 90) {
|
||||
|
|
@ -359,20 +367,20 @@ function CPUTemperatureStatistic({value}) {
|
|||
return <Statistic label='Temp C°' value={value} color={color}/>
|
||||
}
|
||||
|
||||
function CPUUsageProgress({value, label}) {
|
||||
export function CPUUsageProgress({value, label}) {
|
||||
if (value === null) {
|
||||
return <Progress progress={0} color='grey' label='Average CPU Usage ERROR' disabled/>
|
||||
}
|
||||
|
||||
let color = 'grey';
|
||||
let color = 'black';
|
||||
if (value >= 90) {
|
||||
color = 'red';
|
||||
} else if (value >= 70) {
|
||||
color = 'orange';
|
||||
color = 'brown';
|
||||
} else if (value >= 50) {
|
||||
color = 'yellow';
|
||||
color = 'orange';
|
||||
} else if (value >= 30) {
|
||||
color = 'olive';
|
||||
color = 'green';
|
||||
}
|
||||
return <Progress percent={value} progress color={color} label={label}/>
|
||||
}
|
||||
|
|
@ -407,34 +415,35 @@ class Status extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
let body = <Loader active inline='centered'>Loading system status</Loader>;
|
||||
|
||||
if (this.state.status) {
|
||||
const {cpu_info, load, drives} = this.state.status;
|
||||
const {minute_1, minute_5, minute_15} = load;
|
||||
const {percent, cores, temperature} = cpu_info;
|
||||
|
||||
body = (<>
|
||||
<CPUUsageProgress value={percent} label='CPU Usage'/>
|
||||
return <ThemeContext.Consumer>
|
||||
{({i}) => <>
|
||||
<CPUUsageProgress value={percent} label='CPU Usage'/>
|
||||
|
||||
<CPUTemperatureStatistic value={temperature}/>
|
||||
<Statistic label='Cores' value={cores || '?'}/>
|
||||
<Statistic.Group>
|
||||
<LoadStatistic label='1 Minute Load' value={minute_1} cores={cores}/>
|
||||
<LoadStatistic label='5 Minute Load' value={minute_5} cores={cores}/>
|
||||
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
|
||||
</Statistic.Group>
|
||||
<CPUTemperatureStatistic value={temperature}/>
|
||||
<Statistic label='Cores' value={cores || '?'}/>
|
||||
<StatisticGroup>
|
||||
<LoadStatistic label='1 Minute Load' value={minute_1} cores={cores}/>
|
||||
<LoadStatistic label='5 Minute Load' value={minute_5} cores={cores}/>
|
||||
<LoadStatistic label='15 Minute Load' value={minute_15} cores={cores}/>
|
||||
</StatisticGroup>
|
||||
|
||||
<Header as='h2'>Drive Usage</Header>
|
||||
{drives.map(DriveInfo)}
|
||||
</>);
|
||||
<Header as='h2'>Drive Usage</Header>
|
||||
{drives.map((drive) => <DriveInfo key={drive['mount']} {...drive}/>)}
|
||||
</>}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
|
||||
return (
|
||||
<Container fluid style={{marginBottom: '5em'}}>
|
||||
{body}
|
||||
return <ThemeContext.Consumer>
|
||||
{({i}) => <Container fluid style={{marginBottom: '5em'}}>
|
||||
<Loader active inline='centered'>Loading system status</Loader>;
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -529,15 +538,15 @@ class DownloadRow extends React.Component {
|
|||
</Modal.Actions>
|
||||
</Modal>;
|
||||
|
||||
return (
|
||||
<Table.Row positive={positive}>
|
||||
<Table.Cell><a href={url} target='_blank'>{textEllipsis(url, 50)}</a></Table.Cell>
|
||||
<Table.Cell>{secondsToFrequency(frequency)}</Table.Cell>
|
||||
<Table.Cell>{last_successful_download ? secondsToDate(last_successful_download) : null}</Table.Cell>
|
||||
<Table.Cell>{secondsToDate(next_download)}</Table.Cell>
|
||||
<Table.Cell>{error && errorModal}{location && <a href={location}>View</a>}</Table.Cell>
|
||||
</Table.Row>
|
||||
);
|
||||
return <TableRow positive={positive}>
|
||||
<TableCell>
|
||||
<ExternalCardLink to={url}>{textEllipsis(url, 50)}</ExternalCardLink>
|
||||
</TableCell>
|
||||
<TableCell>{secondsToFrequency(frequency)}</TableCell>
|
||||
<TableCell>{last_successful_download ? secondsToDate(last_successful_download) : null}</TableCell>
|
||||
<TableCell>{secondsToDate(next_download)}</TableCell>
|
||||
<TableCell>{error && errorModal}{location && <a href={location}>View</a>}</TableCell>
|
||||
</TableRow>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -587,14 +596,14 @@ class StoppableRow extends React.Component {
|
|||
let {stopOpen, startOpen, errorModalOpen} = this.state;
|
||||
|
||||
let completedAtCell = last_successful_download ? secondsToDate(last_successful_download) : null;
|
||||
let buttonCell = <Table.Cell/>;
|
||||
let buttonCell = <TableCell/>;
|
||||
let positive = false;
|
||||
let negative = false;
|
||||
let warning = false;
|
||||
if (status === 'pending' || status === 'new') {
|
||||
positive = status === 'pending';
|
||||
buttonCell = (
|
||||
<Table.Cell>
|
||||
<TableCell>
|
||||
<Button
|
||||
onClick={this.openStop}
|
||||
color='red'
|
||||
|
|
@ -606,13 +615,13 @@ class StoppableRow extends React.Component {
|
|||
onCancel={this.closeStop}
|
||||
onConfirm={this.handleStop}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</TableCell>
|
||||
);
|
||||
} else if (status === 'failed' || status === 'deferred') {
|
||||
negative = status === 'failed';
|
||||
warning = status === 'deferred';
|
||||
buttonCell = (
|
||||
<Table.Cell>
|
||||
<TableCell>
|
||||
<Button
|
||||
onClick={this.openStop}
|
||||
color='red'
|
||||
|
|
@ -635,13 +644,13 @@ class StoppableRow extends React.Component {
|
|||
onCancel={this.closeStart}
|
||||
onConfirm={this.handleStart}
|
||||
/>
|
||||
</Table.Cell>
|
||||
</TableCell>
|
||||
);
|
||||
} else if (status === 'complete' && location) {
|
||||
buttonCell = (
|
||||
<Table.Cell>
|
||||
<TableCell>
|
||||
<a href={location}>View</a>
|
||||
</Table.Cell>
|
||||
</TableCell>
|
||||
);
|
||||
}
|
||||
if (error) {
|
||||
|
|
@ -665,138 +674,97 @@ class StoppableRow extends React.Component {
|
|||
}
|
||||
|
||||
return (
|
||||
<Table.Row positive={positive} negative={negative} warning={warning}>
|
||||
<Table.Cell><a href={url} target='_blank'>{textEllipsis(url, 50)}</a></Table.Cell>
|
||||
<Table.Cell>{status}</Table.Cell>
|
||||
<Table.Cell>{completedAtCell}</Table.Cell>
|
||||
<TableRow positive={positive} negative={negative} warning={warning}>
|
||||
<TableCell>
|
||||
<ExternalCardLink to={url}>{textEllipsis(url, 50)}</ExternalCardLink>
|
||||
</TableCell>
|
||||
<TableCell>{status}</TableCell>
|
||||
<TableCell>{completedAtCell}</TableCell>
|
||||
{buttonCell}
|
||||
</Table.Row>
|
||||
</TableRow>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Downloads extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
once_downloads: null,
|
||||
recurring_downloads: null,
|
||||
pending_downloads: null,
|
||||
stopOpen: false,
|
||||
disabled: false,
|
||||
};
|
||||
function Downloads() {
|
||||
const {t} = useContext(ThemeContext);
|
||||
|
||||
const {onceDownloads, recurringDownloads, fetchDownloads} = useDownloads();
|
||||
|
||||
const tablePlaceholder = <Placeholder>
|
||||
<PlaceholderLine/>
|
||||
<PlaceholderLine/>
|
||||
</Placeholder>;
|
||||
|
||||
const stoppableHeader = (
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHeaderCell>URL</TableHeaderCell>
|
||||
<TableHeaderCell>Status</TableHeaderCell>
|
||||
<TableHeaderCell>Completed At</TableHeaderCell>
|
||||
<TableHeaderCell>Control</TableHeaderCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
);
|
||||
|
||||
const nonStoppableHeader = (
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHeaderCell>URL</TableHeaderCell>
|
||||
<TableHeaderCell>Download Frequency</TableHeaderCell>
|
||||
<TableHeaderCell>Last Successful Download</TableHeaderCell>
|
||||
<TableHeaderCell>Next Download</TableHeaderCell>
|
||||
<TableHeaderCell>View</TableHeaderCell>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
);
|
||||
|
||||
let onceTable = tablePlaceholder;
|
||||
if (onceDownloads && onceDownloads.length === 0) {
|
||||
onceTable = <p {...t}>No downloads are scheduled.</p>
|
||||
} else if (onceDownloads) {
|
||||
onceTable = (
|
||||
<>
|
||||
<ClearCompleteDownloads callback={fetchDownloads}/>
|
||||
<ClearFailedDownloads callback={fetchDownloads}/>
|
||||
<Table>
|
||||
{stoppableHeader}
|
||||
<TableBody>
|
||||
{onceDownloads.map((i) =>
|
||||
<StoppableRow fetchDownloads={fetchDownloads} key={i.id} {...i}/>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</>);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchDownloads();
|
||||
this.intervalId = setInterval(this.fetchDownloads, 1000 * 10);
|
||||
let recurringTable = tablePlaceholder;
|
||||
if (recurringDownloads && recurringDownloads.length === 0) {
|
||||
recurringTable = <p {...t}>No recurring downloads are scheduled.</p>
|
||||
} else if (recurringDownloads) {
|
||||
recurringTable = <Table>
|
||||
{nonStoppableHeader}
|
||||
<TableBody>
|
||||
{recurringDownloads.map((i) => <DownloadRow key={i.id} {...i}/>)}
|
||||
</TableBody>
|
||||
</Table>;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
return <>
|
||||
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
||||
<DisableDownloadsToggle/>
|
||||
<Header as='h1'>Downloads</Header>
|
||||
{onceTable}
|
||||
|
||||
closeStop = () => {
|
||||
this.setState({stopOpen: false});
|
||||
}
|
||||
|
||||
openStop = () => {
|
||||
this.setState({stopOpen: true});
|
||||
}
|
||||
|
||||
fetchDownloads = async () => {
|
||||
try {
|
||||
let data = await getDownloads();
|
||||
this.setState({
|
||||
once_downloads: data.once_downloads,
|
||||
recurring_downloads: data.recurring_downloads,
|
||||
pending_downloads: data.pending_downloads,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
let tablePlaceholder = (
|
||||
<Placeholder>
|
||||
<Placeholder.Line/>
|
||||
<Placeholder.Line/>
|
||||
</Placeholder>
|
||||
);
|
||||
|
||||
let stoppableHeader = (
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>URL</Table.HeaderCell>
|
||||
<Table.HeaderCell>Status</Table.HeaderCell>
|
||||
<Table.HeaderCell>Completed At</Table.HeaderCell>
|
||||
<Table.HeaderCell>Control</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
);
|
||||
|
||||
let nonStoppableHeader = (
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>URL</Table.HeaderCell>
|
||||
<Table.HeaderCell>Download Frequency</Table.HeaderCell>
|
||||
<Table.HeaderCell>Last Successful Download</Table.HeaderCell>
|
||||
<Table.HeaderCell>Next Download</Table.HeaderCell>
|
||||
<Table.HeaderCell>View</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
);
|
||||
|
||||
let onceTable = tablePlaceholder;
|
||||
if (this.state.once_downloads !== null && this.state.once_downloads.length === 0) {
|
||||
onceTable = <p>No downloads are scheduled.</p>
|
||||
} else if (this.state.once_downloads !== null) {
|
||||
onceTable = (
|
||||
<>
|
||||
<ClearCompleteDownloads callback={() => this.fetchDownloads()}/>
|
||||
<ClearFailedDownloads callback={() => this.fetchDownloads()}/>
|
||||
<Table>
|
||||
{stoppableHeader}
|
||||
<Table.Body>
|
||||
{this.state.once_downloads.map((i) =>
|
||||
<StoppableRow {...i} fetchDownloads={this.fetchDownloads} key={i.id}/>
|
||||
)}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</>);
|
||||
}
|
||||
|
||||
let recurringTable = tablePlaceholder;
|
||||
if (this.state.recurring_downloads !== null && this.state.recurring_downloads.length === 0) {
|
||||
recurringTable = <p>No recurring downloads are scheduled.</p>
|
||||
} else if (this.state.recurring_downloads !== null) {
|
||||
recurringTable = (<Table>
|
||||
{nonStoppableHeader}
|
||||
<Table.Body>
|
||||
{this.state.recurring_downloads.map((i) => <DownloadRow {...i} key={i.id}/>)}
|
||||
</Table.Body>
|
||||
</Table>);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
||||
<DisableDownloadsToggle/>
|
||||
<Header as='h1'>Downloads</Header>
|
||||
{onceTable}
|
||||
|
||||
<Header as='h1'>Recurring Downloads</Header>
|
||||
{recurringTable}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
<Header as='h1'>Recurring Downloads</Header>
|
||||
{recurringTable}
|
||||
</>
|
||||
}
|
||||
|
||||
export default function Admin(props) {
|
||||
|
||||
const links = [
|
||||
{text: 'Downloads', to: '/admin', exact: true, key: 'admin'},
|
||||
{text: 'Downloads', to: '/admin', key: 'admin', end: true},
|
||||
{text: 'Settings', to: '/admin/settings', key: 'settings'},
|
||||
{text: 'Status', to: '/admin/status', key: 'status'},
|
||||
{text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'},
|
||||
|
|
@ -805,10 +773,12 @@ export default function Admin(props) {
|
|||
return (
|
||||
<PageContainer>
|
||||
<TabLinks links={links}/>
|
||||
<Route path='/admin' exact component={Downloads}/>
|
||||
<Route path='/admin/settings' exact component={Settings}/>
|
||||
<Route path='/admin/status' exact component={Status}/>
|
||||
<Route path='/admin/wrol' exact component={WROLMode}/>
|
||||
<Routes>
|
||||
<Route path='/' exact element={<Downloads/>}/>
|
||||
<Route path='settings' exact element={<Settings/>}/>
|
||||
<Route path='status' exact element={<Status/>}/>
|
||||
<Route path='wrol' exact element={<WROLMode/>}/>
|
||||
</Routes>
|
||||
</PageContainer>
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue