1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Move data request into controller to speed up page load

This commit is contained in:
Joe Fiorini 2015-06-05 15:42:36 -04:00
parent 65d20e646d
commit 63b7ec8b67
3 changed files with 102 additions and 135 deletions

View File

@ -9,7 +9,7 @@ export default
'getModuleOptions', 'getModuleOptions',
'resolveVersions', 'resolveVersions',
'lodashAsPromised', 'lodashAsPromised',
function(factScanDataService, getModuleOptions, resolveVersions) { function(factScanDataService, getModuleOptions, resolveVersions, _) {
return function(hostIds, moduleName, leftDate, rightDate) { return function(hostIds, moduleName, leftDate, rightDate) {
var moduleOptions; var moduleOptions;
@ -29,11 +29,8 @@ export default
} }
]; ];
return getModuleOptions(hostIds[0]) return _(hostVersionParams)
.then(function(modules) { .map(function(versionParam) {
moduleOptions = modules;
return hostVersionParams;
}).thenMap(function(versionParam) {
var versionWithRequest = var versionWithRequest =
[ versionParam, [ versionParam,
factScanDataService. factScanDataService.

View File

@ -12,14 +12,16 @@ function controller($rootScope,
$routeParams, $routeParams,
$location, $location,
$q, $q,
initialFactData, moduleOptions,
getDataForComparison, getDataForComparison,
waitIndicator, waitIndicator,
moment, moment,
_) { _) {
// var inventoryId = $routeParams.id; // var inventoryId = $routeParams.id;
var hostIds = $routeParams.hosts.split(','); var hostIds = $routeParams.hosts.split(',');
var hosts = $routeParams.model.hosts; var hosts = $routeParams.model.hosts;
var moduleParam = $routeParams.module || 'packages';
$scope.hostIds = $routeParams.hosts; $scope.hostIds = $routeParams.hosts;
$scope.inventory = $routeParams.model.inventory; $scope.inventory = $routeParams.model.inventory;
@ -27,18 +29,18 @@ function controller($rootScope,
$scope.factModulePickersLabelLeft = "Compare facts collected on or before"; $scope.factModulePickersLabelLeft = "Compare facts collected on or before";
$scope.factModulePickersLabelRight = "To facts collected on or before"; $scope.factModulePickersLabelRight = "To facts collected on or before";
$scope.modules = initialFactData.moduleOptions; $scope.modules = moduleOptions;
var leftSearchRange = searchDateRange('yesterday');
var rightSearchRange = searchDateRange();
var searchConfig = var searchConfig =
{ leftRange: initialFactData.leftSearchRange, { leftRange: leftSearchRange,
rightRange: initialFactData.rightSearchRange rightRange: rightSearchRange
}; };
$scope.leftDate = initialFactData.leftSearchRange.from; $scope.leftDate = leftSearchRange.from;
$scope.rightDate = initialFactData.rightSearchRange.from; $scope.rightDate = rightSearchRange.from;
$scope.leftScanDate = initialFactData.leftScanDate;
$scope.rightScanDate = initialFactData.rightScanDate;
$scope.leftHostname = hosts[0].name; $scope.leftHostname = hosts[0].name;
$scope.rightHostname = hosts.length > 1 ? hosts[1].name : hosts[0].name; $scope.rightHostname = hosts.length > 1 ? hosts[1].name : hosts[0].name;
@ -53,9 +55,9 @@ function controller($rootScope,
var activeModule = searchConfig.module; var activeModule = searchConfig.module;
if (!factData) { waitIndicator('start');
factData =
getDataForComparison( return getDataForComparison(
hostIds, hostIds,
activeModule.name, activeModule.name,
leftRange, leftRange,
@ -68,13 +70,8 @@ function controller($rootScope,
$scope.rightScanDate = moment(responses[1].timestamp); $scope.rightScanDate = moment(responses[1].timestamp);
return data; return data;
}, true); })
}
waitIndicator('start');
return _(factData)
.promise()
.then(function(facts) { .then(function(facts) {
// Make sure we always start comparison against // Make sure we always start comparison against
// a non-empty array // a non-empty array
@ -183,7 +180,7 @@ function controller($rootScope,
$scope.$watch('rightDate', dateWatcher('rightRange'), true); $scope.$watch('rightDate', dateWatcher('rightRange'), true);
$scope.setActiveModule(initialFactData.moduleName, initialFactData); $scope.setActiveModule(moduleParam);
} }
export default export default
@ -192,7 +189,7 @@ export default
'$routeParams', '$routeParams',
'$location', '$location',
'$q', '$q',
'factScanData', 'moduleOptions',
'getDataForComparison', 'getDataForComparison',
'Wait', 'Wait',
'moment', 'moment',

View File

@ -4,8 +4,6 @@
* All Rights Reserved * All Rights Reserved
*************************************************/ *************************************************/
import {searchDateRange} from './search-date-range';
import moment from 'tower/shared/moment/moment';
export default { export default {
name: 'systemTracking', name: 'systemTracking',
@ -14,40 +12,15 @@ export default {
templateUrl: '/static/js/system-tracking/system-tracking.partial.html', templateUrl: '/static/js/system-tracking/system-tracking.partial.html',
reloadOnSearch: false, reloadOnSearch: false,
resolve: { resolve: {
factScanData: moduleOptions:
[ 'getDataForComparison', [ 'getModuleOptions',
'lodashAsPromised', 'lodashAsPromised',
'$route', '$route',
'$location', function(getModuleOptions, _, $route) {
function(getDataForComparison, _, $route, $location) {
var hostIds = $route.current.params.hosts.split(','); var hostIds = $route.current.params.hosts.split(',');
var moduleParam = $location.search().module || 'packages';
var leftDate = searchDateRange('yesterday');
var rightDate = searchDateRange();
if (hostIds.length === 1) {
hostIds = hostIds.concat(hostIds[0]);
}
var data = var data =
getDataForComparison(hostIds, moduleParam, leftDate, rightDate). getModuleOptions(hostIds[0])
then(function(factDataAndModules) {
var moduleOptions = factDataAndModules[0];
var factResponses = factDataAndModules[1];
var factData = _.pluck(factResponses, 'fact');
factData.leftSearchRange = leftDate;
factData.rightSearchRange = rightDate;
factData.leftScanDate = moment(factResponses[0].timestamp);
factData.rightScanDate = moment(factResponses[1].timestamp);
factData.moduleName = moduleParam;
factData.moduleOptions = moduleOptions;
return factData;
}, true)
.value(); .value();
return data; return data;