From 117d702a2a742c924a0cd1ef20864a8cdef9b979 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 20 Nov 2013 20:39:59 +0000 Subject: [PATCH] New dashboard. Modified dahsboard widgets to use API dashboard resource. --- awx/ui/static/js/controllers/Home.js | 79 +++-- .../static/js/widgets/InventorySyncStatus.js | 293 ++++-------------- awx/ui/static/js/widgets/JobStatus.js | 282 +++++------------ awx/ui/static/js/widgets/SCMSyncStatus.js | 200 ++++-------- 4 files changed, 252 insertions(+), 602 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; + + var scope = $rootScope.$new(); + 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' }); - - $rootScope.$on('WidgetLoaded', function() { - // Once all the widgets report back 'loaded', turn off Wait widget - loadedCount++; - if ( loadedCount == waitCount ) { - Wait('stop'); - } - }); - } - - $rootScope.showActivity = function() { Stream(); } - $rootScope.refresh = function() { load(); } - - load(); + if (!$routeParams['login']) { + // If we're not logging in, start the Wait widget. Otherwise, it's already running. + Wait('start'); } -Home.$inject=[ '$routeParams', '$scope', '$rootScope', '$location', 'Wait', 'ObjectCount', 'JobStatus', 'InventorySyncStatus', - 'SCMSyncStatus', 'ClearScope', 'Stream']; + 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'); + } + }); + + 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', '$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 = "
\n"; + html += "
Inventory Sync Status
\n"; + html += "
\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\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 = "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - return html; - } - - counts++; - if (counts == expectedCounts) { - // all the counts came back, now generate the HTML - var html = "
\n"; - html += "
Inventory Sync Status
\n"; - html += "
\n"; - html += "
FailedTotal
"; - html += "" + fail + ""; - html += ""; - html += "" + count + ""; - html += "
\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\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 += "\n"; - } - - html += "\n"; - html += "
FailedTotal
No inventories configured for external sync
\n"; - html += "
\n"; - html += "
\n"; - html += "\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 = "\n"; + html += "\n"; + html += ""; + html += "" + fail + ""; + html += "\n"; + html += ""; + html += "" + count + ""; + html += "\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; - } - } - - 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 }); - }); - } - } + 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' }); - GetChoices({ scope: scope, - url: GetBasePath('inventory_sources'), - variable: 'inventorySources', - field: 'source', - callback: 'CountTypes' }); + // 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 + }); + } + } + + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\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 += "\n"; - html += "\n"; - html += ""; - html += "" + fail + ""; - html += "\n"; - html += "" - html += "" + count + ""; - html += "\n"; - return html; - } - - counts++; - if (counts == expectedCounts) { - // all the counts came back, now generate the HTML - var html = "
\n"; - html += "
Job Status
\n"; - html += "
\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\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 += "\n"; - } - - html += "\n"; - html += "
FailedTotal
No job data found
\n"; - html += "
\n"; - html += "
\n"; - html += "\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 = "
\n"; + html += "
Job Status
\n"; + html += "
\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\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 += "\n"; + html += "\n"; + html += "\n"; + html += "\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 }); - }); + html += "\n"; + html += "
FailedTotal
"; + html += "" + fail + ""; + html += "" + html += "" + count + ""; + html += "
\n"; + html += "
\n"; + html += "
\n"; + html += "\n"; - 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 }); - }); - - 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 = "
\n"; + html += "
Project SCM Status
\n"; + html += "
\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; - if (scope.removeCountReceived) { - scope.removeCountReceived(); + 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 += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + return html; + } + + 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' + }); + + var labelList = []; + for (var type in dashboard.scm_types) { + labelList.push(type); } - 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 += "\n"; - html += "\n"; - html += "\n"; - html += "\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 = "
\n"; - html += "
Project SCM Status
\n"; - html += "
\n"; - html += "
FailedTotal
" + label + ""; + html += "" + fail + ""; + html += "" + html += "" + count + ""; + html += "
" + label + ""; - html += "" + fail + ""; - html += ""; - html += "" + count + ""; - html += "
\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\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 += "\n"; - } - - html += "\n"; - html += "
FailedTotal
No projects configured for SCM sync
\n"; - html += "
\n"; - html += "
\n"; - html += "\n"; - - var element = angular.element(document.getElementById(target)); - element.html(html); - $compile(element)(scope); - $rootScope.$emit('WidgetLoaded'); + 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' + }); } - }); - + } - scope.removeCountProjects = scope.$on('CountProjects', function() { - - var choices = scope['projectChoices']; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; + html += "\n"; - 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; - } - } - - 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 }); - }); - } - } - }); - - 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