Fix "undefined" settings values not saving

Fixes #2494
This commit is contained in:
Gina Häußge committed 2018-03-23 14:17:23 +01:00
1 parent 9af6b42bdd
commit 23f130da58
2 files changed
+20 -10

No files matched your search

+11 -3
View File
@@ -91,6 +91,14 @@
return params;
};
var replaceUndefinedWithNull = function(key, value) {
if (value === undefined) {
return null;
} else {
return value;
}
};
OctoPrintClient.prototype.getBaseUrl = function() {
var url = this.options.baseurl;
if (!_.endsWith(url, "/")) {
@@ -165,7 +173,7 @@
};
OctoPrintClient.prototype.postJson = function(url, data, opts) {
return this.post(url, JSON.stringify(data), contentTypeJson(opts));
return this.post(url, JSON.stringify(data, replaceUndefinedWithNull), contentTypeJson(opts));
};
OctoPrintClient.prototype.put = function(url, data, opts) {
@@ -173,7 +181,7 @@
};
OctoPrintClient.prototype.putJson = function(url, data, opts) {
return this.put(url, JSON.stringify(data), contentTypeJson(opts));
return this.put(url, JSON.stringify(data, replaceUndefinedWithNull), contentTypeJson(opts));
};
OctoPrintClient.prototype.patch = function(url, data, opts) {
@@ -181,7 +189,7 @@
};
OctoPrintClient.prototype.patchJson = function(url, data, opts) {
return this.patch(url, JSON.stringify(data), contentTypeJson(opts));
return this.patch(url, JSON.stringify(data, replaceUndefinedWithNull), contentTypeJson(opts));
};
OctoPrintClient.prototype.delete = function(url, opts) {
+9 -7
View File
@@ -911,15 +911,12 @@ function splitTextToArray(text, sep, stripEmpty, filter) {
* and is optimized to check for value changes, not key updates.
*/
function hasDataChanged(data, oldData) {
if (data == undefined) {
// noinspection EqualityComparisonWithCoercionJS
if (data == oldData && data == undefined) {
return false;
}
if (oldData == undefined) {
return true;
}
if (_.isPlainObject(data)) {
if (_.isPlainObject(data) && _.isPlainObject(oldData)) {
return _.any(_.keys(data), function(key) {return hasDataChanged(data[key], oldData[key]);});
} else {
return !_.isEqual(data, oldData);
@@ -956,10 +953,12 @@ function hasDataChanged(data, oldData) {
* and is optimized to check for value changes, not key updates.
*/
function getOnlyChangedData(data, oldData) {
// noinspection EqualityComparisonWithCoercionJS
if (data == undefined) {
return {};
}
// noinspection EqualityComparisonWithCoercionJS
if (oldData == undefined) {
return data;
}
@@ -972,17 +971,20 @@ function getOnlyChangedData(data, oldData) {
var retval = {};
_.forOwn(root, function(value, key) {
var oldValue = undefined;
// noinspection EqualityComparisonWithCoercionJS
if (oldRoot != undefined && oldRoot.hasOwnProperty(key)) {
oldValue = oldRoot[key];
}
if (_.isPlainObject(value)) {
// noinspection EqualityComparisonWithCoercionJS
if (oldValue == undefined) {
retval[key] = value;
} else if (hasDataChanged(value, oldValue)) {
retval[key] = f(value, oldValue);
}
} else {
if (!_.isEqual(value, oldValue)) {
// noinspection EqualityComparisonWithCoercionJS
if (!(value == oldValue && value == undefined) && !_.isEqual(value, oldValue)) {
retval[key] = value;
}
}