Fixes and improvements with comments

This commit is contained in:
GogoVega 2024-10-25 17:34:51 +02:00
parent eab512ef22
commit 83696abf9d
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -131,12 +131,15 @@
} }
} }
if (node._def.credentials) { if (node._def.credentials) {
const credsDefinition = node._def.credentials; const credDefinition = node._def.credentials;
const credsChanged = updateNodeCredentials(node, credsDefinition, this.inputClass); const credChanges = updateNodeCredentials(node, credDefinition, this.inputClass);
if (credsChanged) { if (Object.keys(credChanges).length) {
editState.changed = true; editState.changed = true;
editState.changes.credentials = node.credentials._; editState.changes.credentials = {
...(editState.changes.credentials || {}),
...credChanges
};
} }
} }
} }
@ -165,10 +168,11 @@
* @param node - the node containing the credentials * @param node - the node containing the credentials
* @param credDefinition - definition of the credentials * @param credDefinition - definition of the credentials
* @param prefix - prefix of the input fields * @param prefix - prefix of the input fields
* @return {boolean} whether anything has changed * @return {object} an object containing the modified properties
*/ */
function updateNodeCredentials(node, credDefinition, prefix) { function updateNodeCredentials(node, credDefinition, prefix) {
var changed = false; const changes = {};
if (!node.credentials) { if (!node.credentials) {
node.credentials = {_:{}}; node.credentials = {_:{}};
} else if (!node.credentials._) { } else if (!node.credentials._) {
@ -181,23 +185,32 @@
if (input.length > 0) { if (input.length > 0) {
var value = input.val(); var value = input.val();
if (credDefinition[cred].type == 'password') { if (credDefinition[cred].type == 'password') {
node.credentials['has_' + cred] = (value !== ""); if (value === '__PWRD__') {
// A cred value exists - no changes
// Skip if the credential has not changed } else if (value === '' && node.credentials['has_' + cred] === false) {
if ((value === '__PWRD__' && node.credentials._['has_' + cred] === true) || // Empty cred value exists - no changes
(value === "" && node.credentials._['has_' + cred] === false)) { } else if (value === node.credentials[cred]) {
continue; // A cred value exists locally in the editor - no changes
// Like the user sets a value, saves the config,
// reopens the config and save the config again
} else {
changes[cred] = node.credentials[cred];
node.credentials[cred] = value;
} }
changed = true; node.credentials['has_' + cred] = (value !== '');
} } else {
node.credentials[cred] = value; // Since these creds are loaded by the editor,
if (value != node.credentials._[cred]) { // values can be directly compared
changed = true; if (value !== node.credentials[cred]) {
changes[cred] = node.credentials[cred];
node.credentials[cred] = value;
}
} }
} }
} }
} }
return changed;
return changes;
} }
})(); })();