aboutsummaryrefslogtreecommitdiff
path: root/modern/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-09-07 23:23:37 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-09-07 23:23:37 -0700
commit514843d04a1253f583612797a1947790c43717c3 (patch)
treeda935f2250766147561b7a5954b58486b78ec64e /modern/src
parentc9ae8f34bbdb75e95500ac8a2736d8eb9b4304d4 (diff)
downloadetbsa-traccar-web-514843d04a1253f583612797a1947790c43717c3.tar.gz
etbsa-traccar-web-514843d04a1253f583612797a1947790c43717c3.tar.bz2
etbsa-traccar-web-514843d04a1253f583612797a1947790c43717c3.zip
Add calendar menu
Diffstat (limited to 'modern/src')
-rw-r--r--modern/src/App.js4
-rw-r--r--modern/src/settings/CalendarPage.js64
-rw-r--r--modern/src/settings/CalendarsPage.js63
-rw-r--r--modern/src/settings/OptionsLayout/useRoutes.js7
4 files changed, 138 insertions, 0 deletions
diff --git a/modern/src/App.js b/modern/src/App.js
index eb1a881..a53ffc6 100644
--- a/modern/src/App.js
+++ b/modern/src/App.js
@@ -24,6 +24,8 @@ import SummaryReportPage from './reports/SummaryReportPage';
import ChartReportPage from './reports/ChartReportPage';
import DriversPage from './settings/DriversPage';
import DriverPage from './settings/DriverPage';
+import CalendarsPage from './settings/CalendarsPage';
+import CalendarPage from './settings/CalendarPage';
import ComputedAttributesPage from './settings/ComputedAttributesPage';
import ComputedAttributePage from './settings/ComputedAttributePage';
import MaintenancesPage from './settings/MaintenancesPage';
@@ -69,6 +71,8 @@ const App = () => {
<Route exact path="/settings/group/:id?" component={GroupPage} />
<Route exact path="/settings/drivers" component={DriversPage} />
<Route exact path="/settings/driver/:id?" component={DriverPage} />
+ <Route exact path="/settings/calendars" component={CalendarsPage} />
+ <Route exact path="/settings/calendar/:id?" component={CalendarPage} />
<Route exact path="/settings/attributes" component={ComputedAttributesPage} />
<Route exact path="/settings/attribute/:id?" component={ComputedAttributePage} />
<Route exact path="/settings/maintenances" component={MaintenancesPage} />
diff --git a/modern/src/settings/CalendarPage.js b/modern/src/settings/CalendarPage.js
new file mode 100644
index 0000000..de714c3
--- /dev/null
+++ b/modern/src/settings/CalendarPage.js
@@ -0,0 +1,64 @@
+import React, { useState } from 'react';
+import TextField from '@material-ui/core/TextField';
+import {
+ Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography,
+} from '@material-ui/core';
+import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
+import EditItemView from '../EditItemView';
+import EditAttributesView from '../attributes/EditAttributesView';
+import { useTranslation } from '../LocalizationProvider';
+
+const useStyles = makeStyles(() => ({
+ details: {
+ flexDirection: 'column',
+ },
+}));
+
+const CalendarPage = () => {
+ const classes = useStyles();
+ const t = useTranslation();
+
+ const [item, setItem] = useState();
+
+ return (
+ <EditItemView endpoint="calendars" 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"
+ />
+ </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 CalendarPage;
diff --git a/modern/src/settings/CalendarsPage.js b/modern/src/settings/CalendarsPage.js
new file mode 100644
index 0000000..076f30c
--- /dev/null
+++ b/modern/src/settings/CalendarsPage.js
@@ -0,0 +1,63 @@
+import React, { useState } from 'react';
+import {
+ TableContainer, Table, TableRow, TableCell, TableHead, TableBody, makeStyles, IconButton,
+} from '@material-ui/core';
+import MoreVertIcon from '@material-ui/icons/MoreVert';
+import { useEffectAsync } from '../reactHelper';
+import EditCollectionView from '../EditCollectionView';
+import OptionsLayout from './OptionsLayout';
+import { useTranslation } from '../LocalizationProvider';
+
+const useStyles = makeStyles((theme) => ({
+ columnAction: {
+ width: theme.spacing(1),
+ padding: theme.spacing(0, 1),
+ },
+}));
+
+const CalendarsView = ({ updateTimestamp, onMenuClick }) => {
+ const classes = useStyles();
+ const t = useTranslation();
+
+ const [items, setItems] = useState([]);
+
+ useEffectAsync(async () => {
+ const response = await fetch('/api/calendars');
+ if (response.ok) {
+ setItems(await response.json());
+ }
+ }, [updateTimestamp]);
+
+ return (
+ <TableContainer>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.columnAction} />
+ <TableCell>{t('sharedName')}</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>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </TableContainer>
+ );
+};
+
+const CalendarsPage = () => (
+ <OptionsLayout>
+ <EditCollectionView content={CalendarsView} editPath="/settings/calendar" endpoint="calendars" />
+ </OptionsLayout>
+);
+
+export default CalendarsPage;
diff --git a/modern/src/settings/OptionsLayout/useRoutes.js b/modern/src/settings/OptionsLayout/useRoutes.js
index 8be4ec3..efbd9eb 100644
--- a/modern/src/settings/OptionsLayout/useRoutes.js
+++ b/modern/src/settings/OptionsLayout/useRoutes.js
@@ -8,6 +8,7 @@ import StorageIcon from '@material-ui/icons/Storage';
import BuildIcon from '@material-ui/icons/Build';
import PeopleIcon from '@material-ui/icons/People';
import BarChartIcon from '@material-ui/icons/BarChart';
+import TodayIcon from '@material-ui/icons/Today';
import { getIsAdmin, getUserId } from '../../common/selectors';
import { useTranslation } from '../../LocalizationProvider';
@@ -61,6 +62,12 @@ const useMainRoutes = (t, userId) => useMemo(() => [
icon: <PersonIcon />,
},
{
+ match: 'calendar',
+ name: t('sharedCalendars'),
+ href: '/settings/calendars',
+ icon: <TodayIcon />,
+ },
+ {
match: 'attribute',
name: t('sharedComputedAttributes'),
href: '/settings/attributes',