From df4aa64883655acf76997435c4ad1d4ff5e97c2b Mon Sep 17 00:00:00 2001 From: proddy Date: Fri, 9 Sep 2022 12:33:15 +0200 Subject: [PATCH] Change name of entity within WebUI #612 --- interface/src/i18n/en/index.ts | 3 +- interface/src/i18n/i18n-types.ts | 8 ++ interface/src/i18n/nl/index.ts | 3 +- .../src/project/SettingsCustomization.tsx | 73 ++++++++++++++++++- interface/src/project/types.ts | 1 + mock-api/server.js | 20 ++--- src/emsdevice.cpp | 8 +- src/emsdevicevalue.cpp | 12 +-- src/emsdevicevalue.h | 18 +++-- 9 files changed, 115 insertions(+), 31 deletions(-) diff --git a/interface/src/i18n/en/index.ts b/interface/src/i18n/en/index.ts index b75ed950e..158974226 100644 --- a/interface/src/i18n/en/index.ts +++ b/interface/src/i18n/en/index.ts @@ -253,7 +253,8 @@ const en: BaseTranslation = { NETWORK_ENABLE_IPV6: 'Enable IPv6 support', NETWORK_FIXED_IP: 'Use Fixed IP address', ADMIN: 'Admin', - GUEST: 'Guest' + GUEST: 'Guest', + NEW: 'New' }; export default en; diff --git a/interface/src/i18n/i18n-types.ts b/interface/src/i18n/i18n-types.ts index ebe8f30ac..60d3becd2 100644 --- a/interface/src/i18n/i18n-types.ts +++ b/interface/src/i18n/i18n-types.ts @@ -1004,6 +1004,10 @@ type RootTranslation = { * Guest */ GUEST: string + /** + * New + */ + NEW: string } export type TranslationFunctions = { @@ -1985,6 +1989,10 @@ export type TranslationFunctions = { * Guest */ GUEST: () => LocalizedString + /** + * New + */ + NEW: () => LocalizedString } export type Formatters = {} diff --git a/interface/src/i18n/nl/index.ts b/interface/src/i18n/nl/index.ts index 9f4fe788f..45f163ab6 100644 --- a/interface/src/i18n/nl/index.ts +++ b/interface/src/i18n/nl/index.ts @@ -253,7 +253,8 @@ const nl: BaseTranslation = { NETWORK_ENABLE_IPV6: 'Activeer IPv6 support', NETWORK_FIXED_IP: 'Gebruik vast IP addres', ADMIN: 'Admin', - GUEST: 'Gast' + GUEST: 'Gast', + NEW: 'Nieuwe' }; export default nl; diff --git a/interface/src/project/SettingsCustomization.tsx b/interface/src/project/SettingsCustomization.tsx index 18cd619e7..d5b5db0e2 100644 --- a/interface/src/project/SettingsCustomization.tsx +++ b/interface/src/project/SettingsCustomization.tsx @@ -40,7 +40,7 @@ import { ButtonRow, FormLoader, ValidatedTextField, SectionContent } from '../co import * as EMSESP from './api'; -import { extractErrorMessage } from '../utils'; +import { extractErrorMessage, updateValue } from '../utils'; import { DeviceShort, Devices, DeviceEntity, DeviceEntityMask } from './types'; @@ -57,6 +57,9 @@ const SettingsCustomization: FC = () => { const [devices, setDevices] = useState(); const [errorMessage, setErrorMessage] = useState(); const [selectedDevice, setSelectedDevice] = useState(-1); + + const [selectedEntity, setSelectedEntity] = useState(); + const [confirmReset, setConfirmReset] = useState(false); const [selectedFilters, setSelectedFilters] = useState(0); const [search, setSearch] = useState(''); @@ -96,6 +99,7 @@ const SettingsCustomization: FC = () => { Row: ` background-color: #1e1e1e; position: relative; + cursor: pointer; .td { border-top: 1px solid #565656; @@ -108,6 +112,11 @@ const SettingsCustomization: FC = () => { font-weight: normal; } + &:hover .td { + border-top: 1px solid #177ac9; + border-bottom: 1px solid #177ac9; + } + &:nth-of-type(odd) .td { background-color: #303030; } @@ -329,6 +338,19 @@ const SettingsCustomization: FC = () => { ); }; + const editEntity = (de: DeviceEntity) => { + if (de.n) { + setSelectedEntity(de); + console.log(de.n); // TODO + } + }; + + const updateEntity = () => { + if (selectedEntity) { + setSelectedEntity(undefined); // TODO + } + }; + const renderDeviceData = () => { if (devices?.devices.length === 0 || deviceEntities[0].id === '') { return; @@ -444,7 +466,7 @@ const SettingsCustomization: FC = () => { {tableList.map((de: DeviceEntity) => ( - + editEntity(de)}> { ); }; + const renderEditEntity = () => { + if (selectedEntity) { + return ( + setSelectedEntity(undefined)}> + Rename Entity + + + {selectedEntity.n} + + + + + + + + + + + + + ); + } + }; + return ( + {renderEditEntity()} {content()} ); diff --git a/interface/src/project/types.ts b/interface/src/project/types.ts index 0cd31875f..de1a6baf4 100644 --- a/interface/src/project/types.ts +++ b/interface/src/project/types.ts @@ -137,6 +137,7 @@ export interface DeviceEntity { id: string; // shortname v?: any; // value, in any format, optional n?: string; // fullname, optional + cn?: string; // custom fullname, optional m: number; // mask om?: number; // original mask before edits w: boolean; // writeable diff --git a/mock-api/server.js b/mock-api/server.js index 52dd44507..0a4509489 100644 --- a/mock-api/server.js +++ b/mock-api/server.js @@ -598,19 +598,13 @@ const emsesp_deviceentities_1 = [ // m: 0, // w: false, // }, - { - v: 'roomTemp', - id: 'hc1/HA climate config creation', - m: 0, - w: false, - }, - { - v: 18.2, - n: 'hc1 selected room temperature', - id: 'hc1/seltemp', - m: 0, - w: true, - }, + // { + // v: 18.2, + // n: 'hc1 selected room temperature', + // id: 'hc1/seltemp', + // m: 0, + // w: true, + // }, { v: 22.6, n: 'hc1 current room temperature', diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index c322d2618..dfd5b9f9b 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -449,8 +449,14 @@ void EMSdevice::add_device_value(uint8_t tag, } }); + // TODO + const __FlashStringHelper * custom_fullname; + + custom_fullname = nullptr; + // add the device entity - devicevalues_.emplace_back(device_type_, tag, value_p, type, options, options_single, numeric_operator, short_name, fullname, uom, has_cmd, min, max, state); + devicevalues_.emplace_back( + device_type_, tag, value_p, type, options, options_single, numeric_operator, short_name, fullname, custom_fullname, uom, has_cmd, min, max, state); // add a new command if it has a function attached if (!has_cmd) { diff --git a/src/emsdevicevalue.cpp b/src/emsdevicevalue.cpp index 4402f4920..7edbf2dc3 100644 --- a/src/emsdevicevalue.cpp +++ b/src/emsdevicevalue.cpp @@ -32,11 +32,12 @@ DeviceValue::DeviceValue(uint8_t device_type, int8_t numeric_operator, const __FlashStringHelper * const short_name, const __FlashStringHelper * const * fullname, - uint8_t uom, - bool has_cmd, - int16_t min, - uint16_t max, - uint8_t state) + const __FlashStringHelper * const custom_fullname, + uint8_t uom, + bool has_cmd, + int16_t min, + uint16_t max, + uint8_t state) : device_type(device_type) , tag(tag) , value_p(value_p) @@ -46,6 +47,7 @@ DeviceValue::DeviceValue(uint8_t device_type, , numeric_operator(numeric_operator) , short_name(short_name) , fullname(fullname) + , custom_fullname(custom_fullname) , uom(uom) , has_cmd(has_cmd) , min(min) diff --git a/src/emsdevicevalue.h b/src/emsdevicevalue.h index 81cad53aa..490092fc3 100644 --- a/src/emsdevicevalue.h +++ b/src/emsdevicevalue.h @@ -150,14 +150,15 @@ class DeviceValue { const __FlashStringHelper * const ** options; // options as a flash char array const __FlashStringHelper * const * options_single; // options are not translated int8_t numeric_operator; - uint8_t options_size; // number of options in the char array, calculated - const __FlashStringHelper * const short_name; // used in MQTT and API - const __FlashStringHelper * const * fullname; // used in Web and Console, is translated - uint8_t uom; // DeviceValueUOM::* - bool has_cmd; // true if there is a Console/MQTT command which matches the short_name - int16_t min; // min range - uint16_t max; // max range - uint8_t state; // DeviceValueState::* + uint8_t options_size; // number of options in the char array, calculated + const __FlashStringHelper * const short_name; // used in MQTT and API + const __FlashStringHelper * const * fullname; // used in Web and Console, is translated + const __FlashStringHelper * const custom_fullname; // optional, from customization + uint8_t uom; // DeviceValueUOM::* + bool has_cmd; // true if there is a Console/MQTT command which matches the short_name + int16_t min; // min range + uint16_t max; // max range + uint8_t state; // DeviceValueState::* DeviceValue(uint8_t device_type, uint8_t tag, @@ -168,6 +169,7 @@ class DeviceValue { int8_t numeric_operator, const __FlashStringHelper * const short_name, const __FlashStringHelper * const * fullname, + const __FlashStringHelper * const custom_fullname, uint8_t uom, bool has_cmd, int16_t min,