mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-10 18:24:27 +05:00
fix: casting types in setupForm fixed #61
This commit is contained in:
@@ -167,6 +167,26 @@
|
||||
<script src="/static/app.js"></script>
|
||||
<script>
|
||||
window.onload = async function () {
|
||||
const fillData = (data) => {
|
||||
setInputValue('#network-hostname', data.hostname);
|
||||
setCheckboxValue('#network-use-dhcp', data.useDhcp);
|
||||
setInputValue('#network-static-ip', data.staticConfig.ip);
|
||||
setInputValue('#network-static-gateway', data.staticConfig.gateway);
|
||||
setInputValue('#network-static-subnet', data.staticConfig.subnet);
|
||||
setInputValue('#network-static-dns', data.staticConfig.dns);
|
||||
setBusy('#network-settings-busy', '#network-settings', false);
|
||||
|
||||
setInputValue('#sta-ssid', data.sta.ssid);
|
||||
setInputValue('#sta-password', data.sta.password);
|
||||
setInputValue('#sta-channel', data.sta.channel);
|
||||
setBusy('#sta-settings-busy', '#sta-settings', false);
|
||||
|
||||
setInputValue('#ap-ssid', data.ap.ssid);
|
||||
setInputValue('#ap-password', data.ap.password);
|
||||
setInputValue('#ap-channel', data.ap.channel);
|
||||
setBusy('#ap-settings-busy', '#ap-settings', false);
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/network/settings', { cache: 'no-cache' });
|
||||
if (!response.ok) {
|
||||
@@ -174,32 +194,16 @@
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
setInputValue('#network-hostname', result.hostname);
|
||||
setCheckboxValue('#network-use-dhcp', result.useDhcp);
|
||||
setInputValue('#network-static-ip', result.staticConfig.ip);
|
||||
setInputValue('#network-static-gateway', result.staticConfig.gateway);
|
||||
setInputValue('#network-static-subnet', result.staticConfig.subnet);
|
||||
setInputValue('#network-static-dns', result.staticConfig.dns);
|
||||
setBusy('#network-settings-busy', '#network-settings', false);
|
||||
fillData(result);
|
||||
|
||||
setInputValue('#sta-ssid', result.sta.ssid);
|
||||
setInputValue('#sta-password', result.sta.password);
|
||||
setInputValue('#sta-channel', result.sta.channel);
|
||||
setBusy('#sta-settings-busy', '#sta-settings', false);
|
||||
|
||||
setInputValue('#ap-ssid', result.ap.ssid);
|
||||
setInputValue('#ap-password', result.ap.password);
|
||||
setInputValue('#ap-channel', result.ap.channel);
|
||||
setBusy('#ap-settings-busy', '#ap-settings', false);
|
||||
setupForm('#network-settings', fillData, ['hostname']);
|
||||
setupNetworkScanForm('#network-scan', '#networks');
|
||||
setupForm('#sta-settings', fillData, ['sta.ssid', 'sta.password']);
|
||||
setupForm('#ap-settings', fillData, ['ap.ssid', 'ap.password']);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
setupForm('#network-settings');
|
||||
setupNetworkScanForm('#network-scan', '#networks');
|
||||
setupForm('#sta-settings');
|
||||
setupForm('#ap-settings');
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -809,7 +809,8 @@
|
||||
|
||||
const result = await response.json();
|
||||
fillData(result);
|
||||
setupForm('#portal-settings', fillData);
|
||||
|
||||
setupForm('#portal-settings', fillData, ['portal.login', 'portal.password']);
|
||||
setupForm('#system-settings', fillData);
|
||||
setupForm('#heating-settings', fillData);
|
||||
setupForm('#dhw-settings', fillData);
|
||||
@@ -817,9 +818,9 @@
|
||||
setupForm('#equitherm-settings', fillData);
|
||||
setupForm('#pid-settings', fillData);
|
||||
setupForm('#opentherm-settings', fillData);
|
||||
setupForm('#mqtt-settings', fillData);
|
||||
setupForm('#mqtt-settings', fillData, ['mqtt.user', 'mqtt.password', 'mqtt.prefix']);
|
||||
setupForm('#outdoor-sensor-settings', fillData);
|
||||
setupForm('#indoor-sensor-settings', fillData);
|
||||
setupForm('#indoor-sensor-settings', fillData, ['sensors.indoor.bleAddresss']);
|
||||
setupForm('#extpump-settings', fillData);
|
||||
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function setupForm(formSelector, onResultCallback = null) {
|
||||
function setupForm(formSelector, onResultCallback = null, noCastItems = []) {
|
||||
const form = document.querySelector(formSelector);
|
||||
if (!form) {
|
||||
return;
|
||||
@@ -68,7 +68,7 @@ function setupForm(formSelector, onResultCallback = null) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: form2json(fd)
|
||||
body: form2json(fd, noCastItems)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -635,15 +635,19 @@ function memberIdToVendor(memberId) {
|
||||
: "unknown vendor";
|
||||
}
|
||||
|
||||
function form2json(data) {
|
||||
function form2json(data, noCastItems = []) {
|
||||
let method = function (object, pair) {
|
||||
let keys = pair[0].replace(/\]/g, '').split('[');
|
||||
let key = keys[0];
|
||||
let value = pair[1];
|
||||
if (value === 'true' || value === 'false') {
|
||||
value = value === 'true';
|
||||
} else if (typeof (value) === 'string' && value.trim() !== '' && !isNaN(value)) {
|
||||
value = parseFloat(value);
|
||||
|
||||
if (!noCastItems.includes(keys.join('.'))) {
|
||||
if (value === 'true' || value === 'false') {
|
||||
value = value === 'true';
|
||||
|
||||
} else if (typeof (value) === 'string' && value.trim() !== '' && !isNaN(value)) {
|
||||
value = parseFloat(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (keys.length > 1) {
|
||||
|
||||
Reference in New Issue
Block a user