diff --git a/frontend/routes/Commands.jsx b/frontend/routes/Commands.jsx new file mode 100644 index 0000000..f229477 --- /dev/null +++ b/frontend/routes/Commands.jsx @@ -0,0 +1,176 @@ +// SPDX-FileCopyrightText: © 2022 Andrej Balyschew +// SPDX-License-Identifier: AGPL-3.0-only + +import * as React from 'react'; +import { + Button, + Dialog, + DialogContent, + DialogActions, + Container, + makeStyles, + Typography, +} from '@material-ui/core'; +import ButtonGroup from '@material-ui/core/ButtonGroup'; + +import { NCTRL_BASE_PATH } from '../util/nctrl.js'; +import { exec } from '../util/exec.js'; + +export const title = 'Commands'; +export const route = '/commands'; +export const position = 2; + +const useStyles = makeStyles(theme => ({ + button: { + flexGrow: 1, + }, + icon: { + marginRight: theme.spacing(2), + }, + heroContent: { + padding: theme.spacing(12, 0, 6), + }, + text: { + textAlign: 'center', + }, + container: { + padding: '0.5rem', + display: 'flex', + justifyContent: 'center', + }, +})); + +export function Component() { + const classes = useStyles(); + + const serviceStatusScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/check_axiom_service_status'); + const [serviceStatus, setServiceStatus] = React.useState(false); + React.useEffect(() => { + const interval = setInterval( + () => serviceStatusScript.value().then(x => setServiceStatus(x === 'true')), + 1000 + ); + return () => { + clearInterval(interval); + }; + }); + + const rebootScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/reboot'); + const poweroffScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/power_off'); + + const startHDMIScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/start_hdmi'); + const stopHDMIScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/stop_hdmi'); + + const startAXIOMScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/start_axiom'); + const stopAXIOMScript = NctrlValue.of(NCTRL_BASE_PATH + 'scripts/stop_axiom'); + + const [isRebootConfirmation, showRebootConfirmation] = React.useState(false); + const handleRebootConfirmation = () => { + showRebootConfirmation(true); + }; + + const [isPowerOffConfirmation, showPowerOffConfirmation] = React.useState(false); + const handlePowerOffConfirmation = () => { + showPowerOffConfirmation(true); + }; + + return ( +
+
+ + Service: {serviceStatus === true ? 'ACTIVE' : 'INACTIVE'} + + + + + + + + + + + + + + + + + + exec('reboot now').catch(err => console.log(err))} + > + exec('shutdown --poweroff').catch(err => console.log(err))} + > + + +
+
+ ); +} + +function ConfirmDialog(props) { + const { title, message, open, setOpen, onConfirm } = props; + + return ( + setOpen(false)}> + + Please confirm {message} + + + + + + + ); +}