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) => {
|
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) => (
|
handleSensorChange = (name: keyof Sensor) => (
|
||||||
@@ -285,7 +287,9 @@ class EMSESPDataForm extends Component<
|
|||||||
};
|
};
|
||||||
|
|
||||||
sendSensor = (sn: Sensor) => {
|
sendSensor = (sn: Sensor) => {
|
||||||
this.setState({ edit_Sensor: sn });
|
if (this.props.authenticatedContext.me.admin) {
|
||||||
|
this.setState({ edit_Sensor: sn });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
noDevices = () => {
|
noDevices = () => {
|
||||||
@@ -391,7 +395,11 @@ class EMSESPDataForm extends Component<
|
|||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.sensors.map((sensorData) => (
|
{data.sensors.map((sensorData) => (
|
||||||
<TableRow key={sensorData.n} hover>
|
<TableRow
|
||||||
|
key={sensorData.n}
|
||||||
|
hover
|
||||||
|
onClick={() => this.sendSensor(sensorData)}
|
||||||
|
>
|
||||||
<TableCell padding="checkbox" style={{ width: 18 }}>
|
<TableCell padding="checkbox" style={{ width: 18 }}>
|
||||||
{me.admin && (
|
{me.admin && (
|
||||||
<CustomTooltip title="edit" placement="left-end">
|
<CustomTooltip title="edit" placement="left-end">
|
||||||
@@ -553,7 +561,6 @@ class EMSESPDataForm extends Component<
|
|||||||
renderDeviceData() {
|
renderDeviceData() {
|
||||||
const { deviceData } = this.state;
|
const { deviceData } = this.state;
|
||||||
const { width } = this.props;
|
const { width } = this.props;
|
||||||
const me = this.props.authenticatedContext.me;
|
|
||||||
|
|
||||||
if (this.noDevices()) {
|
if (this.noDevices()) {
|
||||||
return;
|
return;
|
||||||
@@ -580,9 +587,13 @@ class EMSESPDataForm extends Component<
|
|||||||
<TableHead></TableHead>
|
<TableHead></TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{deviceData.data.map((item, i) => (
|
{deviceData.data.map((item, i) => (
|
||||||
<TableRow hover key={i}>
|
<TableRow
|
||||||
|
hover
|
||||||
|
key={i}
|
||||||
|
onClick={() => this.sendCommand(item)}
|
||||||
|
>
|
||||||
<TableCell padding="checkbox" style={{ width: 18 }}>
|
<TableCell padding="checkbox" style={{ width: 18 }}>
|
||||||
{item.c && me.admin && (
|
{item.c && this.props.authenticatedContext.me.admin && (
|
||||||
<CustomTooltip
|
<CustomTooltip
|
||||||
title="change value"
|
title="change value"
|
||||||
placement="left-end"
|
placement="left-end"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from '@material-ui/core';
|
} from '@material-ui/core';
|
||||||
|
|
||||||
import { FormButton } from '../components';
|
import { FormButton } from '../components';
|
||||||
import { DeviceValue, DeviceValueUOM_s } from './EMSESPtypes';
|
import { DeviceValue, DeviceValueUOM, DeviceValueUOM_s } from './EMSESPtypes';
|
||||||
|
|
||||||
interface ValueFormProps {
|
interface ValueFormProps {
|
||||||
devicevalue: DeviceValue;
|
devicevalue: DeviceValue;
|
||||||
@@ -26,6 +26,16 @@ interface ValueFormProps {
|
|||||||
) => (event: React.ChangeEvent<HTMLInputElement>) => void;
|
) => (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> {
|
class ValueForm extends React.Component<ValueFormProps> {
|
||||||
formRef: RefObject<any> = React.createRef();
|
formRef: RefObject<any> = React.createRef();
|
||||||
|
|
||||||
@@ -69,7 +79,7 @@ class ValueForm extends React.Component<ValueFormProps> {
|
|||||||
{!devicevalue.l && (
|
{!devicevalue.l && (
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="value"
|
id="value"
|
||||||
value={devicevalue.v}
|
value={formatValue(devicevalue.v, devicevalue.u)}
|
||||||
autoFocus
|
autoFocus
|
||||||
fullWidth
|
fullWidth
|
||||||
onChange={handleValueChange('v')}
|
onChange={handleValueChange('v')}
|
||||||
|
|||||||
Reference in New Issue
Block a user