diff --git a/lib/machine-loader.js b/lib/machine-loader.js index a3197be6..72a24ce3 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -4,6 +4,8 @@ const axios = require('axios') const logger = require('./logger') const db = require('./db') const pairing = require('./pairing') +const notifier = require('./notifier') +const dbm = require('./postgresql_interface') const configManager = require('./new-config-manager') const settingsLoader = require('./new-settings-loader') @@ -34,15 +36,40 @@ function getConfig (defaultConfig) { } function getMachineNames (config) { + const fullyFunctionalStatus = {label: 'Fully functional', type: 'success'} + const unresponsiveStatus = {label: 'Unresponsive', type: 'error'} + const stuckStatus = {label: 'Stuck', type: 'error'} + return Promise.all([getMachines(), getConfig(config)]) - .then(([machines, config]) => { + .then(([machines, config]) => Promise.all( + [machines, notifier.checkPings(machines), dbm.machineEvents(), config] + )) + .then(([machines, pings, events, config]) => { + const getPingStatus = (ping) => { + if (!ping) return fullyFunctionalStatus + + if (ping.age) return unresponsiveStatus + + return fullyFunctionalStatus + } + + const getStuckStatus = (stuck) => { + if (!stuck || !stuck.age) return undefined + + return stuckStatus + } + const addName = r => { const cashOutConfig = configManager.getCashOut(r.deviceId, config) const cashOut = !!cashOutConfig.active - // TODO new-admin actually load status based on ping. - const statuses = [{label: 'Unknown detailed status', type: 'warning'}] + const ping = getPingStatus(_.first(pings[r.deviceId])) + const stuck = getStuckStatus(_.first(notifier.checkStuckScreen(events, r.name))) + + const statuses = [ping] + + if (stuck) statuses.push(stuck) return _.assign(r, {cashOut, statuses}) } diff --git a/lib/notifier.js b/lib/notifier.js index 5413062f..96941bea 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -344,4 +344,8 @@ function buildAlertFingerprint (alertRec, notifications) { return crypto.createHash('sha256').update(subject).digest('hex') } -module.exports = { checkNotification } +module.exports = { + checkNotification, + checkPings, + checkStuckScreen +} diff --git a/new-lamassu-admin/src/components/ConfirmDialog.js b/new-lamassu-admin/src/components/ConfirmDialog.js index da195f55..e24a330e 100644 --- a/new-lamassu-admin/src/components/ConfirmDialog.js +++ b/new-lamassu-admin/src/components/ConfirmDialog.js @@ -2,51 +2,50 @@ import { Dialog, DialogActions, DialogContent, - DialogContentText, makeStyles } from '@material-ui/core' -import React, { useEffect, useState, memo } from 'react' +import React, { memo, useState } from 'react' import { Button, IconButton } from 'src/components/buttons' +import { TextInput } from 'src/components/inputs' +import { H4 } from 'src/components/typography' import { ReactComponent as CloseIcon } from 'src/styling/icons/action/close/zodiac.svg' -import { fontSize3 } from 'src/styling/variables' +import { spacer } from 'src/styling/variables' -import { TextInput } from './inputs' -import { H4, P } from './typography' +import ErrorMessage from './ErrorMessage' const useStyles = makeStyles({ - label: { - fontSize: fontSize3 + dialogContent: { + width: 434, + padding: spacer * 2, + paddingRight: spacer * 3.5 }, - spacing: { - padding: 32 + dialogTitle: { + padding: spacer * 2, + paddingRight: spacer * 1.5, + display: 'flex', + 'justify-content': 'space-between', + '& > h4': { + margin: 0 + }, + '& > button': { + padding: 0, + marginTop: -(spacer / 2) + } }, - wrapper: { - display: 'flex' - }, - title: { - margin: [[20, 0, 24, 16]] - }, - closeButton: { - padding: 0, - margin: [[12, 12, 'auto', 'auto']] - // position: 'absolute', - // right: spacer, - // top: spacer + dialogActions: { + padding: spacer * 4, + paddingTop: spacer * 2 } }) export const DialogTitle = ({ children, onClose }) => { const classes = useStyles() return ( -
+
{children} {onClose && ( - + )} @@ -57,50 +56,59 @@ export const DialogTitle = ({ children, onClose }) => { export const ConfirmDialog = memo( ({ title = 'Confirm action', - subtitle = 'This action requires confirmation', + errorMessage = 'This action requires confirmation', open, toBeConfirmed, onConfirmed, onDissmised, - className, ...props }) => { const classes = useStyles() const [value, setValue] = useState('') const [error, setError] = useState(false) - useEffect(() => setValue(''), [open]) - const handleChange = event => { - setValue(event.target.value) + const handleChange = event => setValue(event.target.value) + + const innerOnClose = () => { + setValue('') + setError(false) + onDissmised() } return ( - -

{title}

- {subtitle && ( - -

{subtitle}

-
- )} + +

{title}

- + {errorMessage && ( + + + {errorMessage.split(':').map(error => ( + <> + {error} +
+ + ))} +
+
+ )} + setError(toBeConfirmed !== value)} /> - +