import React, {useContext, useState} from "react"; import {clearCompletedDownloads, clearFailedDownloads, killDownload, postDownload} from "../../api"; import {Link} from "react-router-dom"; import { DisableDownloadsToggle, secondsToElapsedPopup, secondsToFrequency, textEllipsis, WROLModeMessage } from "../Common"; import { Button as SemanticButton, Confirm, Modal, PlaceholderLine, TableBody, TableCell, TableHeader, TableHeaderCell, TableRow } from "semantic-ui-react"; import {Button, Header, Icon, Placeholder, Table} from "../Theme"; import {ThemeContext} from "../../contexts/contexts"; import {useDownloads} from "../../hooks/customHooks"; function ClearCompleteDownloads({callback}) { const [disabled, setDisabled] = React.useState(false); async function localClearDownloads() { setDisabled(true); try { await clearCompletedDownloads(); } finally { setDisabled(false); if (callback) { callback() } } } return <> Clear Completed > } function ClearFailedDownloads({callback}) { 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); if (callback) { callback() } } } return <> setOpen(true)} disabled={disabled} color='red' >Clear Failed setOpen(false)} onConfirm={localDeleteFailed} /> > } class DownloadRow extends React.Component { constructor(props) { super(props); this.state = { errorModalOpen: false, } } render() { let {url, frequency, last_successful_download, status, location, next_download, error} = this.props; const {errorModalOpen} = this.state; const link = location ? (text) => {text} : (text) => {text}; let positive = false; if (status === 'pending') { positive = true; } const errorModal = this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={} > Download Error {error} this.setState({errorModalOpen: false})}>Close ; return {link(textEllipsis(url, 50))} {secondsToFrequency(frequency)} {last_successful_download ? secondsToElapsedPopup(last_successful_download) : null} {secondsToElapsedPopup(next_download)} {error && errorModal}{link('View')} } } class StoppableRow extends React.Component { constructor(props) { super(props); this.state = { stopOpen: false, startOpen: false, errorModalOpen: 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, location, error} = this.props; let {stopOpen, startOpen, errorModalOpen} = this.state; const link = location ? (text) => {text} : (text) => {text}; let completedAtCell = last_successful_download ? secondsToElapsedPopup(last_successful_download) : null; let buttonCell = ; let positive = false; let negative = false; let warning = false; if (status === 'pending' || status === 'new') { positive = status === 'pending'; buttonCell = ( Stop ); } else if (status === 'failed' || status === 'deferred') { negative = status === 'failed'; warning = status === 'deferred'; buttonCell = ( Stop Retry ); } else if (status === 'complete' && location) { buttonCell = ( {link('View')} ); } if (error) { completedAtCell = ( this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={} > Download Error {error} this.setState({errorModalOpen: false})}>Close ) } return ( {link(textEllipsis(url, 50))} {completedAtCell} {buttonCell} ); } } export function Downloads() { const {t} = useContext(ThemeContext); const {onceDownloads, recurringDownloads, fetchDownloads} = useDownloads(); const tablePlaceholder = ; const stoppableHeader = ( URL Completed At Control ); const nonStoppableHeader = ( URL Download Frequency Completed At Next View ); let onceTable = tablePlaceholder; if (onceDownloads && onceDownloads.length === 0) { onceTable = No downloads are scheduled. } else if (onceDownloads) { onceTable = ( <> {stoppableHeader} {onceDownloads.map((i) => )} >); } let recurringTable = tablePlaceholder; if (recurringDownloads && recurringDownloads.length === 0) { recurringTable = No recurring downloads are scheduled. } else if (recurringDownloads) { recurringTable = {nonStoppableHeader} {recurringDownloads.map((i) => )} ; } return <> Downloads {onceTable} Recurring Downloads {recurringTable} > }
{error}
No downloads are scheduled.
No recurring downloads are scheduled.