From 4dbe654290c3d1f6051ea9650549f7c254d321b4 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Thu, 4 Feb 2021 16:33:02 +0530 Subject: Initial Maintenance Screen --- modern/src/App.js | 6 +- modern/src/MainToolbar.js | 7 +++ modern/src/settings/MaintenancePage.js | 97 +++++++++++++++++++++++++++++++++ modern/src/settings/MaintenancesPage.js | 69 +++++++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 modern/src/settings/MaintenancePage.js create mode 100644 modern/src/settings/MaintenancesPage.js diff --git a/modern/src/App.js b/modern/src/App.js index f5ebc148..db2f7a9c 100644 --- a/modern/src/App.js +++ b/modern/src/App.js @@ -26,6 +26,8 @@ import DriversPage from './settings/DriversPage'; import DriverPage from './settings/DriverPage'; import ComputedAttributesPage from './settings/ComputedAttributesPage'; import ComputedAttributePage from './settings/ComputedAttributePage'; +import MaintenancesPage from './settings/MaintenancesPage'; +import MaintenancePage from './settings/MaintenancePage'; const App = () => { const initialized = useSelector(state => !!state.session.server && !!state.session.user); @@ -51,7 +53,9 @@ const App = () => { - + + + diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 91b3d696..8f420e1c 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -30,6 +30,7 @@ import FormatListBulletedIcon from '@material-ui/icons/FormatListBulleted'; import TrendingUpIcon from '@material-ui/icons/TrendingUp'; import FolderIcon from '@material-ui/icons/Folder'; import ReplayIcon from '@material-ui/icons/Replay'; +import PublishIcon from '@material-ui/icons/Publish'; import t from './common/localization'; const useStyles = makeStyles(theme => ({ @@ -185,6 +186,12 @@ const MainToolbar = () => { + history.push('/settings/maintenances')}> + + + + + {adminEnabled && ( <> diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js new file mode 100644 index 00000000..8c4cdf40 --- /dev/null +++ b/modern/src/settings/MaintenancePage.js @@ -0,0 +1,97 @@ +import React, { useState } from 'react'; + +import t from '../common/localization'; +import EditItemView from '../EditItemView'; +import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, TextField, FormControl, InputLabel, MenuItem, Select, } from '@material-ui/core'; +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; +import EditAttributesView from '../attributes/EditAttributesView'; +import positionAttributes from '../attributes/positionAttributes'; + +const useStyles = makeStyles(() => ({ + details: { + flexDirection: 'column', + }, +})); + +const MaintenancePage = () => { + const classes = useStyles(); + + const [item, setItem] = useState(); + + const options = []; + + Object.entries(positionAttributes).map(([key, value]) => { + if (value.type === 'number') { + options.push({ key, name: value.name, type: value.type }) + } + }); + + const handleChange = event => { + const newValue = event.target.value; + setItem({...item, type: newValue}); + } + + return ( + + {item && + <> + + }> + + {t('sharedRequired')} + + + + setItem({...item, name: event.target.value})} + label={t('sharedName')} + variant="filled" /> + + {t('sharedType')} + + + setItem({...item, start: event.target.value})} + label={t('maintenanceStart')} + variant="filled" /> + setItem({...item, period: event.target.value})} + label={t('maintenancePeriod')} + variant="filled" /> + + + + }> + + {t('sharedAttributes')} + + + + setItem({...item, attributes})} + definitions={{}} + /> + + + + } + + ); +} + +export default MaintenancePage; diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js new file mode 100644 index 00000000..9cbf51a5 --- /dev/null +++ b/modern/src/settings/MaintenancesPage.js @@ -0,0 +1,69 @@ +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 MaintenancesView = ({ updateTimestamp, onMenuClick }) => { + const classes = useStyles(); + + const [items, setItems] = useState([]); + + useEffectAsync(async () => { + const response = await fetch('/api/maintenance'); + if (response.ok) { + setItems(await response.json()); + } + }, [updateTimestamp]); + + return ( + + + + + + {t('sharedName')} + {t('sharedType')} + {t('maintenanceStart')} + {t('maintenancePeriod')} + + + + {items.map(item => ( + + + onMenuClick(event.currentTarget, item.id)}> + + + + {item.name} + {item.type} + {item.start} + {item.period} + + ))} + +
+
+ ); +} + +const MaintenacesPage = () => { + return ( + <> + + + + ); +} + +export default MaintenacesPage; -- cgit v1.2.3 From 240518c0fc8b5237557affe8e28b9b94ef46a081 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Sat, 6 Feb 2021 17:35:34 +0530 Subject: Maintenance screen working --- modern/src/MainToolbar.js | 3 ++- modern/src/attributes/positionAttributes.js | 7 +++++- modern/src/common/converter.js | 18 ++++++++++++++ modern/src/settings/MaintenancePage.js | 37 ++++++++++++++++++++++++----- modern/src/settings/MaintenancesPage.js | 26 ++++++++++++++++++-- 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index 8f420e1c..cfbdab94 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -31,6 +31,7 @@ import TrendingUpIcon from '@material-ui/icons/TrendingUp'; import FolderIcon from '@material-ui/icons/Folder'; import ReplayIcon from '@material-ui/icons/Replay'; import PublishIcon from '@material-ui/icons/Publish'; +import BuildIcon from '@material-ui/icons/Build'; import t from './common/localization'; const useStyles = makeStyles(theme => ({ @@ -188,7 +189,7 @@ const MainToolbar = () => { history.push('/settings/maintenances')}> - + diff --git a/modern/src/attributes/positionAttributes.js b/modern/src/attributes/positionAttributes.js index 44926839..c5665da4 100644 --- a/modern/src/attributes/positionAttributes.js +++ b/modern/src/attributes/positionAttributes.js @@ -12,5 +12,10 @@ export default { 'ignition': { name: t('positionIgnition'), type: 'boolean', - }, + }, + 'serviceOdometer': { + name: t('positionServiceOdometer'), + type: 'number', + dataType: 'distance', + }, }; diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index e48b0760..8193e77f 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -3,11 +3,29 @@ export const speedConverter = (value, unit) => { switch (unit) { case 'kmh': factor = 1.852; + break; case 'mph': factor = 1.15078; + break; case 'kn': default: factor = 1; } return (value * factor).toFixed(2); }; + +export const distanceConverter = (value, unit) => { + let factor; + switch (unit) { + case 'mi': + factor = 0.000621371; + break; + case 'nmi': + factor = 0.000539957; + break; + case 'km': + default: + factor = 0.001; + } + return (value * factor).toFixed(2); +} \ No newline at end of file diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index 8c4cdf40..9c274598 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -1,11 +1,12 @@ import React, { useState } from 'react'; - import t from '../common/localization'; import EditItemView from '../EditItemView'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, TextField, FormControl, InputLabel, MenuItem, Select, } from '@material-ui/core'; +import InputAdornment from '@material-ui/core/InputAdornment'; import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditAttributesView from '../attributes/EditAttributesView'; import positionAttributes from '../attributes/positionAttributes'; +import { useAttributePreference } from '../common/preferences'; const useStyles = makeStyles(() => ({ details: { @@ -14,22 +15,40 @@ const useStyles = makeStyles(() => ({ })); const MaintenancePage = () => { + const classes = useStyles(); - const [item, setItem] = useState(); + const [labels, setLabels] = useState({start: '', period: ''}); + + const speedUnit = useAttributePreference('speedUnit'); + const distanceUnit = useAttributePreference('distanceUnit'); const options = []; Object.entries(positionAttributes).map(([key, value]) => { if (value.type === 'number') { - options.push({ key, name: value.name, type: value.type }) + options.push({key, name: value.name, type: value.type}) } }); const handleChange = event => { const newValue = event.target.value; setItem({...item, type: newValue}); - } + + const attribute = positionAttributes[newValue]; + if (attribute && attribute.dataType) { + switch (attribute.dataType) { + case 'distance': + setLabels({ ...labels, start: distanceUnit, period: distanceUnit}); + break; + case 'speed': + setLabels({ ...labels, start: speedUnit, period: speedUnit}); + break; + default: + break; + } + } + } return ( @@ -64,14 +83,20 @@ const MaintenancePage = () => { value={item.start || ''} onChange={event => setItem({...item, start: event.target.value})} label={t('maintenanceStart')} - variant="filled" /> + variant="filled" + InputProps={{ + endAdornment: {labels.start}, + }} /> setItem({...item, period: event.target.value})} label={t('maintenancePeriod')} - variant="filled" /> + variant="filled" + InputProps={{ + endAdornment: {labels.period}, + }} /> diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index 9cbf51a5..5e74e5a6 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -6,6 +6,10 @@ import t from '../common/localization'; import { useEffectAsync } from '../reactHelper'; import EditCollectionView from '../EditCollectionView'; +import positionAttributes from '../attributes/positionAttributes'; +import { formatDistance, formatSpeed } from '../common/formatter'; +import { useAttributePreference } from '../common/preferences'; + const useStyles = makeStyles(theme => ({ columnAction: { width: theme.spacing(1), @@ -17,6 +21,8 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { const classes = useStyles(); const [items, setItems] = useState([]); + const speedUnit = useAttributePreference('speedUnit'); + const distanceUnit = useAttributePreference('distanceUnit'); useEffectAsync(async () => { const response = await fetch('/api/maintenance'); @@ -25,6 +31,22 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { } }, [updateTimestamp]); + const convertAttribute = (key, value) => { + const attribute = positionAttributes[key]; + if (attribute && attribute.dataType) { + switch (attribute.dataType) { + case 'speed': + return formatSpeed(value, speedUnit); + case 'distance': + return formatDistance(value, distanceUnit); + default: + return value; + } + } + + return value; + } + return ( @@ -47,8 +69,8 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { {item.name}{item.type} - {item.start} - {item.period} + {convertAttribute(item.type, item.start)} + {convertAttribute(item.type, item.period)} ))} -- cgit v1.2.3 From 3e5ef37008fd009821181b1d539622a44b8cd745 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Wed, 10 Feb 2021 12:13:13 +0530 Subject: completed maintenance screen --- modern/src/MainToolbar.js | 1 - modern/src/common/converter.js | 8 +++--- modern/src/settings/MaintenancePage.js | 46 ++++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/modern/src/MainToolbar.js b/modern/src/MainToolbar.js index cfbdab94..ebe2efd5 100644 --- a/modern/src/MainToolbar.js +++ b/modern/src/MainToolbar.js @@ -30,7 +30,6 @@ import FormatListBulletedIcon from '@material-ui/icons/FormatListBulleted'; import TrendingUpIcon from '@material-ui/icons/TrendingUp'; import FolderIcon from '@material-ui/icons/Folder'; import ReplayIcon from '@material-ui/icons/Replay'; -import PublishIcon from '@material-ui/icons/Publish'; import BuildIcon from '@material-ui/icons/Build'; import t from './common/localization'; diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 8193e77f..930dba15 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,4 +1,4 @@ -export const speedConverter = (value, unit) => { +export const speedConverter = (value, unit, back = false) => { let factor; switch (unit) { case 'kmh': @@ -11,10 +11,10 @@ export const speedConverter = (value, unit) => { default: factor = 1; } - return (value * factor).toFixed(2); + return back ? (value / factor).toFixed(2):(value * factor).toFixed(2); }; -export const distanceConverter = (value, unit) => { +export const distanceConverter = (value, unit, back = false) => { let factor; switch (unit) { case 'mi': @@ -27,5 +27,5 @@ export const distanceConverter = (value, unit) => { default: factor = 0.001; } - return (value * factor).toFixed(2); + return back ? value / factor : value * factor; } \ No newline at end of file diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index 9c274598..b5486f7a 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -7,6 +7,7 @@ import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditAttributesView from '../attributes/EditAttributesView'; import positionAttributes from '../attributes/positionAttributes'; import { useAttributePreference } from '../common/preferences'; +import { distanceConverter, speedConverter } from '../common/converter'; const useStyles = makeStyles(() => ({ details: { @@ -33,7 +34,7 @@ const MaintenancePage = () => { const handleChange = event => { const newValue = event.target.value; - setItem({...item, type: newValue}); + setItem({...item, type: newValue, start: 0, period: 0}); const attribute = positionAttributes[newValue]; if (attribute && attribute.dataType) { @@ -50,6 +51,41 @@ const MaintenancePage = () => { } } + const rawToValue = (rawValue) => { + + const attribute = positionAttributes[item.type]; + if (attribute && attribute.dataType) { + switch (attribute.dataType) { + case 'speed': + return speedConverter(rawValue, speedUnit, false); + case 'distance': + return distanceConverter(rawValue, distanceUnit, false); + default: + return rawValue; + } + } + + return rawValue; + + } + + const valueToRaw = (value) => { + + const attribute = positionAttributes[item.type]; + if (attribute && attribute.dataType) { + switch (attribute.dataType) { + case 'speed': + return speedConverter(value, speedUnit, true); + case 'distance': + return distanceConverter(value, distanceUnit, true); + default: + return value; + } + } + + return value; + } + return ( {item && @@ -80,8 +116,8 @@ const MaintenancePage = () => { setItem({...item, start: event.target.value})} + value={rawToValue(item.start) || ''} + onChange={event => setItem({...item, start: valueToRaw(event.target.value)})} label={t('maintenanceStart')} variant="filled" InputProps={{ @@ -90,8 +126,8 @@ const MaintenancePage = () => { setItem({...item, period: event.target.value})} + value={rawToValue(item.period) || ''} + onChange={event => setItem({...item, period: valueToRaw(event.target.value)})} label={t('maintenancePeriod')} variant="filled" InputProps={{ -- cgit v1.2.3 From 5970936c860285576848d170dd91bfcc488c941e Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Sun, 14 Feb 2021 13:40:40 +0530 Subject: Code improvement and deduplication --- modern/src/attributes/positionAttributes.js | 4 +-- modern/src/common/converter.js | 24 ++++++++++++--- modern/src/reports/ChartReportPage.js | 4 +-- modern/src/settings/MaintenancePage.js | 47 +++++++++++++++-------------- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/modern/src/attributes/positionAttributes.js b/modern/src/attributes/positionAttributes.js index c5665da4..b1efe3df 100644 --- a/modern/src/attributes/positionAttributes.js +++ b/modern/src/attributes/positionAttributes.js @@ -13,8 +13,8 @@ export default { name: t('positionIgnition'), type: 'boolean', }, - 'serviceOdometer': { - name: t('positionServiceOdometer'), + 'odometer': { + name: t('positionOdometer'), type: 'number', dataType: 'distance', }, diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 930dba15..26e2a82b 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,4 +1,4 @@ -export const speedConverter = (value, unit, back = false) => { +const speedConverter = (value, unit, back = false) => { let factor; switch (unit) { case 'kmh': @@ -11,10 +11,10 @@ export const speedConverter = (value, unit, back = false) => { default: factor = 1; } - return back ? (value / factor).toFixed(2):(value * factor).toFixed(2); + return back ? value / factor: value * factor; }; -export const distanceConverter = (value, unit, back = false) => { +const distanceConverter = (value, unit, back = false) => { let factor; switch (unit) { case 'mi': @@ -28,4 +28,20 @@ export const distanceConverter = (value, unit, back = false) => { factor = 0.001; } return back ? value / factor : value * factor; -} \ No newline at end of file +} + +export const speedFromKnots = (value, unit) => { + return speedConverter(value, unit); +} + +export const speedToKnots = (value, unit) => { + return speedConverter(value, unit, true); +} + +export const distanceFromMeters = (value, unit) => { + return distanceConverter(value, unit); +} + +export const distanceToMeters = (value, unit) => { + return distanceConverter(value, unit, true); +} diff --git a/modern/src/reports/ChartReportPage.js b/modern/src/reports/ChartReportPage.js index 543c8a9e..80424cce 100644 --- a/modern/src/reports/ChartReportPage.js +++ b/modern/src/reports/ChartReportPage.js @@ -5,7 +5,7 @@ import ReportFilter from './ReportFilter'; import Graph from './Graph'; import { useAttributePreference } from '../common/preferences'; import { formatDate } from '../common/formatter'; -import { speedConverter } from '../common/converter'; +import { speedFromKnots } from '../common/converter'; import t from '../common/localization'; const Filter = ({ children, setItems }) => { @@ -19,7 +19,7 @@ const Filter = ({ children, setItems }) => { const positions = await response.json(); let formattedPositions = positions.map(position => { return { - speed: Number(speedConverter(position.speed, speedUnit)), + speed: Number(speedFromKnots(position.speed, speedUnit)), altitude: position.altitude, accuracy: position.accuracy, fixTime: formatDate(position.fixTime) diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index b5486f7a..5ac98c93 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -1,5 +1,6 @@ import React, { useState } from 'react'; import t from '../common/localization'; +import { prefixString } from '../common/stringUtils'; import EditItemView from '../EditItemView'; import { Accordion, AccordionSummary, AccordionDetails, makeStyles, Typography, TextField, FormControl, InputLabel, MenuItem, Select, } from '@material-ui/core'; import InputAdornment from '@material-ui/core/InputAdornment'; @@ -7,7 +8,7 @@ import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; import EditAttributesView from '../attributes/EditAttributesView'; import positionAttributes from '../attributes/positionAttributes'; import { useAttributePreference } from '../common/preferences'; -import { distanceConverter, speedConverter } from '../common/converter'; +import { speedFromKnots, speedToKnots, distanceFromMeters, distanceToMeters } from '../common/converter'; const useStyles = makeStyles(() => ({ details: { @@ -24,15 +25,18 @@ const MaintenancePage = () => { const speedUnit = useAttributePreference('speedUnit'); const distanceUnit = useAttributePreference('distanceUnit'); - const options = []; - - Object.entries(positionAttributes).map(([key, value]) => { - if (value.type === 'number') { - options.push({key, name: value.name, type: value.type}) + const convertToList = (attributes) => { + let otherList = []; + for (const key in attributes) { + const value = attributes[key]; + if (value.type === 'number') { + otherList.push({key, name: value.name, type: value.type}); + } } - }); + return otherList; + } - const handleChange = event => { + const onMaintenanceTypeChange = event => { const newValue = event.target.value; setItem({...item, type: newValue, start: 0, period: 0}); @@ -40,10 +44,10 @@ const MaintenancePage = () => { if (attribute && attribute.dataType) { switch (attribute.dataType) { case 'distance': - setLabels({ ...labels, start: distanceUnit, period: distanceUnit}); + setLabels({ ...labels, start: t(prefixString('shared', distanceUnit)), period: t(prefixString('shared', distanceUnit))}); break; case 'speed': - setLabels({ ...labels, start: speedUnit, period: speedUnit}); + setLabels({ ...labels, start: t(prefixString('shared', speedUnit)), period: t(prefixString('shared', speedUnit))}); break; default: break; @@ -51,22 +55,21 @@ const MaintenancePage = () => { } } - const rawToValue = (rawValue) => { + const rawToValue = (value) => { const attribute = positionAttributes[item.type]; if (attribute && attribute.dataType) { switch (attribute.dataType) { case 'speed': - return speedConverter(rawValue, speedUnit, false); + return speedFromKnots(value, speedUnit); case 'distance': - return distanceConverter(rawValue, distanceUnit, false); + return distanceFromMeters(value, distanceUnit); default: - return rawValue; + return value; } } - return rawValue; - + return value; } const valueToRaw = (value) => { @@ -75,9 +78,9 @@ const MaintenancePage = () => { if (attribute && attribute.dataType) { switch (attribute.dataType) { case 'speed': - return speedConverter(value, speedUnit, true); + return speedToKnots(value, speedUnit); case 'distance': - return distanceConverter(value, distanceUnit, true); + return distanceToMeters(value, distanceUnit); default: return value; } @@ -107,10 +110,10 @@ const MaintenancePage = () => { {t('sharedType')} Date: Mon, 15 Feb 2021 12:35:02 +0530 Subject: More Code Improvements --- modern/src/common/converter.js | 34 +++++++++++++-------------------- modern/src/settings/MaintenancePage.js | 12 +++--------- modern/src/settings/MaintenancesPage.js | 2 +- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 26e2a82b..9cdc6239 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,47 +1,39 @@ -const speedConverter = (value, unit, back = false) => { - let factor; +const speedConverter = unit => { switch (unit) { case 'kmh': - factor = 1.852; - break; + return 1.852; case 'mph': - factor = 1.15078; - break; + return 1.15078; case 'kn': default: - factor = 1; + return 1; } - return back ? value / factor: value * factor; }; -const distanceConverter = (value, unit, back = false) => { - let factor; +const distanceConverter = unit => { switch (unit) { case 'mi': - factor = 0.000621371; - break; + return 0.000621371; case 'nmi': - factor = 0.000539957; - break; + return 0.000539957; case 'km': default: - factor = 0.001; - } - return back ? value / factor : value * factor; + return 0.001; + } } export const speedFromKnots = (value, unit) => { - return speedConverter(value, unit); + return value * speedConverter(unit); } export const speedToKnots = (value, unit) => { - return speedConverter(value, unit, true); + return value / speedConverter(unit); } export const distanceFromMeters = (value, unit) => { - return distanceConverter(value, unit); + return value * distanceConverter(unit); } export const distanceToMeters = (value, unit) => { - return distanceConverter(value, unit, true); + return value / distanceConverter(unit); } diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index 5ac98c93..9263ee30 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -38,7 +38,7 @@ const MaintenancePage = () => { const onMaintenanceTypeChange = event => { const newValue = event.target.value; - setItem({...item, type: newValue, start: 0, period: 0}); + setItem({ ...item, type: newValue, start: 0, period: 0 }); const attribute = positionAttributes[newValue]; if (attribute && attribute.dataType) { @@ -55,7 +55,7 @@ const MaintenancePage = () => { } } - const rawToValue = (value) => { + const rawToValue = value => { const attribute = positionAttributes[item.type]; if (attribute && attribute.dataType) { @@ -64,15 +64,12 @@ const MaintenancePage = () => { return speedFromKnots(value, speedUnit); case 'distance': return distanceFromMeters(value, distanceUnit); - default: - return value; } } - return value; } - const valueToRaw = (value) => { + const valueToRaw = value => { const attribute = positionAttributes[item.type]; if (attribute && attribute.dataType) { @@ -81,11 +78,8 @@ const MaintenancePage = () => { return speedToKnots(value, speedUnit); case 'distance': return distanceToMeters(value, distanceUnit); - default: - return value; } } - return value; } diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index 5e74e5a6..7ba4bd29 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -63,7 +63,7 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { {items.map(item => ( - onMenuClick(event.currentTarget, item.id)}> + onMenuClick(event.currentTarget, item.id)}> -- cgit v1.2.3