From 4c114b1106a10ca98952c598fc17e1f74d1f9765 Mon Sep 17 00:00:00 2001 From: Egor Savkin Date: Mon, 15 Jul 2024 17:34:48 +0800 Subject: [PATCH] Update cards Signed-off-by: Egor Savkin --- static/js/shop/options/validation.js | 32 +++++++++++++ static/js/shop_data.js | 68 +++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/static/js/shop/options/validation.js b/static/js/shop/options/validation.js index d0ee431..9fd1ab3 100644 --- a/static/js/shop/options/validation.js +++ b/static/js/shop/options/validation.js @@ -16,6 +16,36 @@ const ipv6 = (params) => { } } +const hostname = (params) => { + const maxHostnameLength = 253; + const maxLabelLength = 63; + const labelRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/; + + return (text) => { + if (text.length > maxHostnameLength) { + return false; + } + const labels = text.split('.'); + for (const label of labels) { + if (label.length < 1 || label.length > maxLabelLength) { + return false; + } + if (!labelRegex.test(label)) { + return false; + } + } + return true; + } +} + +const ipv4OrHost = (params) => { + const hostnameLocal = hostname(params); + const ipv4Local = ipv4(params); + return (text) => { + return ipv4Local(text) || hostnameLocal(text); + } +} + const ipv4or6 = (params) => { const ipv4Local = ipv4(params); const ipv6Local = ipv6(params); @@ -47,5 +77,7 @@ export const Validation = { ipv4: ipv4, ipv6: ipv6, ipv4or6: ipv4or6, + hostname: hostname, + ipv4OrHost: ipv4OrHost, frequency: frequency }; \ No newline at end of file diff --git a/static/js/shop_data.js b/static/js/shop_data.js index 9219aff..9dcb382 100644 --- a/static/js/shop_data.js +++ b/static/js/shop_data.js @@ -1084,10 +1084,24 @@ const shop_data = { validator: {name: "ipv4or6"}, fallback: {text: "DHCP", checked: false}, tip: "Set up IP address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, {type: "Switch", args: {title: "Ext power", outvar: "ext_pwr", "tip": "Use external power supply in order to reduce number of used EEM connectors"}}, {type: "Switch", args: {title: "Term #0", outvar: "term_0", tip: "Enable termination on ADC channel #0"}}, {type: "Switch", args: {title: "Term #1", outvar: "term_1", tip: "Enable termination on ADC channel #1"}} ], + crateless_options: [ + {type: "SwitchLine", args: {title: "IP", outvar: "ip", + validator: {name: "ipv4or6"}, + fallback: {text: "DHCP", checked: false}, + tip: "Set up IP address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, + ], options_class: "stabilizer", size: 'small', warnings: [ @@ -1118,10 +1132,24 @@ const shop_data = { validator: {name: "ipv4or6"}, fallback: {text: "DHCP", checked: false}, tip: "Set up IP address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, {type: "Switch", args: {title: "Ext power", outvar: "ext_pwr", "tip": "Use external power supply in order to reduce number of used EEM connectors"}}, {type: "Switch", args: {title: "Term #0", outvar: "term_0", tip: "Enable termination on ADC channel #0"}}, {type: "Switch", args: {title: "Term #1", outvar: "term_1", tip: "Enable termination on ADC channel #1"}} ], + crateless_options: [ + {type: "SwitchLine", args: {title: "IP", outvar: "ip", + validator: {name: "ipv4or6"}, + fallback: {text: "DHCP", checked: false}, + tip: "Set up IP address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, + ], options_class: "stabilizer", size: 'small', warnings: [ @@ -1207,7 +1235,25 @@ const shop_data = { '100Base-T Ethernet with PoE.' ], options: [ - {type: "Switch", args: {title: "Ext power", outvar: "ext_pwr", "tip": "Use external power supply in order to reduce number of used EEM connectors"}} + {type: "Switch", args: {title: "Ext power", outvar: "ext_pwr", "tip": "Use external power supply in order to reduce number of used EEM connectors"}}, + {type: "SwitchLine", args: {title: "Static IPv4", outvar: "ip", + validator: {name: "ipv4"}, + fallback: {text: "0.0.0.0", checked: false}, + tip: "Set up static IPv4 address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, + ], + crateless_options: [ + {type: "SwitchLine", args: {title: "Static IPv4", outvar: "ip", + validator: {name: "ipv4"}, + fallback: {text: "0.0.0.0", checked: false}, + tip: "Set up static IPv4 address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, ], size: 'small', warnings: [ @@ -1232,6 +1278,12 @@ const shop_data = { '100Base-T Ethernet with PoE.', 'Can stabilize temperature of Sinara 5432 DAC or external devices containing TEC and thermistor.' ], + crateless_options: [ + {type: "SwitchLine", args: {title: "IPv4", outvar: "ip", + validator: {name: "ipv4"}, + fallback: {text: "192.168.1.26/24", checked: false}, + tip: "Set up IP address used by the device"}}, + ], size: 'small', consumes: { hp: 4 @@ -1283,12 +1335,26 @@ const shop_data = { validator: {name: "ipv4or6"}, fallback: {text: "DHCP", checked: false}, tip: "Set up IP address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, {type: "Switch", args: {title: "Ext power", outvar: "ext_pwr", "tip": "Use external power supply in order to reduce number of used EEM connectors"}}, {type: "SwitchLine", args: {title: "Ext CLK", outvar: "ext_clk", fallback: {text: "125 MHz", checked: false}, validator: {name: "frequency", params: {min: 10e6, max: 1e9}}}}, {type: "Switch", args: {title: "Termination #0", outvar: "term_0", tip: "Enable termination on ADC channel #0"}}, {type: "Switch", args: {title: "Termination #1", outvar: "term_1", tip: "Enable termination on ADC channel #1"}} ], + crateless_options: [ + {type: "SwitchLine", args: {title: "Static IPv4", outvar: "ip", + validator: {name: "ipv4"}, + fallback: {text: "0.0.0.0", checked: false}, + tip: "Set up static IPv4 address used by the device"}}, + {type: "SwitchLine", args: {title: "MQTT broker address", outvar: "broker", + validator: {name: "ipv4OrHost"}, + fallback: {text: "mqtt", checked: false}, + tip: "Set up domain name or IPv4 of the MQTT broker"}}, + ], size: 'big', warnings: [ "no_eem_source",