From 9f40a6c8b43cb1ae9d2ae61ed852b7e3b6a9d8f7 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 20 Nov 2013 21:09:46 +0000 Subject: [PATCH] New dashboard. Modified dahsboard widgets to use API dashboard resource. System summary now working. --- awx/ui/static/js/widgets/ObjectCount.js | 205 +++++++++++------------- 1 file changed, 90 insertions(+), 115 deletions(-) diff --git a/awx/ui/static/js/widgets/ObjectCount.js b/awx/ui/static/js/widgets/ObjectCount.js index e50cc1fc24..3aa48c2676 100644 --- a/awx/ui/static/js/widgets/ObjectCount.js +++ b/awx/ui/static/js/widgets/ObjectCount.js @@ -13,125 +13,100 @@ angular.module('ObjectCountWidget', ['RestServices', 'Utilities']) function($rootScope, $compile, Rest, GetBasePath, ProcessErrors, Wait) { return function(params) { - var current_version; - var scope = $rootScope.$new(); - var counts = {}; + var scope = params.scope; var target = params.target; - var expected; + var dashboard = params.dashboard; - if (scope.removeCountReady) { - scope.removeCountReady(); - } - scope.removeCountReady = scope.$on('countReady', function(e, obj, count) { - var keys=[ 'organizations', 'users', 'teams', 'credentials', 'projects', 'inventory', 'groups', 'hosts', - 'job_templates', 'jobs' ]; - var html, itm; - var cnt = 0; - for (itm in counts) { - cnt++; + + var keys=[ 'organizations', 'users', 'teams', 'credentials', 'projects', 'inventories', 'groups', 'hosts', + 'job_templates', 'jobs' ]; + + html = "
\n"; + html += "
System Summary
\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"; + } + */ - var getCount = function (obj) { - scope.collection = (obj == 'inventory') ? 'inventories' : obj; - var url = current_version + scope.collection + '/'; - Rest.setUrl(url); - Rest.get() - .success( function(data, status, headers, config) { - counts[obj] = data.count; - scope.$emit('countReady'); - }) - .error( function(data, status, headers, config) { - ProcessErrors(scope, data, status, null, - { hdr: 'Error!', msg: 'Failed to get count for ' + obj + '. GET status: ' + status }); - }); - } - - Rest.setUrl('/api/'); - Rest.get() - .success( function(data, status, headers, config) { - - current_version = data.current_version; - - 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 }); + function makeRow(params) { + var html = ''; + var label = params.label; + var link = params.link; + var count = params.count; + html += "\n"; + html += "\n"; + html += "\n"; + return html; + } + + for (var i=0; i < keys.length; i++) { + html += makeRow({ + label: keys[i], + link: '/#/' + keys[i], + count: [(dashboard[keys[i]] && dashboard[keys[i]].total) ? dashboard[keys[i]].total : 0], }); } - }]); + + html += "\n"; + html += "
Total
\n"; + html += "\n"; - html += "
System Summary
\n"; - html += "
\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - html += "\n"; - for (var i=0; i < keys.length; i++) { - html += "\n"; - } - html += "\n"; - html += "
Total
\n"; - html += ""; - html += counts[keys[i]] + "
\n"; - html += "
\n"; - html += "\n" - var element = angular.element(document.getElementById(target)); - element.html(html); - $compile(element)(scope); - $rootScope.$emit('WidgetLoaded'); + html += link; + html += "\""; + html += (label == 'hosts' || label == 'groups') ? " class=\"pad-left-sm\" " : ""; + html += ">"; + if (label == 'inventory') { + html += 'inventories'; } - }); + else { + html += label.replace(/\_/g,' '); + } + html += "
"; + html += counts[keys[i]] + "
" + html += "" + count + ""; + 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