mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 22:37:41 -02:30
New dashboard. Modified dahsboard widgets to use API dashboard resource.
This commit is contained in:
@@ -10,43 +10,60 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function Home ($routeParams, $scope, $rootScope, $location, Wait, ObjectCount, JobStatus, InventorySyncStatus, SCMSyncStatus,
|
function Home ($routeParams, $rootScope, $location, Wait, ObjectCount, JobStatus, InventorySyncStatus, SCMSyncStatus,
|
||||||
ClearScope, Stream) {
|
ClearScope, Stream, Rest, GetBasePath, ProcessErrors) {
|
||||||
|
|
||||||
ClearScope('home'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
ClearScope('home'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
|
||||||
//scope.
|
//scope.
|
||||||
|
|
||||||
var load = function() {
|
var scope = $rootScope.$new();
|
||||||
var waitCount = 4;
|
var waitCount = 4;
|
||||||
var loadedCount = 0;
|
var loadedCount = 0;
|
||||||
|
|
||||||
if (!$routeParams['login']) {
|
if (!$routeParams['login']) {
|
||||||
// If we're not logging in, start the Wait widget. Otherwise, it's already running.
|
// If we're not logging in, start the Wait widget. Otherwise, it's already running.
|
||||||
Wait('start');
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Home.$inject=[ '$routeParams', '$scope', '$rootScope', '$location', 'Wait', 'ObjectCount', 'JobStatus', 'InventorySyncStatus',
|
if (scope.removeWidgetLoaded) {
|
||||||
'SCMSyncStatus', 'ClearScope', 'Stream'];
|
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,
|
function HomeGroups ($location, $routeParams, HomeGroupList, GenerateList, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
|
||||||
|
|||||||
@@ -12,243 +12,78 @@ angular.module('InventorySyncStatusWidget', ['RestServices', 'Utilities'])
|
|||||||
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) {
|
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = $rootScope.$new();
|
var scope = params.scope;
|
||||||
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 target = params.target;
|
var target = params.target;
|
||||||
var results = [];
|
var dashboard = params.dashboard;
|
||||||
var expected;
|
|
||||||
|
|
||||||
if (scope.removeCountReceived) {
|
var html = "<div class=\"panel panel-default\">\n";
|
||||||
scope.removeCountReceived();
|
html += "<div class=\"panel-heading\">Inventory Sync Status</div>\n";
|
||||||
}
|
html += "<div class=\"panel-body\">\n";
|
||||||
scope.removeCountReceived = scope.$on('CountReceived', function() {
|
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";
|
||||||
|
|
||||||
var rowcount = 0;
|
function makeRow(params) {
|
||||||
|
var label = params.label;
|
||||||
function makeRow(params) {
|
var count = params.count;
|
||||||
var label = params.label;
|
var fail = params.fail;
|
||||||
var count = params.count;
|
var link = params.link;
|
||||||
var fail = params.fail;
|
var fail_link = params.fail_link;
|
||||||
var link = params.link;
|
var html = "<tr>\n";
|
||||||
var fail_link = params.fail_link;
|
html += "<td><a href=\"" + link + "\"";
|
||||||
var html = "<tr>\n";
|
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
|
||||||
html += "<td><a href=\"" + link + "\"";
|
html += ">" + label + "</a></td>\n";
|
||||||
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
|
html += "<td class=\"failed-column text-right\">";
|
||||||
html += ">" + label + "</a></td>\n";
|
html += "<a href=\"" + fail_link + "\">" + fail + "</a>";
|
||||||
html += "<td class=\"failed-column text-right\">";
|
html += "</td>\n";
|
||||||
html += "<a href=\"" + fail_link + "\">" + fail + "</a>";
|
html += "<td class=\"text-right\">";
|
||||||
html += "</td>\n";
|
html += "<a href=\"" + link + "\">" + count + "</a>";
|
||||||
html += "<td class=\"text-right\">";
|
html += "</td></tr>\n";
|
||||||
html += "<a href=\"" + link + "\">" + count + "</a>";
|
return html;
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'
|
||||||
});
|
});
|
||||||
|
|
||||||
var url = GetBasePath('inventory') + '?has_inventory_sources=true&page=1';
|
html += makeRow({ label: 'Groups',
|
||||||
Rest.setUrl(url);
|
count: [(dashboard.groups && dashboard.groups.total) ? dashboard.groups.total : 0],
|
||||||
Rest.get()
|
fail: [(dashboard.groups && dashboard.groups.inventory_failed) ? dashboard.groups.inventory_failed : 0],
|
||||||
.success( function(data, status, headers, config) {
|
link: '/#/home/groups/?has_external_source=true',
|
||||||
inventoryCount=data.count;
|
fail_link: '/#/home/groups/?status=failed'
|
||||||
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) {
|
// Each inventory source
|
||||||
scope.CountProjects();
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scope.removeCountProjects = scope.$on('CountTypes', function() {
|
|
||||||
|
|
||||||
var choices = scope['inventorySources'];
|
html += "</tbody>\n";
|
||||||
|
html += "</table>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
|
||||||
function getLabel(config) {
|
var element = angular.element(document.getElementById(target));
|
||||||
var url = config.url;
|
element.html(html);
|
||||||
var type = url.match(/source=.*\&/)[0].replace(/source=/,'').replace(/\&/,'');
|
$compile(element)(scope);
|
||||||
var label;
|
scope.$emit('WidgetLoaded');
|
||||||
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' });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
@@ -12,215 +12,83 @@ angular.module('JobStatusWidget', ['RestServices', 'Utilities'])
|
|||||||
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) {
|
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = $rootScope.$new();
|
var scope = params.scope;
|
||||||
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;
|
var target = params.target;
|
||||||
|
var dashboard = params.dashboard;
|
||||||
|
|
||||||
if (scope.removeCountReceived) {
|
var html = '';
|
||||||
scope.removeCountReceived();
|
var html = "<div class=\"panel panel-default\">\n";
|
||||||
}
|
html += "<div class=\"panel-heading\">Job Status</div>\n";
|
||||||
scope.removeCountReceived = scope.$on('CountReceived', function() {
|
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";
|
||||||
|
|
||||||
var rowcount = 0;
|
function makeRow(params) {
|
||||||
|
var html = '';
|
||||||
function makeRow(params) {
|
var label = params.label;
|
||||||
var html = '';
|
var link = params.link;
|
||||||
var label = params.label;
|
var fail_link = params.fail_link;
|
||||||
var link = params.link;
|
var count = params.count;
|
||||||
var fail_link = params.fail_link;
|
var fail = params.fail;
|
||||||
var count = params.count;
|
html += "<tr>\n";
|
||||||
var fail = params.fail;
|
html += "<td><a href=\"" + link + "\"";
|
||||||
html += "<tr>\n";
|
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
|
||||||
html += "<td><a href=\"" + link + "\"";
|
html += ">" + label + "</a></td>\n";
|
||||||
html += (label == 'Hosts' || label == 'Groups') ? " class=\"pad-left-sm\" " : "";
|
html += "<td class=\"failed-column text-right\">";
|
||||||
html += ">" + label + "</a></td>\n";
|
html += "<a href=\"" + fail_link + "\">" + fail + "</a>";
|
||||||
html += "<td class=\"failed-column text-right\">";
|
html += "</td>\n";
|
||||||
html += "<a href=\"" + fail_link + "\">" + fail + "</a>";
|
html += "<td class=\"text-right\">"
|
||||||
html += "</td>\n";
|
html += "<a href=\"" + link + "\" >" + count + "</a>";
|
||||||
html += "<td class=\"text-right\">"
|
html += "</td></tr>\n";
|
||||||
html += "<a href=\"" + link + "\" >" + count + "</a>";
|
return html;
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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';
|
html += "</tbody>\n";
|
||||||
Rest.setUrl(url);
|
html += "</table>\n";
|
||||||
Rest.get()
|
html += "</div>\n";
|
||||||
.success( function(data, status, headers, config) {
|
html += "</div>\n";
|
||||||
jobCount=data.count;
|
html += "</div>\n";
|
||||||
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';
|
var element = angular.element(document.getElementById(target));
|
||||||
Rest.setUrl(url);
|
element.html(html);
|
||||||
Rest.get()
|
$compile(element)(scope);
|
||||||
.success( function(data, status, headers, config) {
|
scope.$emit('WidgetLoaded');
|
||||||
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 });
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
@@ -12,147 +12,77 @@ angular.module('SCMSyncStatusWidget', ['RestServices', 'Utilities'])
|
|||||||
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) {
|
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait, GetChoices) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var scope = $rootScope.$new();
|
var scope = params.scope;
|
||||||
var target = params.target;
|
var target = params.target;
|
||||||
var expected = 0;
|
var dashboard = params.dashboard;
|
||||||
var results = [];
|
|
||||||
var scm_choices;
|
|
||||||
|
|
||||||
if (scope.removeCountReceived) {
|
var html = "<div class=\"panel panel-default\">\n";
|
||||||
scope.removeCountReceived();
|
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";
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
scope.removeCountReceived = scope.$on('CountReceived', function(e, label, count, fail) {
|
labelList.sort();
|
||||||
|
var type;
|
||||||
var rowcount = 0;
|
for (var i=0; i < labelList.length; i++) {
|
||||||
|
type = labelList[i];
|
||||||
function makeRow(label, count, fail) {
|
if (dashboard.scm_types[type].total) {
|
||||||
var value;
|
html += makeRow({
|
||||||
for (var i=0; i < scope['projectChoices'].length; i++) {
|
label: dashboard.scm_types[type].label,
|
||||||
if (scope['projectChoices'][i].label == label) {
|
link: '/#/projects/?scm_type=' + type,
|
||||||
value = scope['projectChoices'][i].value;
|
count: [(dashboard.scm_types[type].total) ? dashboard.scm_types[type].total : 0],
|
||||||
break;
|
fail: [(dashboard.scm_types[type].failed) ? dashboard.scm_types[type].failed : 0],
|
||||||
}
|
fail_link: '/#/projects/?scm_type=' + type + '&status=failed'
|
||||||
}
|
});
|
||||||
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";
|
|
||||||
|
|
||||||
var element = angular.element(document.getElementById(target));
|
|
||||||
element.html(html);
|
|
||||||
$compile(element)(scope);
|
|
||||||
$rootScope.$emit('WidgetLoaded');
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
html += "</tbody>\n";
|
||||||
|
html += "</table>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
|
||||||
scope.removeCountProjects = scope.$on('CountProjects', function() {
|
var element = angular.element(document.getElementById(target));
|
||||||
|
element.html(html);
|
||||||
var choices = scope['projectChoices'];
|
$compile(element)(scope);
|
||||||
|
scope.$emit('WidgetLoaded');
|
||||||
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'
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}]);
|
}]);
|
||||||
Reference in New Issue
Block a user