diff options
author | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-02-10 12:13:13 +0530 |
---|---|---|
committer | Ashutosh Bishnoi <mail2bishnoi@gmail.com> | 2021-02-10 12:13:13 +0530 |
commit | 3e5ef37008fd009821181b1d539622a44b8cd745 (patch) | |
tree | 0f3452f76dea3f3e364988c1709c2dd59325095a /modern | |
parent | 240518c0fc8b5237557affe8e28b9b94ef46a081 (diff) | |
download | trackermap-web-3e5ef37008fd009821181b1d539622a44b8cd745.tar.gz trackermap-web-3e5ef37008fd009821181b1d539622a44b8cd745.tar.bz2 trackermap-web-3e5ef37008fd009821181b1d539622a44b8cd745.zip |
completed maintenance screen
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/MainToolbar.js | 1 | ||||
-rw-r--r-- | modern/src/common/converter.js | 8 | ||||
-rw-r--r-- | 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 ( <EditItemView endpoint="maintenance" item={item} setItem={setItem}> {item && @@ -80,8 +116,8 @@ const MaintenancePage = () => { <TextField margin="normal" type="number" - value={item.start || ''} - onChange={event => 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 = () => { <TextField margin="normal" type="number" - value={item.period || ''} - onChange={event => 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={{ |