show number of edits on screen

This commit is contained in:
proddy
2023-01-19 09:09:10 +01:00
parent 115a596c1e
commit 80d42d92db

View File

@@ -249,9 +249,12 @@ const SettingsCustomization: FC = () => {
} }
}; };
const saveCustomization = async () => { const getChanges = () => {
if (devices && deviceEntities && selectedDevice !== -1) { if (!deviceEntities || selectedDevice === -1) {
const masked_entities = deviceEntities return [];
}
return deviceEntities
.filter((de) => de.m !== de.o_m || de.cn !== de.o_cn || de.ma !== de.o_ma || de.mi !== de.o_mi) .filter((de) => de.m !== de.o_m || de.cn !== de.o_cn || de.ma !== de.o_ma || de.mi !== de.o_mi)
.map( .map(
(new_de) => (new_de) =>
@@ -262,6 +265,11 @@ const SettingsCustomization: FC = () => {
(new_de.mi ? '>' + new_de.mi : '') + (new_de.mi ? '>' + new_de.mi : '') +
(new_de.ma ? '<' + new_de.ma : '') (new_de.ma ? '<' + new_de.ma : '')
); );
};
const saveCustomization = async () => {
if (devices && deviceEntities && selectedDevice !== -1) {
const masked_entities = getChanges();
// check size in bytes to match buffer in CPP, which is 4096 // check size in bytes to match buffer in CPP, which is 4096
const bytes = new TextEncoder().encode(JSON.stringify(masked_entities)).length; const bytes = new TextEncoder().encode(JSON.stringify(masked_entities)).length;
@@ -545,7 +553,10 @@ const SettingsCustomization: FC = () => {
</Dialog> </Dialog>
); );
const renderContent = () => ( const renderContent = () => {
const num_changes = getChanges().length;
return (
<> <>
<Typography sx={{ pt: 2, pb: 2 }} variant="h6" color="primary"> <Typography sx={{ pt: 2, pb: 2 }} variant="h6" color="primary">
{LL.DEVICE_ENTITIES()} {LL.DEVICE_ENTITIES()}
@@ -555,9 +566,11 @@ const SettingsCustomization: FC = () => {
<Box display="flex" flexWrap="wrap"> <Box display="flex" flexWrap="wrap">
<Box flexGrow={1}> <Box flexGrow={1}>
<ButtonRow> <ButtonRow>
{num_changes !== 0 && (
<Button startIcon={<SaveIcon />} variant="outlined" color="primary" onClick={() => saveCustomization()}> <Button startIcon={<SaveIcon />} variant="outlined" color="primary" onClick={() => saveCustomization()}>
{LL.SAVE()} {LL.APPLY_CHANGES(num_changes)}
</Button> </Button>
)}
</ButtonRow> </ButtonRow>
</Box> </Box>
<ButtonRow> <ButtonRow>
@@ -574,6 +587,7 @@ const SettingsCustomization: FC = () => {
{renderResetDialog()} {renderResetDialog()}
</> </>
); );
};
const renderEditDialog = () => { const renderEditDialog = () => {
if (deviceEntity) { if (deviceEntity) {
@@ -582,48 +596,7 @@ const SettingsCustomization: FC = () => {
<Dialog open={!!deviceEntity} onClose={() => setDeviceEntity(undefined)}> <Dialog open={!!deviceEntity} onClose={() => setDeviceEntity(undefined)}>
<DialogTitle>{LL.EDIT() + ' ' + LL.ENTITY() + ' "' + de.id + '"'}</DialogTitle> <DialogTitle>{LL.EDIT() + ' ' + LL.ENTITY() + ' "' + de.id + '"'}</DialogTitle>
<DialogContent dividers> <DialogContent dividers>
<ToggleButtonGroup <Box color="warning.main" mb={2}>
size="small"
color="secondary"
value={getMaskString(de.m)}
onChange={(event, mask) => {
de.m = getMaskNumber(mask);
if (de.n === '' && de.m & DeviceEntityMask.DV_READONLY) {
de.m = de.m | DeviceEntityMask.DV_WEB_EXCLUDE;
}
if (de.m & DeviceEntityMask.DV_WEB_EXCLUDE) {
de.m = de.m & ~DeviceEntityMask.DV_FAVORITE;
}
setMasks(['']);
}}
>
<ToggleButton value="8" disabled={(de.m & 1) !== 0 || de.n === undefined}>
<OptionIcon
type="favorite"
isSet={(de.m & DeviceEntityMask.DV_FAVORITE) === DeviceEntityMask.DV_FAVORITE}
/>
</ToggleButton>
<ToggleButton value="4" disabled={!de.w || (de.m & 3) === 3}>
<OptionIcon
type="readonly"
isSet={(de.m & DeviceEntityMask.DV_READONLY) === DeviceEntityMask.DV_READONLY}
/>
</ToggleButton>
<ToggleButton value="2" disabled={de.n === ''}>
<OptionIcon
type="api_mqtt_exclude"
isSet={(de.m & DeviceEntityMask.DV_API_MQTT_EXCLUDE) === DeviceEntityMask.DV_API_MQTT_EXCLUDE}
/>
</ToggleButton>
<ToggleButton value="1" disabled={de.n === undefined}>
<OptionIcon
type="web_exclude"
isSet={(de.m & DeviceEntityMask.DV_WEB_EXCLUDE) === DeviceEntityMask.DV_WEB_EXCLUDE}
/>
</ToggleButton>
</ToggleButtonGroup>
<Box color="warning.main" p={0} pl={0} pr={0} mt={2} mb={2}>
<Typography variant="body2"> <Typography variant="body2">
{LL.DEFAULT(1) + ' ' + LL.NAME(1)}:&nbsp;{deviceEntity.n} {LL.DEFAULT(1) + ' ' + LL.NAME(1)}:&nbsp;{deviceEntity.n}
</Typography> </Typography>
@@ -679,7 +652,7 @@ const SettingsCustomization: FC = () => {
onClick={() => updateEntity()} onClick={() => updateEntity()}
color="warning" color="warning"
> >
{LL.SAVE()} {LL.UPDATE()}
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>