1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
import React, { useState } from 'react';
import { useHistory } from 'react-router-dom';
import { makeStyles } from '@material-ui/core/styles';
import { useDispatch, useSelector } from 'react-redux';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import Button from '@material-ui/core/Button';
import IconButton from '@material-ui/core/IconButton';
import MenuIcon from '@material-ui/icons/Menu';
import Drawer from '@material-ui/core/Drawer';
import List from '@material-ui/core/List';
import ListSubheader from '@material-ui/core/ListSubheader';
import Divider from '@material-ui/core/Divider';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import MapIcon from '@material-ui/icons/Map';
import BarChartIcon from '@material-ui/icons/BarChart';
import PeopleIcon from '@material-ui/icons/People';
import StorageIcon from '@material-ui/icons/Storage';
import PersonIcon from '@material-ui/icons/Person';
import NotificationsIcon from '@material-ui/icons/Notifications';
import DescriptionIcon from '@material-ui/icons/Description';
import FolderIcon from '@material-ui/icons/Folder';
import CreateIcon from '@material-ui/icons/Create';
import ReplayIcon from '@material-ui/icons/Replay';
import BuildIcon from '@material-ui/icons/Build';
import { sessionActions } from './store';
import t from './common/localization';
const useStyles = makeStyles((theme) => ({
flex: {
flexGrow: 1,
},
appBar: {
zIndex: theme.zIndex.drawer + 1,
},
list: {
width: 250,
},
menuButton: {
marginLeft: -12,
marginRight: 20,
},
}));
const MainToolbar = () => {
const dispatch = useDispatch();
const [drawer, setDrawer] = useState(false);
const classes = useStyles();
const history = useHistory();
const adminEnabled = useSelector((state) => state.session.user && state.session.user.administrator);
const userId = useSelector((state) => state.session.user && state.session.user.id);
const openDrawer = () => { setDrawer(true); };
const closeDrawer = () => { setDrawer(false); };
const handleLogout = async () => {
const response = await fetch('/api/session', { method: 'DELETE' });
if (response.ok) {
dispatch(sessionActions.updateUser(null));
history.push('/login');
}
};
return (
<>
<AppBar position="static" className={classes.appBar}>
<Toolbar>
<IconButton
className={classes.menuButton}
color="inherit"
onClick={openDrawer}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" className={classes.flex}>
Traccar
</Typography>
<Button color="inherit" onClick={handleLogout}>{t('loginLogout')}</Button>
</Toolbar>
</AppBar>
<Drawer open={drawer} onClose={closeDrawer}>
<div
tabIndex={0}
className={classes.list}
role="button"
onClick={closeDrawer}
onKeyDown={closeDrawer}
>
<List>
<ListItem button onClick={() => history.push('/')}>
<ListItemIcon>
<MapIcon />
</ListItemIcon>
<ListItemText primary={t('mapTitle')} />
</ListItem>
<ListItem button onClick={() => history.push('/replay')}>
<ListItemIcon>
<ReplayIcon />
</ListItemIcon>
<ListItemText primary={t('reportReplay')} />
</ListItem>
<ListItem button onClick={() => history.push('/reports/route')}>
<ListItemIcon>
<DescriptionIcon />
</ListItemIcon>
<ListItemText primary={t('reportTitle')} />
</ListItem>
</List>
<Divider />
<List
subheader={(
<ListSubheader>
{t('settingsTitle')}
</ListSubheader>
)}
>
<ListItem button disabled={!userId} onClick={() => history.push(`/user/${userId}`)}>
<ListItemIcon>
<PersonIcon />
</ListItemIcon>
<ListItemText primary={t('settingsUser')} />
</ListItem>
<ListItem button onClick={() => history.push('/geofences')}>
<ListItemIcon>
<CreateIcon />
</ListItemIcon>
<ListItemText primary={t('sharedGeofences')} />
</ListItem>
<ListItem button onClick={() => history.push('/settings/notifications')}>
<ListItemIcon>
<NotificationsIcon />
</ListItemIcon>
<ListItemText primary={t('sharedNotifications')} />
</ListItem>
<ListItem button onClick={() => history.push('/settings/groups')}>
<ListItemIcon>
<FolderIcon />
</ListItemIcon>
<ListItemText primary={t('settingsGroups')} />
</ListItem>
<ListItem button onClick={() => history.push('/settings/drivers')}>
<ListItemIcon>
<PersonIcon />
</ListItemIcon>
<ListItemText primary={t('sharedDrivers')} />
</ListItem>
<ListItem button onClick={() => history.push('/settings/attributes')}>
<ListItemIcon>
<StorageIcon />
</ListItemIcon>
<ListItemText primary={t('sharedComputedAttributes')} />
</ListItem>
<ListItem button onClick={() => history.push('/settings/maintenances')}>
<ListItemIcon>
<BuildIcon />
</ListItemIcon>
<ListItemText primary={t('sharedMaintenance')} />
</ListItem>
</List>
{adminEnabled && (
<>
<Divider />
<List
subheader={(
<ListSubheader>
{t('userAdmin')}
</ListSubheader>
)}
>
<ListItem button onClick={() => history.push('/admin/server')}>
<ListItemIcon>
<StorageIcon />
</ListItemIcon>
<ListItemText primary={t('settingsServer')} />
</ListItem>
<ListItem button onClick={() => history.push('/admin/users')}>
<ListItemIcon>
<PeopleIcon />
</ListItemIcon>
<ListItemText primary={t('settingsUsers')} />
</ListItem>
<ListItem button onClick={() => history.push('/admin/statistics')}>
<ListItemIcon>
<BarChartIcon />
</ListItemIcon>
<ListItemText primary={t('statisticsTitle')} />
</ListItem>
</List>
</>
)}
</div>
</Drawer>
</>
);
};
export default MainToolbar;
|