mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 09:51:09 +03:00
New dashboard. Modified dahsboard widgets to use API dashboard resource.
This commit is contained in:
parent
98cb95b510
commit
117d702a2a
@ -10,13 +10,13 @@
|
||||
|
||||
'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 scope = $rootScope.$new();
|
||||
var waitCount = 4;
|
||||
var loadedCount = 0;
|
||||
|
||||
@ -25,28 +25,45 @@ function Home ($routeParams, $scope, $rootScope, $location, Wait, ObjectCount, J
|
||||
Wait('start');
|
||||
}
|
||||
|
||||
JobStatus({ target: 'container1' });
|
||||
InventorySyncStatus({ target: 'container2' });
|
||||
SCMSyncStatus({ target: 'container4' });
|
||||
ObjectCount({ target: 'container3' });
|
||||
|
||||
$rootScope.$on('WidgetLoaded', function() {
|
||||
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 });
|
||||
})
|
||||
}
|
||||
|
||||
$rootScope.showActivity = function() { Stream(); }
|
||||
$rootScope.refresh = function() { load(); }
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -12,25 +12,22 @@ 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;
|
||||
|
||||
if (scope.removeCountReceived) {
|
||||
scope.removeCountReceived();
|
||||
}
|
||||
scope.removeCountReceived = scope.$on('CountReceived', function() {
|
||||
|
||||
var rowcount = 0;
|
||||
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";
|
||||
|
||||
function makeRow(params) {
|
||||
var label = params.label;
|
||||
@ -51,51 +48,30 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
|
||||
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,
|
||||
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' });
|
||||
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++;
|
||||
}
|
||||
}
|
||||
fail_link: '/#/inventories/?inventory_sources_with_failures=true'
|
||||
});
|
||||
|
||||
if (rowcount == 0) {
|
||||
html += "<tr><td colspan=\"3\">No inventories configured for external sync</td></tr>\n";
|
||||
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'
|
||||
});
|
||||
|
||||
// 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 += "</tbody>\n";
|
||||
@ -103,152 +79,11 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
|
||||
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 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');
|
||||
}
|
||||
});
|
||||
|
||||
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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
GetChoices({ scope: scope,
|
||||
url: GetBasePath('inventory_sources'),
|
||||
variable: 'inventorySources',
|
||||
field: 'source',
|
||||
callback: 'CountTypes' });
|
||||
scope.$emit('WidgetLoaded');
|
||||
|
||||
}
|
||||
}]);
|
@ -12,25 +12,23 @@ 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 scope = params.scope;
|
||||
var target = params.target;
|
||||
var dashboard = params.dashboard;
|
||||
|
||||
if (scope.removeCountReceived) {
|
||||
scope.removeCountReceived();
|
||||
}
|
||||
scope.removeCountReceived = scope.$on('CountReceived', function() {
|
||||
|
||||
var rowcount = 0;
|
||||
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 = '';
|
||||
@ -52,66 +50,34 @@ angular.module('JobStatusWidget', ['RestServices', 'Utilities'])
|
||||
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,
|
||||
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'
|
||||
});
|
||||
rowcount++;
|
||||
}
|
||||
if (inventoryCount > 0) {
|
||||
html += makeRow({
|
||||
label: 'Inventories',
|
||||
link: '/#/inventories',
|
||||
count: inventoryCount,
|
||||
fail: inventoryFails,
|
||||
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'
|
||||
});
|
||||
rowcount++;
|
||||
}
|
||||
if (groupCount > 0) {
|
||||
html += makeRow({
|
||||
label: 'Groups',
|
||||
link: '/#/home/groups',
|
||||
count: groupCount,
|
||||
fail: groupFails,
|
||||
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'
|
||||
});
|
||||
rowcount++;
|
||||
}
|
||||
if (hostCount > 0) {
|
||||
html += makeRow({
|
||||
label: 'Hosts',
|
||||
link: '/#/home/hosts',
|
||||
count: hostCount,
|
||||
fail: hostFails,
|
||||
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'
|
||||
});
|
||||
rowcount++;
|
||||
}
|
||||
|
||||
if (rowcount == 0) {
|
||||
html += "<tr><td colspan=\"3\">No job data found</td></tr>\n";
|
||||
}
|
||||
|
||||
html += "</tbody>\n";
|
||||
html += "</table>\n";
|
||||
@ -122,105 +88,7 @@ angular.module('JobStatusWidget', ['RestServices', 'Utilities'])
|
||||
var element = angular.element(document.getElementById(target));
|
||||
element.html(html);
|
||||
$compile(element)(scope);
|
||||
$rootScope.$emit('WidgetLoaded');
|
||||
}
|
||||
});
|
||||
|
||||
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 });
|
||||
});
|
||||
|
||||
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 });
|
||||
});
|
||||
scope.$emit('WidgetLoaded');
|
||||
|
||||
}
|
||||
}]);
|
@ -12,43 +12,9 @@ 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;
|
||||
|
||||
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 dashboard = params.dashboard;
|
||||
|
||||
var html = "<div class=\"panel panel-default\">\n";
|
||||
html += "<div class=\"panel-heading\">Project SCM Status</div>\n";
|
||||
@ -63,14 +29,48 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
|
||||
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++;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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'
|
||||
});
|
||||
}
|
||||
if (rowcount == 0) {
|
||||
html += "<tr><td colspan=\"3\">No projects configured for SCM sync</td></tr>\n";
|
||||
}
|
||||
|
||||
html += "</tbody>\n";
|
||||
@ -82,77 +82,7 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
|
||||
var element = angular.element(document.getElementById(target));
|
||||
element.html(html);
|
||||
$compile(element)(scope);
|
||||
$rootScope.$emit('WidgetLoaded');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
});
|
||||
scope.$emit('WidgetLoaded');
|
||||
|
||||
}
|
||||
}]);
|
Loading…
Reference in New Issue
Block a user