diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 570ec5f70c..9f3095896c 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -408,11 +408,10 @@ angular.module('Tower', [ templateUrl: urlPrefix + 'partials/home.html', controller: 'Home', resolve: { - graphData: function($q, jobStatusGraphData) { + graphData: function($q, jobStatusGraphData, hostCountGraphData) { return $q.all({ - jobStatus: jobStatusGraphData.get("month", "all").then(function(data) { - return data; - }) + jobStatus: jobStatusGraphData.get("month", "all"), + hostCounts: hostCountGraphData.get() }); } } diff --git a/awx/ui/static/js/directives/host-count-graph.js b/awx/ui/static/js/directives/host-count-graph.js index 7981c88c9a..24d532b53e 100644 --- a/awx/ui/static/js/directives/host-count-graph.js +++ b/awx/ui/static/js/directives/host-count-graph.js @@ -7,10 +7,13 @@ angular.module('DashboardGraphs'). link: link }; - function link(scope, element, attrs) { + function link(scope, element, attr) { var url, license, license_graph; - url = getBasePath('config'); + scope.$watch(attr.data, function(data) { + if(!data) return; + createGraph(data.hosts, data.license); + }); angular.element($window).on('resize', function(e) { if(!license_graph) return; @@ -22,38 +25,8 @@ angular.module('DashboardGraphs'). }); - Rest.setUrl(url); - Rest.get() - .success(function (data){ - license = data.license_info.instance_count; - scope.$emit('licenseCountReady', license); - }) - .error(function (data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to get: ' + url + ' GET returned: ' + status }); - }); - if (scope.removeLicenseCountReady) { - scope.removeLicenseCountReady(); - } - scope.removeLicenseCountReady = scope.$on('licenseCountReady', function (e, license) { - url = getBasePath('dashboard')+'graphs/inventory/'; - Rest.setUrl(url); - Rest.get() - .success(function (data) { - scope.$emit('hostDataReady', data, license); - }) - .error(function (data, status) { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Failed to get: ' + url + ' GET returned: ' + status }); - }); - - }); - - if (scope.removeHostDataReady) { - scope.removeHostDataReady(); - } - scope.removeHostDataReady = scope.$on('hostDataReady', function (e, data, license) { + function createGraph(data, license) { //url = getBasePath('dashboard')+'graphs/'; var graphData = [ @@ -137,6 +110,6 @@ angular.module('DashboardGraphs'). return license_graph; - }); + } } }]); diff --git a/awx/ui/static/js/services/data-services.js b/awx/ui/static/js/services/data-services.js new file mode 100644 index 0000000000..fb6b4dc4fd --- /dev/null +++ b/awx/ui/static/js/services/data-services.js @@ -0,0 +1 @@ +angular.module('DataServices', []); diff --git a/awx/ui/static/js/services/host-count-graph-data.js b/awx/ui/static/js/services/host-count-graph-data.js new file mode 100644 index 0000000000..db447cc640 --- /dev/null +++ b/awx/ui/static/js/services/host-count-graph-data.js @@ -0,0 +1,44 @@ +angular.module('DataServices') + .service('hostCountGraphData', + ["Rest", + "GetBasePath", + "ProcessErrors", + "$q", + HostCountGraphData]); + +function HostCountGraphData(Rest, getBasePath, processErrors, $q) { + + function pluck(property, promise) { + return promise.then(function(value) { + return value[property]; + }); + } + + function getLicenseData() { + url = getBasePath('config'); + Rest.setUrl(url); + return Rest.get() + .then(function (data){ + license = data.data.license_info.instance_count; + return license; + }) + } + + function getHostData() { + url = getBasePath('dashboard')+'graphs/inventory/'; + Rest.setUrl(url); + return pluck('data', Rest.get()); + } + + return { + get: function() { + return $q.all({ + license: getLicenseData(), + hosts: getHostData() + }).catch(function (data, status) { + processErrors(null, data, status, null, { hdr: 'Error!', + msg: 'Failed to get: ' + url + ' GET returned: ' + status }); + }); + } + }; +} diff --git a/awx/ui/static/js/services/job-status-graph-data.js b/awx/ui/static/js/services/job-status-graph-data.js index 1c2f528a3c..f578041d3a 100644 --- a/awx/ui/static/js/services/job-status-graph-data.js +++ b/awx/ui/static/js/services/job-status-graph-data.js @@ -1,4 +1,4 @@ -angular.module('DataServices', []) +angular.module('DataServices') .service('jobStatusGraphData', ["Rest", "GetBasePath", diff --git a/awx/ui/static/partials/home.html b/awx/ui/static/partials/home.html index a9155bc49d..c4df41acb2 100644 --- a/awx/ui/static/partials/home.html +++ b/awx/ui/static/partials/home.html @@ -27,7 +27,7 @@