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

View File

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