1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

[system_tracking] Refactor flat comparison logic

This commit is contained in:
Joe Fiorini 2015-06-12 09:38:53 -04:00
parent 06da1e16c2
commit b0d773325b
2 changed files with 35 additions and 48 deletions

View File

@ -33,12 +33,17 @@ export default
var matchingFact = _.where(comparatorFacts.facts, searcher);
var diffs;
if (_.isEmpty(matchingFact)) {
if (!_.isUndefined(factTemplate)) {
basisValue = factTemplate.render(basisFact);
slottedValues = slotFactValues(basisFacts.position, basisValue, 'absent');
if (_.isEmpty(matchingFact)) {
comparatorValue = 'absent';
} else {
comparatorValue = factTemplate.render(matchingFact[0]);
}
slottedValues = slotFactValues(basisFacts.position, basisValue, comparatorValue);
diffs =
{ keyName: basisFact[nameKey],
@ -48,60 +53,40 @@ export default
} else {
diffs =
_.map(basisFact, function(value, key) {
var slottedValues = slotFactValues(basisFacts.position, value, 'absent');
if (_.isEmpty(matchingFact)) {
matchingFact = {};
} else {
matchingFact = matchingFact[0];
}
return { keyName: key,
diffs =
_(basisFact).map(function(value, key) {
var slottedValues = slotFactValues(basisFacts.position, value, matchingFact[key] || 'absent');
var keyName;
if (slottedValues.right !== 'absent') {
if(slottedValues.left === slottedValues.right) {
return;
}
if (!_.include(compareKeys, key)) {
return;
}
keyName = basisFact[nameKey];
} else {
keyName = key;
}
return { keyName: keyName,
value1: slottedValues.left,
value1IsAbsent: slottedValues.left === 'absent',
value2: slottedValues.right,
value2IsAbsent: slottedValues.right === 'absent'
};
});
}
} else {
matchingFact = matchingFact[0];
if (!_.isUndefined(factTemplate)) {
basisValue = factTemplate.render(basisFact);
comparatorValue = factTemplate.render(matchingFact);
slottedValues = slotFactValues(basisFacts.position, basisValue, comparatorValue);
if (basisValue !== comparatorValue) {
diffs =
{ keyName: basisFact[nameKey],
value1: slottedValues.left,
value2: slottedValues.right
};
}
} else {
diffs = _(compareKeys)
.map(function(key) {
var slottedValues = slotFactValues(basisFacts.position,
basisFact[key],
matchingFact[key]);
if (slottedValues.left !== slottedValues.right) {
return {
keyName: basisFact[nameKey],
value1: slottedValues.left,
value2: slottedValues.right
};
}
}).compact()
.value();
}
}
var descriptor =
{ displayKeyPath: basisFact[nameKey],
nestingLevel: 0,

View File

@ -54,7 +54,9 @@ describe('CompareFacts.Flat', function() {
facts:
[{ keyName: 'foo',
value1: 'bar',
value2: 'baz'
value1IsAbsent: false,
value2: 'baz',
value2IsAbsent: false
}]
}]);
});