aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshutosh Bishnoi <mail2bishnoi@gmail.com>2020-12-16 15:13:08 +0530
committerAshutosh Bishnoi <mail2bishnoi@gmail.com>2020-12-16 15:13:08 +0530
commit2ea3cf62d8649588094b820652de017d5baae888 (patch)
treeede75b5d1cb8c6a5ee43176deb16cc4d77d60d86
parentfca5aa3cdb5d335dca14115722cacae1b724fe4f (diff)
downloadtrackermap-web-2ea3cf62d8649588094b820652de017d5baae888.tar.gz
trackermap-web-2ea3cf62d8649588094b820652de017d5baae888.tar.bz2
trackermap-web-2ea3cf62d8649588094b820652de017d5baae888.zip
Driver Implementations
-rw-r--r--modern/src/App.js4
-rw-r--r--modern/src/MainToolbar.js6
-rw-r--r--modern/src/settings/DriverPage.js65
-rw-r--r--modern/src/settings/DriversPage.js65
4 files changed, 140 insertions, 0 deletions
diff --git a/modern/src/App.js b/modern/src/App.js
index 83fd9315..94f1ed72 100644
--- a/modern/src/App.js
+++ b/modern/src/App.js
@@ -22,6 +22,8 @@ import TripReportPage from './reports/TripReportPage';
import StopReportPage from './reports/StopReportPage';
import SummaryReportPage from './reports/SummaryReportPage';
import ChartReportPage from './reports/ChartReportPage';
+import DriversPage from './settings/DriversPage';
+import DriverPage from './settings/DriverPage';
const App = () => {
const initialized = useSelector(state => !!state.session.server && !!state.session.user);
@@ -52,6 +54,8 @@ const App = () => {
<Route exact path='/reports/stop' component={StopReportPage} />
<Route exact path='/reports/summary' component={SummaryReportPage} />
<Route exact path='/reports/chart' component={ChartReportPage} />
+ <Route exact path='/settings/drivers' component={DriversPage} />
+ <Route exact path='/settings/driver/:id?' component={DriverPage} />
</Switch>
)}
</Route>
diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js
index 930e66a0..6e2981f2 100644
--- a/modern/src/MainToolbar.js
+++ b/modern/src/MainToolbar.js
@@ -173,6 +173,12 @@ const MainToolbar = () => {
</ListItemIcon>
<ListItemText primary={t('settingsGroups')} />
</ListItem>
+ <ListItem button onClick={() => history.push('/settings/drivers')}>
+ <ListItemIcon>
+ <PersonIcon />
+ </ListItemIcon>
+ <ListItemText primary={t('sharedDrivers')} />
+ </ListItem>
</List>
{adminEnabled && (
<>
diff --git a/modern/src/settings/DriverPage.js b/modern/src/settings/DriverPage.js
new file mode 100644
index 00000000..86feab84
--- /dev/null
+++ b/modern/src/settings/DriverPage.js
@@ -0,0 +1,65 @@
+import React, { useState } from 'react';
+import TextField from '@material-ui/core/TextField';
+import t from '../common/localization';
+import EditItemView from '../EditItemView';
+import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography } from '@material-ui/core';
+import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
+import EditAttributesView from '../attributes/EditAttributesView';
+
+const useStyles = makeStyles(() => ({
+ details: {
+ flexDirection: 'column',
+ },
+}));
+
+const DriverPage = () => {
+ const classes = useStyles();
+
+ const [item, setItem] = useState();
+
+ return (
+ <EditItemView endpoint="drivers" item={item} setItem={setItem}>
+ {item &&
+ <>
+ <Accordion defaultExpanded>
+ <AccordionSummary expandIcon={<ExpandMoreIcon />}>
+ <Typography variant="subtitle1">
+ {t('sharedRequired')}
+ </Typography>
+ </AccordionSummary>
+ <AccordionDetails className={classes.details}>
+ <TextField
+ margin="normal"
+ value={item.name || ''}
+ onChange={event => setItem({...item, name: event.target.value})}
+ label={t('sharedName')}
+ variant="filled" />
+ <TextField
+ margin="normal"
+ value={item.uniqueId || ''}
+ onChange={event => setItem({...item, uniqueId: event.target.value})}
+ label={t('deviceIdentifier')}
+ variant="filled" />
+ </AccordionDetails>
+ </Accordion>
+ <Accordion>
+ <AccordionSummary expandIcon={<ExpandMoreIcon />}>
+ <Typography variant="subtitle1">
+ {t('sharedAttributes')}
+ </Typography>
+ </AccordionSummary>
+ <AccordionDetails className={classes.details}>
+ <EditAttributesView
+ attributes={item.attributes}
+ setAttributes={attributes => setItem({...item, attributes})}
+ definitions={{}}
+ />
+ </AccordionDetails>
+ </Accordion>
+ </>
+ }
+ </EditItemView>
+ );
+}
+
+export default DriverPage;
diff --git a/modern/src/settings/DriversPage.js b/modern/src/settings/DriversPage.js
new file mode 100644
index 00000000..957e2250
--- /dev/null
+++ b/modern/src/settings/DriversPage.js
@@ -0,0 +1,65 @@
+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';
+
+const useStyles = makeStyles(theme => ({
+ columnAction: {
+ width: theme.spacing(1),
+ padding: theme.spacing(0, 1),
+ },
+}));
+
+const DriversView = ({ updateTimestamp, onMenuClick }) => {
+ const classes = useStyles();
+
+ const [items, setItems] = useState([]);
+
+ useEffectAsync(async () => {
+ const response = await fetch('/api/drivers');
+ if (response.ok) {
+ setItems(await response.json());
+ }
+ }, [updateTimestamp]);
+
+ return (
+ <TableContainer>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.columnAction} />
+ <TableCell>{t('sharedName')}</TableCell>
+ <TableCell>{t('deviceIdentifier')}</TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {items.map((item) => (
+ <TableRow key={item.id}>
+ <TableCell className={classes.columnAction} padding="none">
+ <IconButton onClick={(event) => onMenuClick(event.currentTarget, item.id)}>
+ <MoreVertIcon />
+ </IconButton>
+ </TableCell>
+ <TableCell>{item.name}</TableCell>
+ <TableCell>{item.uniqueId}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </TableContainer>
+ );
+}
+
+const DriversPage = () => {
+ return (
+ <>
+ <MainToolbar />
+ <EditCollectionView content={DriversView} editPath="/settings/driver" endpoint="drivers" />
+ </>
+ );
+}
+
+export default DriversPage;