mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
click row to edit
This commit is contained in:
@@ -219,7 +219,9 @@ class EMSESPDataForm extends Component<
|
||||
};
|
||||
|
||||
sendCommand = (dv: DeviceValue) => {
|
||||
this.setState({ edit_devicevalue: dv });
|
||||
if (dv.c && this.props.authenticatedContext.me.admin) {
|
||||
this.setState({ edit_devicevalue: dv });
|
||||
}
|
||||
};
|
||||
|
||||
handleSensorChange = (name: keyof Sensor) => (
|
||||
@@ -285,7 +287,9 @@ class EMSESPDataForm extends Component<
|
||||
};
|
||||
|
||||
sendSensor = (sn: Sensor) => {
|
||||
this.setState({ edit_Sensor: sn });
|
||||
if (this.props.authenticatedContext.me.admin) {
|
||||
this.setState({ edit_Sensor: sn });
|
||||
}
|
||||
};
|
||||
|
||||
noDevices = () => {
|
||||
@@ -391,7 +395,11 @@ class EMSESPDataForm extends Component<
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data.sensors.map((sensorData) => (
|
||||
<TableRow key={sensorData.n} hover>
|
||||
<TableRow
|
||||
key={sensorData.n}
|
||||
hover
|
||||
onClick={() => this.sendSensor(sensorData)}
|
||||
>
|
||||
<TableCell padding="checkbox" style={{ width: 18 }}>
|
||||
{me.admin && (
|
||||
<CustomTooltip title="edit" placement="left-end">
|
||||
@@ -553,7 +561,6 @@ class EMSESPDataForm extends Component<
|
||||
renderDeviceData() {
|
||||
const { deviceData } = this.state;
|
||||
const { width } = this.props;
|
||||
const me = this.props.authenticatedContext.me;
|
||||
|
||||
if (this.noDevices()) {
|
||||
return;
|
||||
@@ -580,9 +587,13 @@ class EMSESPDataForm extends Component<
|
||||
<TableHead></TableHead>
|
||||
<TableBody>
|
||||
{deviceData.data.map((item, i) => (
|
||||
<TableRow hover key={i}>
|
||||
<TableRow
|
||||
hover
|
||||
key={i}
|
||||
onClick={() => this.sendCommand(item)}
|
||||
>
|
||||
<TableCell padding="checkbox" style={{ width: 18 }}>
|
||||
{item.c && me.admin && (
|
||||
{item.c && this.props.authenticatedContext.me.admin && (
|
||||
<CustomTooltip
|
||||
title="change value"
|
||||
placement="left-end"
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '@material-ui/core';
|
||||
|
||||
import { FormButton } from '../components';
|
||||
import { DeviceValue, DeviceValueUOM_s } from './EMSESPtypes';
|
||||
import { DeviceValue, DeviceValueUOM, DeviceValueUOM_s } from './EMSESPtypes';
|
||||
|
||||
interface ValueFormProps {
|
||||
devicevalue: DeviceValue;
|
||||
@@ -26,6 +26,16 @@ interface ValueFormProps {
|
||||
) => (event: React.ChangeEvent<HTMLInputElement>) => void;
|
||||
}
|
||||
|
||||
function formatValue(value: any, uom: number) {
|
||||
if (uom === DeviceValueUOM.DEGREES) {
|
||||
return new Intl.NumberFormat(undefined, {
|
||||
minimumFractionDigits: 1
|
||||
}).format(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
class ValueForm extends React.Component<ValueFormProps> {
|
||||
formRef: RefObject<any> = React.createRef();
|
||||
|
||||
@@ -69,7 +79,7 @@ class ValueForm extends React.Component<ValueFormProps> {
|
||||
{!devicevalue.l && (
|
||||
<OutlinedInput
|
||||
id="value"
|
||||
value={devicevalue.v}
|
||||
value={formatValue(devicevalue.v, devicevalue.u)}
|
||||
autoFocus
|
||||
fullWidth
|
||||
onChange={handleValueChange('v')}
|
||||
|
||||
Reference in New Issue
Block a user