2021-11-01 16:42:52 -06:00
|
|
|
import React from 'react';
|
2021-12-20 16:08:13 -07:00
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Checkbox,
|
|
|
|
|
Confirm,
|
2022-05-20 15:15:31 -06:00
|
|
|
Container,
|
|
|
|
|
Dimmer,
|
2021-12-20 16:08:13 -07:00
|
|
|
Divider,
|
|
|
|
|
Form,
|
|
|
|
|
Header,
|
2022-04-30 12:20:49 -06:00
|
|
|
Icon,
|
2021-12-20 16:08:13 -07:00
|
|
|
Loader,
|
2022-04-30 12:29:43 -06:00
|
|
|
Modal,
|
2021-12-20 16:08:13 -07:00
|
|
|
Placeholder,
|
|
|
|
|
Table
|
|
|
|
|
} from "semantic-ui-react";
|
2022-04-01 16:45:59 -06:00
|
|
|
import {
|
|
|
|
|
clearCompletedDownloads,
|
|
|
|
|
clearFailedDownloads,
|
|
|
|
|
getDownloads,
|
|
|
|
|
getSettings,
|
|
|
|
|
killDownload,
|
|
|
|
|
postDownload,
|
|
|
|
|
saveSettings
|
|
|
|
|
} from "../api";
|
2021-11-01 16:42:52 -06:00
|
|
|
import TimezoneSelect from 'react-timezone-select';
|
2022-02-04 13:55:13 -07:00
|
|
|
import {
|
|
|
|
|
DisableDownloadsToggle,
|
|
|
|
|
HotspotToggle,
|
|
|
|
|
PageContainer,
|
|
|
|
|
secondsToDate,
|
|
|
|
|
secondsToFrequency,
|
|
|
|
|
TabLinks,
|
|
|
|
|
textEllipsis,
|
2022-02-07 13:37:58 -07:00
|
|
|
ThrottleToggle,
|
2022-02-04 13:55:13 -07:00
|
|
|
WROLModeMessage
|
|
|
|
|
} from "./Common";
|
2022-01-29 22:25:35 -07:00
|
|
|
import {Route} from "react-router-dom";
|
2022-04-30 12:20:49 -06:00
|
|
|
import QRCode from "react-qr-code";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
class Settings extends React.Component {
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
disabled: false,
|
2022-04-30 12:20:49 -06:00
|
|
|
hotspot_encryption: 'WPA',
|
2022-05-18 19:43:25 -06:00
|
|
|
pending: false,
|
2022-04-30 12:20:49 -06:00
|
|
|
qrCodeValue: '',
|
2022-04-30 12:35:48 -06:00
|
|
|
qrOpen: false,
|
2021-11-01 16:42:52 -06:00
|
|
|
ready: false,
|
2022-02-16 21:57:27 -07:00
|
|
|
|
|
|
|
|
download_on_startup: null,
|
|
|
|
|
hotspot_on_startup: null,
|
2022-04-30 12:20:49 -06:00
|
|
|
hotspot_password: null,
|
|
|
|
|
hotspot_ssid: null,
|
2022-02-16 21:57:27 -07:00
|
|
|
hotspot_status: null,
|
|
|
|
|
throttle_on_startup: null,
|
|
|
|
|
throttle_status: null,
|
|
|
|
|
timezone: {timezone: null},
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.handleSubmit = this.handleSubmit.bind(this);
|
2022-05-01 08:38:43 -06:00
|
|
|
this.handleHotspotChange = this.handleHotspotChange.bind(this);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2022-05-01 21:03:30 -06:00
|
|
|
try {
|
|
|
|
|
const settings = await getSettings();
|
|
|
|
|
this.setState({
|
|
|
|
|
ready: true,
|
|
|
|
|
disabled: settings.wrol_mode,
|
|
|
|
|
download_on_startup: settings.download_on_startup,
|
|
|
|
|
hotspot_on_startup: settings.hotspot_on_startup,
|
|
|
|
|
hotspot_password: settings.hotspot_password,
|
|
|
|
|
hotspot_ssid: settings.hotspot_ssid,
|
|
|
|
|
hotspot_status: settings.hotspot_status,
|
|
|
|
|
throttle_on_startup: settings.throttle_on_startup,
|
|
|
|
|
throttle_status: settings.throttle_status,
|
|
|
|
|
timezone: {value: settings.timezone, label: settings.timezone},
|
|
|
|
|
}, this.handleHotspotChange);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async handleSubmit(e) {
|
|
|
|
|
e.preventDefault();
|
2022-05-18 19:43:25 -06:00
|
|
|
this.setState({disabled: true, pending: true});
|
2022-02-16 21:57:27 -07:00
|
|
|
let settings = {
|
|
|
|
|
download_on_startup: this.state.download_on_startup,
|
|
|
|
|
hotspot_on_startup: this.state.hotspot_on_startup,
|
2022-04-30 12:20:49 -06:00
|
|
|
hotspot_password: this.state.hotspot_password,
|
|
|
|
|
hotspot_ssid: this.state.hotspot_ssid,
|
2022-02-16 21:57:27 -07:00
|
|
|
throttle_on_startup: this.state.throttle_on_startup,
|
2021-11-01 16:42:52 -06:00
|
|
|
timezone: this.state.timezone.value,
|
|
|
|
|
}
|
2022-02-16 21:57:27 -07:00
|
|
|
await saveSettings(settings);
|
2022-05-18 19:43:25 -06:00
|
|
|
this.setState({disabled: false, pending: false});
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-30 12:20:49 -06:00
|
|
|
handleInputChange = async (e, name, value) => {
|
2022-05-01 21:03:30 -06:00
|
|
|
if (e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
}
|
2022-04-30 12:20:49 -06:00
|
|
|
this.setState({[name]: value});
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-01 08:38:43 -06:00
|
|
|
handleHotspotChange = async () => {
|
2022-04-30 12:20:49 -06:00
|
|
|
let {hotspot_ssid, hotspot_encryption, hotspot_password} = this.state;
|
|
|
|
|
// Special string which allows a mobile device to connect to a specific Wi-Fi.
|
|
|
|
|
let qrCodeValue = `WIFI:S:${hotspot_ssid};T:${hotspot_encryption};P:${hotspot_password};;`;
|
|
|
|
|
this.setState({qrCodeValue});
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
render() {
|
|
|
|
|
if (this.state.ready === false) {
|
|
|
|
|
return <Loader active inline='centered'/>
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-30 12:20:49 -06:00
|
|
|
let {
|
|
|
|
|
disabled,
|
|
|
|
|
download_on_startup,
|
|
|
|
|
hotspot_on_startup,
|
|
|
|
|
hotspot_password,
|
|
|
|
|
hotspot_ssid,
|
2022-05-18 19:43:25 -06:00
|
|
|
pending,
|
2022-04-30 12:20:49 -06:00
|
|
|
qrCodeValue,
|
|
|
|
|
throttle_on_startup,
|
|
|
|
|
timezone,
|
|
|
|
|
} = this.state;
|
2022-02-16 21:57:27 -07:00
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
return (
|
2022-01-04 09:07:28 -07:00
|
|
|
<Container fluid>
|
2022-01-12 09:38:21 -07:00
|
|
|
<WROLModeMessage content='Settings are disabled because WROL Mode is enabled.'/>
|
2022-02-04 09:41:08 -07:00
|
|
|
|
2022-02-04 13:55:13 -07:00
|
|
|
<HotspotToggle/>
|
2022-02-07 13:37:58 -07:00
|
|
|
<br/>
|
|
|
|
|
<ThrottleToggle style={{marginTop: '0.5em'}}/>
|
2022-02-04 09:41:08 -07:00
|
|
|
<Divider/>
|
2022-02-16 21:57:27 -07:00
|
|
|
|
|
|
|
|
<Header as='h3'>
|
|
|
|
|
The settings for your WROLPi.
|
|
|
|
|
</Header>
|
2021-11-01 16:42:52 -06:00
|
|
|
<p className="text-muted">
|
2022-02-16 21:57:27 -07:00
|
|
|
Any changes will be written to <i>config/wrolpi.yaml</i>.
|
2021-11-01 16:42:52 -06:00
|
|
|
</p>
|
|
|
|
|
|
2022-02-16 21:57:27 -07:00
|
|
|
<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)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<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)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
|
|
|
|
|
<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)}
|
|
|
|
|
/>
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-04-30 12:20:49 -06:00
|
|
|
<Form.Group inline>
|
2022-05-01 08:38:43 -06:00
|
|
|
<Form.Input
|
|
|
|
|
label='Hotspot SSID'
|
|
|
|
|
value={hotspot_ssid}
|
|
|
|
|
disabled={disabled || hotspot_ssid === null}
|
|
|
|
|
onChange={(e, d) =>
|
|
|
|
|
this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)}
|
|
|
|
|
/>
|
|
|
|
|
<Form.Input
|
|
|
|
|
label='Hotspot Password'
|
|
|
|
|
disabled={disabled || hotspot_password === null}
|
|
|
|
|
value={hotspot_password}
|
|
|
|
|
onChange={(e, d) =>
|
|
|
|
|
this.setState({hotspot_password: d.value}, this.handleHotspotChange)}
|
|
|
|
|
/>
|
|
|
|
|
<Modal closeIcon
|
|
|
|
|
onClose={() => this.setState({qrOpen: false})}
|
|
|
|
|
onOpen={() => this.setState({qrOpen: true})}
|
|
|
|
|
open={this.state.qrOpen}
|
|
|
|
|
trigger={<Button icon><Icon name='qrcode' size='big'/></Button>}
|
|
|
|
|
>
|
|
|
|
|
<Modal.Header>
|
|
|
|
|
Scan this code to join the hotspot
|
|
|
|
|
</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<QRCode value={qrCodeValue} size={300}/>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
</Modal>
|
2022-04-30 12:20:49 -06:00
|
|
|
</Form.Group>
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
<Form.Field>
|
|
|
|
|
<label>Timezone</label>
|
|
|
|
|
<TimezoneSelect
|
2022-02-16 21:57:27 -07:00
|
|
|
value={timezone}
|
2022-05-01 08:38:43 -06:00
|
|
|
onChange={(v) => this.handleInputChange(null, 'timezone', v)}
|
2021-11-01 16:42:52 -06:00
|
|
|
/>
|
|
|
|
|
</Form.Field>
|
|
|
|
|
|
2022-02-16 21:57:27 -07:00
|
|
|
<Button color="blue" type="submit" disabled={disabled}>
|
2021-11-01 16:42:52 -06:00
|
|
|
Save
|
|
|
|
|
</Button>
|
|
|
|
|
|
2022-05-18 19:43:25 -06:00
|
|
|
<Dimmer active={pending} inverted>
|
|
|
|
|
<Loader active={pending} size='large'/>
|
|
|
|
|
</Dimmer>
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
</Form>
|
|
|
|
|
</Container>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class WROLMode extends React.Component {
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
WROLMode: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2022-05-01 21:03:30 -06:00
|
|
|
try {
|
|
|
|
|
let settings = await getSettings();
|
|
|
|
|
this.setState({ready: true, WROLMode: settings.wrol_mode});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toggleWROLMode = async () => {
|
|
|
|
|
// Handle WROL Mode toggling by itself so that other settings are not modified.
|
|
|
|
|
let config = {
|
|
|
|
|
wrol_mode: !this.state.WROLMode,
|
|
|
|
|
}
|
2022-02-16 21:57:27 -07:00
|
|
|
await saveSettings(config);
|
2021-11-01 16:42:52 -06:00
|
|
|
this.setState({disabled: !this.state.WROLMode, WROLMode: !this.state.WROLMode});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
if (this.state.ready === false) {
|
|
|
|
|
return <Loader active inline='centered'/>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-04 09:07:28 -07:00
|
|
|
<Container fluid>
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
<Header as="h1">WROL Mode</Header>
|
|
|
|
|
<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>
|
|
|
|
|
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'}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
</Container>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 11:17:53 -06:00
|
|
|
function ClearCompleteDownloads({callback}) {
|
2022-04-01 16:31:49 -06:00
|
|
|
const [disabled, setDisabled] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
async function localClearDownloads() {
|
|
|
|
|
setDisabled(true);
|
2022-04-01 16:45:59 -06:00
|
|
|
try {
|
|
|
|
|
await clearCompletedDownloads();
|
|
|
|
|
} finally {
|
|
|
|
|
setDisabled(false);
|
2022-04-07 11:17:53 -06:00
|
|
|
if (callback) {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
2022-04-01 16:45:59 -06:00
|
|
|
}
|
2022-04-01 16:31:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={localClearDownloads}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
color='yellow'
|
|
|
|
|
>Clear Completed</Button>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 11:17:53 -06:00
|
|
|
function ClearFailedDownloads({callback}) {
|
2022-04-01 16:45:59 -06:00
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
const [disabled, setDisabled] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
async function localDeleteFailed() {
|
|
|
|
|
setDisabled(true);
|
|
|
|
|
try {
|
|
|
|
|
await clearFailedDownloads();
|
|
|
|
|
} finally {
|
|
|
|
|
setDisabled(false);
|
|
|
|
|
setOpen(false);
|
2022-04-07 11:17:53 -06:00
|
|
|
if (callback) {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
2022-04-01 16:45:59 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => setOpen(true)}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
color='red'
|
|
|
|
|
>Clear Failed</Button>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={open}
|
|
|
|
|
content='Are you sure you want to delete failed downloads? They will not be retried.'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onCancel={() => setOpen(false)}
|
|
|
|
|
onConfirm={localDeleteFailed}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
class DownloadRow extends React.Component {
|
2022-05-20 15:15:31 -06:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
errorModalOpen: false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
|
|
|
|
|
render() {
|
2022-05-20 15:15:31 -06:00
|
|
|
let {url, frequency, last_successful_download, status, location, next_download, error} = this.props;
|
|
|
|
|
const {errorModalOpen} = this.state;
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
let positive = false;
|
|
|
|
|
if (status === 'pending') {
|
|
|
|
|
positive = true;
|
|
|
|
|
}
|
2022-05-20 15:15:31 -06:00
|
|
|
|
|
|
|
|
const errorModal = <Modal
|
|
|
|
|
closeIcon
|
|
|
|
|
onClose={() => this.setState({errorModalOpen: false})}
|
|
|
|
|
onOpen={() => this.setState({errorModalOpen: true})}
|
|
|
|
|
open={errorModalOpen}
|
|
|
|
|
trigger={<Button icon='exclamation circle' color='red'/>}
|
|
|
|
|
>
|
|
|
|
|
<Modal.Header>Download Error</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<pre style={{overflowX: 'scroll'}}>{error}</pre>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button onClick={() => this.setState({errorModalOpen: false})}>Close</Button>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>;
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
return (
|
|
|
|
|
<Table.Row positive={positive}>
|
2022-03-09 18:16:45 -07:00
|
|
|
<Table.Cell><a href={url} target='_blank'>{textEllipsis(url, 50)}</a></Table.Cell>
|
2021-12-20 16:08:13 -07:00
|
|
|
<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>
|
2022-05-20 15:15:31 -06:00
|
|
|
<Table.Cell>{error && errorModal}{location && <a href={location}>View</a>}</Table.Cell>
|
2021-12-20 16:08:13 -07:00
|
|
|
</Table.Row>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class StoppableRow extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
stopOpen: false,
|
|
|
|
|
startOpen: false,
|
2022-05-03 10:46:10 -06:00
|
|
|
errorModalOpen: false,
|
2021-12-20 16:08:13 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openStop = () => {
|
|
|
|
|
this.setState({stopOpen: true});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeStop = () => {
|
|
|
|
|
this.setState({stopOpen: false});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openStart = () => {
|
|
|
|
|
this.setState({startOpen: true});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeStart = () => {
|
|
|
|
|
this.setState({startOpen: false});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleStop = async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
await killDownload(this.props.id);
|
|
|
|
|
this.closeStop();
|
|
|
|
|
await this.props.fetchDownloads();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
handleStart = async (e) => {
|
|
|
|
|
e.preventDefault();
|
2021-12-30 20:45:11 -07:00
|
|
|
let downloader = this.props.downloader || null;
|
|
|
|
|
await postDownload(`${this.props.url}`, downloader);
|
2021-12-20 16:08:13 -07:00
|
|
|
this.closeStart();
|
|
|
|
|
await this.props.fetchDownloads();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2022-05-03 10:46:10 -06:00
|
|
|
let {url, last_successful_download, status, location, error} = this.props;
|
|
|
|
|
let {stopOpen, startOpen, errorModalOpen} = this.state;
|
2021-12-20 16:08:13 -07:00
|
|
|
|
2022-05-03 10:46:10 -06:00
|
|
|
let completedAtCell = last_successful_download ? secondsToDate(last_successful_download) : null;
|
2021-12-20 16:08:13 -07:00
|
|
|
let buttonCell = <Table.Cell/>;
|
|
|
|
|
let positive = false;
|
|
|
|
|
let negative = false;
|
|
|
|
|
let warning = false;
|
|
|
|
|
if (status === 'pending' || status === 'new') {
|
|
|
|
|
positive = status === 'pending';
|
|
|
|
|
buttonCell = (
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={this.openStop}
|
|
|
|
|
color='red'
|
|
|
|
|
>Stop</Button>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={stopOpen}
|
|
|
|
|
content='Are you sure you want to stop this download? It will not be retried.'
|
|
|
|
|
confirmButton='Stop'
|
|
|
|
|
onCancel={this.closeStop}
|
|
|
|
|
onConfirm={this.handleStop}
|
|
|
|
|
/>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
);
|
|
|
|
|
} else if (status === 'failed' || status === 'deferred') {
|
|
|
|
|
negative = status === 'failed';
|
|
|
|
|
warning = status === 'deferred';
|
|
|
|
|
buttonCell = (
|
|
|
|
|
<Table.Cell>
|
2022-05-03 10:46:10 -06:00
|
|
|
<Button
|
|
|
|
|
onClick={this.openStop}
|
|
|
|
|
color='red'
|
|
|
|
|
>Stop</Button>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={stopOpen}
|
|
|
|
|
content='Are you sure you want to stop this download? It will not be retried.'
|
|
|
|
|
confirmButton='Stop'
|
|
|
|
|
onCancel={this.closeStop}
|
|
|
|
|
onConfirm={this.handleStop}
|
|
|
|
|
/>
|
2021-12-20 16:08:13 -07:00
|
|
|
<Button
|
|
|
|
|
onClick={this.openStart}
|
|
|
|
|
color='green'
|
2022-05-03 10:46:10 -06:00
|
|
|
>Retry</Button>
|
2021-12-20 16:08:13 -07:00
|
|
|
<Confirm
|
|
|
|
|
open={startOpen}
|
|
|
|
|
content='Are you sure you want to restart this download?'
|
|
|
|
|
confirmButton='Start'
|
|
|
|
|
onCancel={this.closeStart}
|
|
|
|
|
onConfirm={this.handleStart}
|
|
|
|
|
/>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
);
|
2022-05-03 10:46:10 -06:00
|
|
|
} else if (status === 'complete' && location) {
|
|
|
|
|
buttonCell = (
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
<a href={location}>View</a>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (error) {
|
|
|
|
|
completedAtCell = (
|
|
|
|
|
<Modal
|
|
|
|
|
closeIcon
|
|
|
|
|
onClose={() => this.setState({errorModalOpen: false})}
|
|
|
|
|
onOpen={() => this.setState({errorModalOpen: true})}
|
|
|
|
|
open={errorModalOpen}
|
|
|
|
|
trigger={<Button icon='exclamation circle' color='red'/>}
|
|
|
|
|
>
|
2022-05-16 17:56:55 -06:00
|
|
|
<Modal.Header>Download Error</Modal.Header>
|
2022-05-03 10:46:10 -06:00
|
|
|
<Modal.Content>
|
2022-05-18 17:24:50 -06:00
|
|
|
<pre style={{overflowX: 'scroll'}}>{error}</pre>
|
2022-05-03 10:46:10 -06:00
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button onClick={() => this.setState({errorModalOpen: false})}>Close</Button>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Table.Row positive={positive} negative={negative} warning={warning}>
|
2022-03-09 18:16:45 -07:00
|
|
|
<Table.Cell><a href={url} target='_blank'>{textEllipsis(url, 50)}</a></Table.Cell>
|
2021-12-20 16:08:13 -07:00
|
|
|
<Table.Cell>{status}</Table.Cell>
|
2022-05-03 10:46:10 -06:00
|
|
|
<Table.Cell>{completedAtCell}</Table.Cell>
|
2021-12-20 16:08:13 -07:00
|
|
|
{buttonCell}
|
|
|
|
|
</Table.Row>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Downloads extends React.Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
once_downloads: null,
|
|
|
|
|
recurring_downloads: null,
|
|
|
|
|
pending_downloads: null,
|
2022-01-11 10:08:47 -07:00
|
|
|
stopOpen: false,
|
2022-01-12 09:38:21 -07:00
|
|
|
disabled: false,
|
2021-12-20 16:08:13 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
|
await this.fetchDownloads();
|
2022-03-08 13:26:03 -07:00
|
|
|
this.intervalId = setInterval(this.fetchDownloads, 1000 * 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
|
clearInterval(this.intervalId);
|
2022-01-11 10:08:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closeStop = () => {
|
|
|
|
|
this.setState({stopOpen: false});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
openStop = () => {
|
|
|
|
|
this.setState({stopOpen: true});
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetchDownloads = async () => {
|
2022-05-01 21:03:30 -06:00
|
|
|
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);
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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>
|
2022-05-03 10:46:10 -06:00
|
|
|
<Table.HeaderCell>Completed At</Table.HeaderCell>
|
2021-12-20 16:08:13 -07:00
|
|
|
<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>
|
2022-05-03 10:46:10 -06:00
|
|
|
<Table.HeaderCell>View</Table.HeaderCell>
|
2021-12-20 16:08:13 -07:00
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Header>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let onceTable = tablePlaceholder;
|
|
|
|
|
if (this.state.once_downloads !== null && this.state.once_downloads.length === 0) {
|
2022-04-07 15:47:55 -06:00
|
|
|
onceTable = <p>No downloads are scheduled.</p>
|
2021-12-20 16:08:13 -07:00
|
|
|
} else if (this.state.once_downloads !== null) {
|
2022-04-01 16:31:49 -06:00
|
|
|
onceTable = (
|
|
|
|
|
<>
|
2022-04-07 11:17:53 -06:00
|
|
|
<ClearCompleteDownloads callback={() => this.fetchDownloads()}/>
|
|
|
|
|
<ClearFailedDownloads callback={() => this.fetchDownloads()}/>
|
2022-04-01 16:31:49 -06:00
|
|
|
<Table>
|
|
|
|
|
{stoppableHeader}
|
|
|
|
|
<Table.Body>
|
|
|
|
|
{this.state.once_downloads.map((i) =>
|
|
|
|
|
<StoppableRow {...i} fetchDownloads={this.fetchDownloads} key={i.id}/>
|
|
|
|
|
)}
|
|
|
|
|
</Table.Body>
|
|
|
|
|
</Table>
|
|
|
|
|
</>);
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let recurringTable = tablePlaceholder;
|
|
|
|
|
if (this.state.recurring_downloads !== null && this.state.recurring_downloads.length === 0) {
|
2022-04-07 15:47:55 -06:00
|
|
|
recurringTable = <p>No recurring downloads are scheduled.</p>
|
2021-12-20 16:08:13 -07:00
|
|
|
} else if (this.state.recurring_downloads !== null) {
|
|
|
|
|
recurringTable = (<Table>
|
|
|
|
|
{nonStoppableHeader}
|
|
|
|
|
<Table.Body>
|
2022-02-04 13:55:13 -07:00
|
|
|
{this.state.recurring_downloads.map((i) => <DownloadRow {...i} key={i.id}/>)}
|
2021-12-20 16:08:13 -07:00
|
|
|
</Table.Body>
|
|
|
|
|
</Table>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2022-01-12 09:38:21 -07:00
|
|
|
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
2022-02-04 13:55:13 -07:00
|
|
|
<DisableDownloadsToggle/>
|
2021-12-20 16:08:13 -07:00
|
|
|
<Header as='h1'>Downloads</Header>
|
|
|
|
|
{onceTable}
|
|
|
|
|
|
|
|
|
|
<Header as='h1'>Recurring Downloads</Header>
|
|
|
|
|
{recurringTable}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
export default function Admin(props) {
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
const links = [
|
2022-02-02 14:02:51 -07:00
|
|
|
{text: 'Downloads', to: '/admin', exact: true, key: 'admin'},
|
|
|
|
|
{text: 'Settings', to: '/admin/settings', key: 'settings'},
|
|
|
|
|
{text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'},
|
2022-01-29 22:25:35 -07:00
|
|
|
];
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
return (
|
2022-01-31 09:32:06 -07:00
|
|
|
<PageContainer>
|
2022-01-29 22:25:35 -07:00
|
|
|
<TabLinks links={links}/>
|
|
|
|
|
<Route path='/admin' exact component={Downloads}/>
|
|
|
|
|
<Route path='/admin/settings' exact component={Settings}/>
|
|
|
|
|
<Route path='/admin/wrol' exact component={WROLMode}/>
|
2022-01-31 09:32:06 -07:00
|
|
|
</PageContainer>
|
2022-01-29 22:25:35 -07:00
|
|
|
)
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
}
|