Web selectbox for enum commands (like bool)

This commit is contained in:
MichaelDvP
2021-07-11 15:02:24 +02:00
parent 82978a25c5
commit 358d6010b0
11 changed files with 107 additions and 58 deletions

View File

@@ -125,6 +125,7 @@ function formatValue(value: any, uom: number) {
case DeviceValueUOM.MINUTES:
return value ? formatDuration(value) : '0 minutes';
case DeviceValueUOM.NONE:
case DeviceValueUOM.LIST:
return value;
case DeviceValueUOM.NUM:
return new Intl.NumberFormat().format(value);

View File

@@ -64,6 +64,7 @@ export interface DeviceValue {
u: number;
n: string;
c: string;
l: string[];
}
export interface EMSESPDeviceData {
@@ -88,7 +89,8 @@ export enum DeviceValueUOM {
SECONDS,
DBM,
NUM,
BOOLEAN
BOOLEAN,
LIST
}
export const DeviceValueUOM_s = [
@@ -108,5 +110,6 @@ export const DeviceValueUOM_s = [
'seconds',
'dBm',
'number',
'on/off'
'on/off',
''
];

View File

@@ -51,24 +51,40 @@ class ValueForm extends React.Component<ValueFormProps> {
>
<DialogTitle id="user-form-dialog-title">Change Value</DialogTitle>
<DialogContent dividers>
{devicevalue.u !== DeviceValueUOM.BOOLEAN && (
<OutlinedInput
id="outlined-adornment-value"
{devicevalue.u === DeviceValueUOM.LIST && (
<TextField
id="outlined-select-value"
select
value={devicevalue.v}
autoFocus
fullWidth
onChange={handleValueChange('v')}
endAdornment={
<InputAdornment position="end">
{DeviceValueUOM_s[devicevalue.u]}
</InputAdornment>
}
aria-describedby="outlined-value-helper-text"
inputProps={{
'aria-label': 'value'
}}
/>
variant="outlined"
>
{devicevalue.l.map((val) => (
<MenuItem value={val}>{val}</MenuItem>
))}
</TextField>
)}
{devicevalue.u !== DeviceValueUOM.BOOLEAN &&
devicevalue.u !== DeviceValueUOM.LIST && (
<OutlinedInput
id="outlined-adornment-value"
value={devicevalue.v}
autoFocus
fullWidth
onChange={handleValueChange('v')}
endAdornment={
<InputAdornment position="end">
{DeviceValueUOM_s[devicevalue.u]}
</InputAdornment>
}
aria-describedby="outlined-value-helper-text"
inputProps={{
'aria-label': 'value'
}}
/>
)}
{devicevalue.u === DeviceValueUOM.BOOLEAN && (
<TextField
id="outlined-select-value"