show all mask icons

This commit is contained in:
proddy
2022-03-29 18:32:47 +02:00
parent a5ba70a6d7
commit d3002ce415

View File

@@ -39,6 +39,8 @@ import SaveIcon from '@mui/icons-material/Save';
import RemoveIcon from '@mui/icons-material/RemoveCircleOutline'; import RemoveIcon from '@mui/icons-material/RemoveCircleOutline';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder'; import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined';
import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined';
import DeviceIcon from './DeviceIcon'; import DeviceIcon from './DeviceIcon';
@@ -64,7 +66,8 @@ import {
AnalogType, AnalogType,
AnalogTypeNames, AnalogTypeNames,
Sensor, Sensor,
Analog Analog,
DeviceEntityMask
} from './types'; } from './types';
const StyledTableCell = styled(TableCell)(({ theme }) => ({ const StyledTableCell = styled(TableCell)(({ theme }) => ({
@@ -487,39 +490,25 @@ const DashboardData: FC = () => {
return; return;
} }
const hasMask = (entityName: string, mask: number) => (parseInt(entityName.slice(0, 2), 16) & mask) === mask;
const sendCommand = (dv: DeviceValue) => { const sendCommand = (dv: DeviceValue) => {
if (dv.c && me.admin) { if (dv.c && me.admin && !hasMask(dv.n, DeviceEntityMask.DV_READONLY)) {
setDeviceValue(dv); setDeviceValue(dv);
} }
}; };
const renderNameCell = (dv: DeviceValue) => { const renderNameCell = (dv: DeviceValue) => (
var mask = Number(dv.n.slice(0, 2)); <>
var name = dv.n.slice(2); {dv.n.slice(2)}&nbsp;
if (dv.v === undefined && dv.c) { {hasMask(dv.n, DeviceEntityMask.DV_FAVORITE) && <FavoriteBorderIcon color="success" sx={{ fontSize: 12 }} />}
return ( {hasMask(dv.n, DeviceEntityMask.DV_READONLY) && <EditOffOutlinedIcon color="primary" sx={{ fontSize: 12 }} />}
<StyledTableCell component="th" scope="row"> {hasMask(dv.n, DeviceEntityMask.DV_API_MQTT_EXCLUDE) && (
{name}&nbsp; <CommentsDisabledOutlinedIcon color="primary" sx={{ fontSize: 12 }} />
<PlayArrowIcon color="primary" sx={{ fontSize: 12 }} /> )}
</StyledTableCell> {dv.v === undefined && dv.c && <PlayArrowIcon color="primary" sx={{ fontSize: 14 }} />}
</>
); );
}
if ((mask & 8) === 8) {
return (
<StyledTableCell component="th" scope="row">
{name}&nbsp;
<FavoriteBorderIcon color="success" sx={{ fontSize: 10 }} />
</StyledTableCell>
);
}
return (
<StyledTableCell component="th" scope="row">
{name}
</StyledTableCell>
);
};
return ( return (
<> <>
@@ -536,17 +525,27 @@ const DashboardData: FC = () => {
</TableHead> </TableHead>
<TableBody> <TableBody>
{deviceData.data.map((dv, i) => ( {deviceData.data.map((dv, i) => (
<StyledTableRow key={i} onClick={() => sendCommand(dv)}> <TableRow
key={i}
onClick={() => sendCommand(dv)}
// sx={
// hasMask(dv.n, DeviceEntityMask.DV_FAVORITE)
// ? { backgroundColor: '#334900' }
// : { backgroundColor: 'black' }
// }
>
<StyledTableCell padding="checkbox"> <StyledTableCell padding="checkbox">
{dv.c && me.admin && ( {dv.c && me.admin && !hasMask(dv.n, DeviceEntityMask.DV_READONLY) && (
<IconButton size="small"> <IconButton size="small">
<EditIcon color="primary" fontSize="small" /> <EditIcon color="primary" fontSize="small" />
</IconButton> </IconButton>
)} )}
</StyledTableCell> </StyledTableCell>
<StyledTableCell component="th" scope="row">
{renderNameCell(dv)} {renderNameCell(dv)}
</StyledTableCell>
<StyledTableCell align="right">{formatValue(dv.v, dv.u)}</StyledTableCell> <StyledTableCell align="right">{formatValue(dv.v, dv.u)}</StyledTableCell>
</StyledTableRow> </TableRow>
))} ))}
</TableBody> </TableBody>
</Table> </Table>