mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Present a single date picker for host-to-host
This commit is contained in:
parent
0d81d4a62b
commit
6edee0a864
@ -0,0 +1,36 @@
|
|||||||
|
export default
|
||||||
|
function dedupeVersions(nonEmptyResults) {
|
||||||
|
|
||||||
|
if (_.any(nonEmptyResults, 'versions.length', 0)) {
|
||||||
|
return _.pluck(nonEmptyResults, 'versions[0]');
|
||||||
|
}
|
||||||
|
|
||||||
|
var firstTimestamp = nonEmptyResults[0].versions[0].timestamp;
|
||||||
|
|
||||||
|
var hostIdsWithDupes =
|
||||||
|
_(nonEmptyResults)
|
||||||
|
.pluck('versions[0]')
|
||||||
|
.filter('timestamp', firstTimestamp)
|
||||||
|
.map(function(version, index) {
|
||||||
|
return nonEmptyResults[index].hostId;
|
||||||
|
})
|
||||||
|
.value();
|
||||||
|
|
||||||
|
if (hostIdsWithDupes.length === 1) {
|
||||||
|
return _.pluck(nonEmptyResults, 'versions[0]');
|
||||||
|
}
|
||||||
|
|
||||||
|
var bestScanResults = _.max(nonEmptyResults, "versions.length");
|
||||||
|
|
||||||
|
return nonEmptyResults.map(function(scan, index) {
|
||||||
|
var hasDupe =
|
||||||
|
_.include(hostIdsWithDupes, scan.hostId);
|
||||||
|
|
||||||
|
if (hasDupe && index === 1) {
|
||||||
|
return bestScanResults.versions[0];
|
||||||
|
} else {
|
||||||
|
return bestScanResults.versions[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
@ -51,7 +51,8 @@ function (Rest, GetBasePath, ProcessErrors, _) {
|
|||||||
Rest.setUrl(url);
|
Rest.setUrl(url);
|
||||||
promise = Rest.get();
|
promise = Rest.get();
|
||||||
return promise.then(function(response) {
|
return promise.then(function(response) {
|
||||||
return response.data.results;
|
versionParams.versions = response.data.results;
|
||||||
|
return versionParams;
|
||||||
}).catch(function (response) {
|
}).catch(function (response) {
|
||||||
ProcessErrors(null, response.data, response.status, null, {
|
ProcessErrors(null, response.data, response.status, null, {
|
||||||
hdr: 'Error!',
|
hdr: 'Error!',
|
||||||
|
@ -4,15 +4,20 @@
|
|||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*************************************************/
|
*************************************************/
|
||||||
|
|
||||||
|
import dedupeVersions from './dedupe-versions';
|
||||||
|
|
||||||
export default
|
export default
|
||||||
[ 'factScanDataService',
|
[ 'factScanDataService',
|
||||||
'getModuleOptions',
|
'getModuleOptions',
|
||||||
'resolveVersions',
|
'resolveEmptyVersions',
|
||||||
'lodashAsPromised',
|
'lodashAsPromised',
|
||||||
function(factScanDataService, getModuleOptions, resolveVersions, _) {
|
function(factScanDataService, getModuleOptions, resolveEmptyVersions, _) {
|
||||||
return function(hostIds, moduleName, leftDate, rightDate) {
|
return function(hostIds, moduleName, leftDate, rightDate) {
|
||||||
|
|
||||||
|
var singleHostMode = false;
|
||||||
|
|
||||||
if (hostIds.length === 1) {
|
if (hostIds.length === 1) {
|
||||||
|
singleHostMode = true;
|
||||||
hostIds = hostIds.concat(hostIds[0]);
|
hostIds = hostIds.concat(hostIds[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,26 +32,36 @@ export default
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
return _(hostVersionParams)
|
return _(factScanDataService.getVersion(hostVersionParams[1]))
|
||||||
.map(function(versionParam) {
|
.then(function(result) {
|
||||||
var versionWithRequest =
|
return resolveEmptyVersions(result);
|
||||||
[ versionParam,
|
}).thenAll(function(firstResult) {
|
||||||
factScanDataService.
|
|
||||||
getVersion(versionParam)
|
|
||||||
];
|
|
||||||
|
|
||||||
return versionWithRequest;
|
return factScanDataService.getVersion(hostVersionParams[0])
|
||||||
}).thenAll(function(versions) {
|
.then(function(secondResult) {
|
||||||
return resolveVersions(versions);
|
if (_.isEmpty(secondResult.versions)) {
|
||||||
}, true)
|
secondResult = resolveEmptyVersions(secondResult);
|
||||||
.thenMap(function(versionData) {
|
}
|
||||||
|
|
||||||
|
return [firstResult, secondResult];
|
||||||
|
});
|
||||||
|
}).thenAll(function(results) {
|
||||||
|
var finalSet;
|
||||||
|
|
||||||
|
if (singleHostMode) {
|
||||||
|
finalSet = dedupeVersions(results.reverse());
|
||||||
|
} else {
|
||||||
|
finalSet = _.pluck(results, 'versions[0]').reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalSet;
|
||||||
|
}).thenMap(function(versionData) {
|
||||||
if (versionData) {
|
if (versionData) {
|
||||||
return factScanDataService.getFacts(versionData);
|
return factScanDataService.getFacts(versionData);
|
||||||
} else {
|
} else {
|
||||||
return { fact: [] };
|
return { fact: [] };
|
||||||
}
|
}
|
||||||
})
|
}).thenAll(function(hostFacts) {
|
||||||
.thenAll(function(hostFacts) {
|
|
||||||
return hostFacts;
|
return hostFacts;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
import moment from 'tower/shared/moment/moment';
|
||||||
|
|
||||||
|
function resolveEmptyVersions(service, _, candidate, previousResult) {
|
||||||
|
|
||||||
|
candidate = _.merge({}, candidate);
|
||||||
|
|
||||||
|
if (_.isEmpty(candidate.versions)) {
|
||||||
|
var originalStartDate = candidate.dateRange.from.clone();
|
||||||
|
|
||||||
|
if (!_.isUndefined(previousResult)) {
|
||||||
|
candidate.dateRange.from = moment(previousResult.versions[0].timestamp);
|
||||||
|
} else {
|
||||||
|
candidate.dateRange.from = originalStartDate.clone().subtract(1, 'year');
|
||||||
|
}
|
||||||
|
|
||||||
|
candidate.dateRange.to = originalStartDate;
|
||||||
|
|
||||||
|
return service.getVersion(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _.promise(candidate);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default
|
||||||
|
[ 'factScanDataService',
|
||||||
|
'lodashAsPromised',
|
||||||
|
function(factScanDataService, lodash) {
|
||||||
|
return _.partial(resolveEmptyVersions, factScanDataService, lodash);
|
||||||
|
}
|
||||||
|
];
|
@ -1,86 +0,0 @@
|
|||||||
function resolveVersions(service, _, results) {
|
|
||||||
|
|
||||||
function transformToObjects(versionArray) {
|
|
||||||
|
|
||||||
var converted = versionArray[0];
|
|
||||||
converted.versions = versionArray[1];
|
|
||||||
|
|
||||||
return converted;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveEmpties(result) {
|
|
||||||
|
|
||||||
var newResult = _.merge({}, result);
|
|
||||||
|
|
||||||
if (_.isEmpty(newResult.versions)) {
|
|
||||||
var originalStartDate = result.dateRange.from.clone();
|
|
||||||
|
|
||||||
newResult.dateRange.from = originalStartDate.clone().subtract(1, 'year');
|
|
||||||
newResult.dateRange.to = originalStartDate;
|
|
||||||
|
|
||||||
return [newResult, service.getVersion(newResult)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return [newResult, _.promise(newResult.versions)];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveDuplicates(nonEmptyResults) {
|
|
||||||
var allSameHost =
|
|
||||||
_.every(nonEmptyResults, { 'hostId': nonEmptyResults[0].hostId });
|
|
||||||
|
|
||||||
if (allSameHost) {
|
|
||||||
|
|
||||||
if (_.any(nonEmptyResults, 'versions.length', 0)) {
|
|
||||||
return _.pluck(nonEmptyResults, 'versions[0]');
|
|
||||||
}
|
|
||||||
|
|
||||||
var firstTimestamp = nonEmptyResults[0].versions[0].timestamp;
|
|
||||||
|
|
||||||
var hostIdsWithDupes =
|
|
||||||
_(nonEmptyResults)
|
|
||||||
.pluck('versions[0]')
|
|
||||||
.filter('timestamp', firstTimestamp)
|
|
||||||
.map(function(version, index) {
|
|
||||||
return nonEmptyResults[index].hostId;
|
|
||||||
})
|
|
||||||
.value();
|
|
||||||
|
|
||||||
if (hostIdsWithDupes.length === 1) {
|
|
||||||
return _.pluck(nonEmptyResults, 'versions[0]');
|
|
||||||
}
|
|
||||||
|
|
||||||
return nonEmptyResults.map(function(scan, index) {
|
|
||||||
var hasDupe =
|
|
||||||
_.include(hostIdsWithDupes, scan.hostId);
|
|
||||||
|
|
||||||
if (hasDupe && index === 1) {
|
|
||||||
return scan.versions[1];
|
|
||||||
} else {
|
|
||||||
return scan.versions[0];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return _.pluck(nonEmptyResults, 'versions[0]');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _(results)
|
|
||||||
.map(transformToObjects)
|
|
||||||
.map(resolveEmpties)
|
|
||||||
.thenAll(function(resolved) {
|
|
||||||
var versionObjects = resolved.map(transformToObjects);
|
|
||||||
return resolveDuplicates(versionObjects);
|
|
||||||
}, true)
|
|
||||||
.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
export default
|
|
||||||
[ 'factScanDataService',
|
|
||||||
'lodashAsPromised',
|
|
||||||
function(factScanDataService, lodash) {
|
|
||||||
return _.partial(resolveVersions, factScanDataService, lodash);
|
|
||||||
}
|
|
||||||
];
|
|
@ -8,7 +8,7 @@ import route from './system-tracking.route';
|
|||||||
import factScanDataService from './data-services/fact-scan-data.service';
|
import factScanDataService from './data-services/fact-scan-data.service';
|
||||||
import getDataForComparison from './data-services/get-data-for-comparison.factory';
|
import getDataForComparison from './data-services/get-data-for-comparison.factory';
|
||||||
import getModuleOptions from './data-services/get-module-options.factory';
|
import getModuleOptions from './data-services/get-module-options.factory';
|
||||||
import resolveVersions from './data-services/resolve-versions.factory';
|
import resolveEmptyVersions from './data-services/resolve-empty-versions.factory';
|
||||||
import controller from './system-tracking.controller';
|
import controller from './system-tracking.controller';
|
||||||
import stringOrDateFilter from './string-or-date.filter';
|
import stringOrDateFilter from './string-or-date.filter';
|
||||||
import shared from 'tower/shared/main';
|
import shared from 'tower/shared/main';
|
||||||
@ -24,7 +24,7 @@ export default
|
|||||||
.service('factScanDataService', factScanDataService)
|
.service('factScanDataService', factScanDataService)
|
||||||
.factory('getDataForComparison', getDataForComparison)
|
.factory('getDataForComparison', getDataForComparison)
|
||||||
.factory('getModuleOptions', getModuleOptions)
|
.factory('getModuleOptions', getModuleOptions)
|
||||||
.factory('resolveVersions', resolveVersions)
|
.factory('resolveEmptyVersions', resolveEmptyVersions)
|
||||||
.filter('stringOrDate', stringOrDateFilter)
|
.filter('stringOrDate', stringOrDateFilter)
|
||||||
.controller('systemTracking', controller)
|
.controller('systemTracking', controller)
|
||||||
.config(['$routeProvider', function($routeProvider) {
|
.config(['$routeProvider', function($routeProvider) {
|
||||||
|
@ -23,11 +23,17 @@ function controller($rootScope,
|
|||||||
var hosts = $routeParams.model.hosts;
|
var hosts = $routeParams.model.hosts;
|
||||||
var moduleParam = $routeParams.module || 'packages';
|
var moduleParam = $routeParams.module || 'packages';
|
||||||
|
|
||||||
|
$scope.compareMode =
|
||||||
|
hostIds.length === 1 ? 'single-host' : 'host-to-host';
|
||||||
$scope.hostIds = $routeParams.hosts;
|
$scope.hostIds = $routeParams.hosts;
|
||||||
$scope.inventory = $routeParams.model.inventory;
|
$scope.inventory = $routeParams.model.inventory;
|
||||||
|
|
||||||
$scope.factModulePickersLabelLeft = "Compare latest facts collected on or before";
|
if ($scope.compareMode === 'host-to-host') {
|
||||||
$scope.factModulePickersLabelRight = "To latest facts collected on or before";
|
$scope.factModulePickersLabelLeft = "Compare latest facts collected across both hosts on or before";
|
||||||
|
} else {
|
||||||
|
$scope.factModulePickersLabelLeft = "Compare latest facts collected on or before";
|
||||||
|
$scope.factModulePickersLabelRight = "To latest facts collected on or before";
|
||||||
|
}
|
||||||
|
|
||||||
$scope.modules = moduleOptions;
|
$scope.modules = moduleOptions;
|
||||||
|
|
||||||
@ -53,6 +59,9 @@ function controller($rootScope,
|
|||||||
var rightRange = searchConfig.rightRange;
|
var rightRange = searchConfig.rightRange;
|
||||||
var activeModule = searchConfig.module;
|
var activeModule = searchConfig.module;
|
||||||
|
|
||||||
|
if ($scope.compareMode === 'host-to-host') {
|
||||||
|
rightRange = searchConfig.leftRange;
|
||||||
|
}
|
||||||
|
|
||||||
waitIndicator('start');
|
waitIndicator('start');
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<span class="FactModulePickers-label">{{ factModulePickersLabelLeft }}</span>
|
<span class="FactModulePickers-label">{{ factModulePickersLabelLeft }}</span>
|
||||||
<date-picker date="leftDate"></date-picker>
|
<date-picker date="leftDate"></date-picker>
|
||||||
</div>
|
</div>
|
||||||
<div class="FactModulePickers-dateContainer FactModulePickers-dateContainer--right">
|
<div class="FactModulePickers-dateContainer FactModulePickers-dateContainer--right" ng-show="compareMode == 'single-host'">
|
||||||
<span class="FactModulePickers-label">{{ factModulePickersLabelRight }}</span>
|
<span class="FactModulePickers-label">{{ factModulePickersLabelRight }}</span>
|
||||||
<date-picker date="rightDate"></date-picker>
|
<date-picker date="rightDate"></date-picker>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user