diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-03 16:22:21 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-03 16:22:21 -0700 |
commit | b418d001a498b5a5108bb13983b4f3aba6c60dbc (patch) | |
tree | 464dd5e4fc3f13a6209c05df4d3db3cbbe8e85d6 /modern | |
parent | 5d17af8102f17d41610acb9ff34aabbff871cda1 (diff) | |
download | trackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.tar.gz trackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.tar.bz2 trackermap-web-b418d001a498b5a5108bb13983b4f3aba6c60dbc.zip |
Support feature disabling
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/common/attributes/useCommonUserAttributes.js | 24 | ||||
-rw-r--r-- | modern/src/common/util/useFeatures.js | 30 | ||||
-rw-r--r-- | modern/src/settings/DevicePage.js | 59 | ||||
-rw-r--r-- | modern/src/settings/GroupPage.js | 59 | ||||
-rw-r--r-- | modern/src/settings/components/SettingsMenu.js | 59 |
5 files changed, 145 insertions, 86 deletions
diff --git a/modern/src/common/attributes/useCommonUserAttributes.js b/modern/src/common/attributes/useCommonUserAttributes.js index fa6d7d8f..c17b5c5d 100644 --- a/modern/src/common/attributes/useCommonUserAttributes.js +++ b/modern/src/common/attributes/useCommonUserAttributes.js @@ -5,18 +5,6 @@ export default (t) => useMemo(() => ({ name: t('attributeNotificationTokens'), type: 'string', }, - /* 'web.liveRouteLength': { - name: t('attributeWebLiveRouteLength'), - type: 'number', - }, - 'web.selectZoom': { - name: t('attributeWebSelectZoom'), - type: 'number', - }, - 'web.maxZoom': { - name: t('attributeWebMaxZoom'), - type: 'number', - }, 'ui.disableEvents': { name: t('attributeUiDisableEvents'), type: 'boolean', @@ -41,6 +29,18 @@ export default (t) => useMemo(() => ({ name: t('attributeUiDisableMaintenance'), type: 'boolean', }, + /* 'web.liveRouteLength': { + name: t('attributeWebLiveRouteLength'), + type: 'number', + }, + 'web.selectZoom': { + name: t('attributeWebSelectZoom'), + type: 'number', + }, + 'web.maxZoom': { + name: t('attributeWebMaxZoom'), + type: 'number', + }, 'ui.hidePositionAttributes': { name: t('attributeUiHidePositionAttributes'), type: 'string', diff --git a/modern/src/common/util/useFeatures.js b/modern/src/common/util/useFeatures.js new file mode 100644 index 00000000..f0a8299a --- /dev/null +++ b/modern/src/common/util/useFeatures.js @@ -0,0 +1,30 @@ +import { useSelector } from 'react-redux'; + +const get = (server, user, key) => { + if (server && user) { + if (server.forceSettings) { + return server.attributes[key] || user.attributes[key] || false; + } + return user.attributes[key] || server.attributes[key] || false; + } + return false; +}; + +export default () => useSelector((state) => { + const { server, user } = state.session; + + const disableVehicleFetures = get(server, user, 'ui.disableVehicleFetures'); + const disableDrivers = disableVehicleFetures || get(server, user, 'ui.disableDrivers'); + const disableMaintenance = disableVehicleFetures || get(server, user, 'ui.disableMaintenance'); + const disableEvents = get(server, user, 'ui.disableEvents'); + const disableComputedAttributes = get(server, user, 'ui.disableComputedAttributes'); + const disableCalendars = get(server, user, 'ui.disableCalendars'); + + return { + disableDrivers, + disableMaintenance, + disableEvents, + disableComputedAttributes, + disableCalendars, + }; +}); diff --git a/modern/src/settings/DevicePage.js b/modern/src/settings/DevicePage.js index d7b67b0b..fb49dbcc 100644 --- a/modern/src/settings/DevicePage.js +++ b/modern/src/settings/DevicePage.js @@ -22,6 +22,7 @@ import useDeviceAttributes from '../common/attributes/useDeviceAttributes'; import { useAdministrator } from '../common/util/permissions'; import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; +import useFeatures from '../common/util/useFeatures'; const useStyles = makeStyles((theme) => ({ details: { @@ -41,6 +42,8 @@ const DevicePage = () => { const commonDeviceAttributes = useCommonDeviceAttributes(t); const deviceAttributes = useDeviceAttributes(t); + const features = useFeatures(); + const [item, setItem] = useState(); const validate = () => item && item.name && item.uniqueId; @@ -160,23 +163,27 @@ const DevicePage = () => { titleGetter={(it) => t(prefixString('event', it.type))} label={t('sharedNotifications')} /> - <LinkField - endpointAll="/api/drivers" - endpointLinked={`/api/drivers?deviceId=${item.id}`} - baseId={item.id} - keyBase="deviceId" - keyLink="driverId" - label={t('sharedDrivers')} - /> - <LinkField - endpointAll="/api/attributes/computed" - endpointLinked={`/api/attributes/computed?deviceId=${item.id}`} - baseId={item.id} - keyBase="deviceId" - keyLink="attributeId" - titleGetter={(it) => it.description} - label={t('sharedComputedAttributes')} - /> + {!features.disableDrivers && ( + <LinkField + endpointAll="/api/drivers" + endpointLinked={`/api/drivers?deviceId=${item.id}`} + baseId={item.id} + keyBase="deviceId" + keyLink="driverId" + label={t('sharedDrivers')} + /> + )} + {!features.disableComputedAttributes && ( + <LinkField + endpointAll="/api/attributes/computed" + endpointLinked={`/api/attributes/computed?deviceId=${item.id}`} + baseId={item.id} + keyBase="deviceId" + keyLink="attributeId" + titleGetter={(it) => it.description} + label={t('sharedComputedAttributes')} + /> + )} <LinkField endpointAll="/api/commands" endpointLinked={`/api/commands?deviceId=${item.id}`} @@ -186,14 +193,16 @@ const DevicePage = () => { titleGetter={(it) => it.description} label={t('sharedSavedCommands')} /> - <LinkField - endpointAll="/api/maintenance" - endpointLinked={`/api/maintenance?deviceId=${item.id}`} - baseId={item.id} - keyBase="deviceId" - keyLink="maintenanceId" - label={t('sharedMaintenance')} - /> + {!features.disableMaintenance && ( + <LinkField + endpointAll="/api/maintenance" + endpointLinked={`/api/maintenance?deviceId=${item.id}`} + baseId={item.id} + keyBase="deviceId" + keyLink="maintenanceId" + label={t('sharedMaintenance')} + /> + )} </AccordionDetails> </Accordion> )} diff --git a/modern/src/settings/GroupPage.js b/modern/src/settings/GroupPage.js index b817ba7e..c4c0fa5c 100644 --- a/modern/src/settings/GroupPage.js +++ b/modern/src/settings/GroupPage.js @@ -15,6 +15,7 @@ import SettingsMenu from './components/SettingsMenu'; import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes'; import useGroupAttributes from '../common/attributes/useGroupAttributes'; import { prefixString } from '../common/util/stringUtils'; +import useFeatures from '../common/util/useFeatures'; const useStyles = makeStyles((theme) => ({ details: { @@ -32,6 +33,8 @@ const GroupPage = () => { const commonDeviceAttributes = useCommonDeviceAttributes(t); const groupAttributes = useGroupAttributes(t); + const features = useFeatures(); + const [item, setItem] = useState(); const validate = () => item && item.name; @@ -115,23 +118,27 @@ const GroupPage = () => { titleGetter={(it) => t(prefixString('event', it.type))} label={t('sharedNotifications')} /> - <LinkField - endpointAll="/api/drivers" - endpointLinked={`/api/drivers?groupId=${item.id}`} - baseId={item.id} - keyBase="groupId" - keyLink="driverId" - label={t('sharedDrivers')} - /> - <LinkField - endpointAll="/api/attributes/computed" - endpointLinked={`/api/attributes/computed?groupId=${item.id}`} - baseId={item.id} - keyBase="groupId" - keyLink="attributeId" - titleGetter={(it) => it.description} - label={t('sharedComputedAttributes')} - /> + {!features.disableDrivers && ( + <LinkField + endpointAll="/api/drivers" + endpointLinked={`/api/drivers?groupId=${item.id}`} + baseId={item.id} + keyBase="groupId" + keyLink="driverId" + label={t('sharedDrivers')} + /> + )} + {!features.disableComputedAttributes && ( + <LinkField + endpointAll="/api/attributes/computed" + endpointLinked={`/api/attributes/computed?groupId=${item.id}`} + baseId={item.id} + keyBase="groupId" + keyLink="attributeId" + titleGetter={(it) => it.description} + label={t('sharedComputedAttributes')} + /> + )} <LinkField endpointAll="/api/commands" endpointLinked={`/api/commands?groupId=${item.id}`} @@ -141,14 +148,16 @@ const GroupPage = () => { titleGetter={(it) => it.description} label={t('sharedSavedCommands')} /> - <LinkField - endpointAll="/api/maintenance" - endpointLinked={`/api/maintenance?groupId=${item.id}`} - baseId={item.id} - keyBase="groupId" - keyLink="maintenanceId" - label={t('sharedMaintenance')} - /> + {!features.disableMaintenance && ( + <LinkField + endpointAll="/api/maintenance" + endpointLinked={`/api/maintenance?groupId=${item.id}`} + baseId={item.id} + keyBase="groupId" + keyLink="maintenanceId" + label={t('sharedMaintenance')} + /> + )} </AccordionDetails> </Accordion> )} diff --git a/modern/src/settings/components/SettingsMenu.js b/modern/src/settings/components/SettingsMenu.js index fae3ad86..ef5b07d7 100644 --- a/modern/src/settings/components/SettingsMenu.js +++ b/modern/src/settings/components/SettingsMenu.js @@ -16,6 +16,7 @@ import { Link, useLocation } from 'react-router-dom'; import { useSelector } from 'react-redux'; import { useTranslation } from '../../common/components/LocalizationProvider'; import { useAdministrator, useManager, useReadonly } from '../../common/util/permissions'; +import useFeatures from '../../common/util/useFeatures'; const MenuItem = ({ title, link, icon, selected, @@ -35,6 +36,8 @@ const SettingsMenu = () => { const manager = useManager(); const userId = useSelector((state) => state.session.user?.id); + const features = useFeatures(); + return ( <> <List> @@ -70,30 +73,38 @@ const SettingsMenu = () => { icon={<FolderIcon />} selected={location.pathname.startsWith('/settings/group')} /> - <MenuItem - title={t('sharedDrivers')} - link="/settings/drivers" - icon={<PersonIcon />} - selected={location.pathname.startsWith('/settings/driver')} - /> - <MenuItem - title={t('sharedCalendars')} - link="/settings/calendars" - icon={<TodayIcon />} - selected={location.pathname.startsWith('/settings/calendar')} - /> - <MenuItem - title={t('sharedComputedAttributes')} - link="/settings/attributes" - icon={<StorageIcon />} - selected={location.pathname.startsWith('/settings/attribute')} - /> - <MenuItem - title={t('sharedMaintenance')} - link="/settings/maintenances" - icon={<BuildIcon />} - selected={location.pathname.startsWith('/settings/maintenance')} - /> + {!features.disableDrivers && ( + <MenuItem + title={t('sharedDrivers')} + link="/settings/drivers" + icon={<PersonIcon />} + selected={location.pathname.startsWith('/settings/driver')} + /> + )} + {!features.disableCalendars && ( + <MenuItem + title={t('sharedCalendars')} + link="/settings/calendars" + icon={<TodayIcon />} + selected={location.pathname.startsWith('/settings/calendar')} + /> + )} + {!features.disableComputedAttributes && ( + <MenuItem + title={t('sharedComputedAttributes')} + link="/settings/attributes" + icon={<StorageIcon />} + selected={location.pathname.startsWith('/settings/attribute')} + /> + )} + {!features.disableMaintenance && ( + <MenuItem + title={t('sharedMaintenance')} + link="/settings/maintenances" + icon={<BuildIcon />} + selected={location.pathname.startsWith('/settings/maintenance')} + /> + )} <MenuItem title={t('sharedSavedCommands')} link="/settings/commands" |