aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modern/src/App.js2
-rw-r--r--modern/src/MainToolbar.js2
-rw-r--r--modern/src/admin/StatisticsPage.js138
3 files changed, 141 insertions, 1 deletions
diff --git a/modern/src/App.js b/modern/src/App.js
index db2f7a9c..a01451b4 100644
--- a/modern/src/App.js
+++ b/modern/src/App.js
@@ -28,6 +28,7 @@ import ComputedAttributesPage from './settings/ComputedAttributesPage';
import ComputedAttributePage from './settings/ComputedAttributePage';
import MaintenancesPage from './settings/MaintenancesPage';
import MaintenancePage from './settings/MaintenancePage';
+import StatisticsPage from './admin/StatisticsPage';
const App = () => {
const initialized = useSelector(state => !!state.session.server && !!state.session.user);
@@ -58,6 +59,7 @@ const App = () => {
<Route exact path='/settings/maintenance/:id?' component={MaintenancePage} />
<Route exact path='/admin/server' component={ServerPage} />
<Route exact path='/admin/users' component={UsersPage} />
+ <Route exact path='/admin/statistics' component={StatisticsPage} />
<Route exact path='/reports/route' component={RouteReportPage} />
<Route exact path='/reports/event' component={EventReportPage} />
<Route exact path='/reports/trip' component={TripReportPage} />
diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js
index ebe2efd5..702a7e50 100644
--- a/modern/src/MainToolbar.js
+++ b/modern/src/MainToolbar.js
@@ -214,7 +214,7 @@ const MainToolbar = () => {
</ListItemIcon>
<ListItemText primary={t('settingsUsers')} />
</ListItem>
- <ListItem button disabled>
+ <ListItem button onClick={() => history.push('/admin/statistics')}>
<ListItemIcon>
<BarChartIcon />
</ListItemIcon>
diff --git a/modern/src/admin/StatisticsPage.js b/modern/src/admin/StatisticsPage.js
new file mode 100644
index 00000000..1e440a46
--- /dev/null
+++ b/modern/src/admin/StatisticsPage.js
@@ -0,0 +1,138 @@
+
+import React, { useState } from 'react';
+import { FormControl, InputLabel,Select, MenuItem, TextField, Button, TableContainer, Table, TableRow, TableCell, TableHead, TableBody, Paper } from '@material-ui/core';
+import t from '../common/localization';
+import { formatDate } from '../common/formatter';
+import ReportLayoutPage from '../reports/ReportLayoutPage';
+import moment from 'moment';
+
+const Filter = ({ setItems }) => {
+ const [period, setPeriod] = useState('today');
+ const [from, setFrom] = useState(moment().subtract(1, 'hour'));
+ const [to, setTo] = useState(moment());
+
+ const handleClick = async () => {
+ let selectedFrom;
+ let selectedTo;
+ switch (period) {
+ case 'today':
+ selectedFrom = moment().startOf('day');
+ selectedTo = moment().endOf('day');
+ break;
+ case 'yesterday':
+ selectedFrom = moment().subtract(1, 'day').startOf('day');
+ selectedTo = moment().subtract(1, 'day').endOf('day');
+ break;
+ case 'thisWeek':
+ selectedFrom = moment().startOf('week');
+ selectedTo = moment().endOf('week');
+ break;
+ case 'previousWeek':
+ selectedFrom = moment().subtract(1, 'week').startOf('week');
+ selectedTo = moment().subtract(1, 'week').endOf('week');
+ break;
+ case 'thisMonth':
+ selectedFrom = moment().startOf('month');
+ selectedTo = moment().endOf('month');
+ break;
+ case 'previousMonth':
+ selectedFrom = moment().subtract(1, 'month').startOf('month');
+ selectedTo = moment().subtract(1, 'month').endOf('month');
+ break;
+ default:
+ selectedFrom = from;
+ selectedTo = to;
+ break;
+ }
+
+ const query = new URLSearchParams({ from: selectedFrom.toISOString(), to: selectedTo.toISOString() });
+ const response = await fetch(`/api/statistics?${query.toString()}`, { Accept: 'application/json' });
+ if (response.ok) {
+ setItems(await response.json());
+ }
+ }
+
+ return (
+ <>
+ <FormControl variant="filled" margin="normal" fullWidth>
+ <InputLabel>{t('reportPeriod')}</InputLabel>
+ <Select value={period} onChange={(e) => setPeriod(e.target.value)}>
+ <MenuItem value="today">{t('reportToday')}</MenuItem>
+ <MenuItem value="yesterday">{t('reportYesterday')}</MenuItem>
+ <MenuItem value="thisWeek">{t('reportThisWeek')}</MenuItem>
+ <MenuItem value="previousWeek">{t('reportPreviousWeek')}</MenuItem>
+ <MenuItem value="thisMonth">{t('reportThisMonth')}</MenuItem>
+ <MenuItem value="previousMonth">{t('reportPreviousMonth')}</MenuItem>
+ <MenuItem value="custom">{t('reportCustom')}</MenuItem>
+ </Select>
+ </FormControl>
+ {period === 'custom' && (
+ <TextField
+ margin="normal"
+ variant="filled"
+ label={t('reportFrom')}
+ type="datetime-local"
+ value={from.format(moment.HTML5_FMT.DATETIME_LOCAL)}
+ onChange={e => setFrom(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))}
+ fullWidth />
+ )}
+ {period === 'custom' && (
+ <TextField
+ margin="normal"
+ variant="filled"
+ label={t('reportTo')}
+ type="datetime-local"
+ value={to.format(moment.HTML5_FMT.DATETIME_LOCAL)}
+ onChange={e => setTo(moment(e.target.value, moment.HTML5_FMT.DATETIME_LOCAL))}
+ fullWidth />
+ )}
+ <Button variant="contained" color="primary" onClick={handleClick} fullWidth>{t('reportShow')}</Button>
+ </>
+ )
+}
+
+const StatisticsPage = () => {
+
+ const [items, setItems] = useState([]);
+
+ return (
+ <ReportLayoutPage filter={<Filter setItems={setItems} />}>
+ <TableContainer component={Paper}>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>{t('statisticsCaptureTime')}</TableCell>
+ <TableCell>{t('statisticsActiveUsers')}</TableCell>
+ <TableCell>{t('statisticsActiveDevices')}</TableCell>
+ <TableCell>{t('statisticsRequests')}</TableCell>
+ <TableCell>{t('statisticsMessagesReceived')}</TableCell>
+ <TableCell>{t('statisticsMessagesStored')}</TableCell>
+ <TableCell>{t('notificatorMail')}</TableCell>
+ <TableCell>{t('notificatorSms')}</TableCell>
+ <TableCell>{t('statisticsGeocoder')}</TableCell>
+ <TableCell>{t('statisticsGeolocation')}</TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {items.map((item) => (
+ <TableRow key={item.id}>
+ <TableCell>{formatDate(item.captureTime)}</TableCell>
+ <TableCell>{item.activeUsers}</TableCell>
+ <TableCell>{item.activeDevices}</TableCell>
+ <TableCell>{item.requests}</TableCell>
+ <TableCell>{item.messagesReceived}</TableCell>
+ <TableCell>{item.messagesStored}</TableCell>
+ <TableCell>{item.mailSent}</TableCell>
+ <TableCell>{item.smsSent}</TableCell>
+ <TableCell>{item.geocoderRequests}</TableCell>
+ <TableCell>{item.geolocationRequests}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </TableContainer>
+ </ReportLayoutPage>
+ );
+}
+
+export default StatisticsPage;