From 236b10503612706ed914678d942ac604f2973f47 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 27 Sep 2020 21:54:39 -0700 Subject: Implement notification settings --- modern/src/settings/NotificationPage.js | 109 +++++++++++++++++++++++++++++++ modern/src/settings/NotificationsPage.js | 82 +++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 modern/src/settings/NotificationPage.js create mode 100644 modern/src/settings/NotificationsPage.js (limited to 'modern/src/settings') diff --git a/modern/src/settings/NotificationPage.js b/modern/src/settings/NotificationPage.js new file mode 100644 index 0000000..f09f3fe --- /dev/null +++ b/modern/src/settings/NotificationPage.js @@ -0,0 +1,109 @@ +import React, { useState } from 'react'; +import TextField from '@material-ui/core/TextField'; + +import t, { findStringKeys } from '../common/localization'; +import EditItemView from '../EditItemView'; +import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, FormControlLabel, Checkbox, FormControl, InputLabel, Select, MenuItem } from '@material-ui/core'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import { useEffectAsync } from '../reactHelper'; +import { prefixString, unprefixString } from '../common/stringUtils'; + +const useStyles = makeStyles(() => ({ + details: { + flexDirection: 'column', + }, +})); + +const NotificationPage = () => { + const classes = useStyles(); + + const [item, setItem] = useState(); + const [types, setTypes] = useState(); + const [notificators, setNotificators] = useState(); + + const alarms = findStringKeys(it => it.startsWith('alarm')).map(it => ({ + key: unprefixString('alarm', it), + name: t(it), + })); + + useEffectAsync(async () => { + const response = await fetch('/api/notifications/types'); + if (response.ok) { + setTypes(await response.json()); + } + }, []); + + useEffectAsync(async () => { + const response = await fetch('/api/notifications/notificators'); + if (response.ok) { + setNotificators(await response.json()); + } + }, []); + + return ( + + {item && + <> + + }> + + {t('sharedRequired')} + + + + {types && + + {t('sharedType')} + + + } + {notificators && + + {t('notificationNotificators')} + + + } + {item.type === 'alarm' && + + {t('sharedAlarms')} + + + } + setItem({...item, always: event.target.checked})} + /> + } + label={t('notificationAlways')} /> + + + + } + + ); +} + +export default NotificationPage; diff --git a/modern/src/settings/NotificationsPage.js b/modern/src/settings/NotificationsPage.js new file mode 100644 index 0000000..15da0de --- /dev/null +++ b/modern/src/settings/NotificationsPage.js @@ -0,0 +1,82 @@ +import React, { useState } from 'react'; +import MainToolbar from '../MainToolbar'; +import { TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton } from '@material-ui/core'; +import MoreVertIcon from '@material-ui/icons/MoreVert'; +import t from '../common/localization'; +import { useEffectAsync } from '../reactHelper'; +import EditCollectionView from '../EditCollectionView'; +import { prefixString } from '../common/stringUtils'; +import { formatBoolean } from '../common/formatter'; + +const useStyles = makeStyles(theme => ({ + columnAction: { + width: theme.spacing(1), + padding: theme.spacing(0, 1), + }, +})); + +const NotificationsView = ({ updateTimestamp, onMenuClick }) => { + const classes = useStyles(); + + const [items, setItems] = useState([]); + + useEffectAsync(async () => { + const response = await fetch('/api/notifications'); + if (response.ok) { + setItems(await response.json()); + } + }, [updateTimestamp]); + + const formatList = (prefix, value) => { + if (value) { + return value + .split(/[, ]+/) + .filter(Boolean) + .map(it => t(prefixString(prefix, it))) + .join(', '); + } + return ''; + }; + + return ( + + + + + + {t('notificationType')} + {t('notificationAlways')} + {t('sharedAlarms')} + {t('notificationNotificators')} + + + + {items.map(item => ( + + + onMenuClick(event.currentTarget, item.id)}> + + + + {t(prefixString('event', item.type))} + {formatBoolean(item.always)} + {formatList('alarm', item.attributes.alarms)} + {formatList('notificator', item.notificators)} + + ))} + +
+
+ ); +} + +const NotificationsPage = () => { + return ( + <> + + + + ); +} + +export default NotificationsPage; -- cgit v1.2.3