mirror of
https://github.com/ansible/awx.git
synced 2026-05-05 16:37:37 -02:30
New dashboard. Modified dahsboard widgets to use API dashboard resource. System summary now working.
This commit is contained in:
@@ -13,125 +13,100 @@ angular.module('ObjectCountWidget', ['RestServices', 'Utilities'])
|
|||||||
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) {
|
function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) {
|
||||||
return function(params) {
|
return function(params) {
|
||||||
|
|
||||||
var current_version;
|
var scope = params.scope;
|
||||||
var scope = $rootScope.$new();
|
|
||||||
var counts = {};
|
|
||||||
var target = params.target;
|
var target = params.target;
|
||||||
var expected;
|
var dashboard = params.dashboard;
|
||||||
|
|
||||||
if (scope.removeCountReady) {
|
|
||||||
scope.removeCountReady();
|
var keys=[ 'organizations', 'users', 'teams', 'credentials', 'projects', 'inventories', 'groups', 'hosts',
|
||||||
}
|
'job_templates', 'jobs' ];
|
||||||
scope.removeCountReady = scope.$on('countReady', function(e, obj, count) {
|
|
||||||
var keys=[ 'organizations', 'users', 'teams', 'credentials', 'projects', 'inventory', 'groups', 'hosts',
|
html = "<div class=\"panel panel-default\">\n";
|
||||||
'job_templates', 'jobs' ];
|
html += "<div class=\"panel-heading\">System Summary</div>\n";
|
||||||
var html, itm;
|
html += "<div class=\"panel-body\">\n";
|
||||||
var cnt = 0;
|
html += "<table class=\"table table-condensed table-hover\">\n";
|
||||||
for (itm in counts) {
|
html += "<thead>\n";
|
||||||
cnt++;
|
html += "<tr>\n";
|
||||||
|
html += "<th class=\"col-md-5 col-lg-4\"></th>\n";
|
||||||
|
html += "<th class=\"col-md-1 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><td class=\"capitalize\">\n";
|
||||||
|
html += "<a href=\"/#/";
|
||||||
|
var link;
|
||||||
|
switch(label) {
|
||||||
|
case 'inventory':
|
||||||
|
link = 'inventories';
|
||||||
|
break;
|
||||||
|
case 'hosts':
|
||||||
|
link = 'home/hosts';
|
||||||
|
break;
|
||||||
|
case 'groups':
|
||||||
|
link = 'home/groups';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
link = label;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (cnt == expected) {
|
html += link;
|
||||||
html = "<div class=\"panel panel-default\">\n";
|
html += "\"";
|
||||||
html += "<div class=\"panel-heading\">System Summary</div>\n";
|
html += (label == 'hosts' || label == 'groups') ? " class=\"pad-left-sm\" " : "";
|
||||||
html += "<div class=\"panel-body\">\n";
|
html += ">";
|
||||||
html += "<table class=\"table table-condensed table-hover\">\n";
|
if (label == 'inventory') {
|
||||||
html += "<thead>\n";
|
html += 'inventories';
|
||||||
html += "<tr>\n";
|
|
||||||
html += "<th class=\"col-md-5 col-lg-4\"></th>\n";
|
|
||||||
html += "<th class=\"col-md-1 col-lg-1 text-right\">Total</th>\n";
|
|
||||||
html += "</tr>\n";
|
|
||||||
html += "</thead>\n";
|
|
||||||
html += "<tbody>\n";
|
|
||||||
for (var i=0; i < keys.length; i++) {
|
|
||||||
html += "<tr><td class=\"capitalize\">\n";
|
|
||||||
html += "<a href=\"/#/";
|
|
||||||
var link;
|
|
||||||
switch(keys[i]) {
|
|
||||||
case 'inventory':
|
|
||||||
link = 'inventories';
|
|
||||||
break;
|
|
||||||
case 'hosts':
|
|
||||||
link = 'home/hosts';
|
|
||||||
break;
|
|
||||||
case 'groups':
|
|
||||||
link = 'home/groups';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
link = keys[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
html += link;
|
|
||||||
html += "\"";
|
|
||||||
html += (keys[i] == 'hosts' || keys[i] == 'groups') ? " class=\"pad-left-sm\" " : "";
|
|
||||||
html += ">";
|
|
||||||
if (keys[i] == 'inventory') {
|
|
||||||
html += 'inventories';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
html += keys[i].replace(/\_/g,' ');
|
|
||||||
}
|
|
||||||
html += "</a></td>\n"
|
|
||||||
html += "<td class=\"text-right\"><a href=\"/#/";
|
|
||||||
html += (keys[i] == 'inventory') ? 'inventories' : keys[i];
|
|
||||||
html += "\">";
|
|
||||||
html += counts[keys[i]] + "</a></td></tr>\n";
|
|
||||||
}
|
|
||||||
html += "</tbody>\n";
|
|
||||||
html += "</table>\n";
|
|
||||||
html += "</div>\n";
|
|
||||||
html += "</div>\n"
|
|
||||||
var element = angular.element(document.getElementById(target));
|
|
||||||
element.html(html);
|
|
||||||
$compile(element)(scope);
|
|
||||||
$rootScope.$emit('WidgetLoaded');
|
|
||||||
}
|
}
|
||||||
});
|
else {
|
||||||
|
html += label.replace(/\_/g,' ');
|
||||||
|
}
|
||||||
|
html += "</a></td>\n"
|
||||||
|
html += "<td class=\"text-right\"><a href=\"/#/";
|
||||||
|
html += ( label == 'inventory') ? 'inventories' : label;
|
||||||
|
html += "\">";
|
||||||
|
html += counts[keys[i]] + "</a></td></tr>\n";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
var getCount = function (obj) {
|
function makeRow(params) {
|
||||||
scope.collection = (obj == 'inventory') ? 'inventories' : obj;
|
var html = '';
|
||||||
var url = current_version + scope.collection + '/';
|
var label = params.label;
|
||||||
Rest.setUrl(url);
|
var link = params.link;
|
||||||
Rest.get()
|
var count = params.count;
|
||||||
.success( function(data, status, headers, config) {
|
html += "<tr>\n";
|
||||||
counts[obj] = data.count;
|
html += "<td class=\"capitalize\"><a href=\"" + link + "\"";
|
||||||
scope.$emit('countReady');
|
html += (label == 'hosts' || label == 'groups') ? " class=\"pad-left-sm\" " : "";
|
||||||
})
|
html += ">" + label.replace(/\_/g,' ') + "</a></td>\n";
|
||||||
.error( function(data, status, headers, config) {
|
html += "<td class=\"text-right\">"
|
||||||
ProcessErrors(scope, data, status, null,
|
html += "<a href=\"" + link + "\" >" + count + "</a>";
|
||||||
{ hdr: 'Error!', msg: 'Failed to get count for ' + obj + '. GET status: ' + status });
|
html += "</td></tr>\n";
|
||||||
});
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rest.setUrl('/api/');
|
for (var i=0; i < keys.length; i++) {
|
||||||
Rest.get()
|
html += makeRow({
|
||||||
.success( function(data, status, headers, config) {
|
label: keys[i],
|
||||||
|
link: '/#/' + keys[i],
|
||||||
current_version = data.current_version;
|
count: [(dashboard[keys[i]] && dashboard[keys[i]].total) ? dashboard[keys[i]].total : 0],
|
||||||
|
|
||||||
Rest.setUrl(current_version);
|
|
||||||
Rest.get()
|
|
||||||
.success( function(data, status, headers, config) {
|
|
||||||
for (var obj in data) {
|
|
||||||
if (obj == 'me' || obj == 'authtoken' || obj == 'config' || obj == 'inventory_sources') {
|
|
||||||
delete data[obj];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expected = 0;
|
|
||||||
for (var obj in data) {
|
|
||||||
expected++;
|
|
||||||
}
|
|
||||||
for (obj in data) {
|
|
||||||
getCount(obj);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to get ' + current_version + '. GET status: ' + status });
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.error( function(data, status, headers, config) {
|
|
||||||
ProcessErrors(scope, data, status, null,
|
|
||||||
{ hdr: 'Error!', msg: 'Failed to get /api/. GET status: ' + status });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}]);
|
|
||||||
|
html += "</tbody>\n";
|
||||||
|
html += "</table>\n";
|
||||||
|
html += "</div>\n";
|
||||||
|
html += "</div>\n"
|
||||||
|
var element = angular.element(document.getElementById(target));
|
||||||
|
element.html(html);
|
||||||
|
$compile(element)(scope);
|
||||||
|
scope.$emit('WidgetLoaded');
|
||||||
|
|
||||||
|
}
|
||||||
|
}]);
|
||||||
Reference in New Issue
Block a user