diff options
author | Chris Houseknecht <chouse@ansibleworks.com> | 2013-11-20 21:39:59 +0100 |
---|---|---|
committer | Chris Houseknecht <chouse@ansibleworks.com> | 2013-11-20 22:09:55 +0100 |
commit | 117d702a2a742c924a0cd1ef20864a8cdef9b979 (patch) | |
tree | 781dcc07f5d75c80941ecea8f142f4398172c860 | |
parent | Add organizations counts to the api dashboard view (diff) | |
download | awx-117d702a2a742c924a0cd1ef20864a8cdef9b979.tar.xz awx-117d702a2a742c924a0cd1ef20864a8cdef9b979.zip |
New dashboard. Modified dahsboard widgets to use API dashboard resource.
-rw-r--r-- | awx/ui/static/js/controllers/Home.js | 75 | ||||
-rw-r--r-- | awx/ui/static/js/widgets/InventorySyncStatus.js | 291 | ||||
-rw-r--r-- | awx/ui/static/js/widgets/JobStatus.js | 282 | ||||
-rw-r--r-- | awx/ui/static/js/widgets/SCMSyncStatus.js | 198 |
4 files changed, 248 insertions, 598 deletions
diff --git a/awx/ui/static/js/controllers/Home.js b/awx/ui/static/js/controllers/Home.js index 03f6203f73..1ba3780aa2 100644 --- a/awx/ui/static/js/controllers/Home.js +++ b/awx/ui/static/js/controllers/Home.js @@ -10,43 +10,60 @@ 'use strict'; -function Home ($routeParams, $scope, $rootScope, $location, Wait, ObjectCount, JobStatus, InventorySyncStatus, SCMSyncStatus, - ClearScope, Stream) { +function Home ($routeParams, $rootScope, $location, Wait, ObjectCount, JobStatus, InventorySyncStatus, SCMSyncStatus, + ClearScope, Stream, Rest, GetBasePath, ProcessErrors) { ClearScope('home'); //Garbage collection. Don't leave behind any listeners/watchers from the prior //scope. - - var load = function() { - var waitCount = 4; - var loadedCount = 0; - - if (!$routeParams['login']) { - // If we're not logging in, start the Wait widget. Otherwise, it's already running. - Wait('start'); - } - - JobStatus({ target: 'container1' }); - InventorySyncStatus({ target: 'container2' }); - SCMSyncStatus({ target: 'container4' }); - ObjectCount({ target: 'container3' }); + + var scope = $rootScope.$new(); + var waitCount = 4; + var loadedCount = 0; - $rootScope.$on('WidgetLoaded', function() { - // Once all the widgets report back 'loaded', turn off Wait widget - loadedCount++; - if ( loadedCount == waitCount ) { - Wait('stop'); - } - }); - } + if (!$routeParams['login']) { + // If we're not logging in, start the Wait widget. Otherwise, it's already running. + Wait('start'); + } - $rootScope.showActivity = function() { Stream(); } - $rootScope.refresh = function() { load(); } + if (scope.removeWidgetLoaded) { + scope.removeWidgetLoaded(); + } + scope.removeWidgetLoaded = scope.$on('WidgetLoaded', function() { + // Once all the widgets report back 'loaded', turn off Wait widget + loadedCount++; + console.log('count: ' + loadedCount); + if ( loadedCount == waitCount ) { + Wait('stop'); + } + }); - load(); + if (scope.removeDashboardReady) { + scope.removeDashboardReady(); + } + scope.removeDashboardReady = scope.$on('dashboardReady', function(e, data) { + JobStatus({ scope: scope, target: 'container1', dashboard: data}); + InventorySyncStatus({ scope: scope, target: 'container2', dashboard: data}); + SCMSyncStatus({ scope: scope, target: 'container4', dashboard: data}); + ObjectCount({ scope: scope, target: 'container3', dashboard: data}); + }); + + scope.showActivity = function() { Stream(); } + scope.refresh = function() { load(); } + + Rest.setUrl(GetBasePath('dashboard')); + Rest.get() + .success( function(data, status, headers, config) { + scope.$emit('dashboardReady', data); + }) + .error ( function(data, status, headers, config) { + Wait('stop'); + ProcessErrors(scope, data, status, null, + { hdr: 'Error!', msg: 'Failed to get dashboard: ' + status }); + }) } -Home.$inject=[ '$routeParams', '$scope', '$rootScope', '$location', 'Wait', 'ObjectCount', 'JobStatus', 'InventorySyncStatus', - 'SCMSyncStatus', 'ClearScope', 'Stream']; +Home.$inject=[ '$routeParams', '$rootScope', '$location', 'Wait', 'ObjectCount', 'JobStatus', 'InventorySyncStatus', + 'SCMSyncStatus', 'ClearScope', 'Stream', 'Rest', 'GetBasePath', 'ProcessErrors']; function HomeGroups ($location, $routeParams, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, diff --git a/awx/ui/static/js/widgets/InventorySyncStatus.js b/awx/ui/static/js/widgets/InventorySyncStatus.js index 0afc96d10b..5dcbf99bca 100644 --- a/awx/ui/static/js/widgets/InventorySyncStatus.js +++ b/awx/ui/static/js/widgets/InventorySyncStatus.js @@ -12,243 +12,78 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities']) function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) { return function(params) { - var scope = $rootScope.$new(); - var inventoryCount = 0; - var inventoryFails = 0; - var groupCount = 0; - var groupFails = 0; - var hostCount = 0; - var hostFails = 0; - var counts = 0; - var expectedCounts = 5; + var scope = params.scope; var target = params.target; - var results = []; - var expected; + var dashboard = params.dashboard; + + var html = "<div class=\"panel panel-default\">\n"; + html += "<div class=\"panel-heading\">Inventory Sync Status</div>\n"; + html += "<div class=\"panel-body\">\n"; + html += "<table class=\"table table-condensed table-hover\">\n"; + html += "<thead>\n"; + html += "<tr>\n"; + html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; + html += "</tr>\n"; + html += "</thead>\n"; + html += "<tbody>\n"; - if (scope.removeCountReceived) { - scope.removeCountReceived(); - } - scope.removeCountReceived = scope.$on('CountReceived', function() { - - var rowcount = 0; - - function makeRow(params) { - var label = params.label; - var count = params.count; - var fail = params.fail; - var link = params.link; - var fail_link = params.fail_link; - var html = "<tr>\n"; - html += "<td><a href=\"" + link + "\""; - html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : ""; - html += ">" + label + "</a></td>\n"; - html += "<td class=\"failed-column text-right\">"; - html += "<a href=\"" + fail_link + "\">" + fail + "</a>"; - html += "</td>\n"; - html += "<td class=\"text-right\">"; - html += "<a href=\"" + link + "\">" + count + "</a>"; - html += "</td></tr>\n"; - return html; - } - - counts++; - if (counts == expectedCounts) { - // all the counts came back, now generate the HTML - var html = "<div class=\"panel panel-default\">\n"; - html += "<div class=\"panel-heading\">Inventory Sync Status</div>\n"; - html += "<div class=\"panel-body\">\n"; - html += "<table class=\"table table-condensed table-hover\">\n"; - html += "<thead>\n"; - html += "<tr>\n"; - html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; - html += "</tr>\n"; - html += "</thead>\n"; - html += "<tbody>\n"; - - if (inventoryCount > 0) { - html += makeRow({ label: 'Inventories', - count: inventoryCount, - fail: inventoryFails, - link: '/#/inventories/?has_inventory_sources=true', - fail_link: '/#/inventories/?inventory_sources_with_failures=true' }); - rowcount++; - } - if (groupCount > 0) { - html += makeRow({ label: 'Groups', - count: groupCount, - fail: groupFails, - link: '/#/home/groups/?has_external_source=true', - fail_link: '/#/home/groups/?status=failed' }); - rowcount++; - } - for (var i=0; i < results.length; i++) { - if (results[i].count > 0) { - html += makeRow({ label: results[i].label, - count: results[i].count, - fail: results[i].fail, - link: '/#/home/groups/?source=' + results[i].source, - fail_link: '/#/home/groups/?status=failed&source=' + results[i].source }); - rowcount++; - } - } - - if (rowcount == 0) { - html += "<tr><td colspan=\"3\">No inventories configured for external sync</td></tr>\n"; - } - - html += "</tbody>\n"; - html += "</table>\n"; - html += "</div>\n"; - html += "</div>\n"; - html += "</div>\n"; - var element = angular.element(document.getElementById(target)); - element.html(html); - $compile(element)(scope); - $rootScope.$emit('WidgetLoaded'); + function makeRow(params) { + var label = params.label; + var count = params.count; + var fail = params.fail; + var link = params.link; + var fail_link = params.fail_link; + var html = "<tr>\n"; + html += "<td><a href=\"" + link + "\""; + html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : ""; + html += ">" + label + "</a></td>\n"; + html += "<td class=\"failed-column text-right\">"; + html += "<a href=\"" + fail_link + "\">" + fail + "</a>"; + html += "</td>\n"; + html += "<td class=\"text-right\">"; + html += "<a href=\"" + link + "\">" + count + "</a>"; + html += "</td></tr>\n"; + return html; } - }); - - var url = GetBasePath('inventory') + '?has_inventory_sources=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - inventoryCount=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - var url = GetBasePath('inventory') + '?inventory_sources_with_failures__gt=0&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - inventoryFails=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - url = GetBasePath('inventory_sources') + '?source__in=ec2,rax&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - groupCount=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('inventory_sources') + '?status=failed&source__in=ec2,rax&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - groupFails=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - /* url = GetBasePath('hosts') + '?has_inventory_sources=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - hostCount=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - */ - - if (scope.removeTypesReady) { - scope.removeTypesReady(); - } - scope.removeTypesReady = scope.$on('TypesReady', function (e, label, count, fail, source) { - results.push({ label: label, count: count, fail: fail, source: source }); - if (results.length == expected) { - scope.$emit('CountReceived'); - } + html += makeRow({ label: 'Inventories', + count: [(dashboard.inventories && dashboard.inventories.total) ? dashboard.inventories.total : 0], + fail: [(dashboard.inventories && dashboard.inventories.inventory_failed) ? dashboard.inventories.inventory_failed : 0], + link: '/#/inventories/?has_inventory_sources=true', + fail_link: '/#/inventories/?inventory_sources_with_failures=true' }); - if (scope.CountProjects) { - scope.CountProjects(); - } - scope.removeCountProjects = scope.$on('CountTypes', function() { - - var choices = scope['inventorySources']; - - function getLabel(config) { - var url = config.url; - var type = url.match(/source=.*\&/)[0].replace(/source=/,'').replace(/\&/,''); - var label; - for (var i=0; i < choices.length; i++) { - if (choices[i].value == type) { - label = choices[i].label; - break; - } - } - return label; - } - - // Remove ---- option from list of choices - for (var i=0; i < choices.length; i++) { - if (choices[i].label.match(/^---/)) { - choices.splice(i,1); - break; - } - } + html += makeRow({ label: 'Groups', + count: [(dashboard.groups && dashboard.groups.total) ? dashboard.groups.total : 0], + fail: [(dashboard.groups && dashboard.groups.inventory_failed) ? dashboard.groups.inventory_failed : 0], + link: '/#/home/groups/?has_external_source=true', + fail_link: '/#/home/groups/?status=failed' + }); - for (var i=0; i < choices.length; i++) { - if (choices[i].label.match(/^Local/)) { - choices.splice(i,1); - break; - } - } - - expected = choices.length; - - for (var i=0; i < choices.length; i++) { - if (!choices[i].label.match(/^---/)) { - var url = GetBasePath('inventory_sources') + '?source=' + choices[i].value + '&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - // figure out the scm_type we're looking at and its label - var label = getLabel(config); - var count = data.count; - var fail = 0; - for (var i=0; i < data.results.length; i++) { - if (data.results[i].status == 'failed') { - fail++; - } - } - scope.$emit('TypesReady', label, count, fail, - config.url.match(/source=.*\&/)[0].replace(/source=/,'').replace(/\&/,'')); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - } + // Each inventory source + for (var src in dashboard.inventory_sources) { + if (dashboard.inventory_sources[src].total) { + html += makeRow({ label: dashboard.inventory_sources[src].label, + count: [(dashboard.inventory_sources[src].total) ? dashboard.inventory_sources[src].total : 0], + fail: [(dashboard.inventory_sources[src].failed) ? dashboard.inventory_sources[src].failed : 0], + link: '/#/home/groups/?source=' + src, + fail_link: '/#/home/groups/?status=failed&source=' + src + }); } - }); + } - GetChoices({ scope: scope, - url: GetBasePath('inventory_sources'), - variable: 'inventorySources', - field: 'source', - callback: 'CountTypes' }); + html += "</tbody>\n"; + html += "</table>\n"; + html += "</div>\n"; + html += "</div>\n"; + html += "</div>\n"; + + var element = angular.element(document.getElementById(target)); + element.html(html); + $compile(element)(scope); + scope.$emit('WidgetLoaded'); } }]);
\ No newline at end of file diff --git a/awx/ui/static/js/widgets/JobStatus.js b/awx/ui/static/js/widgets/JobStatus.js index 9e0f2769d6..e24007fa50 100644 --- a/awx/ui/static/js/widgets/JobStatus.js +++ b/awx/ui/static/js/widgets/JobStatus.js @@ -12,215 +12,83 @@ angular.module('JobStatusWidget', ['RestServices', 'Utilities']) function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) { return function(params) { - var scope = $rootScope.$new(); - var jobCount = 0; - var jobFails = 0; - var inventoryCount = 0; - var inventoryFails = 0; - var groupCount = 0; - var groupFails = 0; - var hostCount = 0; - var hostFails = 0; - var counts = 0; - var expectedCounts = 8; - var target = params.target; - - if (scope.removeCountReceived) { - scope.removeCountReceived(); - } - scope.removeCountReceived = scope.$on('CountReceived', function() { - - var rowcount = 0; - - function makeRow(params) { - var html = ''; - var label = params.label; - var link = params.link; - var fail_link = params.fail_link; - var count = params.count; - var fail = params.fail; - html += "<tr>\n"; - html += "<td><a href=\"" + link + "\""; - html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : ""; - html += ">" + label + "</a></td>\n"; - html += "<td class=\"failed-column text-right\">"; - html += "<a href=\"" + fail_link + "\">" + fail + "</a>"; - html += "</td>\n"; - html += "<td class=\"text-right\">" - html += "<a href=\"" + link + "\" >" + count + "</a>"; - html += "</td></tr>\n"; - return html; - } - - counts++; - if (counts == expectedCounts) { - // all the counts came back, now generate the HTML - var html = "<div class=\"panel panel-default\">\n"; - html += "<div class=\"panel-heading\">Job Status</div>\n"; - html += "<div class=\"panel-body\">\n"; - html += "<table class=\"table table-condensed table-hover\">\n"; - html += "<thead>\n"; - html += "<tr>\n"; - html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; - html += "</tr>\n"; - html += "</thead>\n"; - html += "<tbody>\n"; - - if (jobCount > 0) { - html += makeRow({ - label: 'Jobs', - link: '/#/jobs', - count: jobCount, - fail: jobFails, - fail_link: '/#/jobs/?status=failed' - }); - rowcount++; - } - if (inventoryCount > 0) { - html += makeRow({ - label: 'Inventories', - link: '/#/inventories', - count: inventoryCount, - fail: inventoryFails, - fail_link: '/#/inventories/?has_active_failures=true' - }); - rowcount++; - } - if (groupCount > 0) { - html += makeRow({ - label: 'Groups', - link: '/#/home/groups', - count: groupCount, - fail: groupFails, - fail_link: '/#/home/groups/?has_active_failures=true' - }); - rowcount++; - } - if (hostCount > 0) { - html += makeRow({ - label: 'Hosts', - link: '/#/home/hosts', - count: hostCount, - fail: hostFails, - fail_link: '/#/home/hosts/?has_active_failures=true' - }); - rowcount++; - } - - if (rowcount == 0) { - html += "<tr><td colspan=\"3\">No job data found</td></tr>\n"; - } - - html += "</tbody>\n"; - html += "</table>\n"; - html += "</div>\n"; - html += "</div>\n"; - html += "</div>\n"; - - var element = angular.element(document.getElementById(target)); - element.html(html); - $compile(element)(scope); - $rootScope.$emit('WidgetLoaded'); - } + var scope = params.scope; + var target = params.target; + var dashboard = params.dashboard; + + var html = ''; + var html = "<div class=\"panel panel-default\">\n"; + html += "<div class=\"panel-heading\">Job Status</div>\n"; + html += "<div class=\"panel-body\">\n"; + html += "<table class=\"table table-condensed table-hover\">\n"; + html += "<thead>\n"; + html += "<tr>\n"; + html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; + html += "</tr>\n"; + html += "</thead>\n"; + html += "<tbody>\n"; + + function makeRow(params) { + var html = ''; + var label = params.label; + var link = params.link; + var fail_link = params.fail_link; + var count = params.count; + var fail = params.fail; + html += "<tr>\n"; + html += "<td><a href=\"" + link + "\""; + html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : ""; + html += ">" + label + "</a></td>\n"; + html += "<td class=\"failed-column text-right\">"; + html += "<a href=\"" + fail_link + "\">" + fail + "</a>"; + html += "</td>\n"; + html += "<td class=\"text-right\">" + html += "<a href=\"" + link + "\" >" + count + "</a>"; + html += "</td></tr>\n"; + return html; + } + + html += makeRow({ + label: 'Jobs', + link: '/#/jobs', + count: [(dashboard.jobs && dashboard.jobs.total) ? dashboard.jobs.total : 0], + fail: [(dashboard.jobs && dashboard.jobs.failed) ? dashboard.jobs.failed : 0], + fail_link: '/#/jobs/?status=failed' + }); + html += makeRow({ + label: 'Inventories', + link: '/#/inventories', + count: [(dashboard.inventories && dashboard.inventories.total) ? dashboard.inventories.total : 0], + fail: [(dashboard.inventories && dashboard.inventories.job_failed) ? dashboard.inventories.job_failed : 0], + fail_link: '/#/inventories/?has_active_failures=true' + }); + html += makeRow({ + label: 'Groups', + link: '/#/home/groups', + count: [(dashboard.groups && dashboard.groups.total) ? dashboard.groups.total : 0], + fail: [(dashboard.groups && dashboard.groups.fob_failed) ? dashboard.groups.job_failed : 0], + fail_link: '/#/home/groups/?has_active_failures=true' + }); + html += makeRow({ + label: 'Hosts', + link: '/#/home/hosts', + count: [(dashboard.hosts && dashboard.hosts.total) ? dashboard.hosts.total : 0], + fail: [(dashboard.hosts && dashboard.hosts.failed) ? dashboard.hosts.failed : 0], + fail_link: '/#/home/hosts/?has_active_failures=true' }); - var url = GetBasePath('jobs') + '?page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - jobCount=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('jobs') + '?failed=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - jobFails=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('inventory') + '?page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - inventoryCount=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('inventory') + '?has_active_failures=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - inventoryFails=data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('groups') + '?page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - groupCount = data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('groups') + '?has_active_failures=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - groupFails = data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - - url = GetBasePath('hosts') + '?page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - hostCount = data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); + html += "</tbody>\n"; + html += "</table>\n"; + html += "</div>\n"; + html += "</div>\n"; + html += "</div>\n"; - url = GetBasePath('hosts') + '?has_active_failures=true&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - hostFails = data.count; - scope.$emit('CountReceived'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); + var element = angular.element(document.getElementById(target)); + element.html(html); + $compile(element)(scope); + scope.$emit('WidgetLoaded'); } - }]); + }]);
\ No newline at end of file diff --git a/awx/ui/static/js/widgets/SCMSyncStatus.js b/awx/ui/static/js/widgets/SCMSyncStatus.js index 7e35a986a5..e9ce8cb04e 100644 --- a/awx/ui/static/js/widgets/SCMSyncStatus.js +++ b/awx/ui/static/js/widgets/SCMSyncStatus.js @@ -12,147 +12,77 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities']) function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) { return function(params) { - var scope = $rootScope.$new(); + var scope = params.scope; var target = params.target; - var expected = 0; - var results = []; - var scm_choices; + var dashboard = params.dashboard; + + var html = "<div class=\"panel panel-default\">\n"; + html += "<div class=\"panel-heading\">Project SCM Status</div>\n"; + html += "<div class=\"panel-body\">\n"; + html += "<table class=\"table table-condensed table-hover\">\n"; + html += "<thead>\n"; + html += "<tr>\n"; + html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; + html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; + html += "</tr>\n"; + html += "</thead>\n"; + html += "<tbody>\n"; - if (scope.removeCountReceived) { - scope.removeCountReceived(); - } - scope.removeCountReceived = scope.$on('CountReceived', function(e, label, count, fail) { - - var rowcount = 0; - - function makeRow(label, count, fail) { - var value; - for (var i=0; i < scope['projectChoices'].length; i++) { - if (scope['projectChoices'][i].label == label) { - value = scope['projectChoices'][i].value; - break; - } - } - var html = '' - html += "<tr><td><a href=\"/#/projects/?source_type=" + value + "\">" + label + "</a></td>\n"; - html += "<td class=\"failed-column text-right\">"; - html += "<a href=\"/blah/blah\">" + fail + "</a>"; - html += "</td>\n"; - html += "<td class=\"text-right\">"; - html += "<a href=\"/blah/blah\">" + count + "</a>"; - html += "</td>\n"; - html += "</tr>\n"; - return html; - } - - results.push({ label: label, count: count, fail: fail }); - - if (results.length == expected) { - // all the counts came back, now generate the HTML - - var html = "<div class=\"panel panel-default\">\n"; - html += "<div class=\"panel-heading\">Project SCM Status</div>\n"; - html += "<div class=\"panel-body\">\n"; - html += "<table class=\"table table-condensed table-hover\">\n"; - html += "<thead>\n"; - html += "<tr>\n"; - html += "<th class=\"col-md-4 col-lg-3\"></th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Failed</th>\n"; - html += "<th class=\"col-md-2 col-lg-1 text-right\">Total</th>\n"; - html += "</tr>\n"; - html += "</thead>\n"; - html += "<tbody>\n"; - - for (var i=0; i < results.length; i++) { - if (results[i].count > 0) { - html += makeRow(results[i].label, results[i].count, results[i].fail); - rowcount++; - } - } - if (rowcount == 0) { - html += "<tr><td colspan=\"3\">No projects configured for SCM sync</td></tr>\n"; - } - - html += "</tbody>\n"; - html += "</table>\n"; - html += "</div>\n"; - html += "</div>\n"; - html += "</div>\n"; + function makeRow(params) { + var html = ''; + var label = params.label; + var link = params.link; + var fail_link = params.fail_link; + var count = params.count; + var fail = params.fail; + html += "<tr>\n"; + html += "<td><a href=\"" + link + "\">" + label + "</a></td>\n"; + html += "<td class=\"failed-column text-right\">"; + html += "<a href=\"" + fail_link + "\">" + fail + "</a>"; + html += "</td>\n"; + html += "<td class=\"text-right\">" + html += "<a href=\"" + link + "\" >" + count + "</a>"; + html += "</td></tr>\n"; + return html; + } - var element = angular.element(document.getElementById(target)); - element.html(html); - $compile(element)(scope); - $rootScope.$emit('WidgetLoaded'); - } + html += makeRow({ label: 'Projects', + link: '/#/projects', + count: [(dashboard.projects && dashboard.projects.total) ? dashboard.projects.total : 0], + fail: [(dashboard.projects && dashboard.projects.failed) ? dashboard.projects.failed : 0], + fail_link: '/#/projects/?scm_type=&status=failed' }); - - - scope.removeCountProjects = scope.$on('CountProjects', function() { - - var choices = scope['projectChoices']; - - function getScmLabel(config) { - var url = config.url; - var scm_type = url.match(/scm_type=.*\&/)[0].replace(/scm_type=/,'').replace(/\&/,''); - var label; - for (var i=0; i < choices.length; i++) { - if (choices[i].value == scm_type) { - label = choices[i].label; - break; - } - } - return label; - } - - // Remove ---- option from list of choices - for (var i=0; i < choices.length; i++) { - if (choices[i].value.match(/^---/)) { - choices.splice(i,1); - break; - } - } - // Remove Manual option from list of choices - for (var i=0; i < choices.length; i++) { - if (choices[i].label.match(/Manual/)) { - choices.splice(i,1); - break; - } + + var labelList = []; + for (var type in dashboard.scm_types) { + labelList.push(type); + } + labelList.sort(); + var type; + for (var i=0; i < labelList.length; i++) { + type = labelList[i]; + if (dashboard.scm_types[type].total) { + html += makeRow({ + label: dashboard.scm_types[type].label, + link: '/#/projects/?scm_type=' + type, + count: [(dashboard.scm_types[type].total) ? dashboard.scm_types[type].total : 0], + fail: [(dashboard.scm_types[type].failed) ? dashboard.scm_types[type].failed : 0], + fail_link: '/#/projects/?scm_type=' + type + '&status=failed' + }); } - - expected = choices.length; + } - for (var i=0; i < choices.length; i++) { - if (!choices[i].label.match(/^---/)) { - var url = GetBasePath('projects') + '?scm_type=' + choices[i].value + '&page=1'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - // figure out the scm_type we're looking at and its label - var label = getScmLabel(config); - var count = data.count; - var fail = 0; - for (var i=0; i < data.results.length; i++) { - if (data.results[i].status == 'failed') { - fail++; - } - } - scope.$emit('CountReceived', label, count, fail); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get ' + url + '. GET status: ' + status }); - }); - } - } - }); + html += "</tbody>\n"; + html += "</table>\n"; + html += "</div>\n"; + html += "</div>\n"; + html += "</div>\n"; - GetChoices({ - scope: scope, - url: GetBasePath('projects'), - variable: 'projectChoices', - field: 'scm_type', - callback: 'CountProjects' - }); + var element = angular.element(document.getElementById(target)); + element.html(html); + $compile(element)(scope); + scope.$emit('WidgetLoaded'); } }]);
\ No newline at end of file |