From 335ad7ceb02036d221795fa207d4b4ce0c31ad49 Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 29 Sep 2022 12:02:09 -0600 Subject: [PATCH] Splitting Admin components into admin directory. --- app/src/App.js | 3 +- app/src/components/Admin.js | 784 -------------------------- app/src/components/admin/Admin.js | 87 +++ app/src/components/admin/Downloads.js | 343 +++++++++++ app/src/components/admin/Settings.js | 235 ++++++++ app/src/components/admin/Status.js | 114 ++++ 6 files changed, 781 insertions(+), 785 deletions(-) delete mode 100644 app/src/components/Admin.js create mode 100644 app/src/components/admin/Admin.js create mode 100644 app/src/components/admin/Downloads.js create mode 100644 app/src/components/admin/Settings.js create mode 100644 app/src/components/admin/Status.js diff --git a/app/src/App.js b/app/src/App.js index 1e8c224f..2bebf3f2 100644 --- a/app/src/App.js +++ b/app/src/App.js @@ -3,7 +3,7 @@ import './App.css'; import {NavBar} from "./components/Nav"; import {Link, Route, Routes} from "react-router-dom"; import {VideosRoute, VideoWrapper} from "./components/Videos"; -import Admin, {CPUUsageProgress} from "./components/Admin"; +import Admin from "./components/admin/Admin"; import {Container, Divider} from "semantic-ui-react"; import 'semantic-ui-offline/semantic.min.css'; import {SemanticToastContainer} from 'react-semantic-toasts'; @@ -18,6 +18,7 @@ import {useSearchFiles, useSettingsInterval, useStatus} from "./hooks/customHook import {MapRoute} from "./components/Map"; import {SettingsContext, ThemeContext} from "./contexts/contexts"; import {Header, Segment, Statistic, StatisticGroup, ThemeWrapper} from "./components/Theme"; +import {CPUUsageProgress} from "./components/admin/Status"; function Dashboard() { useTitle('Dashboard'); diff --git a/app/src/components/Admin.js b/app/src/components/Admin.js deleted file mode 100644 index 63170008..00000000 --- a/app/src/components/Admin.js +++ /dev/null @@ -1,784 +0,0 @@ -import React, {useContext} from 'react'; -import { - Confirm, - Container, - Dimmer, - Divider, - Icon, - Modal, - PlaceholderLine, - TableBody, - TableCell, - TableHeader, - TableHeaderCell, - TableRow -} from "semantic-ui-react"; -import { - clearCompletedDownloads, - clearFailedDownloads, - getSettings, - getStatus, - killDownload, - postDownload, - saveSettings -} from "../api"; -import TimezoneSelect from 'react-timezone-select'; -import { - DisableDownloadsToggle, - HelpPopup, - HotspotToggle, - humanFileSize, - LoadStatistic, - PageContainer, - secondsToElapsedPopup, - secondsToFrequency, - TabLinks, - textEllipsis, - ThrottleToggle, - Toggle, - WROLModeMessage -} from "./Common"; -import {Route, Routes} from "react-router-dom"; -import QRCode from "react-qr-code"; -import {ThemeContext} from "../contexts/contexts"; -import {useDownloads} from "../hooks/customHooks"; -import { - Button, - Form, - FormField, - FormGroup, - FormInput, - Header, - Loader, - Placeholder, - Progress, - Statistic, - StatisticGroup, - Table -} from "./Theme"; - -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, - download_timeout: null, - hotspot_device: 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, - download_timeout: settings.download_timeout || '', - hotspot_device: settings.hotspot_device, - 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, - download_timeout: this.state.download_timeout ? parseInt(this.state.download_timeout) : 0, - hotspot_device: this.state.hotspot_device, - 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}); - } - - handleTimeoutChange = async (e, name, value) => { - if (e) { - e.preventDefault() - } - // Restrict timeout to numbers. - value = value.replace(/[^\d]/, ''); - this.setState({[name]: value}); - } - - render() { - if (this.state.ready === false) { - return - } - - let { - disabled, - download_on_startup, - download_timeout, - hotspot_device, - hotspot_on_startup, - hotspot_password, - hotspot_ssid, - pending, - qrCodeValue, - throttle_on_startup, - timezone, - } = this.state; - - const qrButton = ; - - return - {({i, t}) => - - - - - - -
- The settings for your WROLPi. -
-

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

- -
-
- this.handleInputChange(null, 'download_on_startup', checked)} - /> -
- -
- this.handleInputChange(null, 'hotspot_on_startup', checked)} - /> -
- -
- this.handleInputChange(null, 'throttle_on_startup', checked)} - /> -
- - - - Download Timeout - - } - value={download_timeout} - disabled={disabled || download_timeout === null} - onChange={(e, d) => this.handleTimeoutChange(e, 'download_timeout', d.value)} - /> - - - - - this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)} - /> - - this.setState({hotspot_password: d.value}, this.handleHotspotChange)} - /> - this.handleInputChange(e, 'hotspot_device', d.value)} - /> - - - this.setState({qrOpen: false})} - onOpen={() => this.setState({qrOpen: true})} - open={this.state.qrOpen} - trigger={qrButton} - > - - Scan this code to join the hotspot - - - - - - - - - this.handleInputChange(null, 'timezone', i)} - /> - - - - - - - - -
-
- } -
- } -} - -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 (checked) => { - // Handle WROL Mode toggling by itself so that other settings are not modified. - let config = { - wrol_mode: checked, - } - await saveSettings(config); - this.setState({disabled: !this.state.WROLMode, WROLMode: checked}); - } - - render() { - if (this.state.ready === false) { - return - } - - return - {({i, t}) => - -
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 DriveInfo({used, size, percent, mount}) { - let color; - if (percent >= 90) { - color = 'red'; - } else if (percent >= 80) { - color = 'orange'; - } - return -} - -function CPUTemperatureStatistic({value}) { - if (!value) { - return - } - let color; - if (value >= 75) { - color = 'red'; - } else if (value >= 50) { - color = 'yellow'; - } - return -} - -export function CPUUsageProgress({value, label}) { - if (value === null) { - return - } - - let color = 'black'; - if (value >= 90) { - color = 'red'; - } else if (value >= 70) { - color = 'brown'; - } else if (value >= 50) { - color = 'orange'; - } else if (value >= 30) { - color = 'green'; - } - return -} - -class Status extends React.Component { - - constructor(props) { - super(props); - this.state = { - status: null, - } - this.fetchStatus = this.fetchStatus.bind(this); - } - - async componentDidMount() { - await this.fetchStatus(); - this.intervalId = setInterval(this.fetchStatus, 1000 * 5); - } - - componentWillUnmount() { - clearInterval(this.intervalId); - } - - fetchStatus = async () => { - try { - let status = await getStatus(); - this.setState({status: status}); - } catch (e) { - console.error(e); - this.setState({status: null}); - } - } - - render() { - if (this.state.status) { - const {cpu_info, load, drives} = this.state.status; - const {minute_1, minute_5, minute_15} = load; - const {percent, cores, temperature} = cpu_info; - - return - {({i}) => <> - - - - - - - - - - -
Drive Usage
- {drives.map((drive) => )} - } -
- } - - return - {({i}) => - Loading system status; - - } - - } -} - -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 { - 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; - - let positive = false; - if (status === 'pending') { - positive = true; - } - - const errorModal = this.setState({errorModalOpen: false})} - onOpen={() => this.setState({errorModalOpen: true})} - open={errorModalOpen} - trigger={ - - ; - - return - - - {textEllipsis(url, 50)} - - - {secondsToFrequency(frequency)} - {last_successful_download ? secondsToElapsedPopup(last_successful_download) : null} - {secondsToElapsedPopup(next_download)} - {error && errorModal}{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 ? 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 = ( - - - - - ); - } 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)} - - {completedAtCell} - {buttonCell} - - ); - } -} - -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} - -} - -export default function Admin(props) { - - const links = [ - {text: 'Downloads', to: '/admin', key: 'admin', end: true}, - {text: 'Settings', to: '/admin/settings', key: 'settings'}, - {text: 'Status', to: '/admin/status', key: 'status'}, - {text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'}, - ]; - - return ( - - - - }/> - }/> - }/> - }/> - - - ) - -} diff --git a/app/src/components/admin/Admin.js b/app/src/components/admin/Admin.js new file mode 100644 index 00000000..fad8cfc2 --- /dev/null +++ b/app/src/components/admin/Admin.js @@ -0,0 +1,87 @@ +import React from 'react'; +import {Container} from "semantic-ui-react"; +import {getSettings, saveSettings} from "../../api"; +import {PageContainer, TabLinks, Toggle} from "../Common"; +import {Route, Routes} from "react-router-dom"; +import {ThemeContext} from "../../contexts/contexts"; +import {Header, Loader} from "../Theme"; +import {Downloads} from "./Downloads"; +import {Settings} from "./Settings"; +import {Status} from "./Status"; + +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 (checked) => { + // Handle WROL Mode toggling by itself so that other settings are not modified. + let config = { + wrol_mode: checked, + } + await saveSettings(config); + this.setState({disabled: !this.state.WROLMode, WROLMode: checked}); + } + + render() { + if (this.state.ready === false) { + return + } + + return + {({i, t}) => + +
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. +

+ + +
} +
+ } +} + +export default function Admin() { + + const links = [ + {text: 'Downloads', to: '/admin', key: 'admin', end: true}, + {text: 'Settings', to: '/admin/settings', key: 'settings'}, + {text: 'Status', to: '/admin/status', key: 'status'}, + {text: 'WROL Mode', to: '/admin/wrol', key: 'wrol'}, + ]; + + return ( + + + + }/> + }/> + }/> + }/> + + + ) + +} diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js new file mode 100644 index 00000000..d3c85a1f --- /dev/null +++ b/app/src/components/admin/Downloads.js @@ -0,0 +1,343 @@ +import React, {useContext} from "react"; +import {clearCompletedDownloads, clearFailedDownloads, killDownload, postDownload} from "../../api"; +import {Link} from "react-router-dom"; +import { + DisableDownloadsToggle, + secondsToElapsedPopup, + secondsToFrequency, + textEllipsis, + WROLModeMessage +} from "../Common"; +import { + Confirm, + Modal, + PlaceholderLine, + TableBody, + TableCell, + TableHeader, + TableHeaderCell, + TableRow +} from "semantic-ui-react"; +import {Button, Header, 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 <> + + +} + +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 { + 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={ + + ; + + 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 = ( + + + + + ); + } else if (status === 'failed' || status === 'deferred') { + negative = status === 'failed'; + warning = status === 'deferred'; + buttonCell = ( + + + + + + + ); + } else if (status === 'complete' && location) { + buttonCell = ( + + {link('View')} + + ); + } + if (error) { + completedAtCell = ( + this.setState({errorModalOpen: false})} + onOpen={() => this.setState({errorModalOpen: true})} + open={errorModalOpen} + trigger={ + + + ) + } + + 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} + +} diff --git a/app/src/components/admin/Settings.js b/app/src/components/admin/Settings.js new file mode 100644 index 00000000..3186f956 --- /dev/null +++ b/app/src/components/admin/Settings.js @@ -0,0 +1,235 @@ +import React from "react"; +import {getSettings, saveSettings} from "../../api"; +import {Button, Form, FormField, FormGroup, FormInput, Header, Loader} from "../Theme"; +import {Container, Dimmer, Divider, Icon, Modal} from "semantic-ui-react"; +import {ThemeContext} from "../../contexts/contexts"; +import {HelpPopup, HotspotToggle, ThrottleToggle, Toggle, WROLModeMessage} from "../Common"; +import QRCode from "react-qr-code"; +import TimezoneSelect from "react-timezone-select"; + +export 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, + download_timeout: null, + hotspot_device: 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, + download_timeout: settings.download_timeout || '', + hotspot_device: settings.hotspot_device, + 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, + download_timeout: this.state.download_timeout ? parseInt(this.state.download_timeout) : 0, + hotspot_device: this.state.hotspot_device, + 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}); + } + + handleTimeoutChange = async (e, name, value) => { + if (e) { + e.preventDefault() + } + // Restrict timeout to numbers. + value = value.replace(/[^\d]/, ''); + this.setState({[name]: value}); + } + + render() { + if (this.state.ready === false) { + return + } + + let { + disabled, + download_on_startup, + download_timeout, + hotspot_device, + hotspot_on_startup, + hotspot_password, + hotspot_ssid, + pending, + qrCodeValue, + throttle_on_startup, + timezone, + } = this.state; + + const qrButton = ; + + return + {({i, t}) => + + + + + + +
+ The settings for your WROLPi. +
+

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

+ +
+
+ this.handleInputChange(null, 'download_on_startup', checked)} + /> +
+ +
+ this.handleInputChange(null, 'hotspot_on_startup', checked)} + /> +
+ +
+ this.handleInputChange(null, 'throttle_on_startup', checked)} + /> +
+ + + + Download Timeout + + } + value={download_timeout} + disabled={disabled || download_timeout === null} + onChange={(e, d) => this.handleTimeoutChange(e, 'download_timeout', d.value)} + /> + + + + + this.setState({hotspot_ssid: d.value}, this.handleHotspotChange)} + /> + + this.setState({hotspot_password: d.value}, this.handleHotspotChange)} + /> + this.handleInputChange(e, 'hotspot_device', d.value)} + /> + + + this.setState({qrOpen: false})} + onOpen={() => this.setState({qrOpen: true})} + open={this.state.qrOpen} + trigger={qrButton} + > + + Scan this code to join the hotspot + + + + + + + + + this.handleInputChange(null, 'timezone', i)} + /> + + + + + + + + +
+
+ } +
+ } +} diff --git a/app/src/components/admin/Status.js b/app/src/components/admin/Status.js new file mode 100644 index 00000000..70cee0e4 --- /dev/null +++ b/app/src/components/admin/Status.js @@ -0,0 +1,114 @@ +import {Header, Loader, Progress, Statistic, StatisticGroup} from "../Theme"; +import React from "react"; +import {humanFileSize, LoadStatistic} from "../Common"; +import {getStatus} from "../../api"; +import {ThemeContext} from "../../contexts/contexts"; +import {Container} from "semantic-ui-react"; + +function DriveInfo({used, size, percent, mount}) { + let color; + if (percent >= 90) { + color = 'red'; + } else if (percent >= 80) { + color = 'orange'; + } + return +} + +function CPUTemperatureStatistic({value}) { + if (!value) { + return + } + let color; + if (value >= 75) { + color = 'red'; + } else if (value >= 50) { + color = 'yellow'; + } + return +} + +export function CPUUsageProgress({value, label}) { + if (value === null) { + return + } + + let color = 'black'; + if (value >= 90) { + color = 'red'; + } else if (value >= 70) { + color = 'brown'; + } else if (value >= 50) { + color = 'orange'; + } else if (value >= 30) { + color = 'green'; + } + return +} + +export class Status extends React.Component { + + constructor(props) { + super(props); + this.state = { + status: null, + } + this.fetchStatus = this.fetchStatus.bind(this); + } + + async componentDidMount() { + await this.fetchStatus(); + this.intervalId = setInterval(this.fetchStatus, 1000 * 5); + } + + componentWillUnmount() { + clearInterval(this.intervalId); + } + + fetchStatus = async () => { + try { + let status = await getStatus(); + this.setState({status: status}); + } catch (e) { + console.error(e); + this.setState({status: null}); + } + } + + render() { + if (this.state.status) { + const {cpu_info, load, drives} = this.state.status; + const {minute_1, minute_5, minute_15} = load; + const {percent, cores, temperature} = cpu_info; + + return + {({i}) => <> + + + + + + + + + + +
Drive Usage
+ {drives.map((drive) => )} + } +
+ } + + return + {({i}) => + Loading system status; + + } + + } +}