From bbab9000393bcc20fbdff769107a187c2a9237b4 Mon Sep 17 00:00:00 2001
From: jlikeme <270615179@qq.com>
Date: Tue, 25 Mar 2025 18:06:30 +0800
Subject: [PATCH 1/2] feat: support multiple device protocols list
Signed-off-by: GaoJing <270615179@qq.com>
---
.../device-protocol.component.html | 93 +++++++++++--------
.../device-protocol.component.ts | 77 ++++++++++++---
2 files changed, 122 insertions(+), 48 deletions(-)
diff --git a/web/src/app/metadata/device/device-protocol/device-protocol.component.html b/web/src/app/metadata/device/device-protocol/device-protocol.component.html
index c7c75c62..824fbec2 100644
--- a/web/src/app/metadata/device/device-protocol/device-protocol.component.html
+++ b/web/src/app/metadata/device/device-protocol/device-protocol.component.html
@@ -102,51 +102,70 @@
-
-
-
diff --git a/web/src/app/metadata/device/device-protocol/device-protocol.component.ts b/web/src/app/metadata/device/device-protocol/device-protocol.component.ts
index 4b276db8..61f5b9a5 100644
--- a/web/src/app/metadata/device/device-protocol/device-protocol.component.ts
+++ b/web/src/app/metadata/device/device-protocol/device-protocol.component.ts
@@ -63,6 +63,7 @@ export class DeviceProtocolComponent implements OnInit {
customProtocolName?: string;
customProtocolPropertyBearer: ProtocolProperty[] = []
+ customProtocols: Map
= new Map()
builtinProtocolName?: string
builtinProtocolTemplateSelected: any;
@@ -146,7 +147,25 @@ export class DeviceProtocolComponent implements OnInit {
this.validate()
}
- onCustomProtocolNameChange() {
+ onCustomProtocolNameChange(protocolName: string, property: ProtocolProperty[]) {
+ this.customProtocols.set(protocolName, property as ProtocolProperty[])
+ // this.customProtocols.delete(this.customProtocolName as string)
+ this.customProtocolName = protocolName
+ this.validate()
+ }
+
+ onCustomProtocolNameFocus(protocolName: string) {
+ this.customProtocolName = protocolName
+ this.validate()
+ }
+
+ onCustomProtocolNameBlur(protocolName: string, property: ProtocolProperty[]) {
+ if (this.customProtocolName === protocolName) {
+ return
+ }
+ this.customProtocols.set(protocolName, property as ProtocolProperty[])
+ this.customProtocols.delete(this.customProtocolName as string)
+ this.customProtocolName = protocolName
this.validate()
}
@@ -155,17 +174,49 @@ export class DeviceProtocolComponent implements OnInit {
return
}
- for (const [key, value] of Object.entries(this.deviceProtocols[this.customProtocolName])) {
- this.customProtocolPropertyBearer.push({ propertyName: key, propertyValue: value as string })
+ for (const [protocolName, property] of Object.entries(this.deviceProtocols)) {
+ if (!this.customProtocols.has(protocolName)) {
+ this.customProtocols.set(protocolName, [])
+ }
+ for (const [key, value] of Object.entries(property)) {
+ this.customProtocols.get(protocolName)?.push({ propertyName: key, propertyValue: value as string })
+ }
}
}
- addCustomProtocolProperty() {
- this.customProtocolPropertyBearer.push({propertyName:'', propertyValue: ''})
+ addCustomProtocolProperty(protocolName: string) {
+ if (!this.customProtocols.has(protocolName)) {
+ this.customProtocols.set(protocolName, [])
+ }
+ this.customProtocols.forEach((p, pName) => {
+ if ( pName === protocolName) {
+ p.push({propertyName:'', propertyValue: ''})
+ }
+ })
+ }
+
+ removeCustomProtocolProperty(protocolName: string, property: ProtocolProperty) {
+ this.customProtocols.forEach((p, pName) => {
+ if ( pName === protocolName) {
+ p.splice(p.indexOf(property),1)
+ }
+ })
+ }
+
+ addCustomProtocol() {
+ this.customProtocols.set("", [])
+ this.customProtocolName = ""
+ this.validate()
}
- removeCustomProtocolProperty(property: ProtocolProperty) {
- this.customProtocolPropertyBearer.splice(this.customProtocolPropertyBearer.indexOf(property),1)
+ removeCustomProtocol(protocolName: string) {
+ if (this.customProtocols.has(protocolName)) {
+ this.customProtocols.delete(protocolName)
+ }
+ this.customProtocols.forEach((p, pName) => {
+ this.customProtocolName = pName
+ })
+ this.validate()
}
getDeviceProtocols(): protocol {
@@ -173,11 +224,15 @@ export class DeviceProtocolComponent implements OnInit {
if (this.protocolTemplateMode === this.TEMPLATE_BUILT_IN) {
this.deviceProtocols[this.builtinProtocolName as string] = Object.assign({}, this.builtinProtocolTemplateSelected)
} else {
- let property: properties = {}
- this.customProtocolPropertyBearer.forEach(p => {
- property[p.propertyName] = p.propertyValue
+ this.customProtocols.forEach((p, pName) => {
+ if (pName !== "") {
+ let property: properties = {}
+ p.forEach(p => {
+ property[p.propertyName] = p.propertyValue
+ })
+ this.deviceProtocols[pName] = property
+ }
})
- this.deviceProtocols[this.customProtocolName as string] = property
}
return this.deviceProtocols
}
From c7d4d0fff92fefeb0e085eae893277d53a53ee0d Mon Sep 17 00:00:00 2001
From: GaoJing <270615179@qq.com>
Date: Fri, 18 Apr 2025 10:04:42 +0800
Subject: [PATCH 2/2] fix: card body for device protocol list
---
.../device/device-protocol/device-protocol.component.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/web/src/app/metadata/device/device-protocol/device-protocol.component.html b/web/src/app/metadata/device/device-protocol/device-protocol.component.html
index 824fbec2..a4dff531 100644
--- a/web/src/app/metadata/device/device-protocol/device-protocol.component.html
+++ b/web/src/app/metadata/device/device-protocol/device-protocol.component.html
@@ -106,8 +106,8 @@
Add More Protocol
-