From 1861365124011421e0853b9670c32901bcc5bdc2 Mon Sep 17 00:00:00 2001 From: Proddy Date: Fri, 28 Apr 2023 21:03:29 +0200 Subject: [PATCH] removed SAVE --- interface/src/i18n/de/index.ts | 1 - interface/src/i18n/en/index.ts | 1 - interface/src/i18n/fr/index.ts | 1 - interface/src/i18n/nl/index.ts | 1 - interface/src/i18n/no/index.ts | 1 - interface/src/i18n/pl/index.ts | 1 - interface/src/i18n/sv/index.ts | 1 - interface/src/i18n/tr/index.ts | 1 - interface/src/project/DashboardDevices.tsx | 230 +++++------------- .../src/project/DashboardDevicesDialog.tsx | 123 ++++++++++ .../DashboardSensorsTemperatureDialog.tsx | 2 +- .../project/SettingsCustomizationDialog.tsx | 6 +- .../src/project/SettingsSchedulerDialog.tsx | 4 +- 13 files changed, 187 insertions(+), 186 deletions(-) create mode 100644 interface/src/project/DashboardDevicesDialog.tsx diff --git a/interface/src/i18n/de/index.ts b/interface/src/i18n/de/index.ts index 27e58e311..2ad6345b5 100644 --- a/interface/src/i18n/de/index.ts +++ b/interface/src/i18n/de/index.ts @@ -46,7 +46,6 @@ const de: Translation = { CHANGE_VALUE: 'Wert ändern', CANCEL: 'Abbrechen', RESET: 'Zurücksetzen', - SEND: 'Senden', APPLY_CHANGES: 'Apply Changes ({0})', // TODO translate UPDATE: 'Update', // TODO translate REMOVE: 'Entfernen', diff --git a/interface/src/i18n/en/index.ts b/interface/src/i18n/en/index.ts index 11422d5f6..31f8dc798 100644 --- a/interface/src/i18n/en/index.ts +++ b/interface/src/i18n/en/index.ts @@ -46,7 +46,6 @@ const en: Translation = { CHANGE_VALUE: 'Change Value', CANCEL: 'Cancel', RESET: 'Reset', - SEND: 'Send', APPLY_CHANGES: 'Apply Changes ({0})', UPDATE: 'Update', REMOVE: 'Remove', diff --git a/interface/src/i18n/fr/index.ts b/interface/src/i18n/fr/index.ts index 1569300b9..905418d45 100644 --- a/interface/src/i18n/fr/index.ts +++ b/interface/src/i18n/fr/index.ts @@ -46,7 +46,6 @@ const fr: Translation = { CHANGE_VALUE: 'Changer la valeur', CANCEL: 'Annuler', RESET: 'Réinitialiser', - SEND: 'Envoyer', APPLY_CHANGES: 'Apply Changes ({0})', // TODO translate UPDATE: 'Update', // TODO translate REMOVE: 'Enlever', diff --git a/interface/src/i18n/nl/index.ts b/interface/src/i18n/nl/index.ts index e7970a2a9..1fde01341 100644 --- a/interface/src/i18n/nl/index.ts +++ b/interface/src/i18n/nl/index.ts @@ -46,7 +46,6 @@ const nl: Translation = { CHANGE_VALUE: 'Wijzig waarde', CANCEL: 'Annuleren', RESET: 'Reset', - SEND: 'Verzenden', APPLY_CHANGES: 'Apply Changes ({0})', // TODO translate UPDATE: 'Update', // TODO translate REMOVE: 'Verwijderen', diff --git a/interface/src/i18n/no/index.ts b/interface/src/i18n/no/index.ts index 61f8511c5..880927925 100644 --- a/interface/src/i18n/no/index.ts +++ b/interface/src/i18n/no/index.ts @@ -46,7 +46,6 @@ const no: Translation = { CHANGE_VALUE: 'Endre Verdi', CANCEL: 'Avbryt', RESET: 'Nullstill', - SEND: 'Send', APPLY_CHANGES: 'Utfør endringer({0})', UPDATE: 'Oppdater', REMOVE: 'Fjern', diff --git a/interface/src/i18n/pl/index.ts b/interface/src/i18n/pl/index.ts index 14f8e62bb..c420d8669 100644 --- a/interface/src/i18n/pl/index.ts +++ b/interface/src/i18n/pl/index.ts @@ -46,7 +46,6 @@ const pl: BaseTranslation = { CHANGE_VALUE: 'Zmień wartość', CANCEL: 'Anuluj', RESET: 'Reset{{uj|owanie|}}', - SEND: 'Wyślij', APPLY_CHANGES: 'Zapisz zmiany ({0})', UPDATE: 'Uaktualnij', REMOVE: 'Usuń', diff --git a/interface/src/i18n/sv/index.ts b/interface/src/i18n/sv/index.ts index a48d2f19b..2f752c855 100644 --- a/interface/src/i18n/sv/index.ts +++ b/interface/src/i18n/sv/index.ts @@ -46,7 +46,6 @@ const sv: Translation = { CHANGE_VALUE: 'Ändra Värde', CANCEL: 'Avbryt', RESET: 'Nollställ', - SEND: 'Skicka', APPLY_CHANGES: 'Apply Changes ({0})', // TODO translate UPDATE: 'Update', // TODO translate REMOVE: 'Ta bort', diff --git a/interface/src/i18n/tr/index.ts b/interface/src/i18n/tr/index.ts index 8ac4cc23c..da9d53e80 100644 --- a/interface/src/i18n/tr/index.ts +++ b/interface/src/i18n/tr/index.ts @@ -46,7 +46,6 @@ const tr: Translation = { CHANGE_VALUE: 'Değeri Değiştir', CANCEL: 'İptal', RESET: 'Reset', - SEND: 'Gönder', APPLY_CHANGES: 'Apply Changes ({0})', UPDATE: 'Update', REMOVE: 'Kaldır', diff --git a/interface/src/project/DashboardDevices.tsx b/interface/src/project/DashboardDevices.tsx index 3f0c837be..33088ebbd 100644 --- a/interface/src/project/DashboardDevices.tsx +++ b/interface/src/project/DashboardDevices.tsx @@ -1,5 +1,3 @@ -import AddCircleOutlineOutlinedIcon from '@mui/icons-material/AddCircleOutlineOutlined'; -import CancelIcon from '@mui/icons-material/Cancel'; import CommentsDisabledOutlinedIcon from '@mui/icons-material/CommentsDisabledOutlined'; import EditIcon from '@mui/icons-material/Edit'; import EditOffOutlinedIcon from '@mui/icons-material/EditOffOutlined'; @@ -9,27 +7,19 @@ import KeyboardArrowDownOutlinedIcon from '@mui/icons-material/KeyboardArrowDown import KeyboardArrowUpOutlinedIcon from '@mui/icons-material/KeyboardArrowUpOutlined'; import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import RefreshIcon from '@mui/icons-material/Refresh'; -import RemoveIcon from '@mui/icons-material/RemoveCircleOutline'; import StarIcon from '@mui/icons-material/Star'; -import SendIcon from '@mui/icons-material/TrendingFlat'; import UnfoldMoreOutlinedIcon from '@mui/icons-material/UnfoldMoreOutlined'; -import WarningIcon from '@mui/icons-material/Warning'; import { Button, Typography, - Box, Dialog, DialogTitle, DialogContent, DialogActions, - MenuItem, - InputAdornment, - FormHelperText, IconButton, List, ListItem, ListItemText, - Grid, FormControlLabel, Checkbox } from '@mui/material'; @@ -41,35 +31,34 @@ import { useState, useContext, useCallback, useEffect } from 'react'; import { IconContext } from 'react-icons'; import { toast } from 'react-toastify'; +import DashboarDevicesDialog from './DashboardDevicesDialog'; import DeviceIcon from './DeviceIcon'; import * as EMSESP from './api'; import { DeviceValueUOM, DeviceValueUOM_s, DeviceEntityMask } from './types'; -import type { SensorData, Device, CoreData, DeviceData, DeviceValue, TemperatureSensor, AnalogSensor } from './types'; +import type { Device, CoreData, DeviceData, DeviceValue } from './types'; import type { FC } from 'react'; -import { ButtonRow, ValidatedTextField, SectionContent, MessageBox } from 'components'; +import { ButtonRow, SectionContent, MessageBox } from 'components'; import { AuthenticatedContext } from 'contexts/authentication'; import { useI18nContext } from 'i18n/i18n-react'; -import { numberValue, updateValue, extractErrorMessage } from 'utils'; +import { extractErrorMessage } from 'utils'; const DashboardDevices: FC = () => { const { me } = useContext(AuthenticatedContext); const { LL } = useI18nContext(); const [deviceData, setDeviceData] = useState({ label: '', data: [] }); - const [deviceValue, setDeviceValue] = useState(); - const [deviceDialog, setDeviceDialog] = useState(-1); + const [selectedDeviceValue, setSelectedDeviceValue] = useState(); + const [deviceDetails, setDeviceDetails] = useState(-1); const [onlyFav, setOnlyFav] = useState(false); + const [selectedDevice, setSelectedDevice] = useState(); + const [deviceValueDialogOpen, setDeviceValueDialogOpen] = useState(false); + const [coreData, setCoreData] = useState({ connected: true, devices: [] }); - const [selectedDevice, setSelectedDevice] = useState(); - - const [sensorData, setSensorData] = useState({ ts: [], as: [] }); - const [analog, setAnalog] = useState(); - const [sensor, setSensor] = useState(); const common_theme = useTheme({ BaseRow: ` @@ -198,14 +187,6 @@ const DashboardDevices: FC = () => { } ); - // const fetchSensorData = async () => { - // try { - // setSensorData((await EMSESP.readSensorData()).data); - // } catch (error) { - // toast.error(extractErrorMessage(error, LL.PROBLEM_LOADING())); - // } - // }; - const fetchDeviceData = async (id: number) => { try { setDeviceData((await EMSESP.readDeviceData({ id })).data); @@ -224,46 +205,19 @@ const DashboardDevices: FC = () => { useEffect(() => { void fetchCoreData(); - }, [fetchCoreData]); - - // const refreshDataIndex = (selectedDevice: string) => { - // // if (selectedDevice === 'sensor') { - // // void fetchSensorData(); - // // return; - // // } - - // // setSensorData({ sensors: [], analogs: [] }); - // if (selectedDevice) { - // void fetchDeviceData(selectedDevice); - // } else { - // void fetchCoreData(); - // } - // }; + }, []); const refreshData = () => { - // const selectedDevice = device_select.state.id; - // if (selectedDevice === 'sensor') { - // // void fetchSensorData(); - // return; - // } - - // setSensorData({ sensors: [], analogs: [] }); if (selectedDevice) { void fetchDeviceData(selectedDevice); } else { void fetchCoreData(); } - - // refreshDataIndex(device_select.state.id); }; function onSelectChange(action: any, state: any) { setSelectedDevice(device_select.state.id); - if (action.type === 'ADD_BY_ID_EXCLUSIVELY') { - refreshData(); - } else { - // setSensorData({ sensors: [], analogs: [] }); - } + refreshData(); } const escapeCsvCell = (cell: any) => { @@ -322,7 +276,7 @@ const DashboardDevices: FC = () => { return () => { clearInterval(timer); }; - }, [analog, sensor, deviceValue, sensorData]); + }, []); const isCmdOnly = (dv: DeviceValue) => dv.v === '' && dv.c; @@ -375,140 +329,60 @@ const DashboardDevices: FC = () => { } } - const setUom = (uom: number) => { - switch (uom) { - case DeviceValueUOM.HOURS: - return LL.HOURS(); - case DeviceValueUOM.MINUTES: - return LL.MINUTES(); - case DeviceValueUOM.SECONDS: - return LL.SECONDS(); - default: - return DeviceValueUOM_s[uom]; - } - }; - - const sendDeviceValue = async () => { - if (deviceValue) { - try { - const response = await EMSESP.writeDeviceValue({ - id: Number(device_select.state.id), - devicevalue: deviceValue - }); - if (response.status === 204) { - toast.error(LL.WRITE_CMD_FAILED()); - } else if (response.status === 403) { - toast.error(LL.ACCESS_DENIED()); - } else { - toast.success(LL.WRITE_CMD_SENT()); - } - setDeviceValue(undefined); - } catch (error) { - toast.error(extractErrorMessage(error, LL.PROBLEM_UPDATING())); - } finally { - refreshData(); - setDeviceValue(undefined); + const deviceValueDialogSave = async (dv: DeviceValue) => { + try { + const response = await EMSESP.writeDeviceValue({ + id: Number(device_select.state.id), + devicevalue: dv + }); + if (response.status === 204) { + toast.error(LL.WRITE_CMD_FAILED()); + } else if (response.status === 403) { + toast.error(LL.ACCESS_DENIED()); + } else { + toast.success(LL.WRITE_CMD_SENT()); } + } catch (error) { + toast.error(extractErrorMessage(error, LL.PROBLEM_UPDATING())); + } finally { + setDeviceValueDialogOpen(false); + setSelectedDeviceValue(undefined); + refreshData(); } }; - const renderDeviceValueDialog = () => { - if (deviceValue) { + const renderDeviceDetails = () => { + if (coreData && coreData.devices.length > 0 && deviceDetails !== -1) { return ( - setDeviceValue(undefined)}> - {isCmdOnly(deviceValue) ? LL.RUN_COMMAND() : LL.CHANGE_VALUE()} - - {deviceValue.l && ( - - {deviceValue.l.map((val) => ( - - {val} - - ))} - - )} - {!deviceValue.l && ( - {setUom(deviceValue.u)} - }} - /> - )} - {deviceValue.h && {deviceValue.h}} - - - - - - - ); - } - }; - - const renderDeviceDialog = () => { - if (coreData && coreData.devices.length > 0 && deviceDialog !== -1) { - return ( - setDeviceDialog(-1)}> + setDeviceDetails(-1)}> {LL.DEVICE_DETAILS()} - + - + - + - + - + - @@ -546,7 +420,7 @@ const DashboardDevices: FC = () => { {device.n} {device.e} - setDeviceDialog(index)}> + setDeviceDetails(index)}> @@ -559,14 +433,19 @@ const DashboardDevices: FC = () => { ); + const deviceValueDialogClose = () => { + setDeviceValueDialogOpen(false); + }; + const renderDeviceData = () => { - if (!device_select.state.id || device_select.state.id === 'sensor') { + if (!device_select.state.id) { return; } const sendCommand = (dv: DeviceValue) => { if (dv.c && me.admin && !hasMask(dv.id, DeviceEntityMask.DV_READONLY)) { - setDeviceValue(dv); + setSelectedDeviceValue(dv); + setDeviceValueDialogOpen(true); } }; @@ -662,8 +541,17 @@ const DashboardDevices: FC = () => { {renderCoreData()} {renderDeviceData()} - {renderDeviceDialog()} - {renderDeviceValueDialog()} + {renderDeviceDetails()} + {console.log('redndering device data')} + + {selectedDeviceValue && ( + + )} + + + + ); +}; + +export default DashboarDevicesDialog; diff --git a/interface/src/project/DashboardSensorsTemperatureDialog.tsx b/interface/src/project/DashboardSensorsTemperatureDialog.tsx index ddda88a3c..3089dc363 100644 --- a/interface/src/project/DashboardSensorsTemperatureDialog.tsx +++ b/interface/src/project/DashboardSensorsTemperatureDialog.tsx @@ -69,7 +69,7 @@ const DashboardSensorsTemperatureDialog = ({ return ( - {LL.EDIT()} {LL.TEMP_SENSOR()} + {LL.EDIT()} {LL.TEMP_SENSOR()} diff --git a/interface/src/project/SettingsCustomizationDialog.tsx b/interface/src/project/SettingsCustomizationDialog.tsx index 3e23d44f3..8d48f57fc 100644 --- a/interface/src/project/SettingsCustomizationDialog.tsx +++ b/interface/src/project/SettingsCustomizationDialog.tsx @@ -67,13 +67,11 @@ const SettingsCustomizationDialog = ({ open, onClose, onSave, selectedItem }: Se {LL.EDIT() + ' ' + LL.ENTITY()} - - {LL.ENTITY()}: {editItem.id} - + {editItem.id} - {LL.DEFAULT(1) + ' ' + LL.NAME(1)}: {editItem.n} + {LL.DEFAULT(1) + ' ' + LL.ENTITY_NAME()}: {editItem.n} diff --git a/interface/src/project/SettingsSchedulerDialog.tsx b/interface/src/project/SettingsSchedulerDialog.tsx index 7c360a874..514b36610 100644 --- a/interface/src/project/SettingsSchedulerDialog.tsx +++ b/interface/src/project/SettingsSchedulerDialog.tsx @@ -131,7 +131,7 @@ const SettingsSchedulerDialog = ({ return ( - {creating ? LL.ADD(1) + ' ' + LL.NEW(1) : LL.EDIT()} {LL.ENTITY()} + {creating ? LL.ADD(1) + ' ' + LL.NEW(1) : LL.EDIT()} {LL.SCHEDULE(0)} @@ -215,7 +215,7 @@ const SettingsSchedulerDialog = ({ />