Skip to content

Commit

Permalink
GH-18 | Simplify resetting settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jun 10, 2023
1 parent 5638b0d commit afa0ff1
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions octoprint_SpoolManager/static/js/ResetSettingsUtilV3.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,32 @@ function ResetSettingsUtilV3(pluginSettings) {
$.ajax({
url: `${API_BASEURL}plugin/${PLUGIN_ID_string}?action=resetSettings`,
type: "GET",
}).done(function(data) {
}).done(function(newSettingsData) {
new PNotify({
title: "Default settings saved!",
text: "The plugin settings have now been reset to the default values.<br>Please do a Browser reload (Strg + F5) to update all settings in the UI.",
type: "info",
hide: true,
});
// reset all values
for (let propName in data) {
const propValue = data[propName];
// nested object, like databaseSettings? only a depth of 1
if (typeof propValue == "object") {
for (let subPropName in propValue) {
subPropValue = propValue[subPropName];
pluginSettingsFromPlugin[propName][subPropName](propValue);
}
} else {
pluginSettingsFromPlugin[propName](propValue);

// Reset all values in in-memory storage
Object.entries(newSettingsData).forEach(([ key, value ]) => {
if (
typeof value !== "object" ||
!value
) {
pluginSettingsFromPlugin[key](value);

return;
}
}

Object.entries(value).forEach(([ nestedKey, nestedValue ]) => {
pluginSettingsFromPlugin[key][nestedKey](nestedValue);
});
});

// delegate to the client. So client is able to reset/init other values
mapSettingsToViewModel_function(data);
mapSettingsToViewModel_function(newSettingsData);
});
});

Expand Down

0 comments on commit afa0ff1

Please sign in to comment.