Get available modules from OPTIONS endpoint

This commit is contained in:
Joe Fiorini
2015-05-28 11:26:43 -04:00
parent 657b41510c
commit caf7c30de7
4 changed files with 73 additions and 32 deletions

View File

@@ -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;
});
};
}

View File

@@ -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);
}
];

View File

@@ -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) {

View File

@@ -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';