setOpen(false)}
onConfirm={localDeleteFailed}
/>
>
}
class DownloadRow extends React.Component {
render() {
let {url, frequency, last_successful_download, status, next_download} = this.props;
let positive = false;
if (status === 'pending') {
positive = true;
}
return (
{textEllipsis(url, 50)}
{secondsToFrequency(frequency)}
{last_successful_download ? secondsToDate(last_successful_download) : null}
{secondsToDate(next_download)}
{status}
);
}
}
class StoppableRow extends React.Component {
constructor(props) {
super(props);
this.state = {
stopOpen: false,
startOpen: false,
};
}
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();
let downloader = this.props.downloader || null;
await postDownload(`${this.props.url}`, downloader);
this.closeStart();
await this.props.fetchDownloads();
};
render() {
let {url, last_successful_download, status} = this.props;
let {stopOpen, startOpen} = this.state;
let buttonCell = ;
let positive = false;
let negative = false;
let warning = false;
if (status === 'pending' || status === 'new') {
positive = status === 'pending';
buttonCell = (
);
} else if (status === 'failed' || status === 'deferred') {
negative = status === 'failed';
warning = status === 'deferred';
buttonCell = (
);
}
return (
{textEllipsis(url, 50)}
{last_successful_download ? secondsToDate(last_successful_download) : null}
{status}
{buttonCell}
);
}
}
class Downloads extends React.Component {
constructor(props) {
super(props);
this.state = {
once_downloads: null,
recurring_downloads: null,
pending_downloads: null,
stopOpen: false,
disabled: false,
};
}
async componentDidMount() {
await this.fetchDownloads();
this.intervalId = setInterval(this.fetchDownloads, 1000 * 10);
}
componentWillUnmount() {
clearInterval(this.intervalId);
}
closeStop = () => {
this.setState({stopOpen: false});
}
openStop = () => {
this.setState({stopOpen: true});
}
fetchDownloads = async () => {
let data = await getDownloads();
this.setState({
once_downloads: data.once_downloads,
recurring_downloads: data.recurring_downloads,
pending_downloads: data.pending_downloads,
});
}
render() {
let tablePlaceholder = (
);
let stoppableHeader = (
URL
Completed At
Status
Control
);
let nonStoppableHeader = (
URL
Download Frequency
Last Successful Download
Next Download
Status
);
let onceTable = tablePlaceholder;
if (this.state.once_downloads !== null && this.state.once_downloads.length === 0) {
onceTable = No downloads are scheduled to be downloaded.
} else if (this.state.once_downloads !== null) {
onceTable = (
<>
{stoppableHeader}
{this.state.once_downloads.map((i) =>
)}
>);
}
let recurringTable = tablePlaceholder;
if (this.state.recurring_downloads !== null && this.state.recurring_downloads.length === 0) {
recurringTable = No downloads are scheduled to be downloaded.
} else if (this.state.recurring_downloads !== null) {
recurringTable = (
{nonStoppableHeader}
{this.state.recurring_downloads.map((i) => )}
);
}
return (
{onceTable}
{recurringTable}
);
}
}
export default function Admin(props) {
const links = [
{text: 'Downloads', to: '/admin', exact: true, key: 'admin'},
{text: 'Settings', to: '/admin/settings', key: 'settings'},
{text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'},
];
return (
)
}