import React from 'react'; import { Button, Checkbox, Confirm, Container, Dimmer, Divider, Form, Header, Icon, Loader, Modal, Placeholder, Table } from "semantic-ui-react"; import { clearCompletedDownloads, clearFailedDownloads, getDownloads, getSettings, killDownload, postDownload, saveSettings } from "../api"; import TimezoneSelect from 'react-timezone-select'; import { DisableDownloadsToggle, HotspotToggle, PageContainer, secondsToDate, secondsToFrequency, TabLinks, textEllipsis, ThrottleToggle, WROLModeMessage } from "./Common"; import {Route} from "react-router-dom"; import QRCode from "react-qr-code"; class Settings extends React.Component { constructor(props) { super(props); this.state = { disabled: false, hotspot_encryption: 'WPA', pending: false, qrCodeValue: '', qrOpen: false, ready: false, download_on_startup: null, hotspot_on_startup: null, hotspot_password: null, hotspot_ssid: null, hotspot_status: null, throttle_on_startup: null, throttle_status: null, timezone: {timezone: null}, } this.handleSubmit = this.handleSubmit.bind(this); this.handleHotspotChange = this.handleHotspotChange.bind(this); } async componentDidMount() { 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); } } async handleSubmit(e) { e.preventDefault(); this.setState({disabled: true, pending: true}); let settings = { download_on_startup: this.state.download_on_startup, hotspot_on_startup: this.state.hotspot_on_startup, hotspot_password: this.state.hotspot_password, hotspot_ssid: this.state.hotspot_ssid, throttle_on_startup: this.state.throttle_on_startup, timezone: this.state.timezone.value, } await saveSettings(settings); this.setState({disabled: false, pending: false}); } handleInputChange = async (e, name, value) => { if (e) { e.preventDefault() } this.setState({[name]: value}); } handleHotspotChange = async () => { 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}); } render() { if (this.state.ready === false) { return } let { disabled, download_on_startup, hotspot_on_startup, hotspot_password, hotspot_ssid, pending, qrCodeValue, throttle_on_startup, timezone, } = this.state; return (
The settings for your WROLPi.

Any changes will be written to config/wrolpi.yaml.

this.handleInputChange(e, 'download_on_startup', d.checked)} />
this.handleInputChange(e, 'hotspot_on_startup', d.checked)} />
this.handleInputChange(e, 'throttle_on_startup', d.checked)} /> this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)} /> this.setState({hotspot_password: d.value}, this.handleHotspotChange)} /> this.setState({qrOpen: false})} onOpen={() => this.setState({qrOpen: true})} open={this.state.qrOpen} trigger={} > Scan this code to join the hotspot this.handleInputChange(null, 'timezone', v)} />
) } } class WROLMode extends React.Component { constructor(props) { super(props); this.state = { WROLMode: false, } } async componentDidMount() { try { let settings = await getSettings(); this.setState({ready: true, WROLMode: settings.wrol_mode}); } catch (e) { console.error(e); } } toggleWROLMode = async () => { // Handle WROL Mode toggling by itself so that other settings are not modified. let config = { wrol_mode: !this.state.WROLMode, } await saveSettings(config); this.setState({disabled: !this.state.WROLMode, WROLMode: !this.state.WROLMode}); } render() { if (this.state.ready === false) { return } return (
WROL Mode

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.

Note: User settings and favorites can still be modified.

) } } function ClearCompleteDownloads({callback}) { const [disabled, setDisabled] = React.useState(false); async function localClearDownloads() { setDisabled(true); try { await clearCompletedDownloads(); } finally { setDisabled(false); if (callback) { callback() } } } return <> } 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(false)} onConfirm={localDeleteFailed} /> } class DownloadRow extends React.Component { render() { let {url, frequency, last_successful_download, status, location, 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)} {location && 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; let completedAtCell = last_successful_download ? secondsToDate(last_successful_download) : null; 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 = ( ); } else if (status === 'complete' && location) { buttonCell = ( View ); } if (error) { completedAtCell = ( this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={ ) } return ( {textEllipsis(url, 50)} {status} {completedAtCell} {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 () => { 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 = ( ); let stoppableHeader = ( URL Status Completed At Control ); let nonStoppableHeader = ( URL Download Frequency Last Successful Download Next Download View ); let onceTable = tablePlaceholder; if (this.state.once_downloads !== null && this.state.once_downloads.length === 0) { onceTable =

No downloads are scheduled.

} else if (this.state.once_downloads !== null) { onceTable = ( <> this.fetchDownloads()}/> this.fetchDownloads()}/> {stoppableHeader} {this.state.once_downloads.map((i) => )}
); } let recurringTable = tablePlaceholder; if (this.state.recurring_downloads !== null && this.state.recurring_downloads.length === 0) { recurringTable =

No recurring downloads are scheduled.

} else if (this.state.recurring_downloads !== null) { recurringTable = ( {nonStoppableHeader} {this.state.recurring_downloads.map((i) => )}
); } return (
Downloads
{onceTable}
Recurring Downloads
{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 ( ) }