mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 16:06:19 -05:00
Displaying downloads link when user submits download.
This commit is contained in:
parent
46cf28dee8
commit
0689c03866
2 changed files with 47 additions and 17 deletions
|
|
@ -6,6 +6,7 @@ import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
|||
import {ThemeContext} from "../contexts/contexts";
|
||||
import {Accordion, Button, Form, FormField, FormGroup, FormInput, Header, Loader, Segment, TextArea} from "./Theme";
|
||||
import {AccordionContent, AccordionTitle, FormDropdown} from "semantic-ui-react";
|
||||
import {Link} from "react-router-dom";
|
||||
|
||||
const validUrl = /^(http|https):\/\/[^ "]+$/;
|
||||
|
||||
|
|
@ -20,17 +21,18 @@ class Downloader extends React.Component {
|
|||
pending: false,
|
||||
urls: '',
|
||||
valid: true,
|
||||
submitted: false,
|
||||
};
|
||||
}
|
||||
|
||||
submitDownload = async () => {
|
||||
let {urls, downloader, destination} = this.state;
|
||||
if (urls) {
|
||||
this.setState({pending: true});
|
||||
this.setState({pending: true, submitted: false});
|
||||
try {
|
||||
let response = await postDownload(urls, downloader, null, null, null, destination);
|
||||
if (response.status === 204) {
|
||||
this.setState({urls: '', pending: false});
|
||||
this.setState({urls: '', pending: false, submitted: true});
|
||||
}
|
||||
} finally {
|
||||
this.setState({pending: false});
|
||||
|
|
@ -60,9 +62,24 @@ class Downloader extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleKeydown = async (e) => {
|
||||
const {valid, urls} = this.state;
|
||||
if (e.keyCode === 13 && e.ctrlKey && urls && valid) {
|
||||
await this.submitDownload();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.addEventListener('keydown', this.handleKeydown);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
document.removeEventListener('keydown', this.handleKeydown);
|
||||
}
|
||||
|
||||
render() {
|
||||
let disabled = !this.state.urls || !this.state.valid || this.state.pending || !this.state.downloader;
|
||||
const {advancedOpen, destination} = this.state;
|
||||
const {advancedOpen, destination, submitted} = this.state;
|
||||
const {header, withDestination} = this.props;
|
||||
|
||||
const advancedAccordion = <Accordion>
|
||||
|
|
@ -86,6 +103,8 @@ class Downloader extends React.Component {
|
|||
</AccordionContent>
|
||||
</Accordion>;
|
||||
|
||||
const viewDownloads = <Link to='/admin'><Icon name='checkmark'/> View downloads</Link>;
|
||||
|
||||
return <ThemeContext.Consumer>
|
||||
{({i}) => (<Form onSubmit={this.submitDownload}>
|
||||
<WROLModeMessage content='Downloading is disabled while WROL Mode is enabled'/>
|
||||
|
|
@ -99,6 +118,7 @@ class Downloader extends React.Component {
|
|||
{withDestination && advancedAccordion}
|
||||
<Button content='Cancel' onClick={this.props.clearSelected}/>
|
||||
<Button primary style={{marginTop: '1em'}} disabled={disabled}>Download</Button>
|
||||
{submitted && viewDownloads}
|
||||
</Form>)}
|
||||
</ThemeContext.Consumer>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,9 +180,18 @@ class StoppableRow extends React.Component {
|
|||
stopOpen: false,
|
||||
startOpen: false,
|
||||
errorModalOpen: false,
|
||||
deleteOpen: false,
|
||||
};
|
||||
}
|
||||
|
||||
openDelete = () => {
|
||||
this.setState({deleteOpen: true});
|
||||
}
|
||||
|
||||
closeDelete = () => {
|
||||
this.setState({deleteOpen: false});
|
||||
}
|
||||
|
||||
openStop = () => {
|
||||
this.setState({stopOpen: true});
|
||||
}
|
||||
|
|
@ -199,6 +208,13 @@ class StoppableRow extends React.Component {
|
|||
this.setState({startOpen: false});
|
||||
}
|
||||
|
||||
handleDelete = async (e) => {
|
||||
e.preventDefault();
|
||||
await deleteDownload(this.props.id);
|
||||
this.closeDelete();
|
||||
await this.props.fetchDownloads();
|
||||
};
|
||||
|
||||
handleStop = async (e) => {
|
||||
e.preventDefault();
|
||||
await killDownload(this.props.id);
|
||||
|
|
@ -216,7 +232,7 @@ class StoppableRow extends React.Component {
|
|||
|
||||
render() {
|
||||
let {url, last_successful_download, status, location, error} = this.props;
|
||||
let {stopOpen, startOpen, errorModalOpen} = this.state;
|
||||
let {stopOpen, startOpen, errorModalOpen, deleteOpen} = this.state;
|
||||
|
||||
const link = location ?
|
||||
(text) => <Link to={location}>{text}</Link> :
|
||||
|
|
@ -243,21 +259,15 @@ class StoppableRow extends React.Component {
|
|||
} else if (status === 'failed' || status === 'deferred') {
|
||||
buttonCell = (
|
||||
<TableCell>
|
||||
<Button
|
||||
onClick={this.openStop}
|
||||
color='red'
|
||||
>Stop</Button>
|
||||
<Button icon='trash' onClick={this.openDelete} color='red'/>
|
||||
<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}
|
||||
open={deleteOpen}
|
||||
content='Are you sure you want to delete this download?'
|
||||
confirmButton='Delete'
|
||||
onCancel={this.closeDelete}
|
||||
onConfirm={this.handleDelete}
|
||||
/>
|
||||
<Button
|
||||
onClick={this.openStart}
|
||||
color='green'
|
||||
>Retry</Button>
|
||||
<Button onClick={this.openStart} color='green'>Retry</Button>
|
||||
<Confirm
|
||||
open={startOpen}
|
||||
content='Are you sure you want to restart this download?'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue