diff --git a/awx/ui/static/js/system-tracking/data-services/get-data-for-comparison.factory.js b/awx/ui/static/js/system-tracking/data-services/get-data-for-comparison.factory.js index 1eea1edc54..8865d62bea 100644 --- a/awx/ui/static/js/system-tracking/data-services/get-data-for-comparison.factory.js +++ b/awx/ui/static/js/system-tracking/data-services/get-data-for-comparison.factory.js @@ -6,17 +6,24 @@ export default [ 'factScanDataService', + 'getModuleOptions', 'lodashAsPromised', - function(factScanDataService, _) { + function(factScanDataService, getModuleOptions, _) { return function(hostIds, moduleName, leftDate, rightDate) { + var moduleOptions; + if (hostIds.length === 1) { hostIds = hostIds.concat(hostIds[0]); } - return _(hostIds) - .promise() - .thenMap(function(hostId, index) { + return getModuleOptions(hostIds[0]) + .then(function(modules) { + moduleOptions = modules; + return modules; + }).then(function() { + return hostIds; + }).thenMap(function(hostId, index) { var date = leftDate; var fetchScanNumber; @@ -42,6 +49,9 @@ export default .bind(factScanDataService); return getHostFacts(params); + }).then(function(hostFacts) { + hostFacts.moduleOptions = moduleOptions; + return hostFacts; }); }; } diff --git a/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js b/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js new file mode 100644 index 0000000000..031396da9d --- /dev/null +++ b/awx/ui/static/js/system-tracking/data-services/get-module-options.factory.js @@ -0,0 +1,56 @@ +var moduleConfig = + { 'packages': + { compareKey: ['release', 'version'], + nameKey: 'name', + displayType: 'flat' + }, + 'services': + { compareKey: ['state', 'source'], + nameKey: 'name', + displayType: 'flat' + }, + 'files': + { compareKey: ['size', 'mode', 'md5', 'mtime', 'gid', 'uid'], + nameKey: 'path', + displayType: 'flat' + }, + 'custom': + { displayType: 'nested' + } + }; + +function makeModule(option) { + var name = option[0]; + var displayName = option[1]; + var config = moduleConfig.hasOwnProperty(name) ? + moduleConfig[name] : moduleConfig.custom; + + return { + name: name, + displayName: displayName, + compareKey: config.compareKey, + nameKey: config.nameKey, + displayType: config.displayType + }; +} + +function factory(hostId, rest, getBasePath, _) { + var url = [ getBasePath('hosts') + hostId, + 'fact_versions' + ].join('/'); + + rest.setUrl(url); + return _(rest.options()) + .then(function(response) { + return response.data.actions.GET.module.choices; + }).thenMap(makeModule); +} + +export default + [ 'Rest', + 'GetBasePath', + 'lodashAsPromised', + function(rest, getBasePath, lodash) { + return _.partialRight(factory, rest, getBasePath, lodash); + } + ]; diff --git a/awx/ui/static/js/system-tracking/main.js b/awx/ui/static/js/system-tracking/main.js index 7f20e86d89..be08358455 100644 --- a/awx/ui/static/js/system-tracking/main.js +++ b/awx/ui/static/js/system-tracking/main.js @@ -7,6 +7,7 @@ import route from './system-tracking.route'; import factScanDataService from './data-services/fact-scan-data.service'; import getDataForComparison from './data-services/get-data-for-comparison.factory'; +import getModuleOptions from './data-services/get-module-options.factory'; import controller from './system-tracking.controller'; import stringOrDateFilter from './string-or-date.filter'; import shared from 'tower/shared/main'; @@ -22,6 +23,7 @@ export default ]) .service('factScanDataService', factScanDataService) .factory('getDataForComparison', getDataForComparison) + .factory('getModuleOptions', getModuleOptions) .filter('stringOrDate', stringOrDateFilter) .controller('systemTracking', controller) .config(['$routeProvider', function($routeProvider) { diff --git a/awx/ui/static/js/system-tracking/system-tracking.controller.js b/awx/ui/static/js/system-tracking/system-tracking.controller.js index 8244874bbf..f3dc587ca5 100644 --- a/awx/ui/static/js/system-tracking/system-tracking.controller.js +++ b/awx/ui/static/js/system-tracking/system-tracking.controller.js @@ -27,34 +27,7 @@ function controller($rootScope, $scope.factModulePickersLabelLeft = "Compare facts collected on"; $scope.factModulePickersLabelRight = "To facts collected on"; - $scope.modules = - [{ name: 'packages', - displayName: 'Packages', - compareKey: ['release', 'version'], - nameKey: 'name', - isActive: true, - displayType: 'flat' - }, - { name: 'services', - compareKey: ['state', 'source'], - nameKey: 'name', - displayName: 'Services', - isActive: false, - displayType: 'flat' - }, - { name: 'files', - displayName: 'Files', - nameKey: 'path', - compareKey: ['size', 'mode', 'md5', 'mtime', 'gid', 'uid'], - isActive: false, - displayType: 'flat' - }, - { name: 'ansible', - displayName: 'Ansible', - isActive: false, - displayType: 'nested' - } - ]; + $scope.modules = initialFactData.moduleOptions; // Use this to determine how to orchestrate the services var viewType = hostIds.length > 1 ? 'multiHost' : 'singleHost';