Streamline API calls from UI (incl. Fix #1311, #1314) (#1312)

* JSONeditor: Disable watchers when updating selections dynamically

* Refactor - Load last instance config when loading UI page

* LED Devices - Notify getproperties watchers for configured hostname

* Remove unused variable

* Fix #1314 - Additional classic & matrix configuration items were not saved
This commit is contained in:
LordGrey
2021-08-31 10:55:32 +02:00
committed by GitHub
parent 42e7f85864
commit 12cdd1d58a
7 changed files with 70 additions and 48 deletions

View File

@@ -383,22 +383,24 @@ function blackListLeds(nonBlacklistLedArray, blackList) {
}
function getLedConfig() {
var ledConfig = { classic: {}, matrix: {} };
var slConfig = window.serverConfig.ledConfig;
for (var key in slConfig.classic) {
if (typeof (slConfig.classic[key]) === "boolean")
var ledConfig = { classic: {}, matrix: {} };
var classicSchema = window.serverSchema.properties.ledConfig.properties.classic.properties;
for (var key in classicSchema) {
if (classicSchema[key].type === "boolean")
ledConfig.classic[key] = $('#ip_cl_' + key).is(':checked');
else if (Number.isInteger(slConfig.classic[key]))
else if (classicSchema[key].type === "integer")
ledConfig.classic[key] = parseInt($('#ip_cl_' + key).val());
else
ledConfig.classic[key] = $('#ip_cl_' + key).val();
}
for (var key in slConfig.matrix) {
if (typeof (slConfig.matrix[key]) === "boolean")
var matrixSchema = window.serverSchema.properties.ledConfig.properties.matrix.properties;
for (var key in matrixSchema) {
if (matrixSchema[key].type === "boolean")
ledConfig.matrix[key] = $('#ip_ma_' + key).is(':checked');
else if (Number.isInteger(slConfig.matrix[key]))
else if (matrixSchema[key].type === "integer")
ledConfig.matrix[key] = parseInt($('#ip_ma_' + key).val());
else
ledConfig.matrix[key] = $('#ip_ma_' + key).val();
@@ -876,6 +878,8 @@ $(document).ready(function () {
break;
case 'NONE':
conf_editor.getEditor(specOptPath + "host").enable();
//Trigger getProperties via host value
conf_editor.notifyWatchers(specOptPath + "host");
break;
case 'SELECT':
conf_editor.getEditor(specOptPath + "host").setValue("");
@@ -884,9 +888,8 @@ $(document).ready(function () {
break;
default:
conf_editor.getEditor(specOptPath + "host").disable();
//Reset host value, to trigger getProperties via host value
conf_editor.getEditor(specOptPath + "host").setValue("");
conf_editor.getEditor(specOptPath + "host").setValue(val);
//Trigger getProperties via host value
conf_editor.notifyWatchers(specOptPath + "host");
break;
}
@@ -1510,10 +1513,10 @@ async function getProperties_device(ledType, key, params) {
if (!devicesProperties[ledType][key]) {
const res = await requestLedDeviceProperties(ledType, params);
if (res && !res.error) {
var deviceProperties = res.info.properties;
var ledDeviceProperties = res.info.properties;
if (!jQuery.isEmptyObject(deviceProperties)) {
devicesProperties[ledType][key] = deviceProperties;
if (!jQuery.isEmptyObject(ledDeviceProperties)) {
devicesProperties[ledType][key] = ledDeviceProperties;
if (!window.readOnlyMode) {
$('#btn_submit_controller').attr('disabled', false);